epygram.formats.FA
— Interface-Class to the FA format¶
Contains the class for FA format.
- epygram.formats.FA.get_generic_fid(fieldname)[source]¶
Return a generic fid from fieldname (via FaGribDef).
- class epygram.formats.FA.FaGribDef(actual_init=True, concepts=['faFieldName', 'faModelName', 'faLevelName'])[source]¶
Bases:
epygram.extra.griberies.GribDef
Handle FA-related GRIB definition files. To add user files: a) use env vars GRIBAPI|ECCODES_DEFINITION_PATH or b) move it under {config.userlocaldir}/{FaGribDef.dirname}
- FA2GRIB(*args, **kwargs)¶
Convert FA field name to GRIB fid, including vertical level identification.
- Parameters
grib_edition – among (‘grib1’, ‘grib2’), the version of GRIB fid
include_comments – if a comment is present if grib def, bring it in fid
fatal – if True and fieldname is not retrieved, raise a ValueError; else, return a default 255 fid
filter_non_GRIB_keys – filter out the non-GRIB keys that may be present in grib def of field
- GRIB2FA(*args, **kwargs)¶
Look for a unique matching field in tables. ! WARNING ! the unicity might not be ensured depending on the version of grib definitions files.
- Parameters
grib_edition – among (‘grib1’, ‘grib2’), the version of GRIB fid
- lookup_FA(*args, **kwargs)¶
Look for all the fields which FA name contain partial_fieldname.
- Parameters
grib_edition – among (‘grib1’, ‘grib2’), the version of GRIB fid
include_comments – if a comment is present if grib def, bring it in fid
filter_non_GRIB_keys – filter out the non-GRIB keys that may be present in grib def of field
- lookup_GRIB(*args, **kwargs)¶
Look for all the fields which GRIB fid contain partial_fid.
- Parameters
grib_edition – among (‘grib1’, ‘grib2’), the version of GRIB fid
include_comments – if a comment is present if grib def, bring it in fid
filter_non_GRIB_keys – filter out the non-GRIB keys that may be present in grib def of field
- class epygram.formats.FA.FA(*args, **kwargs)[source]¶
Bases:
epygram.resources.FileResource.FileResource
Class implementing all specificities for FA resource format.
Note
This class is managed by footprint.
info: Not documented
priority: PriorityLevel::DEFAULT (rank=1)
Automatic parameters from the footprint:
cdiden (
builtins.str
) - rwx - With openmode == ‘w’, identifies the FA by a keyword, usually the model abbreviation.Optional. Default is ‘unknown’.
default_compression (
footprints.stdtypes.FPDict
) - rxx - Default compression for writing fields in resource.Optional. Default is None.
filename (
builtins.str
) - rxx - File name (absolute or relative) of the resource.fmtdelayedopen (
builtins.bool
) - rxx - Opening of the resource delayed (not at time of construction).Optional. Default is False.
format (
builtins.str
) - rxx - Format of the resource.Optional. Default is ‘FA’.
Values: set([‘FA’])
headername (
builtins.str
) - rxx - With openmode == ‘w’, name of an existing header, for the new FA to use its geometry.Optional. Default is None.
openmode (
builtins.str
) - rxx - Opening mode.Values: set([‘append’, ‘r’, ‘read’, ‘w’, ‘a’, ‘write’])
Remap: dict(append = ‘a’, read = ‘r’, write = ‘w’,)
processtype (
builtins.str
) - rwx - With openmode == ‘w’, identifies the processus that produced the resource.Optional. Default is ‘analysis’.
validity (
epygram.base.FieldValidityList
) - rwx - With openmode == ‘w’, describes the temporal validity of the resource.Optional. Default is None.
Constructor. See its footprint for arguments.
- cdiden¶
With openmode == ‘w’, identifies the FA by a keyword, usually the model abbreviation (see the documentation above for more details).
- default_compression¶
Default compression for writing fields in resource (see the documentation above for more details).
- extract_subdomain(*args, **kwargs)¶
Extracts a subdomain from the FA resource, given its fid and the geometry to use.
- Parameters
pseudoname – must have syntax: ‘K*PARAMETER’, K being the kind of surface (S,P,H,V), * being a true star character, and PARAMETER being the name of the parameter requested, as named in FA.
geometry – is the geometry on which extract data. None to keep the geometry untouched.
vertical_coordinate – defines the requested vertical coordinate of the V2DField (cf. epygram.geometries.vertical_coordinates possible values).
interpolation –
defines the interpolation function used to compute the profile points locations from the fields grid:
if ‘nearest’, each horizontal point of the section is taken as the horizontal nearest neighboring gridpoint;
if ‘linear’ (default), each horizontal point of the section is computed with linear spline interpolation;
if ‘cubic’, each horizontal point of the section is computed with linear spline interpolation.
cheap_height – if True and vertical_coordinate among (‘altitude’, ‘height’), the computation of heights is done without taking hydrometeors into account (in R computation) nor NH Pressure departure (Non-Hydrostatic data). Computation therefore faster.
global_shift_center – for global lon/lat grids, shift the center by the requested angle (in degrees). Enables a [0,360] grid to be shifted to a [-180,180] grid, for instance (with -180 argument).
- extractprofile(*args, **kwargs)¶
Extracts a vertical profile from the FA resource, given its pseudoname and the geographic location (lon/lat) of the profile.
- Parameters
pseudoname – must have syntax: ‘K*PARAMETER’, K being the kind of surface (S,P,H,V), * being a true star character, and PARAMETER being the name of the parameter requested, as named in FA.
lon – the longitude of the desired point.
lat – the latitude of the desired point. If both None, extract a horizontally-averaged profile.
geometry – can replace lon/lat, geometry on which to extract data. If None, it is built from lon/lat.
vertical_coordinate – defines the requested vertical coordinate of the V1DField, as number of GRIB2 norm: http://apps.ecmwf.int/codes/grib/format/grib2/ctables/4/5, (cf. epygram.geometries.vertical_coordinates possible values).
interpolation –
defines the interpolation function used to compute the profile at requested lon/lat from the fields grid:
if ‘nearest’ (default), extracts profile at the horizontal nearest neighboring gridpoint;
if ‘linear’, computes profile with horizontal linear spline interpolation;
if ‘cubic’, computes profile with horizontal cubic spline interpolation.
cheap_height – if True and vertical_coordinate among (‘altitude’, ‘height’), the computation of heights is done without taking hydrometeors into account (in R computation) nor NH Pressure departure (Non-Hydrostatic data). Computation therefore faster.
external_distance – can be a dict containing the target point value and an external field on the same grid as self, to which the distance is computed within the 4 horizontally nearest points; e.g. {‘target_value’:4810, ‘external_field’:an_H2DField_with_same_geometry}. If so, the nearest point is selected with distance = abs(target_value - external_field.data)
- extractsection(*args, **kwargs)¶
Extracts a vertical section from the FA resource, given its pseudoname and the geographic (lon/lat) coordinates of its ends. The section is returned as a V2DField.
- Parameters
pseudoname – must have syntax: ‘K*PARAMETER’, K being the kind of surface (S,P,H,V), * being a true star character, and PARAMETER being the name of the parameter requested, as named in FA.
end1 – must be a tuple (lon, lat).
end2 – must be a tuple (lon, lat).
geometry – can replace end1/end2, geometry on which to extract data. If None, defaults to linearily spaced positions computed from points_number.
points_number – defines the total number of horizontal points of the section (including ends). If None, defaults to a number computed from the ends and the resolution.
resolution – defines the horizontal resolution to be given to the field. If None, defaults to the horizontal resolution of the field.
vertical_coordinate – defines the requested vertical coordinate of the V2DField aka typeOfFirstFixedSurface in GRIB2, (cf. epygram.geometries.vertical_coordinates possible values).
interpolation –
defines the interpolation function used to compute the profile points locations from the fields grid:
if ‘nearest’, each horizontal point of the section is taken as the horizontal nearest neighboring gridpoint;
if ‘linear’ (default), each horizontal point of the section is computed with linear spline interpolation;
if ‘cubic’, each horizontal point of the section is computed with linear spline interpolation.
cheap_height – if True and vertical_coordinate among (‘altitude’, ‘height’), the computation of heights is done without taking hydrometeors into account (in R computation) nor NH Pressure departure (Non-Hydrostatic data). Computation therefore faster.
global_shift_center – for global lon/lat grids, shift the center by the requested angle (in degrees). Enables a [0,360] grid to be shifted to a [-180,180] grid, for instance (with -180 argument).
- classmethod field_type(fieldname)[source]¶
Get field type, either ‘H2D’ or the meta-data types registered in cls.sfxflddesc If field is unknown, supposed to be a H2D.
- fieldencoding(*args, **kwargs)¶
Returns a dict containing info about how the field fieldname is encoded: spectralness and compression. Interface to ifsaux’ FANION. If update_fieldscompression, store compression info in attribute fieldscompression.
- filename¶
File name (absolute or relative) of the resource (see the documentation above for more details).
- find_fields_in_resource(seed=None, fieldtype=[], generic=False)[source]¶
Returns a list of the fields from resource whose name match the given seed.
- Parameters
seed – might be a regular expression, a list of regular expressions or None. If None (default), returns the list of all fields in resource.
fieldtype – optional, among (‘H2D’, ‘Misc’) or a list of these strings. If provided, filters out the fields not of the given types.
generic – if True, returns complete fid’s, union of {‘FORMATname’:fieldname} and the according generic fid of the fields.
- fmtdelayedopen¶
Opening of the resource delayed (not at time of construction) (see the documentation above for more details).
- format¶
Format of the resource (see the documentation above for more details).
- headername¶
With openmode == ‘w’, name of an existing header, for the new FA to use its geometry (see the documentation above for more details).
- listfields(**kwargs)[source]¶
Returns a list containing the FA identifiers of all the fields of the resource.
- open(geometry=None, spectral_geometry=None, validity=None, openmode=None)[source]¶
Opens a FA with ifsaux’ FAITOU, and initializes some attributes.
Actually, as FAITOU needs an existing header with ‘w’ openmode, opening file in ‘w’ openmode will require else an existing header to which the resource is linked, or to create a header from a geometry via _create_header_from_geometry() function. This explains the eventual need for geometry/spectral_geometry/validity in open() method. If neither headername nor geometry are available, resource is not opened: the open() will be called again at first writing of a field in resource.
- Parameters
geometry – optional, must be a
epygram.geometries.Geometry
(or heirs) instance.spectral_geometry – optional, must be a
epygram.geometries.SpectralGeometry
instance.validity – optional, must be a
epygram.base.FieldValidity
or aepygram.base.FieldValidityList
instance.openmode – optional, to open with a specific openmode, eventually different from the one specified at initialization.
- openmode¶
Opening mode (see the documentation above for more details).
- processtype¶
With openmode == ‘w’, identifies the processus that produced the resource (see the documentation above for more details).
- readfield(*args, **kwargs)¶
Reads one field, given its FA name, and returns a Field instance. Interface to Fortran routines from ‘ifsaux’.
- Parameters
fieldname – FA fieldname
getdata – if False, only metadata are read, the field do not contain data.
footprints_proxy_as_builder – if True, uses footprints.proxy to build fields.
- readfields(requestedfields=None, getdata=True)[source]¶
Returns a
epygram.base.FieldSet
containing requested fields read in the resource.- Parameters
requestedfields –
might be:
a regular expression (e.g. ‘S*WIND.[U,V].PHYS’)
a list of FA fields identifiers with regular expressions (e.g. [‘SURFTEMPERATURE’, ‘S0[10-20]WIND.?.PHYS’])
if not specified, interpretated as all fields that will be found in resource
getdata – optional, if False, only metadata are read, the fields do not contain data. Default is True.
- sortfields()[source]¶
Returns a sorted list of fields with regards to their name and nature, as a dict of lists.
- split_UV(fieldseed)[source]¶
Return two lists of fids corresponding respectively to U and V components of wind, given a fieldseed.
- validity¶
With openmode == ‘w’, describes the temporal validity of the resource (see the documentation above for more details).
- what(*args, **kwargs)¶
Writes in file a summary of the contents of the FA.
- Parameters
out – the output open file-like object.
details – ‘spectral’ if spectralness of fields is requested; ‘compression’ if information about fields compression is requested.
sortfields – True if the fields have to be sorted by type.
- writefield(field, compression=None)[source]¶
Write a field in the resource.
- Parameters
field – a
epygram.base.Field
instance orepygram.fields.H2DField
.compression – optional, a (possibly partial) dict containing parameters for field compression (in case of a
epygram.fields.H2DField
). Ex: {‘KNGRIB’: 2, ‘KDMOPL’: 5, ‘KPUILA’: 1, ‘KSTRON’: 10, ‘KNBPDG’: 24, ‘KNBCSP’: 24}
- writefields(fieldset, compression=None)[source]¶
Write the fields of the fieldset in the resource.
- Parameters
fieldset – must be a
epygram.base.FieldSet
instance.compression – must be a list of compression dicts (cf. writefield() method), of length equal to the length of the fieldset, and with the same order.