epygram.base
— Basic, non-specific classes¶
Contains some base classes of epygram.
- class epygram.base.Resource(*args, **kwargs)[source]¶
Bases:
epygram.util.RecursiveObject
,footprints.FootprintBase
Generic abstract class implementing a Resource.
Note
This class is managed by footprint.
info: Not documented
priority: PriorityLevel::DEFAULT (rank=1)
Automatic parameters from the footprint:
openmode (
builtins.str
) - rxx - Opening mode.Values: set([‘append’, ‘r’, ‘read’, ‘w’, ‘a’, ‘write’])
Remap: dict(append = ‘a’, read = ‘r’, write = ‘w’,)
Constructor. See its footprint for arguments.
- find_fields_in_resource_by_generic_fid(handgrip)[source]¶
Find in resource the fields whose generic fid (if the resource is able to give one) matches the handgrip.
- listfields(**kwargs)[source]¶
Returns a list containing the identifiers (in the resource format) of all the fields of the resource.
(Generic wrapper with buffering if openmode == ‘r’.)
- openmode¶
Opening mode (see the documentation above for more details).
- readfields(requestedfields, getdata=True)[source]¶
Returns a
FieldSet
containing requested fields read in the resource.- Parameters
requestedfields – a field identifier of the resource format, or a list of.
getdata – optional, if False, only metadata are read, the fields do not contain data. Default is True.
- class epygram.base.Field(*args, **kwargs)[source]¶
Bases:
epygram.util.RecursiveObject
,footprints.FootprintBase
Generic abstract class implementing a Field, composed of an identifier and a data.
The field identifier fid identifies a field with a set of keys. Each key (named after the format name) identifies the field for a given format. A specific key ‘generic’ is a GRIB2-like description. E.g. *{‘FA’:’SURFTEMPERATURE’,
‘generic’:{‘typeOfFirstFixedSurface’:1, ‘discipline’:2, ‘parameterCategory’:3, ‘parameterNumber’:18}}*.
Note
This class is managed by footprint.
info: Not documented
priority: PriorityLevel::DEFAULT (rank=1)
Automatic parameters from the footprint:
comment (
builtins.str
) - rwd - Not documented, sorry.Optional. Default is None.
fid (
footprints.stdtypes.FPDict
) - rwx - Not documented, sorry.misc_metadata (
footprints.stdtypes.FPDict
) - rwd - Not documented, sorry.Optional. Default is FPDict::<<as_dict:: dict()>>.
units (
builtins.str
) - rwd - Not documented, sorry.Optional. Default is ‘’.
Constructor. See its footprint for arguments.
- comment¶
(see the documentation above for more details).
- compare_to(other)[source]¶
Compare a field to another one, with several criteria:
bias: average of errors distribution
std: standard deviation of errors distribution
errmax: maximum absolute error
common_mask: indicate whether fields have the same mask or not; beware that above statistics apply only to commonly unmasked data
:return ({bias, std, errmax}, common_mask)
- correlation(other, commonmask=False, mask_outside=1e+19)[source]¶
Compute a correlation coefficient R to another field.
- Parameters
commonmask – if True, compute distance on the subset of point that are not masked for any of the two fields.
mask_outside – if None, mask is empty; else, mask data outside +/- this value
- property data¶
Accessor to the field data.
- fid¶
(see the documentation above for more details).
- getdata()[source]¶
Returns the field data. Generic, default method for inheriting classes that do not overwrite it.
- misc_metadata¶
(see the documentation above for more details).
- nonzero(**kwargs)[source]¶
Returns the number of non-zero values (whose absolute value > config.epsilon).
- normalized_comparison(ref)[source]¶
Compare field to a reference, with prior normalization (by reference magnitude) of both fields. Hence the figures of comparison can be interpretated as percentages.
- operation(operation, operand=None)[source]¶
Makes the requested operation on the field.
- Parameters
operation – any of ‘+’, ‘-’, ‘*’, ‘/’, or ‘normalize’, ‘ceil’, ‘exp’, ‘log’… and you can try with every other numpy function.
operand – operand for the 4 basic operations, may be a scalar or another field with according geometry.
- operation_with_other(operation, other)[source]¶
Makes an in-place operation with another field.
- Parameters
operation – among (‘+’, ‘-’, ‘*’, ‘/’)
other – another field, with according dimensions
- scalar_operation(operation, scalar)[source]¶
Makes an in-place scalar operation on field.
- Parameters
operation – among (‘+’, ‘-’, ‘*’, ‘/’)
scalar – a float or int.
- stats(**kwargs)[source]¶
Computes some basic statistics on the field, as a dict containing: {‘min’, ‘max’, ‘mean’, ‘std’, ‘quadmean’, ‘nonzero’}.
See each of these methods for details.
Optional arguments can be passed, depending on the inheriting class, passed to getdata().
- units¶
(see the documentation above for more details).
- class epygram.base.FieldSet(fields=())[source]¶
Bases:
epygram.util.RecursiveObject
,list
Handles a set of Fields, in the manner of Python’s builtin list, with some extra features, especially ensuring its components all are Fields.
Constructor optional argument fields has to be either a
Field
or an iterable of.Constructor. Checks that optional ‘fields’ argument is actually iterable and contains Field instances, or is a single Field.
- filter(by, criteria)[source]¶
Not Implemented Yet.
Returns a new FieldSet filtered according to criteria specified in argument.
Args:
by: the kind of filter; on what to filter ?
criteria: how to filter on that ?
Examples of filters:
by=’id’, criteria={typefmt:identifier} will return only fields whose id[typefmt] match value…
- index(fid)[source]¶
Returns the index of the first field of the FieldSet whose fid matches fid, fid being a dict.
- insert(position, field)[source]¶
Checks that field is a
Field
instance before inserting it at the position.
- listfields(fidkey=None)[source]¶
Returns a list of the identifiers of the FieldSet. If fidkey is supplied, the list contains only fid[*fidkey*], and not whole fid.
- remove(fid)[source]¶
Removes from the FieldSet the first field whose fid matches fid, fid being a dict.
- sort(attribute, key=None, reverse=False)[source]¶
Sorts the fields of the FieldSet by the increasing criterion.
If attribute is a string, sorting will be done according to field.attribute[key] or field.attribute (if key is None).
If attribute is a list [a1, a2…], sorting will be done according to field.a1.a2[key] or field.a1.a2 (if key==None).
If reverse is True, sorts by decreasing order.
- class epygram.base.FieldValidity(date_time=None, basis=None, term=None, cumulativeduration=None, statistical_process_on_duration=None, statistical_time_increment=None)[source]¶
Bases:
epygram.util.RecursiveObject
This class handles a unique temporal validity for a meteorological field: its date and time of validity (date_time), as well as the validity of its origin (basis, i.e. for a forecast field for instance, the beginning of the forecast) and its term.
An additional optional cumulativeduration parameter can define the duration for which cumulative fields (e.g. precipitation) are valid.
If such, optional statistical_process_on_duration can be supplied as a string or an int (cf. GRIB2 table typeOfStatisticalProcessing) to describe the kind of statistical process that runs over the cumulativeduration.
Constructor arguments: cf. set() method.
Constructor.
- Parameters
date_time – has to be of type datetime.datetime;
basis – has to be of type datetime.datetime;
term – has to be of type datetime.timedelta;
cumulativeduration – has to be of type datetime.timedelta;
statistical_process_on_duration – kind of statistical process that runs over the cumulative duration.
statistical_time_increment – time step over used for statistical process.
- cumulativeduration(fmt=None)[source]¶
This method returns the cumulative duration, i.e. the duration for which cumulative fields (e.g. precipitation) are valid.
By default, it is returned as a
datetime.timedelta
; otherwise, fmt argument can specify the desired return format.Coded versions of fmt: ‘IntHours’, ‘IntSeconds’, and that’s all for now…
- get(fmt=None)[source]¶
Returns the date and time of validity.
By default, as a
datetime.datetime
; otherwise, fmt argument can specify the desired return format.Coded versions of fmt: ‘IntStr’ (e.g. ‘20140731104812’ = 2014 july 31th at 10h, 48m, 12s). And that’s all for now…
- getbasis(fmt=None)[source]¶
Returns the date and time of origin (basis).
By default, as a
datetime.datetime
; otherwise, fmt argument can specify the desired return format.Coded versions of fmt: ‘IntStr’ (e.g. ‘20140731104812’ = 2014 july 31th at 10h, 48m, 12s). And that’s all for now…
- set(date_time=None, basis=None, term=None, cumulativeduration=None, statistical_process_on_duration=None, statistical_time_increment=None)[source]¶
Sets validity and basis according to arguments. A consistency check is done if the three arguments are provided (which is useless anyway).
Args:
- Parameters
date_time – has to be of type
datetime.datetime
basis – has to be of type
datetime.datetime
term – has to be of type
datetime.timedelta
cumulativeduration – has to be of type
datetime.timedelta
statistical_process_on_duration – kind of statistical process that runs over the cumulative duration. Cf. GRIB2 typeOfStatisticalProcessing
statistical_time_increment – time step over used for statistical process.
- statistical_process_on_duration(asGRIB2code=False)[source]¶
If the field describes a cumulative process over a cumulativeduration, returns the kind of statistical process that runs over the duration.
If asGRIB2code, returned as a GRIB2 code (cf. GRIB2 table 4.10).
- statistical_time_increment(fmt=None)[source]¶
This method returns the statistical_time_increment, i.e. the time step used for statistical process over cumulative duration.
By default, it is returned as a
datetime.timedelta
; otherwise, fmt argument can specify the desired return format.Coded versions of fmt: ‘IntHours’, ‘IntSeconds’, and that’s all for now…
- term(fmt=None)[source]¶
This method returns the term as the difference between date and time of validity and basis.
By default, it is returned as a
datetime.timedelta
; otherwise, fmt argument can specify the desired return format.Coded versions of fmt: ‘IntHours’, ‘IntSeconds’, and that’s all for now…
- class epygram.base.FieldValidityList(validity_instance=None, length=1, **kwargs)[source]¶
Bases:
epygram.util.RecursiveObject
,list
This class handles a list of temporal validity.
Constructor.
validity_instance, if given is an instance of FieldValidity
length, to build a series of validities from either the
validity_instance or from an uninitialized one. - other kwargs: same as
FieldValidity
constructor.- cumulativeduration(one=True, **kwargs)[source]¶
This method returns the cumulative duration of all the validities.
- getbasis(one=True, **kwargs)[source]¶
Returns the date and time of origin (basis) of all the validities.
- statistical_process_on_duration(one=True, **kwargs)[source]¶
This method returns the statistical process on duration of all the validities.