Skip to content

Commit

Permalink
Update uncertainty vignette
Browse files Browse the repository at this point in the history
  • Loading branch information
katieb1 committed Oct 11, 2024
1 parent c4605b2 commit 53a4f36
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
28 changes: 14 additions & 14 deletions vignettes/a01_rsyncrosim_vignette_basic.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ myLibrary <- ssimLibrary(name = "helloworldLibrary.ssim",
myLibrary
```

```{r delete library if it exists, echo = FALSE, results = 'hide'}
```{r delete library if it exists, echo = FALSE, message=FALSE}
if (file.exists("helloworldLibrary.ssim")){
deleteLibrary("helloworldLibrary.ssim", force = TRUE)
}
Expand Down Expand Up @@ -281,7 +281,7 @@ From this output we can see the the `Run Control` and `Inputs` datasheets only a
To view a specific datasheet rather than just a data frame of available datasheets, set the `name` parameter in the `datasheet()` function to the name of the datasheet you want to view. The general syntax of the name is: "\<name of package\>_\<name of Datasheet\>". From the list of datasheets above, we can see that there are 3 datasheets specific to the `helloworldTime` package.

```{r view specific datasheet, warning = FALSE}
# View the input datasheet for the scenario
# View the Inputs datasheet for the scenario
datasheet(myScenario, name = "helloworldTime_InputDatasheet")
```

Expand Down Expand Up @@ -413,13 +413,13 @@ For more information use the `runLog()` function, in which the only argument is
# Get run details for the first result scenario
runLog(myResultScenario)
```
*Note*: if your scenario fails to run, it will still produce a *results scenario* that you can use the `runLog()` function on to see more information about why the run failed.
*Note*: if your scenario fails to run, it will still produce a *result scenario* that you can use the `runLog()` function on to see more information about why the run failed.

## View results

### Results scenarios
### Result scenarios

A *results scenario* is generated when a scenario is run, and is an exact copy of the original scenario (i.e. it contains the original scenario's values for all input datasheets). The results scenario is passed to the transformer in order to generate model output, with the results of the transformer's calculations then being added to the results scenario as output datasheets. In this way the results scenario contains both the output of the run and a snapshot record of all the model inputs.
A *result scenario* is generated when a scenario is run, and is an exact copy of the original scenario (i.e. it contains the original scenario's values for all Inputs datasheets). The result scenario is passed to the transformer in order to generate model output, with the results of the transformer's calculations then being added to the result scenario as output datasheets. In this way the result scenario contains both the output of the run and a snapshot record of all the model inputs.

Check out the current scenarios in your library using the `scenario()` function.

Expand All @@ -428,19 +428,19 @@ Check out the current scenarios in your library using the `scenario()` function.
scenario(myLibrary)
```

The first scenario is our original scenario, and the second is the results scenario with a time and date stamp of when it was run. We can also see some other information about these scenarios, such as whether or not the scenario is a result or not (i.e. `isResult` column).
The first scenario is our original scenario, and the second is the result scenario with a time and date stamp of when it was run. We can also see some other information about these scenarios, such as whether or not the scenario is a result or not (i.e. `isResult` column).

We can also look at how the datasheets differ between the results scenario and the original scenario using the `datasheet()` function.
We can also look at how the datasheets differ between the result scenario and the original scenario using the `datasheet()` function.

```{r}
# Take a look at original scenario datasheets
datasheet(myScenario, optional = TRUE)
# Take a look at Results scenario datasheets
# Take a look at result scenario datasheets
datasheet(myResultScenario, optional = TRUE)
```

Looking at the `data` column, the `Outputs` does not contain any data in the original scenario, but does in the results scenario.
Looking at the `data` column, the `Outputs` does not contain any data in the original scenario, but does in the result scenario.


### Viewing results with `datasheet()`
Expand Down Expand Up @@ -527,9 +527,9 @@ The output that is returned from running many scenarios at once is actually a li
datasheet(myResultScenarioAll[2], name = "helloworldTime_OutputDatasheet")
```

### Identifying the parent scenario of a results scenario using `parentId()`
### Identifying the parent scenario of a result scenario using `parentId()`

If you have many alternative scenarios and many results scenarios, you can always find the parent scenario that was run in order to generate the Rrsults scenario using the `rsyncrosim` function `parentId()`.
If you have many alternative scenarios and many result scenarios, you can always find the parent scenario that was run in order to generate the Rrsults scenario using the `rsyncrosim` function `parentId()`.

```{r get parent ID, warning = FALSE}
parentId(myResultScenarioAll[[1]])
Expand Down Expand Up @@ -600,10 +600,10 @@ Now, you can use the `backup()` function from `rsyncrosim` to backup a library,
backup(myLibrary)
```

## `rsyncrosim` and the SyncroSim Windows User Interface
## `rsyncrosim` and SyncroSim Studio

It can be useful to work in both `rsyncrosim` and the SyncroSim Windows User Interface at the same time. You can easily modify datasheets and run scenarios in `rsyncrosim`, while simultaneously refreshing the library and plotting outputs in the User Interface as you go. To sync the library in the User Interface with the latest changes from the `rsyncrosim` code, click the refresh icon (circled in red below) in the upper tool bar of the User Interface.
It can be useful to work in both `rsyncrosim` and SyncroSim Studio at the same time. You can easily modify datasheets and run scenarios in `rsyncrosim`, while simultaneously refreshing the library and plotting outputs in SyncroSim Studio as you go. To sync the library in SyncroSim Studio with the latest changes from the `rsyncrosim` code, click the refresh icon (circled in red below) in the upper tool bar of SyncroSim Studio.

![Using `rsyncrosim` with the SyncroSim Windows User Interface](./rsyncrosim-with-UI.PNG){width=600px}
![Using `rsyncrosim` with SyncroSim Studio](./rsyncrosim-with-UI.PNG){width=600px}


33 changes: 17 additions & 16 deletions vignettes/a02_rsyncrosim_vignette_uncertainty.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ For more information on these scopes, see the [Introduction to `rsyncrosim`](htt

### Set up library, project, and scenario

```{r delete library if it exists, echo = FALSE, results = 'hide'}
```{r delete library if it exists, echo = FALSE, message=FALSE}
if (file.exists("helloworldLibrary.ssim")){
deleteLibrary("helloworldLibrary.ssim", force = TRUE)
}
Expand Down Expand Up @@ -140,7 +140,7 @@ View the datasheets associated with your new scenario using the `datasheet()` fu
datasheet(myScenario)
```

From the list of datasheets above, we can see that there are three datasheets specific to the `helloworldUncertainty` package. Let's view the contents of the input datasheet as an R data frame.
From the list of datasheets above, we can see that there are three datasheets specific to the `helloworldUncertainty` package. Let's view the contents of the Inputs datasheet as an R data frame.

```{r view specific datasheet, warning = FALSE}
# View the contents of the Inputs datasheet for the scenario
Expand All @@ -149,20 +149,20 @@ datasheet(myScenario, name = "helloworldUncertainty_InputDatasheet")

### Configure model inputs using `datasheet()` and `addRow()`

**Input Datasheet**
**Inputs Datasheet**

Currently our input scenario datasheet is empty! We need to add some values to our Inputs datasheet (`InputDatasheet`) so we can run our model. First, assign the contents of the input datasheet to a new data frame variable using `datasheet()`, then check the columns that need input values.
Currently our input scenario datasheet is empty! We need to add some values to our Inputs datasheet (`InputDatasheet`) so we can run our model. First, assign the contents of the Inputs datasheet to a new data frame variable using `datasheet()`, then check the columns that need input values.

```{r assign input data, warning = FALSE}
# Load the input datasheet to an R data frame
# Load the Inputs datasheet to an R data frame
myInputDataframe <- datasheet(myScenario,
name = "helloworldUncertainty_InputDatasheet")
# Check the columns of the input data frame
str(myInputDataframe)
```

The input datasheet requires three values:
The Inputs datasheet requires three values:

* `mMean` : the mean of the slope normal distribution.
* `mSD` : the standard deviation of the slope normal distribution.
Expand Down Expand Up @@ -202,14 +202,14 @@ str(myPipeline)

The Pipeline datasheet requires 2 values:

* `StageNameId` : the pipeline stage (transformer). This column is a factor that has only a single level: "Hello World Uncertainty".
* `StageNameId` : the pipeline stage (transformer). This column is a factor that has only a single level: "Hello World Uncertainty (R)".
* `RunOrder` : the numerical order in which the stages will be run.

Below, we use the `addRow()` and `saveDatasheet()` functions to update the Pipeline datasheet with the transformer(s) we want to run and the order in which we want to run them. In this case, there is only a single transformer available from the `helloworldTime` package, called "Hello World Uncertainty", so we will add this transformer to the data frame and set the `RunOrder` to `1`.
Below, we use the `addRow()` and `saveDatasheet()` functions to update the Pipeline datasheet with the transformer(s) we want to run and the order in which we want to run them. In this case, there is only a single transformer available from the `helloworldUncertainty` package, called "Hello World Uncertainty (R)", so we will add this transformer to the data frame and set the `RunOrder` to `1`.

```{r add pipeline data, warning = FALSE}
# Create pipeline data and add it to the pipeline data frame
myPipelineRow <- data.frame(StageNameId = "Hello World Uncertainty", RunOrder = 1)
myPipelineRow <- data.frame(StageNameId = "Hello World Uncertainty (R)", RunOrder = 1)
myPipeline <- addRow(myPipeline, myPipelineRow)
# Check values
Expand Down Expand Up @@ -257,7 +257,8 @@ Finally, save the R data frame to a SyncroSim datasheet using `saveDatasheet()`.

```{r}
# Save RunControl R data frame to a SyncroSim datasheet
saveDatasheet(ssimObject = myScenario, data = runSettings,
saveDatasheet(ssimObject = myScenario,
data = runSettings,
name = "helloworldUncertainty_RunControl")
```

Expand Down Expand Up @@ -297,10 +298,10 @@ Now, when we run our scenario, it will use the desired multiprocessing configura
myResultScenario <- run(myScenario)
```

Running the original scenario creates a new scenario object, known as a Results scenario, that contains a read-only snapshot of the input datasheets, as well as the output datasheets filled with result data. We can view which scenarios are Results scenarios using the `scenario()` function from `rsyncrosim`.
Running the original scenario creates a new scenario object, known as a result scenario, that contains a read-only snapshot of the Inputs datasheets, as well as the Outputs datasheets filled with result data. We can view which scenarios are result scenarios using the `scenario()` function from `rsyncrosim`.

```{r}
# Check that we have two scenarios, and one is a Results scenario
# Check that we have two scenarios, and one is a result scenario
scenario(myLibrary)
```

Expand All @@ -310,7 +311,7 @@ scenario(myLibrary)

### Viewing results with `datasheet()`

The next step is to view the output datasheets added to the Result scenario when it was run. We can load the result tables using the `datasheet()` function. In this package, the datasheet containing the results is called "OutputDatasheet".
The next step is to view the Outputs datasheets added to the result scenario when it was run. We can load the result tables using the `datasheet()` function. In this package, the datasheet containing the results is called "OutputDatasheet".


```{r view results datasheets, warning = FALSE}
Expand All @@ -322,11 +323,11 @@ resultsSummary <- datasheet(myResultScenario,
head(resultsSummary)
```

### Plotting uncertainty in the SyncroSim Windows User Interface
### Plotting uncertainty in SyncroSim Studio

Now that we have run multiple iterations, we can visualize the uncertainty in our results. For this plot, we will plot the average *y* values over time, while showing the 20th and 80th percentiles.

To create a plot using the Results scenario we just generated, open the current library in the User Interface and sync the updates from `rsyncrosim` using the "refresh" button in the upper toolbar (circled in red below). All the updates made in `rsyncrosim` should appear in the User Interface. We can now add the Results scenario to the Results Viewer and create our plot. For more information on generating plots in the User Interface, see the SyncroSim tutorials on <a href="http://docs.syncrosim.com/how_to_guides/results_chart_create.html" target="_blank">creating</a> and <a href="http://docs.syncrosim.com/how_to_guides/results_chart_customize.html" target="_blank">customizing</a> charts.
To create a plot using the result scenario we just generated, open the current library in SyncroSim Studio and sync the updates from `rsyncrosim` using the "refresh" button in the upper toolbar (circled in red below). All the updates made in `rsyncrosim` should appear in SyncroSim Studio. We can now add the result scenario to the Results Viewer and create our plot. For more information on generating plots in SyncroSim Studio, see the SyncroSim tutorials on <a href="http://docs.syncrosim.com/how_to_guides/results_chart_create.html" target="_blank">creating</a> and <a href="http://docs.syncrosim.com/how_to_guides/results_chart_customize.html" target="_blank">customizing</a> charts.

![Using `rsyncrosim` with the SyncroSim Windows User Interface to plot uncertainty](./rsyncrosim-with-UI-uncertainty.png){width=600px}
![Using `rsyncrosim` with SyncroSim Studio to plot uncertainty](./rsyncrosim-with-UI-uncertainty.png){width=600px}

Binary file modified vignettes/rsyncrosim-with-UI-uncertainty.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 53a4f36

Please sign in to comment.