Menu Close

ST-Sim Library with an external program example

Syncrosim Forums ST-Sim & State-and-Transition Simulation Models ST-Sim Library with an external program example

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #21203
    katie-birchardkatie-birchard
    Keymaster

    A user recently requested an example of a simple ST-Sim library that runs an R script interactively.

    We created a very simple worked example based on the ST-Sim spatial template library that uses the External Program feature. During the simulation, at the beginning of each timestep, ST-Sim will pause and pass an output raster to an R script. The R script will then generate a spatial transition multiplier raster based on the output raster and pass it back to ST-Sim. ST-Sim will then simulate the next timestep and so-on.

    The example ST-Sim Library is set up to pass the output age raster to an R script at each timestep which generates a spatial transition multiplier for fire transitions. The oldest 20 cells in the age raster are assigned to 1 in the spatial transition multiplier, while all other cells are assigned to 0. This means that the oldest 20 cells at each timestep are forced to undergo a fire transition. Below are instructions on how to run this example.
    We created this example using the following software and packages:

    First, download the ST-Sim Library and external program R script here. Open the ST-Sim Library in a new SyncroSim session and make sure to store the external program R script in an accessible location on your computer.

    To run an R script interactively in ST-Sim, you will need to use the External Program feature. This feature can be accessed from the SyncroSim User Interface using the following steps:

    1. Right-click on the Scenario called “Burn 20 oldest cells” and select Properties from the dropdown menu.
    2. Navigate to the Advanced tab.
    3. Select External Program from the menu on the left-hand side.

    ST-Sim External Program Example Configuration

    The External Program Datasheet contains the following inputs:

    1. External program: the file path to your Rscript executable (e.g., “C:\Program Files\R\R-4.2.1\bin\Rscript.exe”). Note that you will need to change the file path to your own Rscript executable here.
    2. External script: the file path to your external program script. Note that you will need to change the file path to wherever you stored the downloaded external program R script here.
    3. Call before timesteps: the timesteps where the simulation is paused to run the external program R script. Because we have values 1-3 selected, this means that the simulation will pause to run the R script before timesteps 1, 2, and 3.

    After adding the external program and external script file paths, save the Library. Now, if you right-click on the Scenario and select Run, the external program will be invoked before each timestep. Once the run has completed, you can select the Fire Transitions map from the Results Viewer.

    ST-Sim External Program Example Fire Transition Maps

    Each of these raster maps contains the 20 oldest cells that were forced to undergo a fire transition, as carried out by our external program R script.

    #21208
    colin-danielcolin-daniel
    Keymaster

    As with everything in SyncroSim, you can also do all this using an R or Python script (instead of through the UI) using the corresponding rsyncrosim or pysyncrosim packages.

    #21295
    davidandersondavidanderson
    Participant

    Are there any examples of how this might work with pysyncrosim? Without having done it I have good idea how it should work but without trying it I’m a bit fuzzy on the details.

    #21302
    katie-birchardkatie-birchard
    Keymaster

    There will be an example of an external program script using pysyncrosim forthcoming.

    #21384
    leonardo-fridleonardo-frid
    Keymaster

    The steps to run an External Program using a Python script are similar to the above example, with a few minor changes outlined below.

    The example was created using the following software and packages:

    You can use the same ST-Sim Library as the above example. However, you will also need to download the external program Python script example here.

    Update the External Program Datasheet within the Scenario Properties to include your Python executable file and Python script.

    External Program - Python

    Follow the remaining instructions above to retrieve the desired outputs.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.