This tutorial demonstrates how to run a backward simulation with FLEXPART and how to visualise the results in various ways.
Please enter folder 'backward' to start working.
In this exercise we will perform a backward simulation to compute the residence time of the particles reaching Inverness in Scotland.
Running a backward simulation
The simulation itself is defined by the 'bwd_time' FLEXPART Run icon and the 'rel_inv' FLEXPART Release icon, respectively. Both these are encompassed in a single macro called 'bwd_time.mv'. For simplicity will use this macro to examine the settings in detail.
The macro starts with defining the release like this:
rel_inv = flexpart_release( name : "INVERNESS", starting_date : 1, starting_time : 12, ending_date : 2, ending_time : 12, area : [57.44/-4.23/57.46/-4.21], top_level : 500, bottom_level : 0, particle_count : 10000, masses : 1 )
This says that the backward release will happen over a 24 h period in the lower 500 m layer at Inverness.
Please note that
- for the masses we set 1 since any value given here will be normalised for the residence time computations
- we used dates relative to the starting date of the simulation (see also in
flexpart_run()
)
The actual simulation is carried out by calling flexpart_run()
:
#Run flexpart (asynchronous call!) r= flexpart_run( output_path : "result_bwd", input_path : "../data", simulation_direction : "backward", starting_date : 20120517, starting_time : 12, ending_date : 20120519, ending_time : 12, output_field_type : "rtime", output_area : [40,-25,66,10], output_grid : [0.25,0.25], output_levels : [100,200,300,400,500,600,700,800,900,1000,1100,1200,1500,2000,3000,4000,5000], release_species : 8, release_units : "mass", receptor_units : "mass", output_for_each_release : "on", releases : rel_inv ) print(r)
Here we defined both the input and output paths and specified the simulation period, the output grid and levels as well. We also told FLEXPART to generate residence time fields on output.
If we run this macro (or alternatively right-click execute
the FLEXPART Run icon) the results (after a minute or so) will be available in folder 'result_bwd'. The computations actually took place in a temporary folder then Metview copied the results to the output folder. If we open this folder we will see two files:
- time_s001.grib is a GRIB file containing the gridded residence time field
- log.txt is the logfile generated by FLEXPART
Plotting residence times
Step 1 - Residence time
In this step we will plot the residence time for a given level.
Inspecting the FLEXPART GRIB file
Before seeing the macro code to generate the plot we inspect the file itself we want to plot. Double-click on the 'time_s001.grib' GRIB icon' in folder 'result_bwd' to start up the Grib Examiner. We can see that this file contains the "fprt" (=Residence time) fields we want to visualise. We can find out further details about this parameter by setting the Dump mode to Namespace and Namespace to Parameter:
Generating the plot
The macro to visualise the residence time on a given level is 'plot_time_step1.mv'.
In the macro first we define the level (700 m) and the parameter ("fprt") we want to plot. Then we call the flexpart_filter() to extract the data for all the timesteps:
dIn="result_fwd/" inFile=dIn & "time_s001.grib" lev=700 par="fprt" #Read fields on the given height level g=flexpart_filter(source: inFile, param: par, levType: "hl", level: lev)
Next, we normalise the values with the maximum value of the fields and convert the units to percentage:
#Compute the maximum residence time for all the steps maxTime=maxvalue(g) #Derive percentages with regard to the maximum value if maxTime > 1E-30 then g=100*g/maxTime end if
Next, we define the contouring:
Next, we build the title with flexpart_build_title(). Please note that we need to explicitly specify the plotting units!
#Set precision for printing maxTime precision(4) #Define the title title=flexpart_build_title(data: g, fontsize: 0.3, units: "% of max=" & maxTime & "s")
Finally we define the mapview:
and generate the plot:
plot(view,g,time_shade,title)
Having run the macro we will get a plot like this (after navigating to step -27h):
Step 2 - Total residence time in a layer
In this step we will plot the total residence time summed up for the bottom 500m layer.
The macro to use is 'plot_time_step2.mv'. This macro is basically the same as the one in Step 1, but the data access and processing go like this:
dIn="result_bwd_time/" inFile=dIn & "time_s001.grib" #Define layer and parameter par="fprt" top_level=500 bottom_level=0 #Compute total column residence time between the specified levels #for all the timesteps g=flexpart_total_column(source: inFile, param: par, top_level: top_level, bottom_level: bottom_level) #Compute the maximum value maxTime=maxvalue(g) #Derive percentages with regard to the max if maxTime > 1E-30 then g=100*g/maxTime end if
In the code above we called flexpart_total_column() to add up the residence times in the specified layer. Then we took the result and normalised it with the maximum value.
We also need to customise the title:
#Set precision for printing maxTime precision(4) #Define the title title=flexpart_build_title(data:g, fontsize: 0.3, level: bottom_level & "-" & top_level & "m", units: "% of max=" & maxTime & "s" )
Having run the macro we will get a plot like this (after navigating to step -27h):
Step 3 - Total residence time in the whole atmospheric column
Macro 'plot_time_step3.mv' shows how to plot the total residence time for the whole atmospheric column. It goes exactly like Step 2 but we need to omit top_level
and bottom_level
in the flexpart_total_column() call:
g=flexpart_total_column(source: inFile, param: par)
and we need to adjust the title as wel:
title=flexpart_build_title(data:g, fontsize: 0.3, level: "total column", units: "% of max=" & maxTime & "s" )
Having run the macro we will get a plot like this (after navigating to step -27h):
Step 4 - Total residence time in a layer for the whole period
In this step we will plot the total residence time summed up for the whole period for the bottom 500m layer.
The macro to use is 'plot_time_step4.mv'. This macro is basically the same as the one in Step 2, but after calling flexpart_total_column() we call sum()
to sum up the fields over time:
#Compute total column residence time between the specified levels #for all the timesteps g=flexpart_total_column(source: inFile, param: par, top_level: top_level, bottom_level: bottom_level) #Sum up g=sum(g)
Having run the macro we will get a plot like this:
Step 5 - Total residence time in the whole atmospheric column for the whole period
In this step we will plot the total residence time summed up for the whole period for the whole atmospheric column.
The macro to use is 'plot_time_step5.mv'. This macro is basically the same as the one in Step 3, but after calling flexpart_total_column() we call sum()
to sum up the fields over time:
#Compute total column residence time for all the timesteps g=flexpart_total_column(source: inFile, param: par) #Sum up g=sum(g)
Having run the macro we will get a plot like this: