cfdm.NetCDFArray


class cfdm.NetCDFArray(filename=None, ncvar=None, varid=None, group=None, dtype=None, ndim=None, shape=None, size=None, mask=True)[source]

Bases: cfdm.data.abstract.array.Array

An underlying array stored in a netCDF file.

New in version (cfdm): 1.7.0

Initialisation

Parameters
filename: str

The name of the netCDF file containing the array.

ncvar: str, optional

The name of the netCDF variable containing the array. Required unless varid is set.

varid: int, optional

The UNIDATA netCDF interface ID of the variable containing the array. Required if ncvar is not set, ignored if ncvar is set.

group: None or sequence of str, optional

Specify the netCDF4 group to which the netCDF variable belongs. By default, or if group is None or an empty sequence, it assumed to be in the root group. The last element in the sequence is the name of the group in which the variable lies, with other elements naming any parent groups (excluding the root group).

Parameter example:

To specify that a variable is in the root group: group=() or group=None

Parameter example:

To specify that a variable is in the group ‘/forecasts’: group=['forecasts']

Parameter example:

To specify that a variable is in the group ‘/forecasts/model2’: group=['forecasts', 'model2']

New in version (cfdm): 1.8.6.0

dtype: numpy.dtype

The data type of the array in the netCDF file. May be None if the numpy data-type is not known (which can be the case for netCDF string types, for example).

shape: tuple

The array dimension sizes in the netCDF file.

size: int

Number of elements in the array in the netCDF file.

ndim: int

The number of array dimensions in the netCDF file.

mask: bool

If False then do not mask by convention when reading data from disk. By default data is masked by convention.

A netCDF array is masked depending on the values of any of the netCDF variable attributes valid_min, valid_max, valid_range, _FillValue and missing_value.

New in version (cfdm): 1.8.2

Examples:

>>> import netCDF4
>>> nc = netCDF4.Dataset('file.nc', 'r')
>>> v = nc.variable['tas']
>>> a = NetCDFFileArray(filename='file.nc', ncvar='tas',
...                     group=['forecast'], dtype=v.dtype,
...                     ndim=v.ndim, shape=v.shape, size=v.size)

Inspection

Methods

get_ncvar

The name of the netCDF variable containing the array.

get_varid

The UNIDATA netCDF interface ID of the array’s variable.

get_compression_type

Returns the array’s compression type.

get_subspace

Return a subspace, defined by indices, of a numpy array.

Attributes

array

Return an independent numpy array containing the data.

dtype

Data-type of the data elements.

ndim

Number of array dimensions.

shape

Tuple of array dimension sizes.

size

Number of elements in the array.

File

Methods

close

Close the netCDF4.Dataset for the file containing the data.

open

Returns an open netCDF4.Dataset for the array’s file.

get_filename

The name of the netCDF file containing the array.

get_group

The netCDF4 group structure of the netCDF variable.

get_mask

The mask of the data array.

Miscellaneous

copy

Return a deep copy of the array.

to_memory

Bring an array on disk into memory and retain it there.

Special

__getitem__

Returns a subspace of the array as a numpy array.

Docstring substitutions

Methods

_docstring_special_substitutions

Return the special docstring substitutions.

_docstring_substitutions

Returns the substitutions that apply to methods of the class.

_docstring_package_depth

Returns the class {{package}} substitutions package depth.

_docstring_method_exclusions

Returns method names excluded in the class substitutions.