Versions Compared

Key

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

...

Save the changes, and visualise this new icon. See how the settings in the visualiser icon correspond to the variable names in the data. Now visualise another field from the same file. Use the supplied shading_20_levels icon on the plot.

Handling netCDF in Macro

In Macro, the read() function reads the given netCDF file into a netcdf variable.

Once read in, Metview can perform various manipulations on the data. These are based on the concept of the current variable. Out of the N variables contained in a netCDF file, one is always set to be the current variable. Functions and operators acting upon the netCDF file will act only upon the current variable.

Have a look at the variable v2d inside the netCDF file - its values are stored in degrees Kelvin. As an exercise, we will change them to Celcius. Type the following code into a new Macro:

Code Block
languagepy
nc = read('netcdf.nc')
setcurrent(netcdf, XXX)
nc = nc - 273.15

We can then write this to a new file:

Code Block
languagepy
 write('new_netcdf.nc', nc)

The only difference between this and the original file should be in the values of the variable v2d. Visualise the new file to check that its values are in Celsius.

Operations can also be performed between two netCDF files (e.g. diff = nc1 - nc2), noting that the operation is performed using only the current variable in each.

Various meta-data can be extracted from a netCDF - try the following in a macro:

Code Block
languagepy
nc = read('netcdf.nc')
print('Variables: ', variables(nc))
print('Global attributes: ', global_attributes(nc))

plots.

Exporting Cross Sections and Profiles as netCDF

Metview uses netCDF internally for the results of some computations. In particular, the analysis views (e.g. Cross Section ViewVertical Profile View) do this, but their result data is not available to the user. Therefore, each of these views has a corresponding Data view - for example, there exist both a Cross Section View and a Cross Section Data icon. If the intention is to simply plot the result, then the View icons are more useful. But to store the result data, the Data icon is required.

...

All of this can also be put into a macro, where the resulting netcdf variable can be further manipulated before being written to file (or visualised).

Write a short macro which computes a vertical profile from the data (use the Vertical Profile Data icon that you already set up) and writes the result to a file. To write a netcdf variable to a file, the syntax is the same as for any other data type:

Code Block
languagepy
write('output_file', data)

Your macro should be 3 lines long (well, 3 commands anyway) - one to read the input GRIB file, one to compute the profile and one to write the result to disk.

Geopoints

Format overview

...