epygram.formats.netCDF — Interface-Class to the netCDF format

Contains classes for netCDF4 resource.

class epygram.formats.netCDF.netCDF(*args, **kwargs)[source]

Bases: epygram.resources.FileResource.FileResource

Class implementing all specificities for netCDF (4) resource format.

Note

This class is managed by footprint.

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

Automatic parameters from the footprint:

  • behaviour (footprints.stdtypes.FPDict) - rxx - Describes how fields are defined in resource.
    • Optional. Default is dict(H1D_is_H2D_unstructured = True, flatten_horizontal_grids = False, reverse_Yaxis = False, write_lonlat_grid = True,).
  • 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 ‘netCDF’.
    • Values: set([‘netCDF’])
  • openmode (str) - rxx - Opening mode.
    • Values: set([‘a’, ‘write’, ‘r’, ‘w’, ‘read’, ‘append’])
    • Remap: dict(append = ‘a’, read = ‘r’, write = ‘w’,)
behave(**kwargs)[source]

Set-up the given arguments in self.behaviour, for the purpose of building fields from netCDF.

close()[source]

Closes a netCDF.

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 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.
ncinfo_field(*args, **kwargs)

Get info about the field (dimensions and meta-data of the netCDF variable).

Parameters:fid – netCDF field identifier
open(openmode=None)[source]

Opens a netCDF and initializes some attributes.

Parameters:openmode – optional, to open with a specific openmode, eventually different from the one specified at initialization.
readfield(*args, **kwargs)

Reads one field, given its netCDF name, and returns a Field instance.

Parameters:
  • fid – netCDF field identifier
  • getdata – if False, only metadata are read, the field do not contain data.
  • only – to specify indexes [0 ... n-1] of specific dimensions, e.g. {‘time’:5,} to select only the 6th term of time dimension.
  • adhoc_behaviour – to specify “on the fly” a behaviour (usual dimensions or grids, ...).
set_default_global_attributes()[source]

Set default global attributes (those from config.netCDF_default_global_attributes).

set_global_attributes(**attributes)[source]

Set the given global attributes.

variables_number()[source]

Return the number of variables in resource.

what(out=<open file '<stdout>', mode 'w'>, **_)[source]

Writes in file a summary of the contents of the GRIB.

writefield(field, compression=4, metadata=None, adhoc_behaviour=None)[source]

Write a field in resource.

Parameters:field – the Field object to write
:param compression ranges from 1 (low compression, fast writing)
to 9 (high compression, slow writing). 0 is no compression.
Parameters:
  • metadata – dict, can be filled by any meta-data, that will be stored as attribute of the netCDF variable.
  • adhoc_behaviour – to specify “on the fly” a behaviour (usual dimensions or grids, ...).