cf.FieldList.select_by_ncvar¶
-
FieldList.
select_by_ncvar
(*ncvars)[source]¶ Select field constructs by netCDF variable name.
To find the inverse of the selection, use a list comprehension with
match_by_ncvar
method of the field constucts. For example, to select all field 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
select
,select_by_identity
,select_by_construct
,select_by_naxes
,select_by_rank
,select_by_units
- Parameters
- ncvars: optional
Select field constructs. May be one or more:
The netCDF name of a field construct.
A field 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 field constructs whose netCDF variable names match viare.search
.If no netCDF variable names are provided then all field are selected.
- Returns
FieldList
The matching field 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))>]