Click on your picture in the top right corner, go to Preferences and select your notification preferences.
Please keep in mind:
1. To only comment on the topic where the discussion is about. Do you have a new question or topic? Please start a new discussion.
2. Be kind to other users!
Change/add rain event to overlay
Hi,
I am using the Python SDK for Tygron, but I have a question regarding adding a rain event. The project I am using is made in the Tygron Engine before using the Python SDK, but now I want to learn and use the Python SDK.
Is it possible to edit/change the current rain event that is configured in the Tygron Application? I was looking at events and add the attribute RAIN_M. But I think this did not work, because when I again load the overlay items and looked at the Attributes, there was no RAIN_M.
Could you please help? Thank you!
Best Answer
-
Hi Anne,
Please take a look at one of the examples which is includes in the Python SDK:
https://github.com/Tygron/python-tygronsdk/blob/main/examples/basics/project_session_manual.py
Here you see the complete flow of interactions to start, join, and stop a session, including the firing of events. You will be able to first create an event, and then use the connector for the session to fire that event.
For completeness sake, I will emphasize that where possible it is recommended to use the interactions prepared in the interactions submodules, such as:
sdk.base.projects.get_project( project_to_run )
(where projects is a collection of interactions specifically to interact with projects)
Or
sdk.session.creation.generate_map(size_x, size_y, location_x:, location_y)
(where creation is a collection of interactions part of the session API, specifically to handle project creation tasks)
However, not all possibilities are currently part of the interactions available. For any missing or specialist operations, it is also possible to manually construct events. In order of recommendation:
# First set up an sdk and authenticate:
import tygronsdk
sdk = tygronsdk.sdk.sdk()
auth_result = sdk.authenticate(tygronsdk.load_credentials_from_file('credentials.json'))
# If an Event Definition exists: Create an event based on a definition, then fire it using the sdk's connector:
event1 = tygronsdk.events.io.get_project_data(project_name='demo_heat_stress')
response1 = sdk.base.connector.fire_event(event1)
print( str(response1.get_response_body_json()) )
# If an Event Definition does not yet exist: Manually make an event call to an event endpoint:
response2 = sdk.base.connector.request(url='event/io/get_project_data',method='POST',data=['demo_heat_stress'])
print( str(response2.get_response_body_json()) )
# I have also pushed an update to the SDK allowing for wrapped events which have a built-in reference to their connector:
event3 = sdk.base.events.io.get_project_data(project_name='demo_heat_stress')
response3 = event3.execute()
print( str(response3.get_response_body_json()) )
Sprawling spreadsheets so intricate Alexander the Great cuts them in half.
Answers
Hey there!
When making the shift from the client application to API-based or even SDK-based tooling, the rule of thumb I recommend is to make changes in the client application, and then locate those changes both in the client application itself as well as in the data structure offered by the API.
For the specific case of the rain event, this data is stored in a Weather datatype. The Water Overlay has a reference to a Weather, and it is the Weather which has the attribute RAIN_M.
Weather can be found in the client application by opening the Project in the Editor, and then navigating to Tools -> Environment -> Show Weather (in the dropdown)
More information about Weather in relation to the Water Overlay can be found here:
https://support.tygron.com/wiki/Weather_(Water_Overlay)
Regards!
Sprawling spreadsheets so intricate Alexander the Great cuts them in half.
Hi Rudolf,
Thanks for your quick response! I think that that was not exactly what I meant.
I am using the python SDK and used the following code (this example is to change the number of timeframes):
sdk.session.events.editoroverlay.set_attribute(overlay_id=overlay_id, attribute_name='TIMEFRAMES', attribute_values=[30])
But when I do this, the number of timeframes is not changed. I think I need to post/fire this event. But I am not sure how to do it.
I tried the same with the rain attribute, but this did also not work.
sdk.session.events.editoroverlay.set_attribute(overlayid=overlay_id, attribute_name='RAIN_M', attribute_values=[(0, 10), (10, 4), (20, 0)]).
Kind regards,
Anne