Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
apps:datastudio:comparescenarioscriptdetails [2021/11/23 13:24] freddiapps:datastudio:comparescenarioscriptdetails [2022/01/29 12:32] (current) freddi
Line 1: Line 1:
 +==== Requirements ====
 +
 +This script needs **matplotlib** and **numpy** installed. For an instruction how to install python-libraries [[howToInstallPythonLibs| click here]].
 +
 +==== Description ====
 +The "Compare Scenario Script" analyses an user defined area of interest and compares the values inside this area between two given simulation outputs. 
 +The idea of the script is, that the impact of two different planning scenarios on an area of interest is directly compareable. Hence, the script output shows two figures. The upper figure directly compares the values inside the area of interest from scenario 1 with the values inside the area of interest from scenario 2 for each timestep. The lower figure shows the absolute difference between scenario 1 and scenario 2 for each timestep. 
 +
 +=== General advice ===
 +  * Only change one input parameter at once (e.g. for scenario 2: only change the meteorological conditions and keep the model area the same or do it the other way around). Thus, the results are still compareable. 
 +  * The area of interest should exist in both scenarios.
 +  * The script output should be shown together with screenshots of both model areas (scenario 1 and scenario 2) 
 ==== Example ==== ==== Example ====
 +
 +=== Settings ===
 +In this example, we would like to compare the Potential Air Temperature [°C] between both scenarios in the defined area. 
 +
 +== File path ==
 +
 +The Potential Air Temperture is saved in the atmosphere output folder. Hence, we need to set the Datafile 1 and Datafile 2 to the atmosphere folder of each scenario. Datafile 1 represents scenario A and Datafile 2 represents scenario B. For each, select a random .EDX-file in the corresponding atmosphere folder.
 +
 +In addition you can also define a diagram-title which will be used in the output figure. Anyway, if you leave the Diagram Title field empty the script generates a appropriate title automatically. 
 +
 +Now click on the script and click "Copy to Python Console" to adjust the remaining settings.   
 +
 +{{:apps:datastudio:settings_GUI.png}}
 +
  
 === Model Area === === Model Area ===
Line 13: Line 39:
 z_to = 4 z_to = 4
 </code> </code>
 +//(lines 16 - 22 in current script version)//
  
 x and y defines the horizontal position of the area of interst in your model area and z defines the vertical extend of your area of interest. x and y defines the horizontal position of the area of interst in your model area and z defines the vertical extend of your area of interest.
Line 28: Line 55:
  
 {{:apps:datastudio:scen2_modelarea_compareArea.png}} {{:apps:datastudio:scen2_modelarea_compareArea.png}}
- 
-=== Settings === 
-In this example, we would like to compare the Potential Air Temperature [°C] between both scenarios in the defined area.  
- 
-== File path == 
- 
-The Potential Air Temperture is saved in the atmosphere output folder. Hence, we need to set the folder location of the atmosphere output folder and a single EDX-file from the folder for both scenarios: 
- 
-<code python> 
-# define the file and filepath for scenario 1 
-# as file_1, choose a normal EDX-file from your output folder  
-file_1 = 'D:/enviprojects/Leonardo_Scripts_DummyProject/DummyProject_Leonardo_output/atmosphere/DummyProject_Leonardo_AT_2018-06-23_10.00.01.EDX' 
-# as scenario_1, choose the folder which you would like to analyse (here: atmosphere), provide an absolute path and be sure that every "\" is replaced by a "/" 
-scenario_1 = 'D:/enviprojects/Leonardo_Scripts_DummyProject/DummyProject_Leonardo_output/atmosphere' 
- 
-# define the file and filepath for scenario 2 
-file_2 = 'D:/enviprojects/Leonardo_Scripts_DummyProject_Scen2/DummyProject_Leonardo_Scen2_output/atmosphere/DummyProject_Leonardo_Scen2_AT_2018-06-23_10.00.01.EDX' 
-scenario_2 = 'D:/enviprojects/Leonardo_Scripts_DummyProject_Scen2/DummyProject_Leonardo_Scen2_output/atmosphere' 
-</code> 
  
 == Data index == == Data index ==
Line 57: Line 65:
 data_index = 8 data_index = 8
 </code> </code>
 +//(line 26 in current script version)//
  
 == Timespan == == Timespan ==
Line 63: Line 72:
 {{:apps:datastudio:folder_scen1_atm.png}} {{:apps:datastudio:folder_scen1_atm.png}}
  
-If both scenarios where simulated for the same time period, the indexes between both output folders should match (e.g. the 0 index in both folders(scenario 1 atmosphere folder, scenario 2 atmosphere folder) is dated to 23.06.2018 08:00h). In this case it is enough to edit the following lines:+If both scenarios were simulated for the same time period, the indexes between both output folders should match (e.g. the 0 index in both folders(scenario 1 atmosphere folder, scenario 2 atmosphere folder) is dated to 23.06.2018 08:00h). In this case it is enough to edit the following lines:
 <code python> <code python>
 time_from = 0 time_from = 0
-time_to = 30 +time_to = 92 
-<code>+</code> 
 +//(lines 32 - 33 in current script version)//
  
-With index 0 we start at 23.06.2018 08:00h and with index 30 we end at 24.06.2018 14:00h. +With index 0 we start at 23.06.2018 08:00h and with index 92 we end at 27.06.2018 04:00h. 
  
 Anyway, if the simulation periods between both scenarios do not match, we need to define the indexes separately for each folder (scenario).  Anyway, if the simulation periods between both scenarios do not match, we need to define the indexes separately for each folder (scenario). 
 Example: Example:
 Your first scenario simulation started at 23.06.2018 at 07:00h, so your first output (with index 0) is 23.06.2018 08:00h.  Your first scenario simulation started at 23.06.2018 at 07:00h, so your first output (with index 0) is 23.06.2018 08:00h. 
-Your second scenario simulation started at 23.06.2018 at 05:00h, so your wfirst output (with index 0) is 23.06.2018 6:00h +Your second scenario simulation started at 23.06.2018 at 05:00h, so your first output (with index 0) is 23.06.2018 6:00h 
 Then you need to define the indexes separately as follows: Then you need to define the indexes separately as follows:
 <code python> <code python>
 time_from = 0 time_from = 0
-time_to = 30+time_to = 92
  
 time_from_scen2 = 2 time_from_scen2 = 2
-time_to_scen2 = 32+time_to_scen2 = 94
 </code> </code>
 +//(lines 40 - 41 in current script version)//
 +
 Now the timespteps match again. Otherwise you would compare different timesteps. Now the timespteps match again. Otherwise you would compare different timesteps.
  
 +=== Advanced Settings ===
 +
 +There is the option to compare maximum or minimum values instead of the mean values. To do so, change lines 133 - 139 (in current script version) as follows:
 +== Mean vallues (default) ==
 +<code python>
 +#vals1 = (np.nanmin(data1, axis=1), "Min.")
 +#vals1 = (np.nanmax(data1, axis=1), "Max.")
 +vals1 = (np.nanmean(data1, axis=1), "Mean")
 +
 +#vals2 = (np.nanmin(data2, axis=1), "Min.")
 +#vals2 = (np.nanmax(data2, axis=1), "Max.")
 +vals2 = (np.nanmean(data2, axis=1), "Mean")
 +</code>
 +
 +== Maximum values ==
 +<code python>
 +#vals1 = (np.nanmin(data1, axis=1), "Min.")
 +vals1 = (np.nanmax(data1, axis=1), "Max.")
 +#vals1 = (np.nanmean(data1, axis=1), "Mean")
 +
 +#vals2 = (np.nanmin(data2, axis=1), "Min.")
 +vals2 = (np.nanmax(data2, axis=1), "Max.")
 +#vals2 = (np.nanmean(data2, axis=1), "Mean")
 +</code>
 +
 +== Minimum values == 
 +<code python>
 +vals1 = (np.nanmin(data1, axis=1), "Min.")
 +#vals1 = (np.nanmax(data1, axis=1), "Max.")
 +#vals1 = (np.nanmean(data1, axis=1), "Mean")
 +
 +vals2 = (np.nanmin(data2, axis=1), "Min.")
 +#vals2 = (np.nanmax(data2, axis=1), "Max.")
 +#vals2 = (np.nanmean(data2, axis=1), "Mean")
 +</code>
  
 === Output === === Output ===
 +If all settings are done, the script is ready to get executed. The output should look like this:
 +
 +{{:apps:datastudio:compscenoutput_atm.png}}
 +
 +If you would like to analyse pollutant-data instead, an output for e.g. NO2-concentration could look like this:
 +
 +{{:apps:datastudio:compscenoutput_polu.png}}
  
-{{:apps:datastudio:compscenoutput.png}}+==== Technical Note ==== 
 +Note that the execution-time of the script may be unexpected high, especially when you compare longer time periods or large areas. This is caused by limited implementation options caused by the Delphi-Python-interface. During execution, the GUI might not be reactive.