epygram.resources — Real and virtual resources handling

Module contains:

  • resource for data contained in file (FileResource).
  • other resources built on top of FileResource:
    • MultiValiditiesResource: join several resources to furnish fields with temporal evolution;
    • CombineLevelsResource: from a resource containing 2D fields on adjacent levels, emulates a resource that provide 3D fields
  • a proxy function to build such meta resources

class epygram.resources.open_and_close_resource(r)[source]

Bases: object

Context manager for automatically open/close resources.

Parameters:r – resource to open

epygram.resources.meta_resource(filenames_or_resources, openmode, rtype)[source]

Factory for meta resources, such as MultiValiditiesResource or CombineLevelsResource.

Parameters:
  • filenames_or_resources – can be either a filename or a list of, or a resource or a list of.
  • openmode – among ‘r’, ‘w’, ‘a’
  • rtype

    resource type, e.g.:

    • ‘MV’ for a MultiValiditiesResource,
    • ‘CL’ for a CombineLevelsResource
    • ‘MV+CL’ for a composition of both (should be similar to CL+MV)

class epygram.resources.FileResource(*args, **kwargs)[source]

Bases: epygram.base.Resource

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:

  • filename (str) - rxx - File name (absolute or relative) of the resource.
  • fmtdelayedopen (bool) - rxx - Opening of the resource delayed (not at time of construction).
    • Optional. Default is False.
  • format (str) - rxx - Format of the resource.
    • Optional. Default is None.
  • openmode (str) - rxx - Opening mode.
    • Values: set([‘a’, ‘write’, ‘r’, ‘w’, ‘read’, ‘append’])
    • Remap: dict(append = ‘a’, read = ‘r’, write = ‘w’,)
open(openmode=None)[source]

Opens the resource properly.

Parameters:openmode – to open with a specific openmode, eventually different from

the one specified at initialization.


class epygram.resources.MultiValiditiesResource(*args, **kwargs)[source]

Bases: epygram.base.Resource

Class implementing a MultiValiditiesResource.

Note

This class is managed by footprint.

  • info: Not documented
  • priority: PriorityLevel::DEFAULT (rank=1)

Automatic parameters from the footprint:

  • name (str) - rxx - Not documented, sorry.
    • Values: set([‘MultiValidities’])
  • openmode (str) - rxx - Opening mode.
    • Values: set([‘a’, ‘write’, ‘r’, ‘w’, ‘read’, ‘append’])
    • Remap: dict(append = ‘a’, read = ‘r’, write = ‘w’,)
  • resources (footprints.stdtypes.FPList) - rxx - List of resources to join.
close()[source]

Closes all resources.

extractprofile(*args, **kwargs)[source]

Extracts the profiles in the different resources and join the validities.

extractsection(*args, **kwargs)[source]

Extracts the sections in the different resources and join the validities.

find_fields_in_resource(*args, **kwargs)[source]

Call to find_fields_in_resource

listfields(*args, **kwargs)[source]

Call to listfields.

readfield(*args, **kwargs)[source]

Reads the field in the different resources and join the validities.

sortfields(*args, **kwargs)[source]

Call to sortfields

spectral_geometry

Returns the spectral_geometry

writefield(*args, **kwargs)[source]

Write fields.


class epygram.resources.CombineLevelsResource(*args, **kwargs)[source]

Bases: epygram.base.Resource

Class implementing a CombineLevelsResource.

Note

This class is managed by footprint.

  • info: Not documented
  • priority: PriorityLevel::DEFAULT (rank=1)

Automatic parameters from the footprint:

  • name (str) - rxx - Not documented, sorry.
    • Values: set([‘CombineLevels’])
  • openmode (str) - rxx - Opening mode.
    • Values: set([‘a’, ‘write’, ‘r’, ‘w’, ‘read’, ‘append’])
    • Remap: dict(append = ‘a’, read = ‘r’, write = ‘w’,)
  • resource (epygram.base.Resource) - rxx - Low level resource
  • virtual (bool) - rxx - Must readfield return a virtual field
    • Optional. Default is False.
close()[source]

Closes the low level resource.

extractprofile(*args, **kwargs)[source]

Extracts profiles.

extractsection(*args, **kwargs)[source]

Extracts sections.

find_fields_in_resource(seed=None, generic=False)[source]

Returns a list of the fields from resource whose name match the given seed.

Parameters:
  • seed – might be a ‘handgrip’, i.e. a dict where you can store all requested keys, e.g. {‘shortName’:’t’, ‘indicatorOfTypeOfLevel’:’pl’, ‘level’:850}, a list of handgrips or None. If None (default), returns the list of all fields in resource.
  • generic – if True, returns a list of tuples (fid, fid) of the fields (for mimetism with other formats).
listfields(onlykey=None, select=None, complete=False)[source]

Lists the available fields.

open()[source]

Opens the low level resource

readfield(handgrip, getdata=True)[source]

Read the field in the low level resource and join the levels.

Parameters:
  • handgrip – identification of the field
  • getdata – if False, do not read data but only metadata
readfields(handgrip, getdata=True)[source]

Read the field in the low level resource and join the levels.

Parameters:
  • handgrip – identification of the field
  • getdata – if False, do not read data but only metadata
sortfields(sortingkey, onlykey=None)[source]

Returns a sorted list of fields with regards to the given sortingkey of their fid, as a dict of lists.

Parameters:
  • sortingkey – sorting key
  • onlykey – can be specified as a string or a tuple of strings, so that only specified keys of the fid will returned.
spectral_geometry

Returns the spectral_geometry

writefield(*args, **kwargs)[source]

Write fields.