Versions Compared

Key

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

...

NetCDF can be used to handle a great number of scientific data types. Metview uses NetCDF as an internal format for representing data units which can't be conveniently represented by GRIB, BUFR or geopoints, for example, to handle data arrays representing cross-sections and cross-sectional averages, vertical profiles, Hovmøller matrices, time series (meteograms), etc. Such NetCDF data files can then be imported by other NetCDF conversant software if users so wish.

Metview provides a set of NetCDF handling macro functions, allowing users to apply a number of functions and operators to NetCDF data - see NetCDF Functions.

 

How operators and functions work on NetCDF

NetCDF files can contain a wide variety of data. They can contain a number of data units, e.g. a set of cross section plots, a set of 2D geographical grids, a set of time series or vertical profiles, etc,. Each component of a set is stored in the netCDF file as a separate netcdf variable . The handling of and computations with netCDF files are based on the concept of current variable.

...

However, because functions and operators work only on the current variable, when the netCDF contains more than one variable (a multi-variable netcdfnetCDF), special care must be taken when you need the operator/function to apply to all variables - this is detailed later in this page.

When two netCDF variables are involved, both files have to have the same number of data points in each current variable, as an operation between two netCDFs is carried out between each pair of corresponding data values. Thus :

...

nc3 = nc1+nc2

corresponds to

for each data value i

nc3i = nc2i + nc1i

 

nc2 = nc1+a

corresponds to

for each data value i

nc1i = nc1i + a

 

nc2 = f(nc1)

corresponds to

for each data value i

nc2i = f(nc1i)

 

...

Example 2 : To operate on two netcdf files, assigning the result to a third netcdf, you should create the output netcdf first by a simple copying of one of the input netcdfs :

Code Block
languagebash
# Derive cross sections of temperature forecast and analysis
# in two netcdf variables, tfc_xs and tan_xs....

(...)

# derive the list of netcdf variables
var_list = variables(tfc_xs)

# create output netcdf
diff_xs = tfc_xs

# loop over variables and create fc-an difference cross-section
for i = 1 to count(var_list) do
    setcurrent(tan_xs, i)
    setcurrent(tfc_xs, i)
    setcurrent(diff_xs, i)
    diff_xs = tfc_xs - tan_xs
end for 

Extracting

...

NetCDF

...

values

If

...

you

...

need

...

to

...

have

...

access

...

to

...

the

...

data

...

values

...

of

...

a

...

netcdf

...

current

...

variable,

...

you

...

can

...

use

...

function

...

values()

...

:

     val_list = values(netcdf)

which

...

returns

...

a

...

vector

...

with

...

all

...

the

...

values

...

for

...

the

...

current

...

variable.You

...

can

...

then

...

use

...

the

...

Vector

...

functions

...

to

...

manipulate

...

the

...

data.

...

This

...

technique

...

could

...

even

...

be

...

used

...

to

...

create

...

a

...

new

...

Geopoints

...

variable

...

with

...

the

...

netCDF

...

data,

...

or

...

to

...

insert

...

the

...

values

...

into

...

a

...

GRIB

...

field.

 

An

...

alternative

...

method

...

for

...

accessing

...

individual

...

values

...

is

...

to

...

the

...

use

...

the

...

function

...

value()

...

:

    val = value(netcdf, n)

which

...

returns

...

the

...

nth

...

value

...

from

...

the

...

current

...

netcdf

...

variable.