Versions Compared

Key

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

...

In all of the above operations, a missing value in one of the input fieldsets results in a corresponding missing value in the output fieldset.

 

fieldset ( fieldset op number )
fieldset ( number op fieldset )

...

creates a fieldset c with values of 1 where the corresponding values of fieldset a and fieldset b are both non zero, and 0 otherwise. For an example of the use of boolean operators, see the mask function. A missing value in either input fieldset will result in a missing value in the corresponding place in the output fieldset.

 

fieldset ( fieldset and number )
fieldset ( number or fieldset )

...

# Retrieve land-sea mask and interpolate to LL grid
lsm = retrieve(
   type : "an",
   date : -1,
   param : "lsm",
   grid : [1.5,1.5],
   levtype : "sfc"
)

# The following line forces the values to 0 or 1.
lsm = lsm > 0.5

# Now compute the average value on land and on sea
land = integrate(field, lsm)
sea = integrate(field, not lsm)

...

Generates a matrix containing the values of the input field, or a list of matrices if there are more than one field in the fieldset. Only works with regular lat/long grids.

 

 

fieldset mean ( fieldset )

Computes the mean field of a fieldset. A missing value in any field will result in a missing value in the corresponding place in the output fieldset. With n fields in the input fieldset, if xik is the ith value of the kth input field and yi is the ith value of the resulting field, the formula can be written :

mvug-121.gifImage Modified

 

fieldset mean_ew ( fieldset )

Takes a fieldset as its parameter and computes the mean for each line of constant latitude. The result is a fieldset where the value at each point is the mean of all the points at that latitude. Missing values are excluded; if there are no valid values, then the grib missing value indicator will be returned for those points.

 

fieldset merge ( fieldset,fieldset,... )

Merge several fieldsets. The same as the operator &. The output is a fieldset with as many fields as the total number of fields in all merged fieldsets. Merging with the value nil does nothing, and is used to initialise when building a fieldset from nothing.

 

fieldset mod ( fieldset,fieldset )

Returns a fieldset with as many fields as the input fieldsets; the grid point values of the output fieldset are the remainder of the division of the first fieldset by the second fieldset (the function operating field by field). Where the gridpoint values of the second fieldset are larger than those of the first, the output gridpoint value is set to the integer part of the first input gridpoint value. A missing value in either input fieldset will result in a missing value in the corresponding place in the output fieldset. Note that only the integer parts of the inputs are considered in the calculation, meaning that a second parameter of 0.5 would cause a division by zero.

With n fields in the input fieldsets, if xik, yik are the ith value of the kth input fieldsets and zi is the ith value of the resulting field:


mvug-122.gifImage Modified

 

number or list nearest_gridpoint ( fieldset,list )
number or list nearest_gridpoint ( fieldset,number,number )

Returns the value of the nearest point to a given location in each field of a fieldset. If a list is given, it must contain two numbers - latitude and longitude. If two numbers are given, the first is the latitude, the second the longitude. The field must be a lat-long field. If the fieldset has only one field, a number is returned; otherwise a list is returned. Where it is not possible to generate a sensible value due to lack of valid data in the fieldset, the grib missing indicator is returned.

 

geopoints nearest_gridpoint ( fieldset,geopoints )

Generates a set of geopoints from a field. The first field of the input fieldset is used. The result is a set of geopoints whose values are those of the nearest gridpoints in the field to the geopoints given as a second parameter. Where it is not possible to generate a sensible value due to lack of valid data in the fieldset, the internal geopoints missing value is used (this value can be checked for with the built-in variable geo_missing_value or removed with the function remove_missing_values ).

 

list nearest_gridpoint_info ( fieldset,list )
list nearest_gridpoint_info ( fieldset,number,number )

Returns the value and location of the nearest point to a given location in each field of a fieldset. If a list is given, it must contain two numbers - latitude and longitude. If two numbers are given, the first is the latitude, the second the longitude. The field must be a lat-long field. The return value is a list of definitions, one for each field, and each containing the following members: value , latitude , longitude . Where it is not possible to generate a sensible value due to lack of valid data in the fieldset, the grib missing indicator is returned.

The following example illustrates how to use the function.

fs

...

=

...

read

...

(strGribFile)

...


listdef

...

=

...

nearest_gridpoint_info(fs,

...

51.46,

...

-1.33)

...


loop

...

ngp

...

in

...

listdef

...


...

     print

...

("Value

...

:

...

",

...

ngp.value)

...


...

     print

...

("Latitude

...

:

...

",

...

ngp.latitude)

...


...

     print

...

("Longitude

...

:

...

",

...

ngp.longitude)

...


end

...

loop

...

 

fieldset nobitmap ( fieldset,number )

Returns a copy of the input fieldset (first argument) with all of its missing values replaced with the number specified by the second argument. See also bitmap .

...

 

fieldset pressure ( fieldset )
fieldset pressure ( fieldset,number )
fieldset pressure ( fieldset,list )
fieldset pressure ( fieldset,fieldset )

This function creates fields of pressure from the logarithm of the surface pressure (lnsp) and a list of model levels. Note that this function only works with lat/long grids and assumes that the parameter for lnsp is 152. A newer, more flexible version of this function exists - see unipressure () .

    • The first argument is always a fieldset containing an lnsp field. If no other parameter is given, the list of levels will range from 1 to (number of vertical coordinates/2)-1 as coded in the GRIB header of the lnsp parameter.
    • The second argument specifies the levels at which the output fields must be generated. To generate a single level, pass a number. For more than one level, either pass a list of levels or a fieldset. If a fieldset is passed as the second parameter, the level information is extracted from each field of the fieldset.

Missing values in the lnsp field are retained in the output fieldset.

 

fieldset putksec1 rmask ( fieldset,number,number,list number )
fieldset
putksec2 rmask ( fieldset,list )

fieldset putksec3 ( fieldset,list )

fieldset putksec4 ( fieldset,list )

Note : as of Metview 3.11, these functions are deprecated - please use the new alternatives, grib_set_long and grib_set_double fieldset grib_set_long( fieldset, list ).

This function allows you to set integer elements of the GRIB header Sections in the input fieldset to suitable values specified in the list provided as the second argument. Details on the GRIB section element numbers and their meaning can be found in :

http://www.ecmwf.int/publications/manuals/libraries/gribex/ksec1.html
http://www.ecmwf.int/publications/manuals/libraries/gribex/ksec2.html
http://www.ecmwf.int/publications/manuals/libraries/gribex/ksec3.html
http://www.ecmwf.int/publications/manuals/libraries/gribex/ksec4.html

The structure of the list provided as the second argument is as follows - the index of a GRIB Section element followed by its new value; these element pairs can be repeated as many times as necessary. Example :

     f = putksec1(f,[10,98,18,113])

will assign 98 to ksec1(10) and 113 to ksec1(18). This function does not modify the input fieldset, but returns a new fieldset with the modifications applied.

fieldset putrsec1 ( fieldset,list )

fieldset putrsec2 ( fieldset,list )

fieldset putrsec3 ( fieldset,list )

fieldset putrsec4 ( fieldset,list )

Note : as of Metview 3.11, these functions are deprecated - please use the new alternatives, grib_set_long and grib_set_double fieldset grib_set_long( fieldset, list ).

This function allows you to set real-valued elements of the GRIB header Sections in the input fieldset to suitable values specified in the list provided as the second argument. Details on the GRIB section element numbers and their meaning can be found in :

http://www.ecmwf.int/publications/manuals/libraries/gribex/psec2.html
http://www.ecmwf.int/publications/manuals/libraries/gribex/psec3.html
http://www.ecmwf.int/publications/manuals/libraries/gribex/psec4.html

The structure of the list provided as the second argument is as follows - the index of a GRIB Section element followed by its new value; these element pairs can be repeated as many times as necessary. Example :

     f = putrsec2(f,[12,435,13,520])

will assign 435 to rsec2(12) and 520 to rsec2(13). This function does not modify the input fieldset, but returns a new fieldset with the modifications applied.

 

fieldset rmask ( fieldset,number,number,number )

fieldset rmask ( fieldset,list )

Similar to mask , except that a round mask is computed with a given radius around a geographical centre point. These can be given by either:

Similar to mask , except that a round mask is computed with a given radius around a geographical centre point. These can be given by either:

    • three numbers : latitude, longitude (in degrees)
  • three numbers : latitude, longitude (in degrees)
    • , radius (in meters)
    • a list containing the above three numbers

The name of this function is derived from the fact that it creates a "round mask" or a "radius mask".

 

fieldset rms ( fieldset )

Computes the root mean square of a fieldset. A missing value in any field will result in a missing value in the corresponding place in the output fieldset. With n fields in the input fieldset, if xik is the ith value of the kth input field and yi is the ith value of the resulting field, the formula can be written :


mvug-123.gifImage Modified


Note that the following lines are equivalent :

...

y

...

=

...

rms(x)

...


...

y

...

=

...

sqrt(mean(x*x))

...

 

fieldset sinlat ( fieldset )

For each field in the input fieldset, this function creates a field where each grid point has the value of the sine of its latitude. For example, the following macro adds the coriolis parameter to each grid point of a field :

...

...

#

...

Computes

...

absolute

...

vorticity

...

from

...

vorticity

...


...

omega

...

=

...

2

...

*

...

pi

...

/

...

86400

...


...

coriolis

...

=

...

2

...

*

...

omega

...

*

...

sinlat(vort)

...


...

absvort

...

=

...

vort

...

+

...

coriolis

...

 

fieldset sort ( fieldset )
fieldset sort ( fieldset,string )
fieldset sort ( fieldset,list )
fieldset sort ( fieldset,string,string )
fieldset sort ( fieldset,list,string )
fieldset sort ( fieldset,list,list )

This function accepts a fieldset as input and returns it sorted according to keys and rules specified in the other input arguments.

Specified with only the fieldset as its single argument, sort() sorts in descending order the fieldset according to date, time, step, (ensemble) number, level and parameter.

The second argument allows you to modify the precedence of the sorting keys - e.g. if the second argument is a string "parameter", then the sorting is done according to the parameter first. If the second argument is a list you specify a list of sorting keys - e.g. ["parameter", "date"] sorts on parameter and then date.

The third argument specifies a sorting direction. This can be a string (">" or "<") or a list ([">", "<", ">",...]). If it is a string, the sorting direction it specifies applies to all sorting keys specified in the second argument. If it is a list, then the second argument must also be a list with the same number of elements - the sorting directions apply to each sorting key specified.

 

fieldset stdev ( fieldset )

Computes the standard deviation of a fieldset. A missing value in any field will result in a missing value in the corresponding place in the output fieldset. With n fields in the input fieldset, if xik is the ith value of the kth input field and yi is the ith value of the resulting field, the formula can be written :


mvug-124.gifImage Modified

Note that the following lines are equivalent :

...

y

...

=

...

stdev(x)

...


...

y

...

=

...

sqrt(mean(x*x)-mean(x)*mean(x))

...


...

y

...

=

...

sqrt(var(x))

...

 

number or list stdev_a ( fieldset )
number or list stdev_a ( fieldset,list )

Computes the standard deviation over a weighted area. The area, if specified, is a list of numbers representing North, West, South, East. If the area is not specified, the whole field will be used in the calculation. The result is a number for a single field, or a list for a multi-field fieldset.

 

fieldset sum ( fieldset )

Computes the sum of a fieldset. The result is a single-field fieldset. A missing value in any field will result in a missing value in the corresponding place in the output fieldset. With n fields in the input fieldset, if xik is the ith value of the kth input field and yi is the ith value of the resulting field, the formula can be written :

mvug-125.gifImage Modified

 

fieldset thickness ( fieldset )
fieldset thickness ( fieldset,number )
fieldset thickness ( fieldset,list )
fieldset thickness ( fieldset,fieldset )

This function creates fields of thickness from the logarithm of the surface pressure (lnsp ) and a list of model levels. Note that this function only works with lat/long grids and assumes that the parameter for lnsp is 152. A newer, more flexible version of this function exists - see unithickness () .

    • The first argument is always a fieldset containing an lnsp field. If no other parameter is given, the list of levels will range from 1 to (number of vertical coordinates/2)-1 as coded in the GRIB header of the lnsp .
    • The second argument specifies the levels at which the output fields must be generated. To generate a single level, pass a number. For more than one level, either pass a list of levels or a fieldset. If a fieldset is passed as the second parameter, the level information is extracted from each field of the fieldset.

Missing values in the lnsp field are retained in the output fieldset.

 

fieldset unipressure ( fieldset )
fieldset unipressure ( fieldset,fieldset )
fieldset unipressure ( fieldset,list )
fieldset unipressure ( fieldset,number )
fieldset unipressure ( fieldset,fieldset,number )
fieldset unipressure ( fieldset,list,number )
 

This function creates fields of pressure from the logarithm of the surface pressure (lnsp) and a list of model levels. Unlike pressure() , this function works with all grid types known to Metview (not just lat/long); it also allows the user to override the parameter number for lnsp (default 152).

    • The first argument is always a fieldset containing an lnsp field. If no other parameter is given, then pressure is computed for all model levels that are described in the GRIB header of fieldset .
    • If number is given (always the last parameter) it is the lnsp parameter code (default is 152).
    • list should contain model levels for which pressure is to be computed. Note that also for a single model level one has to use a list (this is a signature difference compared to the old function pressure() ).
    • If fieldset is given as the second parameter then pressure is computed for those model levels found in the second fieldset.

Missing values in the lnsp field are retained in the output fieldset.

 

fieldset unithickness ( fieldset )
fieldset unithickness ( fieldset,fieldset )
fieldset unithickness ( fieldset,list )
fieldset unithickness ( fieldset,number )
fieldset unithickness ( fieldset,fieldset,number )
fieldset unithickness ( fieldset,list,number )

 

This function creates fields of thickness from the logarithm of the surface pressure (lnsp) and a list of model levels. Unlike thickness() , this function works with all grid types known to Metview (not just lat/long); it also allows the user to override the parameter number for lnsp (default 152).

    • The first argument is always a fieldset containing an lnsp field. If no other parameter is given, then thickness is computed for all model levels that are described in the GRIB header of fieldset .
    • If number is given (always the last parameter) it is the lnsp parameter code (default is 152).
    • list should contain model levels for which thickness is to be computed. Note that also for a single model level one has to use a list (this is a signature difference compared to the old function thickness() ).
    • If fieldset is given as the second parameter then thickness is computed for those model levels found in the second fieldset.

Missing values in the lnsp field are retained in the output fieldset.

 

fieldset univertint ( fieldset)
fieldset univertint ( fieldset, fieldset )
fieldset univertint ( fieldset, number )
fieldset univertint ( fieldset, fieldset, number )
fieldset univertint ( fieldset, fieldset, list)

 

Universal vertical integration. This function is similar to vertint() , except that univertint() also works with sparse levels whereas vertint() is restricted to continuous levels.

This function performs a vertical integration of the input fieldset. If just one fieldset is given, it must also contain the logarithm of the surface pressure (lnsp ). If the function is called with two fieldsets, the first one is a fieldset containing an lnsp field, the second one is the multi-level fieldset. A number may optionally be given as the last parameter in order to specify the lnsp code used in the fieldset that contains the lnsp data; its default value is 152. If a list with two elements [top, bottom] is given as the third parameter, then the integration is performed between (and including) these layers.

A missing value in any field will result in a missing value in the corresponding place in the output fieldset.

The function computes :


mvug-126.gifImage Modified

Where f is the fieldset, p is the pressure and g the acceleration of gravity.

 

fieldset var ( fieldset )

 

Computes the variance of a fieldset. A missing value in any field will result in a missing value in the corresponding place in the output fieldset. With n fields in the input fieldset, if xik is the ith value of the kth input field and yi is the ith value of the resulting field, the formula can be written :

...

mvug-127.gifImage Modified

Note that the following lines are equivalent :

...

y

...

=

...

var(x)

...


...

y

...

=

...

mean(x*x)-mean(x)*mean(x)

...

 

number or list var_a ( fieldset )
number or list var_a ( fieldset,list )

Computes the variance over a weighted area. The area, if specified, is a list of numbers representing North, West, South, East. If the area is not specified, the whole field will be used in the calculation. The result is a number for a single field, or a list for a multi-field fieldset.

 

fieldset vertint ( fieldset )

fieldset vertint ( fieldset,fieldset )

This function performs a vertical integration of the input fieldset, which must contain a range of model levels for the same parameter. A missing value in any field will result in a missing value in the corresponding place in the output fieldset. If the function is called with the fieldset as its single argument, it must also contain the logarithm of the surface pressure (lnsp ). If the function is called with two parameters, the first one is a fieldset containing an lnsp field, the second one is the multi-level fieldset.

The function computes :

...

mvug-128.gifImage Modified

Where f is the fieldset, p is the pressure and g the acceleration of gravity.

The following example computes the total amount of liquid water in the atmosphere by integrating the cloud liquid water content (clwc ) over all levels of the model :


...

#

...

Retrieve

...

clwc

...


...

clwc

...

=

...

retrieve(

...


   levtype : "ml",

...


   levelist : [1,"to",31

...

],
   param : "clwc",

...


   date :

...

-1,

...


   grid :

...

[2.5,2.5]

...


...

)

...



...


#

...

Retrieve

...

lnsp

...


...

lnsp

...

=

...

retrieve(

...

         levtype     : "ml",
         levelist        : 1,

...


   levtype : "ml",
   levelist : 1,
   param : "lnsp",

...


   date : -1,

...


   grid : [2.5,2.5]

...


...

)

...


...


#

...

Integrate

...

the

...

field

...


...

x

...

=

...

vertint(lnsp,clwc)

...


...

plot(x)

...