smif.metadata package¶
Metadata describes the details of data structures to be exchanged between models.
Specprovides metadata to describe multi-dimensional variables, with an API modelled on xarrayCoordinateslabel each dimension in aSpec. The elements of a set ofCoordinatescorrespond to ElementSets under the OGC® Open Modelling Interface (OpenMI) Interface Standard
- class smif.metadata.Coordinates(name, elements)[source]¶
Bases:
objectCoordinates provide the labels to index a dimension, along with metadata that may be useful to describe, visualise or convert between dimensions.
Coordinate element names are used to label each position along a finite dimension.
A dict mapping dimension name to list of coordinate elements can be passed to a
Spec(orxarray.DataArray) as coords.- Parameters:
- Raises:
ValueError – If the list of elements is empty, or infinite
KeyError – If the elements are not a list of simple data types or a list of dicts with a ‘name’ key
- property dim¶
Dim (dimension) is an alias for Coordinates.name
- property elements¶
Elements are a list of dicts with at least a ‘name’ key
Coordinate elements should not be changed.
- property ids¶
Element ids is a list of coordinate identifiers
- property names¶
Names is an alias for Coordinates.ids
- class smif.metadata.RelativeTimestep(*values)[source]¶
Bases:
EnumSpecify current, previous or base year timestep
- ALL = 'ALL'¶
- BASE = 'BASE'¶
- CURRENT = 'CURRENT'¶
- PREVIOUS = 'PREVIOUS'¶
- class smif.metadata.Spec(name=None, dims=None, coords=None, dtype=None, abs_range=None, exp_range=None, unit=None, description=None)[source]¶
Bases:
objectN-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 anumpy.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.- coords¶
Dimension coordinate labels
- Type:
- 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.dtypeabs_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
- property abs_range¶
The absolute range of data values that this spec describes.
- property coords¶
Coordinate labels for each dimension.
- property description¶
A human-friendly description
- property dims¶
Names for each dimension
- property dtype¶
The dtype of the data that this spec describes.
- property exp_range¶
The expected range of data values that this spec describes.
- property name¶
The name of the data that this spec describes.
- property ndim¶
The number of dimensions of the data that this spec describes.
- property shape¶
Tuple of dimension sizes. The shape of the data that this spec describes.
- property unit¶
The unit for all data points.
Submodules¶
smif.metadata.coordinates module¶
Each dimension of a multi-dimensional dataset can be indexed by a set of coordinates.
Dimensions might be represented as Euclidean coordinates over a grid:
>>> x = Coordinates('x', range(0, 100))
>>> y = Coordinates('y', range(0, 100))
A subset of Local Authority Districts in England would be a region-based spatial dimension:
>>> local_authority_districts = Coordinates('LADs', ['E07000128', 'E07000180'])
The hours of an average annual day would be a temporal dimension:
>>> hours = Coordinates('daily_hours', [
... {'name': 0, 'interval': [['PT0H', 'PT1H']]}
... {'name': 1, 'interval': [['PT1H', 'PT2H']]}
... {'name': 2, 'interval': [['PT2H', 'PT3H']]}
... ])
The economic sectors from the International Standard Industrial Classification of All Economic Activities (ISIC), revision 4 would be a categorical dimension:
>>> economic_sector = Coordinates('ISICrev4', [
... {'name': 'A', 'desc': 'Agriculture, forestry and fishing'},
... {'name': 'B', 'desc': 'Mining and quarrying'},
... {'name': 'C', 'desc': 'Manufacturing'},
... {'name': 'D', 'desc': 'Electricity, gas, steam and air conditioning supply'}
... ])
- class smif.metadata.coordinates.Coordinates(name, elements)[source]¶
Bases:
objectCoordinates provide the labels to index a dimension, along with metadata that may be useful to describe, visualise or convert between dimensions.
Coordinate element names are used to label each position along a finite dimension.
A dict mapping dimension name to list of coordinate elements can be passed to a
Spec(orxarray.DataArray) as coords.- Parameters:
- Raises:
ValueError – If the list of elements is empty, or infinite
KeyError – If the elements are not a list of simple data types or a list of dicts with a ‘name’ key
- property dim¶
Dim (dimension) is an alias for Coordinates.name
- property elements¶
Elements are a list of dicts with at least a ‘name’ key
Coordinate elements should not be changed.
- property ids¶
Element ids is a list of coordinate identifiers
- property names¶
Names is an alias for Coordinates.ids
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
- 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:
objectN-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 anumpy.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.- coords¶
Dimension coordinate labels
- Type:
- 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.dtypeabs_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
- property abs_range¶
The absolute range of data values that this spec describes.
- property coords¶
Coordinate labels for each dimension.
- property description¶
A human-friendly description
- property dims¶
Names for each dimension
- property dtype¶
The dtype of the data that this spec describes.
- property exp_range¶
The expected range of data values that this spec describes.
- property name¶
The name of the data that this spec describes.
- property ndim¶
The number of dimensions of the data that this spec describes.
- property shape¶
Tuple of dimension sizes. The shape of the data that this spec describes.
- property unit¶
The unit for all data points.
smif.metadata.timestep module¶
smif runs models over a series of planning timesteps.
RelativeTimestep is used to specify one timestep relative to
another in the context of the set of planning timesteps.
For example, if a model needs to know its own outputs from a previous year, we can specify the self-dependency using a relative timestep.