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.

Footprint:

dict(
    attr = dict(
        openmode = dict(
            access = 'rxx', 
            alias = set([]), 
            default = None, 
            info = 'Opening mode.', 
            optional = False, 
            outcast = set([]), 
            remap = dict(
                append = 'a', 
                read = 'r', 
                write = 'w',
            ), 
            values = set(['a', 'write', 'r', 'w', 'read', 'append']),
        ),
    ), 
    bind = [], 
    info = 'Not documented', 
    only = dict(), 
    priority = dict(
        level = footprints.priorities.PriorityLevel::DEFAULT,
    ),
)
find_fields_in_resource_by_generic_fid(handgrip)

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’.)

readfields(requestedfields, getdata=True)[source]

Returns a FieldSet containing requested fields read in the resource.

Args:

  • 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.
writefields(fieldset)[source]

Write the fields of the ‘fieldset’ in the resource; fieldset must be a FieldSet instance.

class epygram.base.Field(*args, **kw)[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) idetifies 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}}*.

Footprint:

dict(
    attr = dict(
        comment = dict(
            access = 'rwd', 
            alias = set([]), 
            default = None, 
            optional = True, 
            outcast = set([]), 
            remap = dict(), 
            type = str, 
            values = set([]),
        ), 
        data = dict(
            access = 'rxx', 
            alias = set([]), 
            default = None, 
            optional = True, 
            outcast = set([]), 
            remap = dict(), 
            values = set([]),
        ), 
        fid = dict(
            access = 'rwx', 
            alias = set([]), 
            default = None, 
            optional = False, 
            outcast = set([]), 
            remap = dict(), 
            type = footprints.stdtypes.FPDict, 
            values = set([]),
        ),
    ), 
    bind = [], 
    info = 'Not documented', 
    only = dict(), 
    priority = dict(
        level = footprints.priorities.PriorityLevel::DEFAULT,
    ),
)
clone(fid=None)

Returns a cloned field, optionally with a new fid given as a dict.

getdata()

Returns the field data. Generic, default method for inheriting classes that do not overwrite it.

max(**kwargs)

Returns the maximum value of data.

mean(**kwargs)

Returns the mean value of data.

min(**kwargs)

Returns the minimum value of data.

nonzero(**kwargs)

Returns the number of non-zero values (whose absolute value > config.epsilon).

operation(operation, operand=None)

Makes the requested operation on the field.

Implemented operation : ‘+’, ‘-‘, ‘*’, ‘/’, ‘normalize’, ‘ceil’, ‘exp’, ‘log’... and you can try with every other numpy function.

operation_with_other(operation, other)

Makes a field-with-other operation, among: (‘+’, ‘-‘, ‘*’, ‘/’).

quadmean(**kwargs)

Returns the quadratic mean of data.

scalar_operation(operation, scalar)

Makes a scalar operation on field:

operation being one of (‘+’, ‘-‘, ‘*’, ‘/’)

scalar being a float or int.

setdata(data)[source]

Sets or overwrites the field data as a numpy array. Mainly useful because a footprints attribute cannot be a numpy array...

setfid(fid)

Sets or overwrites the field fid given as a dict.

stats(**kwargs)

Computes some basic statistics on the field, as a dict containing: {‘min’, ‘max’, ‘mean’, ‘std’, ‘quadmean’, ‘nonzero’}.

Optional arguments can be passed, depending on the inheriting class, passed to getdata().

std(**kwargs)

Returns the standard deviation of data.

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.

append(field)[source]

Checks that field is a Field instance before appending it.

extend(fieldset)[source]

Checks that fieldset is a FieldSet instance before extending with it.

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 ?

Available filters, examples:

  • 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.

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==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)[source]

Bases: epygram.util.RecursiveObject

This class handles a uniq 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 to describe the kind of statistical process that runs over the cumulativeduration.

Constructor arguments: cf. set() method.

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)[source]

Sets validity and basis according to arguments. A consistency check is done if the three arguments are provided (which is useless anyway).

Args:

  • 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_process_on_duration(asGRIB2code=False)

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).

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, **kwargs)

Bases: epygram.util.RecursiveObject, list

This class handles a list of temporal validity.

cumulativeduration(one=True, **kwargs)

This method returns the cumulative duration of all the validities.

get(one=True, **kwargs)

Returns the date and time of all the validities.

getbasis(one=True, **kwargs)

Returns the date and time of origin (basis) of all the validities.

set(**kwargs)

Sets validity objects

statistical_process_on_duration(one=True, **kwargs)

This method returns the statistical process on duration of all the validities.

term(one=True, **kwargs)

This method returns the terms of all the validities

what(out=<open file '<stdout>', mode 'w' at 0x7f7b0e24c150>, cumulativeduration=True)

Writes in file a summary of the validity.

Args:

  • out: the output open file-like object (duck-typing: out.write() only is needed).
  • cumulativeduration: if False, not written.

Previous topic

epygram.util — Utilities

Next topic

epygram.containers — Containers

This Page