...
Info |
---|
FLEXTRA is a free software system released under the GNU General Public License V3.0. The joint homepage of FLEXTRA and FLEXPART (a Lagrangian particle dispersion model) is hosted by the Norwegian Institute for Air Research (NILU) and available at the following address: http://transport.nilu.no/flexpart This website contains a link to the latest available FLEXTRA documentation: |
...
Our FLEXTRA run generated an ASCII file on output which is now represented by our FLEXTRA Run icon. Right-click and examine the icon to look to see its content. This action will start up a window showing the output generated by FLEXTRA. What you are looking at is a custom ASCII format describing the resulting trajectories and some metadata.
Info | ||
---|---|---|
| ||
Flextra assigns an exit code called stop index for each trajectory. Its value can be seen in the FLEXTRA output (the examiner highlights it in blue in the trajectory header). The possible values are as follows:
|
Now close the FLEXTRA examiner. Right-click and save the icon to get a local copy of the FLEXTRA output file. A File Save dialog will appear with a Selection box at the bottom where you can specify the output file name. Type here 'res_normal.txt' and click Ok. After a few seconds a FLEXTRA File icon with the selected name will appear in your folder.
...
This icon now stores your FLEXTRA output data. You can check its content by right-click and examine or edit.
Info |
---|
Saving the results into a file is not essential for using trajectories in Metview but allows you to have a local copy of the results for further processing outside Metview. Be aware that cached data gets deleted on exiting Metview. It means that the trajectory result data stored by the FLEXTRA RUN icon will be deleted between two Metview sessions. Therefore, especially if the computations take a long time, it is worth saving the results into a file. |
Remarks
Flextra assigns an exit code called stop index for each trajectory. Its value can be seen in the FLEXTRA output (the examiner highlights it in blue in the trajectory header). The possible values are as follows:
...
icon will be deleted between two Metview sessions. Therefore, especially if the computations take a long time, it is worth saving the results into a file. |
Visualisation On Maps
In this exercise we will visualise the trajectories that we computed in the previous chapter. We will work in folder 'normal' again.
...
To visualise your FLEXTRA output you need to use a FLEXTRA Visualiser icon (it can be found in the Modules (Plotting) icon drawer).
Create a new FLEXTRA Visualiser icon by dragging it into your folder and rename it 'plot_normal'. Edit it and drop your 'run_normal' FLEXTRA Run icon into the Flextra Data field. This specifies the FLEXTRA output to be visualised. (Please note that you could also have dropped your 'res_normal.txt' FLEXTRA File icon into the FLEXTRA Data field to specify the data to be plotted).
At this point we do not need to set any other parameters the default values will work for us. After these modifications your icon editor should look like this.
Visualising the Icon
Save your FLEXTRA Visualiser icon (Apply) then right-click and visualise to plot the trajectories. This will bring up the Metview Display Window using a custom visualisation assigned to FLEXTRA files.
...
The first thing to note in the plot is the title. It reads as
Code Block |
---|
FLEXTRA: Forward 3D 1512m Katla (-19.05,63.63) |
telling us that we visualised a set of 3D forward trajectories starting from the point called 'Katla'. The legend contains the starting date, time and elevation for each trajectory.
Now click on the 'plot_normal' layer in the Layers tab (on the right hand side of the plot window). If you change the view by clicking on the View metadata toggle button
you will see the meta-data associated with the visualised trajectories.
...
To start with, we have to be aware that Metview assigns an integer ID to each trajectory before it gets visualised. The numbering starts at 1 and the original trajectory order is kept. In this way we assign thevalue of 1 to all the points in the first trajectory. We assign the value of 2 to the points if the second trajectory and so on for the rest of the trajectories. Then in the visualisation Metview uses symbol plotting to assign different graphical attributes to different values i.e. for different trajectories.
To see how it is working in detail let's create a Symbol Plotting icon (it can be found in the Visual Definitions icon drawer, you may need to scroll the drawers to the right). Rename it 'symbol' then edit it.
First, we need to set the symbol plotting type:
...
With these settings we will plot markers (symbols) in the plot. We also set Symbol Table Mode to 'Advanced' so that we can define value intervals to which a separate maker type, colour and size can be assigned. We will construct these intervals by using the trajectory IDs. In this way the points of a given trajectory will all belong to the same interval.
The next step is to set the line properties:
...
This means that we will connect the points of a given trajectory and use the same colour for the lines as for the symbols they connect.
The intervals should be set carefully so that each trajectory ID (we have five trajectories with IDs ranging from one to five) should have a separate interval:
...
The settings above define the following intervals:
Code Block |
---|
[1,2),[2,3),[3,4),[4,5),[5,6). |
Please note intervals in symbol plotting are always closed on left and open on the right.
The last step is to specify the graphical properties we want to assign to the intervals:
Symbol Advanced Table Max Level Colour | Cyan |
Symbol Advanced Table Min Level Colour | Blue |
Symbol Advanced Table Colour Direction | Clockwise |
Symbol Advanced Table Marker List | 15/18/12/14/15 |
Symbol Advanced Table Height List | 0.4 |
With these settings we will automatically generate our colour palette from a colour wheel by interpolating in clockwise direction between Symbol Advanced Table Min Level Colour and Symbol Advanced Table Max Level Colour.
The markers used to denote the trajectory points are defined by parameter Symbol Advanced Table Marker List (see below for the list of available markers).
Now save your changes and drop this icon into the plot to see the effect of the settings.
Remarks:
- The identifiers of the available symbol markers are summarised in the table below:
...
Save your FLEXTRA Visualiser icon (Apply) then right-click and visualise to plot the trajectories.
The Metview Display Window is popping up using a custom visualisation assigned to FLEXTRA files. The title and a legend have been built exactly in the same way as in the map-based visualisation (see Part 4 ).
...
Our plot was generated by using hard-coded symbol plotting settings for trajectory rendering. We can change these settings exactly in the same way as we did for our map-based plot (see Part 4 for details). Now we will not create a new icon but simply reuse the Symbol Plotting icon called 'symbol' we created in Part 4 . Drop this icon into the plot to see the effect of the settings.
Changing the View
We will further customise the plot by changing the axis value ranges and adding axis labels and grid-lines to it. To change these properties we need a Cartesian View icon (it can be found in the Visual Definitions icon drawer).
This time you do not need to create a new icon since there is one called 'xy_view' already prepared for you. Edit his icon to see how the view is constructed (please note that the axis properties are defined via the embedded Horizontal Axis and Vertical Axis icons). Then simply drag it into the Display Window and see how you plot has been changed.
...
...
Backward Trajectories
In this exercise we will see how to compute backward trajectories with FLEXTRA in NORMAL run mode. We will work in folder 'normal' again.
...
Here we set the run mode to 'NORMAL' and defined a set of backward trajectories ending on 14 January 2012 at 3, 9,12 and 15 UTC. The trajectory length will be 72 h and the output data (i.e. trajectory waypoints) will be written out every three hours.
We finish the editing by setting the end point parameters:
...
Save your FLEXTRA Run icon (Apply) then right-click and execute to start the trajectory computations. Within a minute (it might take longer on your machines) the icon should turn green indicating that the run was successful and the results have been cached. Right-click and examine the icon to look at its content. Please note that the first data column contains negative values indicating that we computed backward trajectories.
Visualising the Results
We can visualise the results in exactly the same way as we did in the previous chapter.
Create a new FLEXTRA Visualiser icon. Edit it and drop your 'normal_run_back' FLEXTRA Run icon into the Flextra Data field. Now save your settings (Apply) then right-click and visualise to plot the trajectories. After zooming into the proper area (or dropping the map_Reading icon into the plot) you should see something like this.
...
CET Run Mode
In this exercise we will see how to compute trajectories with FLEXTRA in CET run mode. In this mode we can generate a set of trajectories starting from the points of a uniform three-dimensional grid. Please open folder 'cet' inside 'flextra_tutorial' to start the work.
...
Create a new FLEXTRA Run icon and rename it 'run_cet' then open its editor.
First, we need to set the input data parameters (in the same way as we did it in Part 3 ):
...
Here we set the run mode to 'CET' and defined a set of forward trajectories starting on 11 January 2012 at 3 UTC. The trajectory length will be 72 h and the output data (i.e. trajectory waypoints) will be written out every three hours. Please note that for simplicity we defined only one starting time (of course we could have defined multiple ones just like in the previous chapters).
We finish the editing by setting the starting point grid:
...
We can visualise the results in exactly the same way as we did in the previous chapters.
Create a new FLEXTRA Visualiser icon. Edit it and drop your 'run_cet' FLEXTRA Run icon into the Flextra Data field. Now save your settings (Apply) then right-click and visualise to plot the trajectories. After zooming into the proper area (or dropping the map_Katla Map View icon into the plot) you should see something like this.
...
...
FLIGHT Run Mode
In this exercise we will see how to compute trajectories with FLEXTRA in FLIGHT run mode. In this mode, we can specify the starting location and starting time for each trajectory individually. It is useful to calculate, for instance, trajectories along the flight track of an aircraft. Please open folder 'flight' inside 'flextra_tutorial' to start the work.
...
Here we set the run mode to 'FLIGHT' and defined a set of forward trajectories with the length of 72 h. The output data (i.e. trajectory waypoints) will be written out every three hours. Please note that this time we did not define any starting dates because in FLIGHT mode each starting point has its own starting date (see below). So parameters like Flextra First Starting Date etc. are disabled.
We finish the editing by setting the starting points, dates and times:
...
We can visualise the results in exactly the same way as we did in the previous chapter.
Create a new FLEXTRA Visualiser icon. Edit it and drop your 'run_flight' FLEXTRA Run icon into the Flextra Data field. Now save your settings (Apply) then right-click and visualise to plot the trajectories. After zooming into the proper area (or dropping the map_Eu icon Map View into the plot) you should see something like this.
...
...
Using Macro
In this example we will write the macro equivalent of the exercise we solved in Part 3 and Part 4 : we will compute forward trajectories with FLEXTRA in the NORMAL run mode and then visualise them. Please open folder 'normal' inside 'flextra_tutorial' to start the work.
...
The quickest way to generate a macro is to simply save a visualisation on screen as a Macro icon. Visualise your 'plot_normal' FLEXTRA Visualiser icon again and click on the macro icon in the tool bar of the Display Window.
Now a new Macro icon called 'MacroFrameworkN' is generated in your folder. Right-click visualise this icon. Now you should see your original plot reproduced.
Please note that this macro is to be used primarily as a framework. Depending on the complexity of the plot macros generated in this way may not work as expected and in such cases you may need to fine-tune them manually. So, we will use an alternative way and write our macro in the macro editor.
...
Since we already have all the icons for our example we will not write the macro from scratch but instead we drop the icons into the Macro editor and just re-edit the automatically generated code.
Create a new Macro icon (it can be found in the Macros icon drawer) and rename it 'step1'.
When you open the Macro editor (right-click edit) you can see that the first line contains #Metview Macro. Having this special comment in the first line helps Metview to identify the file as a macro, so we want to keep this comment here.
Position the cursor in the editor a few lines below the line of #Metview Macro. By doing so we specify the position where the code for the icons we drop into the editor will be placed. Then drop your 'plot_normal' FLEXTRA Visualiser icon into the Macro editor. You should see something like this (after removing the comment lines starting with # Importing):
Code Block |
---|
#Metview Macro |
...
run_normal = flextra_run( |
...
flextra_input_mode : "path", |
...
flextra_input_path : "/scratch/graphics/cgr/flextra_data", |
...
flextra_trajectory_length : 720000, |
...
flextra_first_starting_date : 20120111, |
...
flextra_first_starting_time : 030000, |
...
flextra_last_starting_date : 20120111, |
...
flextra_last_starting_time : 150000, |
...
flextra_starting_time_interval : 030000, |
...
flextra_normal_types : 1, |
...
flextra_normal_names : "Katla", |
...
flextra_normal_latitudes : 63.63, |
...
flextra_normal_longitudes : -19.05, |
...
flextra_normal_levels : 1512, |
...
flextra_normal_level_units : 1 |
...
) plot_normal = flextra_visualiser( |
...
flextra_data : run_normal |
...
) |
You only have to add the following command to the macro to plot the result:
Code Block |
---|
plot(plot_normal) |
Now, if you execute this macro (right-click execute or click on the Play button in the Macro editor), Metview will run FLEXTRA to compute the trajectories and you should see a Display Window popping up with the default FLEXTRA visualisation.
...
Duplicate the 'step1' Macro icon (right-click duplicate) and rename the duplicate 'step2'. In this step we will see how to save (write) our FLEXTRA results into a file and read it back into a local variable in order to avoid restarting the FLEXTRA computations every time we change something in the macro.
The macro should look like this:
Code Block |
---|
#Metview Macro |
...
resFile="res_normal_macro.txt" |
...
if not(exist(resFile)) then |
...
run_normal = flextra_run( |
...
... |
...
) write(resFile,run_normal) |
...
else |
...
run_normal=read(resFile) |
...
end if |
...
plot_normal = flextra_visualiser( |
...
flextra_data : run_normal |
...
) |
...
plot(plot_normal) |
Our code now contains an if statement to check if the FLEXTRA output file exits. If it does not exist we run FLEXTRA to compute the trajectories and save the resulting data into this file using the write() function. Otherwise we read the file from the disk with the read() function into our run_normal variable.
Run this macro to make sure that it is working (a FLEXTRA File icon called 'res_normal_macro.txt' should appear in the folder). Then run it again to see that the execution time really became shorter because we bypassed the FLEXTRA trajectory computations.
...
Duplicate the 'step2' Macro icon (right-click duplicate) and rename the duplicate 'step3'. In this step we will change our symbol plotting settings and the map area as well.
Position the cursor above the plot() command in the Macro editor and drop your 'symbol' icon into it. Repeat with the 'map_Katla' icon. Then modify the plot() command by adding these new arguments to it:
Code Block |
---|
plot(map_Katla,plot_normal,symbol) |
Now, if you run this macro you should see your modified plot in the Display Window.
...
Data Access in Macro
In this example we will see how to read metadata and data from our FLEXTRA outputs. We will get to know the usage of two FLEXTRA-specific macro functions: flextra_group_get() and flextra_tr_get(), respectively. Please open folder 'metadata' in folder 'flextra_tutorial' to start the work.
...
In this exercise we will read some metadata from our FLEXTRA output and use it to customise our plot's title.
Create a new Macro icon and rename it 'step1' then open its editor. We start the macro with reading our FLEXTRA output file that we generated in Part 3 (for you convenience there is a copy of it in your current folder):
Code Block |
---|
#Metview Macro |
...
flx=read("res_normal.txt") |
Now variable flx holds all the data of our FLEXTRA output. We continue by adding the following code to the macro:
Code Block |
---|
vals=flextra_group_get(flx, ["type","direction","name", |
...
"startLat","startLon","dx","dy"]) |
Here we used function flextra_group_get() to read the values for a list of metadata keys from the FLEXTRA output. This function accesses metadata that is valid for the whole group of trajectories we have (remember that we have several trajectories in our output). We will use the retrieved string values to build a custom title:
Code Block |
---|
titleTxt="Type: " & vals[1] & " " & vals[2] & " Point: " & |
...
vals[3] & " Lat: " & vals[4] & " Lon: " & vals[5] & |
...
" Grid: " & vals[6] & "x" & vals[7] |
...
title=mtext(text_line_1 : titleTxt) |
The next step is to define a visualiser:
Code Block |
---|
flx_plot=flextra_visualiser(flextra_data: flx) |
Finally we add our objects to the plot() command:
Code Block |
---|
plot(flx_plot,title) |
Now, if you run this macro you should see your plot with the custom title in the Display Window.
Remarks
- Please note that function flextra_group_get() returns values only for those metadata keys which have the same value for all the trajectories in the group. If this condition is not fulfilled the function returns a nil value. For example in our FLEXTRA output each trajectory has a different starting time. So if we specified key startTime for flextra_group_get() it would return a nil value for it.
- The second argument of flextra_group_get() can also be a single key (instead of a list of keys). In this case the return value is a string (instead of a list).
- Please find below the list of the metadata keys used by flextra_group_get():
Key | Description | Might get a nil value |
---|---|---|
cflSpace | Spatial CFL criterion. |
|
cflTime | Temporal CFL criterion. |
|
direction | Trajectory direction. |
|
dx | West-east resolution of the input grid. |
|
dy | North-south resolution of the input grid. |
|
east | Eastern border of the input grid. |
|
integration | Integration scheme. |
|
interpolation | Interpolation type. |
|
maxInterval | The maximum interval between input fields. |
|
name | The name of group (= 'startComment'). |
|
normalInterval | The normal interval between input fields. |
|
north | Northern border of the input grid. |
|
runComment | Label for the FLEXTRA run. |
|
south | Southern border of the input grid. |
|
startComment | The name of the trajectory group (= 'name'). |
|
startDate | Date of starting points. | ● |
startEta | Model level of starting points. | ● |
startLat | Latitude of starting points. | ● |
startLon | Longitude of starting points. | ● |
startPres | Pressure of starting points. | ● |
startPv | Potential vorticity of starting points. | ● |
startTheta | Potential temperature of starting points. | ● |
startTime | Time of starting points. | ● |
startZ | Height (above sea ) of starting points. | ● |
startZAboveGround | Height (above ground) of starting points. | ● |
trNum | Number of trajectories in the group. |
|
type | Trajectory type. |
|
west | Western border of the input grid. |
|
...
In this step we will show how to access the metadata and data of individual trajectories.
Create a new Macro icon and rename it 'step2'. Just like in the previous step the macro starts with reading our FLEXTRA output file.
Code Block |
---|
#Metview Macro |
...
flx=read("res_normal.txt") |
Now variable flx holds all the data in our FLEXTRA output. At first we will find out the number of trajectories we have.
num=number(flextra_group_get(flx,"trNum"))
Here we used function flextra_group_get() to read the value of the number of trajectories. We also used function number() to convert the string flextra_group_get() returns into a number.
Now we will create a for loop to go though all the trajectories in the group and extract and print some data from them:
for i=1 to num do
vals=flextra_tr_get(flx,i,["startTime","stopIndex"])
print("tr: ",i," time: ",vals[1]," stop: ",vals[2])
end for
Here we used function flextra_tr_get() to read the value for a list of metadata keys from the i-th trajectory in the FLEXTRA output.
The next step is to read the actual data values from a given trajectory. It goes like this:
vals=flextra_tr_get(flx,1,["date","lat","lon"]
Here we read the date, latitude and longitude data from the first trajectory. What flextra_tr_get() returns is a list that contains either a vector or a list for a given key. For date we get a lists of dates, while for lat and lon we get vectors.
Finally, we load the results into another set of variables and print their values out in a loop.
dt=vals[1]
lat=vals[2]
lon=vals[3]
for i=1 to count(dt) do
print(dt[i]," ",lat[i]," ",lon[i])
end for
Now, if you run this macro you will see the data values appearing in the standard output.
Remarks
...
plot_Srtromboli=flextra_visualiser(
flextra_data: flx,
flextra_group_index: 2
)
Data Access in Macro
In this example we will see how to access metadata and data from a FLEXTRA output file containing multiple trajectory groups.
Create a new Macro icon and rename it 'step2'. We start editing the macro with reading our FLEXTRA output file.
#Metview Macro
flx=read("res_multi.txt")
Now variable flx holds all the data in our FLEXTRA output. First, we will find out the number of trajectory groups we have by using the count() function.
num=count(flx)
Now we will create a for loop to go though all the trajectory groups and extract and print some data out of them:
for i=1 to num do
vals=flextra_group_get(flx[i],["name","type"])
print("tr: ",i," name: ",vals[1]," type: ",vals[2])
end for
Here we used the flextra_group_get() function to read the value for a list of metadata keys from the i-th trajectory group. Please note that just as in the previous step we specified the trajectory group by the [] operator.
In the next step we will read some data from the first trajectory of the second trajectory group (volcano Stromboli). It goes like this:
vals=flextra_tr_get(flx[2],1,["date","lat","lon"]
In the last step we print the data:
print(" ")
print("date: ",vals[1])
print("lat: ",vals[2])
print("lon: ",vals[3])
Now, if you run this macro you will see the data values appearing in the standard output.
...
Just like the other FLEXTRA icons the FLEXTRA Prepare icon can also be used in Macro. Its macro command equivalent is flextra_prepare().
However, please note that it should be used with extra care. The reason for it is that flextra_prepare() is executed asynchronously and if we do not reference the variable it returns we can run into problems. The following macro code illustrates this situation:
res=flextra_prepare(
flextra_output_path:
"/scratch/graphics/cgr/flextra_data",
...
)
flextra_run(
flextra_input_mode : "path",
flextra_input_path : "/scratch/graphics/cgr/flextra_data",
...
)
With this code we want to generate the input data for FLEXTRA with flextra_prepare() but we do not use the variable it returns in flextra_run(). Instead we simply use the path where the generated input data should be located. Now, because flextra_prepare() is executed asynchronously the macro starts to execute it and does not wait until it finishes but jumps immediately to flextra_run(). Then flextra_run() fails because the input data is not yet in place so the macro fails as well.
We can overcome this difficulty by simply referencing the return value of flextra_prepare() right after it is called e.g. by printing it.
res=flextra_prepare( ...
)
print(res)
flextra_run( ...
)
Alternatively we can set the Macro execution mode to synchronous by using the waitmode() function. We need to place it before calling flextra prepare() like this:
waitmode(1)
res=flextra_prepare( ...
)
flextra_run( ...
)
Please note that this macro is to be used primarily as a framework. Depending on the complexity of the plot macros generated in this way may not work as expected and in such cases you may need to fine-tune them manually. So, we will use an alternative way and write our macro in the macro editor.