Component

class konrad.component.Component(*args, **kwargs)[source]

Base class for all model components.

The class implements a light-weight “book-keeping” of all attributes and items that are stored in an instance. This allows components to be conveniently stored into netCDF files.

Example implementation of a model component:

>>> class FancyComponent(Component):
...     def __init__(self):
...         self.attribute = 'foo'
...         self['variable'] = (('dimension',), [42,])
...         self.coords = {'dimension': [0]}

Usage of the implemented auxiliary variables:

>>> component = FancyComponent()
>>> component.attrs
{'attribute': 'foo'}
>>> component.data_vars
{'variable': (('dimension',), [42])}
__init__()

Methods

__init__()

create_variable(name[, data, dims])

Create a variable in the model component.

from_netcdf(ncfile[, timestep])

Load a model component from a netCDF file.

get(variable[, default, keepdims])

Get values of a given variable.

hash_attributes()

Create a hash from all hashable component attributes.

set(variable, value)

Set the values of a variable.

to_dataset()

Convert model component into an xarray.Dataset.

Attributes

attrs

Dictionary containing all attributes.

data_vars

Dictionary containing all data variables and their dimensions.

netcdf_subgroups

Define subgroups used when storing to netCDF file.