...
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 plots.
Extracting netCDF meta-data
Write the following code into a new Macro:
Code Block | ||
---|---|---|
| ||
# 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 what it prints:
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)
|
The variables()
function returns a list of variable names from the whole netCDF file.
Most of the netCDF functions work on the current variable, set in the setcurrent()
function. The attributes()
function returns a definition - a set of named members, similar to a Python dictionary, relevant to the current variable. A definition's elements can be accessed either using the 'dot' operator, e.g. atts.units
, or using indexing notation, e.g. atts["units"]
.
Adapt this macro so that it plots the t2m field and gives it a title based on its long_name
attribute. Here are some hints:
- drop your NetCDF Visualiser icon into the Macro Editor, also add the Contouring icon
- create a Text Plotting icon and enter a random title string, then drop this into the Macro Editor
- replace the value to the right of
text_line_1
with the value of thelong_name
attribute - add a
plot()
command which contains the NetCDF Visualiser variable, the Contouring variable and the Text Plotting variable - feel free to add the units attribute to the title as well, using the ampersand operator
&
to concatenate parts of the string
Other ASCII Data
ASCII Table Data
...