User Tools

Site Tools


example_scripts

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
example_scripts [2019/12/11 09:52]
erik
example_scripts [2019/12/11 09:52] (current)
erik
Line 1: Line 1:
 ==== Example scripts ==== ==== Example scripts ====
  
-=== Reading results === +  * [[script_reading_results|Reading results]]
-**Version:** Ecolego 6.5,7 +
- +
-<code> +
-import javax.swing.JOptionPane; +
- +
-import se.facilia.ecolego.domain.OutputReference; +
-import se.facilia.ecolego.domain.model.EcolegoProject; +
-import se.facilia.ecolego.scripts.AbstractEcolegoScript; +
-import se.facilia.ecolego.simulation.model.ResultModel; +
- +
-/** +
- * This script demonstrates how to read results from the currently selected project. +
- */ +
-public class ManageResultsScript extends AbstractEcolegoScript { +
- @Override +
- public void launch() throws Exception { +
- // Retrieve the current project +
- EcolegoProject project = getSelectedProject(); +
- +
- // The ResultsModel is a facade used to access simulation results +
- ResultModel resultModel = project.getSimulationModel() +
- .getResultModel(); +
- +
- // An OutputReference represents a simulation result for one output and one set of dependencies (indices) +
- OutputReference ref = OutputReference.create("Concentrations.Soil[Cs-137]"); +
- +
- // See if there are results for this output +
- if (!resultModel.contains(ref)) { +
- JOptionPane.showMessageDialog(null, "There are no results for " + ref); +
- return; +
-+
- +
- // Read the time vector for the latest simulation +
- double[timeVector = resultModel.getTime(); +
- +
- // Read a single value for a single time point and a single iteration. The time point is given as an index of +
- // the time vector +
- +
- int t = 0; +
- int iteration = 0; +
- +
- double d = resultModel.get(ref, t, iteration); +
- +
- // Read all values for a time dependent output for a single iteration +
- double[] values = resultModel.getForAllTimePoints(ref, iteration); +
- +
- // Find the number of iterations of a probabilistic simulation +
- int noIterations = resultModel.getNumberOfSimulations(ref.getContextId()); +
- +
- // Read the mean values of a time dependent output +
- double[] mean = resultModel.getMean(ref, timeVector); +
- +
- // Read the std deviation of a time dependent output +
- double[] stdDev = resultModel.getStdDev(ref, timeVector); +
- +
- // Read a percentile for a time dependent output +
- double[perc95 = resultModel.getPercentile(ref, timeVector, 95.0); +
-+
-+
-</code> +
- +
example_scripts.1576054321.txt.gz · Last modified: 2019/12/11 09:52 by erik