smif.metadata.spec module

Data is typically multi-dimensional. Spec is used to describe each dataset which is supplied to - or output from - each Model in a CompositeModel

Summary

Data:

Spec N-dimensional metadata.

Reference

class smif.metadata.spec.Spec(name=None, dims=None, coords=None, dtype=None, abs_range=None, exp_range=None, unit=None, description=None)[source]

Bases: object

N-dimensional metadata.

Spec labels each dimension with coordinates and enforces data type, units and absolute and expected ranges.

The API here is modelled on xarray.DataArray: dtype and shape describe a numpy.ndarray; dims and coords follow the xarray conventions for labelled axes; and unit, abs_range and exp_range are introduced as supplementary metadata to help validate connections between models.

name

The name of the data that this spec describes

Type:str
description

A human-friendly description

Type:str
dtype

Data type for data values

Type:str
abs_range

Absolute range of data values

Type:tuple
exp_range

Expected range of data values

Type:tuple
shape

Tuple of dimension sizes

Type:tuple[int]
ndim

Number of dimensions

Type:int
dims

Dimension names

Type:list[str]
coords

Dimension coordinate labels

Type:list[Coordinates]
unit

Units of data values

Type:str
Parameters:
  • name (str, optional) – Name to identifiy the variable described (typically an input, output or parameter)
  • description (str, optional) – Short description
  • dims (list[str], optional) – List of dimension names, must be provided if coords is a dict
  • coords (list[Coordinates] or dict[str, list], optional) – A list of :class`Coordinates` or a dict mapping each dimension name to a list of names which label that dimension.
  • dtype (str) – String suitable for contructing a simple numpy.dtype
  • abs_range (tuple, optional) – (min, max) absolute range for numeric values - can be used to raise errors
  • exp_range (tuple, optional) – (min, max) expected range for numeric values - can be used to raise warnings
  • unit (str, optional) – Unit to be used for data values
classmethod from_dict(data_provided)[source]

Create a Spec from a dict representation

as_dict()[source]

Serialise to dict representation

name

The name of the data that this spec describes.

description

A human-friendly description

dtype

The dtype of the data that this spec describes.

abs_range

The absolute range of data values that this spec describes.

exp_range

The expected range of data values that this spec describes.

shape

Tuple of dimension sizes. The shape of the data that this spec describes.

ndim

The number of dimensions of the data that this spec describes.

dims

Names for each dimension

coords

Coordinate labels for each dimension.

dim_coords(dim: str)[source]

Coordinates for a given dimension

dim_names(dim: str)[source]

Names of each coordinate in a given dimension

dim_elements(dim: str)[source]

Elements of each coordinate in a given dimension

unit

The unit for all data points.