Versions Compared

Key

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

...

Code Block
languagepy
# read the netCDF file and print its list of variables
nc = read("fc_12.nc")
vars = variables(nc)
print(vars)   #  we could also do:  print(variables(nc))

# set the current variable to be t2m and print its attributes
setcurrent(nc, 't2m')
atts = attributes(nc)
print(atts)

Run the macro and see - this is what it printsshould print:

Code Block
[longitude,latitude,time,t2m,d2m]
ATTRIBUTES(scale_factor:0.001611,add_offset:254.569370,missing_value:-32767,units:K,long_name:2 metre temperature)

...

Code Block
netcdf_auto_translate_times(0)  # 1 means 'on', 0 means 'off'

...

ASCII Data

ASCII Table Data

Metview incorporates functionality to read, process and visualise data stored in ASCII table files, including the commonly-used CSV (comma-separated value) format.

...

Although Metview has some functionality for handling this type of data in Macro, it can do much more with the geopoints format. Therefore, if the data points are in geographic coordinates, one useful exercise is to read one of these files and convert it to geopoints.

...

First, use the values() function to extract arrays of lats, lons and T2m from the CSV data. These will be returned in variables of type vector - this is an in-memory array of double-precision numbers.

Panel
vector or list values( table, number )
vector or list values( table, string )

Returns the given column specified either by an index (starting at 1) or a name (only valid if the table has a header row). If the column type is number, a vector is returned; if it is string, then a list of strings is returned. If the column cannot be found, an error message is generated.

...

There are many more string functions available. 

Now do the reverse: write this list of parameters into another text file. The new file should look exactly like the original. Here are some hints:

...

There is a dedicated tutorial for handling ODB data in Metview on the Tutorials page.

Extra Work

NetCDF

Modify your first netCDF macro which plots the t2m variable and make it compute the temperature in degrees Celcius by subtracting 273.15 from it before plotting.

Optimisations to file writing

...

See if you can write a macro which extracts lat, lon and value columns into vectors and creates a new geopoints variable from the data.

NetCDF

Modify your first netCDF macro which plots the t2m variable and make it compute the temperature in degrees Celcius by subtracting 273.15 from it before plotting.