Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This dataset was generated through the Metview FLEXTRA interface. Appendix A The chapter on data preparation explains how it works and helps prepare your own dataset if it is needed.

...

In this exercise we will see how to compute trajectories with FLEXTRA in NORMAL run mode. In NORMAL mode we can generate a group of trajectories starting from the same point but at different times. Please open folder 'normal' inside folder 'flextra_tutorial' to start the work.

The FLEXTRA Run Icon

...

With these settings we specified the trajectory type to be three-dimensional (see below for the list of IDs for trajectory types) and set the starting point to volcano Katla (on Iceland) with the height of 1512m.

Remarks  

The format of parameters holding dates is yyyymmdd. Any dates having less than 8 digits are interpreted as relative dates. E.g, -1 = yesterday, 0 = today, 1 = tomorrow etc.

...

Note
titleGRIB2 input fields

Another problem with global GRIB2 input fields is that FLEXTRA interprets the longitude span of the domain either as 0-360 or 180-540 (!!!) degrees depending on the geometry settings in the GRIB headers. The actual range can be figured out from the header of the FLEXTRA output files. In both cases we need to guarantee that the starting point we specify is in the given coordinate range. Otherwise FLEXTRA fails with the following message:

"NOTICE: STARTING POINT OUT OF DOMAIN HAS BEEN DETECTED"

In the first case it is trivial to ensure itwe have the right coordinate values, while in the second case we need to add 360 to the longitude to make FLEXTRA accept the starting point.

...

There is also a macro equivalent command for icon FLEXTRA Prepare, which is used to prepare input data for FLEXTRA. Please see Appendix A the chapter on data preparation for details on it.

Automatic macro generation

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

Warning

This automatically generated 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.

...

It is recommended to use an alternative way and write our own macro in the macro editor.

Step 1 - Writing a macro

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.

...

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.

...

Finally we add our objects to the plot() command:

Code Block
plot(flx_plot,title) 

Now, if If you run this macro you should see your plot with the custom title in the Display Window. 

Remarks

...

Tip
  1. 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.
  2. 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.

(tick)

startEta

Model level of starting points.

(tick)

startLat

Latitude of starting points.

(tick)

startLon

Longitude of starting points.

(tick)

startPres

Pressure of starting points.

(tick)

startPv

Potential vorticity of starting points.

(tick)

startTheta

Potential temperature of starting points.

(tick)

startTime

Time of starting points.

(tick)

startZ

Height (above sea ) of starting points.

(tick)

startZAboveGround

Height (above ground) of starting points.

(tick)

trNum

Number of trajectories in the group.

 

type

Trajectory type.

 

west

Western border of the input grid.

 

...

Now, if you run this macro you will see the data values appearing in the standard output.
 

 

Remarks

...

Tip

The second argument of flextra_tr_get() can also be a single key (instead of a list of keys). In this case the function returns either a single string value, a list or a vector depending of the key specified.

Please find below the list of the metadata keys used by flextra_tr_get():

...

 

Retrun

Key

Description

Return value

date

Date.

list of dates

eta

Model level.

vector

lat

Latitude.

vector

lon

Longitude.

vector

pres

Pressure.

vector

pv

Potential vorticity.

vector

startDate

Date of starting point.

string

startEta

Model level of starting point.

string

startLat

Latitude of starting point.

string

startLon

Longitude of starting point.

string

startPres

Pressure of starting point.

string

startPv

Potential vorticity of starting point.

string

startTheta

Potential temperature of starting point.

string

startTime

Time of starting point.

string

startZ

Height (above sea) of starting point

string

startZAboveGround

Height (above ground) of starting point

string

stopIndex

Stop index of computations.

string

theta

Potential temperature.

vector

z

Height above sea level.

vector

zAboveGroundLevel

Height above ground level.

vector

...

  Now, if you run this macro you will see the data values appearing in the standard output.

Anchor
data_preparation
data_preparation
Input Data Preparation

In this exercise we will see how to generate input data for FLEXTRA runs from ECMWF's MARS archive. Please note that to run the examples you need to have a Metview version being able to connect to MARS. Please open folder 'prepare' in folder 'flextra_tutorial' to start the work.

...

In addition to the GRIB files a FLEXTRA run requires several parameter files as well. Most of these files are automatically generated by Metview in the background, so users do not need to create them. The only exception is the file called AVAILABLE describing the input dates, times and GRIB files. This file can be optionally provided by the users (as we saw it in Part 3 ).

The FLEXTRA Prepare Icon

The The  FLEXTRA Prepare icon is used to generate all the input data needed for a FLEXTRA run including the MARS retrievals, the computations and the generation of the AVAILABLE file as well.

...

Warning

Please be aware that the preparation process is currently only working for operational forecasts having 91 or 137 model levels and requires parameter etadot from MARS. Because parameter etadot has only been archived in MARS since 4 June 2008, earlier dates cannot be used.

...

Code Block
244 	2012-02-02 16:08 AVAILABLE
547200 	2012-02-02 16:07 EN12020100
547200 	2012-02-02 16:08 EN12020103
547200 	2012-02-02 16:08 EN12020106

 If we check the AVAIALBLE AVAILABLE file itself we will see the following content (again, you will see different dates in your file):

...

Right-click and execute to start the data preparations again. This time your icon turnes turns green almost immediately indicating that actually no data retrieval and processing happened. The reason for it is that we set parameter Flextra Reuse Input to 'On'. In this case Metview checks the existence of the data to be generated and if the data is already in place no new data is retrieved. The same happens with the AVAILABLE file.
 

...

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:
 

...

  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.

...

  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:

Code Block
languagebash
waitmode(1) 
 
res=flextra_prepare( ...
 ) 
 
flextra_run( ...
 )