iris.fileformats.cf.dataset#
The format-agnostic description of a CF-conforming array store.
API reference |
Tags: topic_load_save
CFDataset and CFDatasetVariable are what the rest of the CF
layer is written against. They are deliberately small: only what the
CFVariable classes, the CF loader and the CF
saver actually need, with one implementation per storage format.
The property attributes is the only route to a CF attribute, and every
storage property is a named, typed member.
- class iris.fileformats.cf.dataset.CFDataset[source]#
Bases:
ABCA CF-conforming array store, open for reading or writing.
- __exit__(*exc_info)[source]#
Close this dataset on leaving the context, whatever happened in it.
- Return type:
None
- abstract property attributes: MutableMapping#
The store’s global attributes.
- abstract create_dimension(name, size)[source]#
Declare a dimension of the given length.
size=Nonerequests an unlimited dimension. A store with no such concept raisesNotImplementedError.
- abstract create_variable(name, dtype, dimensions=(), *, fill_value=None, **storage_settings)[source]#
Create and return a new variable.
**storage_settingsis storage-specific:zlib,complevelandchunksizesfor netCDF;compressors,chunksandshardsfor Zarr.- Parameters:
name (str)
- Return type:
- abstract finalise()[source]#
Perform the store’s one-shot completion step, after every write.
Deliberately not part of
close(): a worker that writes one region of a store must close its handle without performing a completion step that only one process may perform.- Return type:
None
- abstract property format: str#
The concrete format of this dataset.
Examples:
NETCDF4,NETCDF3_CLASSIC,ZARR_V2orZARR_V3.What the loader, the saver and
LOAD_PROBLEMSsay when they have to name the format. Reconstructing it from the implementation class would be the type test this interface exists to forbid.
- abstract property storage_settings: Mapping#
The store-wide settings this store holds, in the backend’s spelling.
- abstract supports_dtype(dtype)[source]#
Whether this store can hold a variable of this dtype.
The capability question the saver asks before it narrows an integer type. Asking it of the store, rather than testing the format, is what keeps the saver free of format names.
- Parameters:
dtype (
numpy.dtype) – The dtype a variable would be created with.- Return type:
- class iris.fileformats.cf.dataset.CFDatasetVariable[source]#
Bases:
ABCOne named array in a CF-conforming dataset.
- abstract __setitem__(keys, values)[source]#
Write
valuesinto the indexed portion of the variable.- Return type:
None
- abstract property attributes: MutableMapping#
The variable’s CF attributes, materialised once at construction.
- abstract property chunking: tuple | None#
The variable’s storage chunk shape, or
Nonewhen unchunked.
- deprecated_netcdf_member(name)[source]#
Return a netCDF4-only member of the object backing this variable.
The one-release compatibility route for code that reached netCDF4 API through a
CFVariable. A store with no backing netCDF4 object raisesAttributeError.
- abstract property dtype: dtype#
A
numpy.dtype, orstrfor a variable-length string.
- abstract property format: str#
The concrete format of the dataset holding this variable.
Repeated here from the dataset so that a variable can answer for itself, as
locationis. For messages and diagnostics only: generic code asks for a capability, never for a format.
- abstract read_data(chunking_policy)[source]#
Return this variable’s data, lazily where appropriate.
The one route by which the CF loader obtains arrays, so a new storage format mainly needs a new implementation of this method. An implementation is expected to share the CF-layer chunking helpers in
iris.fileformats.cf.loader-_get_actual_dtypefor a lazy result’s dtype and_LAZYVAR_MIN_BYTESfor the small-array cutoff - asNetCDFDatasetVariabledoes, rather than reinventing them. Read_LAZYVAR_MIN_BYTESthrough the module object (loader._LAZYVAR_MIN_BYTES), not byfrom ... import _LAZYVAR_MIN_BYTES, so that tests can patch the cutoff.chunking_policyis called with no arguments and returns the(chunks, dims_fixed)pair for a lazy result. Call it only once the result is known to be lazy, otherwise it may raise. Underfrom_file()it raises for a variable the store has not chunked, and we want to avoid this when a variable is small enough to read whole.
- abstract property storage_settings: Mapping#
The storage settings this variable holds, in the backend’s spelling.
zlib,complevel,chunksizesfor netCDF;chunks,shards,compressors,filters,serializer,zarr_formatfor Zarr. Readable, never interpreted: no generic code may branch on a key. The typed, guaranteed-present member ischunking.
- class iris.fileformats.cf.dataset.TrackedAttributes(source, *, ignored=())[source]#
Bases:
MutableMappingA variable’s attributes, recording which of them have been looked up.
Single-key lookups record:
__getitem__(),get()and__contains__(). Bulk access does not: iteration,keys(),values(),items()andlen()leave the record alone.untrackedreads a single key without recording it.Wrap
source, treating anyignoredname it holds as already read.- Parameters:
source (MutableMapping)
- __delitem__(key)[source]#
Remove
key, and any record of it having been read.- Parameters:
key (str)
- Return type:
None
- clear() None. Remove all items from D.#
- get(k[, d]) D[k] if k in D, else d. d defaults to None.#
- pop(k[, d]) v, remove specified key and return the corresponding#
value. If key is not found, d is returned if given, otherwise KeyError is raised.
- popitem() (k, v), remove and return some (key, value) pair#
as a 2-tuple; but raise KeyError if D is empty.
- setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D#
- update([E, ]**F) None. Update D from mapping/iterable E and F.#
- If E present and has a .keys() method, does:
for k in E.keys(): D[k] = E[k]
- If E present and lacks .keys() method, does:
for (k, v) in E: D[k] = v
- In either case, this is followed by:
for k, v in F.items(): D[k] = v