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 = False, flatten_horizontal_grids = False, reverse_Yaxis = False, write_lonlat_grid = True,).

  • 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 ‘netCDF’.

    • Values: set([‘netCDF’])

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

behave(**kwargs)[source]

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

behaviour

Describes how fields are defined in resource (see the documentation above for more details).

close()[source]

Closes a netCDF.

filename

File name (absolute or relative) of the resource (see the documentation above for more details).

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.

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

ncdump(out)[source]

Outputs dimensions, variables and their attribute information. The information is similar to that of NCAR’s ncdump utility.

Parameters

out – IO where nc_attrs, nc_dims, and nc_vars are printed

nc_attrslist

A Python list of the NetCDF file global attributes

nc_dimslist

A Python list of the NetCDF file dimensions

nc_varslist

A Python list of the NetCDF file variables

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.

openmode

Opening mode (see the documentation above for more details).

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=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, **_)[source]

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

writefield(field, compression=4, metadata=None, adhoc_behaviour=None, fill_value=- 999999.9)[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, …).