Versions Compared

Key

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

...

Code Block
cp -R /home/graphics/cgx/tutorials/wmsodb_tutorial_4.1  $HOME/metview

You should now see a odb_tutorial_4.1 folder appearing in your main Metview folder. This contains all the icons needed for the tutorial and the solutions as well. You will work in this folder so open it up. You should see the following contents:

...


In the ODB Visualiser interface this query cannot be typed in directly but has to be split into the following individual items:

Odb Latitude Variable:specifies the name of the column holding the latitude data in the SELECT statement (here lat@hdr).
Odb Longitude Variable:specifies the name of the column holding the longitude data in the SELECT statement (here lon@hdr)
Odb Value Variablespecifies the name of the column holding the value data in the SELECT statement (here obsvalue@body)
Odb Where

specifies the WHERE statement. In our example it is as follows:

vertco_reference_1@body = 5


Last, we have to specify the units of the geographical co-ordinates (here lat@hdr and lon@hdr) in the Odb Coordinates Unit field. It is necessary since Metview requires geographical co-ordinates in degrees, but there is no general way to find out their units in an ODB database. Instead an explicit declaration is needed from the users. Our database stores co-ordinates in degrees. So, to correctly interpret our co-ordinate values Odb Coordinates Unit should be set to 'Degrees' (which is the default value so we do not need to change it).

...




We will change the plot by using markers instead of numbers and change the colour, as well. Let's create a new Symbol Plotting icon (right-click in the desktop when no icons are selected and use the New icon ... menu):

...




We used the Symbol Table Mode in our icon and set it to 'Advanced' which enabled us to automatically define intervals with a separate maker type, colour and size. These settings work in a similar way as in the Contouring icon.
Our palette was automatically generated from a colour wheel

...

So far we have used the default legend settings, which resulted in a continuous legend. Now we will change our legend so that it could display a histogram showing the data distribution across the data intervals used in the symbol plotting.
Let's create a new Legend icon:

 

Edit it, by setting the following parameter: 

Legend Display Type

Histogram

...

Inspecting the Data Values

...

 

Data values at the cursor position can be inspected with the Cursor Data Tool, which can be activated by pressing on the gun-sight icon in the toolbar of the Display Window. The Cursor Data Tool displays the co-ordinates of the current cursor position and the information for the nearest data point to this position.

...

Second, we need to specify the query by setting the following individual items:

Odb Latitude Variablespecifies the name of the column holding the latitude data in the SELECT statement (here lat@hdr)
Odb Longitude Variablespecifies the name of the column holding the longitude data in the SELECT statement (here lon@hdr)
Odb X Component Variablespecifies the name of the column holding the u wind component data in the SELECT statement (here obsvalue@body)
Odb Y Component Variablespecifies the name of the column holding the v wind component data in the SELECT statement (here obsvalue@body#1)
Odb Value Variablespecifies the name of the column whose values willl be used to generate the colour palette for the wind plotting. We leave this item empty because it instructs Metview to use the wind speed for this purpose.
Odb Fromspecifies the FROM statement (it is only needed for ODB-1 databases).
Odb Where

specifies the WHERE statement. In our example it is as follows:

obstype@hdr = 2 and

varno@body = 3 and

varno@body#1 = 4 and

vertco_reference_1@body < 25000


Last, Odb Coordinates Unit has to be set to 'Radians' since our database stores geographical co-ordinates in radians.

...




We will change the plot by applying a colour palette according to the wind speed and change the wind arrow size and thinning, as well.
Let's create a new  new Wind Plotting icon:


Rename it 'colour_wind' then edit it, by setting the following parameters:

 

Wind Field Type

Arrows

Wind Advanced Method

On

Wind Arrow Unit Velocity

50.

Wind Thinning Factor

1.0

Wind Advanced Colour Max Level Colour

Red

Wind Advanced Colour Min Level Colour

Blue

Wind Advanced Colour Direction

Clockwise


Now drop this icon into the plot to see the effect of the changes.



We used the Wind Advanced Method in our icon that enabled us to automatically define wind speed intervals and assign a nice palette to them. These settings work in a similar way to the Contouring icon. Please note that our palette was automatically generated from a colour wheel by interpolating in clockwise direction between Wind Advanced Colour Min Level Colour and Wind Advanced Colour Max Level Colour.

...

If you zoom in and out of different areas you can see that the palette does not stay constant. The default behaviour is to create 10 interval levels within the range of data actually plotted. As the area changes, so does the range of values being plotted.
Now we will create a palette which will not be altered when we change the area. Copy the Wind Plotting icon (either right-click + duplicate, or drag with the middle mouse button), and rename the copy 'fixed_wind' by clicking on its title. Edit the icon and make the following changes:

...

To change the automatically generated ODB title you need to simply drag an already prepared Text Plotting icon called 'title' into the Display Window.

...


In the ODB Visualiser interface this query cannot be typed in directly but has to be split into the following individual items:

   
Odb X Variablespecifies the name of the column holding the x data in the SELECT statement (here fg_depar@body) 
Odb Y Variablespecifies the name of the column holding the y data in the SELECT statement (here an_depar@body) 
Odb Value Variablespecifies the name of the column whose values will be used to generate the colour palette for the scatter plot. We will leave this item empty because we do not want to use this feature in this example. 
Odb Where

specifies the WHERE statement. In our example it is as follows:

vertco_reference_1@body = 5

 

Having finished the modifications your icon editor should look like this:

...

Set ODB Plot Type to 'Xy_Binning' to indicate that we want to generate a new dataset with binning and want to plot it in a Cartesian view. 

Then, drop your 'bin_100' Binning icon into the Odb Binning field as the picture below illustrates it.

...

Now drop this icon into the plot to see the effect of the changes.



In our Contouring icon we set the minimum value to '1.' to exclude grid cells containing no points at all and used 20 intervals between the minimum and the maximum to define the colour palette. Please note that our palette was automatically generated from a colour wheel by interpolating in clockwise direction between Contour Shade Min Level Colour and Co ntour Contour Shade Max Level Colour.

Changing the View

...

The quickest way to generate a macro is to simply save a visualisation on screen as a Macro icon. Visualise your ODB data again, drop the symbol plotting and title icons into the plot 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.

Note

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.

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.

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 in the first line.

...

Code Block
languagepy
#Metview Macro 
 amsua_2e_db = read("AMSUA.odb") 
 	tb_plot = odb_visualiser(
 	odb_where: " vertco_reference_1@body = 5 ",
 	odb_data: amsua_2e_odb
 )

You only have to add the following command to the macro to plot the result:

...

Duplicate the 'step1' Macro icon (right-click duplicate) and rename the duplicate 'step2'. In this step we will add our symbol plotting and title icons to the macro.

Position the cursor above the plot command in the Macro editor and drop your 'symbol_fixed' icon into it. Repeat this with the 'title' icon. Then modify the plot command by adding these new arguments after the tb_plot variable:

Code Block
languagepy
plot(tb_plot,symbol_fixed,title) 

Now, if you run this macro you should see your modified plot in the Display Window.
  Remarks

Note

The macro equivalent of the wind plotting exercise in Part 3 and that of the scatter plot exercise in Part 4 can be written in a very similar way to what was shown above for symbol plotting. The solutions can be found and studied in folder 'wind_solution' and 'scatter_solution', respectively.

The ODB Filter Icon

In this exercise we will learn about the ODB Filter icon.

In the previous exercises we saw how to visualise ODB data with the ODB Visualiser icon. This icon is working well for visualisation, however, it is not suitable for performing general retrievals (with more than four columns) and does not allow direct access to the retrieved values (for data processing in macro). To achieve these goals we need to use the ODB Filter icon which is able to perform arbitrary ODB queries and save the results as new ODBs on output.

...

As a demonstration of the ODB Filter icon, we will compute and plot the analysis increments in observation space for the brightness temperature. Like in Part 2 we will work again with channel 5 from our 'AMSUA.odb' database. Because our database does not contain the analysis increment we will compute it as the difference of the analysis departure and the first guess departure. First, we will write and perform the query needed for the exercise via the ODB Filter icon, then we will write a macro to do the computations and plot the final result.

...

Open folder 'filter' inside your 'odb_tutorial_4.1' folder. Create a new ODB Filter icon (you can find it in the Filters icon drawer) and rename it 'filter_dep'. Open its editor and perform the following steps:

Drop your 'AMSUA.odb' ODB Database icon into the Odb Data field. This specifies the database for which the query will be performed.

Type in the following ODB/SQL query in the Odb Query multi-line text input field.

Code Block
selectwhere 
 lat@hdr as lat,
 lon@hdr as lon,
 fg_depar@body as fg_dep,
 an_depar@body as an_dep
where
 vertco_reference_1@body = 5 

Now your icon editor should look like this:

Note
titleRemarks
  • It is advised to use the full column names in the query because this fully complies with the SQL standards and newer versions of ODB require this as well.
  • We used aliases (e.g. as lat) since it highly simplifies the referencing to the columns in the visualisation and macro processing.
  • The ODB database for which the query is performed can be alternatively specified by the database path via the Odb Filename input field. Please note that the typed-in database path is only used by Metview if no database icon is present.
  • The maximum number of rows accepted in the ODB retrieval is specified in the Odb Nb Rows input field. By default (-1) there is no upper limit for the number of rows.

Running the Query

Save your ODB Filter icon (Apply) then right-click and execute to run the query. Within a few seconds the icon should turn green indicating that the retrieval was successful and has been cached. Now your icon behaves exactly like an ODB Database icon. Right-click examine to look at its content.

Now you can see that as we defined it in the query the resulting ODB contains only four columns: lat, lon, fg_dep and an_dep.

...

Now we will write a macro to compute the analysis increment and visualise it.

Create a new Macro icon and rename it 'step1'. Open the Macro editor (right-click edit) and move the cursor somewhere below the #Metview Macro line at the top. Then drop your 'filter_dep' icon into the editor. You should see something like this (after removing the comment lines starting with # Importing):

Code Block
#Metview Macro 

 amsua_2e_odb= read("AMSUA.odb") 
 
filter_dep = odb_filter(
 	odb_query: "select " &
 		" lat@hdr as lat, " &
 		" lon@hdr as lon, " &
 		" fg_depar@body as fg_dep, " &
 		" an_depar@body as an_dep " &
 		"where " &
 		" vertco_reference_1@body = 5 ",
 	odb_data: amsua_2e_odb
 ) 

This piece of code performs the query and stores the result in an ODB database which is now represented by the filter_dep macro variable. Metview offers the values built-in macro function to read ODB column data into vectors. We need all the four columns for the computations and the visualisation, so we read them all one by one:

Code Block
languagepy
lat = values(filter_dep,"lat")
lon = values(filter_dep,"lon")
fg_dep = values(filter_dep,"fg_dep")
an_dep = values(filter_dep,"an_dep") 

...

then compute the difference between the all the elements of the an_dep and fg_dep vectors:

Code Block
incr = an_dep –fg_dep 

The last step is the visualisation of the result. The simplest way is to build a geopoints object out of the needed vectors (these are lat, lon and incr, respectively) and pass it to the plot command:

Code Block
geo=create_geo(num,"xyv")
 geo=set_latitudes(geo,lat)
 geo=set_longitudes(geo,lon)
 geo=set_values(geo,incr) 
 plot(geo) 

Now, if you execute this macro (right-click execute or click on the Play button in the Macro editor) you should see a Display Window popping up with this result (your plot might look different depending on your default symbol plotting settings):

...

It is complicated to create such a colour palette with one Symbol Plottingicon but we can overcome this difficulty by using three Symbol Plotting icons instead. This time you do not have to create these icons since they are already prepared for you.

Now visualise your plot again. Find the 'sym_small, 'sym_neg' and 'sym_pos' Symbol Plotting icons in the folder and select them together - either drag a rectangle around them, or click on each whilst holding down SHIFT. Then drag them together into the plot.

In the last step drag the 'title' Text Plotting icon into the plot, as well.

You will see an enhanced plot as shown below:

...

We are satisfied with the new colour palette and with the title as well, so in the last step of the exercise we will add these new settings to our macro.

Duplicate the 'step1' macro icon (right-click Duplicate) and rename the duplicate 'step2'. Position the cursor above the plot command in the Macro editor and drop your 'sym_small', 'sym_neg', 'sym pos' and 'title' icons into it (you can drop them together or one by one).

Then modify the plot command by adding these new arguments after the geo variable:

Code Block
languagepy
plot(geo,sym_neg,sym_small,sym_pos,title) 

Now, if you visualise the macro you should see your modified plot in the Display Window.

Wind Plotting with ODB

...

Data

In this exercise we will present an example macro to show how to plot ODB -2 wind data if both the wind components are stored in the same column in the database. We will demonstrate this plotting technique on aircraft wind data above 250 hPa from our 'AIREP.odb' ODB-2 database.

...

Open folder 'wind_odb2' inside your 'odb_tutorial_4.1' folder. You will find here the 'AIREP.odb' ODB Database icon and a macro called 'plot_wind'. If you right click and visualise the macro it will retrieve and plot the wind data from the database. You should see a Display Window popping up with the result (your plot might look different depending on your default wind plotting settings):


This result was achieved by executing the following steps in the macro:

...

Open the Macro editor for our macro (right-click edit) to study its source code.

The macro starts the #Metview Macro declaration. Then we load our database into a macro object.
 

Code Block
languagepy
mydb= read("AIREP.odb")

 
We  We perform two ODB/SQL queries for this database via the odb_filter command. The first query retrieves the u wind component while the second query retrieves the v wind component. As a result we have two ODB objects: filter_u containing columns lat, lon and u, and filter_v containing columns lat, lon and v. Since the u and v wind data come strictly after each other in the database we can be sure that the two ODBs have the same number of rows and their lat and lon columns are identical.

Code Block
languagepy
filter_u = odb_filter(
 odb_query: "select " &
 	" lat@hdr as lat, " &
 	" lon@hdr as lon, " &
 	" obsvalue@body as u, " &
 	"where " &
 	" obstype@hdr = 2 and " &
 	" varno@body = 3 and "
 	" vertco_reference_1@body > 25000 ",
 odb_data:myodb
 ) 
 filter_v = odb_filter(
 odb_query: "select " &
 	" lat@hdr as lat, " &
 	" lon@hdr as lon, " &
 	" obsvalue@body as v, " &
 	"where " &
 	" obstype@hdr = 2 and " &
 	" varno@body = 4 and "
 	" vertco_reference_1@body > 25000 ",
 odb_data:myodb
 ) 

In the next step we extract the lat, lon, u and v ODB columns into vectors via the values() macro function.

Code Block
languagepy
lat = values(filter_u,"lat")
 lon = values(filter_u,"lon")
 u = values(filter_u,"u")
 v = values(filter_v,"v")

Having each necessary ODB column stored in a vector we build an xy_vector geopoints object out of them.

Code Block
languagepy
geo=create_geo(count(lat),"xy_vector")
 geo=set_latitudes(geo,lat)
 geo=set_longitudes(geo,lon)
 geo=set_values(geo,u)
 geo=set_value2s(geo,v) 

In the last step we specify our wind plotting visual definition

Code Block
languagepy
colour_wind = mwind( … ) 
 

then

...

our title

Code Block
languagepy
 title 
 title = mtext( … ) 

and visualise the geopoints object itself

Code Block
languagepy
plot(geo,colour_wind,title) 

...

  • macro_filter: it shows how to manipulate ODB MARS data with the odb_filter function (see Part 6 ) to derive new datasets.
  • macro_plot: it shows how to plot data from an ODB MARS retrieval. It is basically the macro equivalent of the 'plot_hirs' ODB VisualiseVisuali