cf.FieldList.select_by_ncvar¶
-
FieldList.
select_by_ncvar
(*ncvars)[source]¶ Select list elements by netCDF variable name.
To find the inverse of the selection, use a list comprehension with the
match_by_ncvar
method of the construct elements. For example, to select all constructs which do not have a netCDF name of ‘tas’:>>> gl = cf.FieldList( ... f for f in fl if not f.match_by_ncvar('tas') ... )
New in version 3.0.0.
See also
- Parameters
- ncvars: optional
Select constructs from the list. May be one or more netCDF names of constructs.
A construct is selected if it matches any of the given names.
A netCDF variable name is specified by a string (e.g.
'tas'
, etc.); aQuery
object(e.g.
cf.eq('tas')
); or a compiled regular expression (e.g.re.compile('^air_')
) that selects the constructs whose netCDF variable names match viare.search
.If no netCDF variable names are provided then all are selected.
- Returns
FieldList
The matching constructs.
Examples
>>> fl = cf.FieldList([cf.example_field(0), cf.example_field(1)]) >>> fl [<CF Field: specific_humidity(latitude(5), longitude(8)) 1>, <CF Field: air_temperature(atmosphere_hybrid_height_coordinate(1), grid_latitude(10), grid_longitude(9)) K>] >>> f[0].nc_get_variable() 'humidity' >>> f[1].nc_get_variable() 'temp'
>>> fl.select_by_ncvar('humidity') [<CF Field: specific_humidity(cf_role=timeseries_id(4), ncdim%timeseries(9))>] >>> fl.select_by_ncvar('humidity', 'temp') [<CF Field: specific_humidity(cf_role=timeseries_id(4), ncdim%timeseries(9))>, <CF Field: air_temperature(cf_role=timeseries_id(4), ncdim%timeseries(9)) Celsius>] >>> fl.select_by_ncvar() [<CF Field: specific_humidity(cf_role=timeseries_id(4), ncdim%timeseries(9))>, <CF Field: air_temperature(cf_role=timeseries_id(4), ncdim%timeseries(9)) Celsius>]
>>> import re >>> fl.select_by_ncvar(re.compile('^hum')) [<CF Field: specific_humidity(cf_role=timeseries_id(4), ncdim%timeseries(9))>]