xso.component

Module Contents

Functions

_create_variables_dict(process_cls)

Get all phydra variables declared in a component.

_convert_2_xsimlabvar(var[, intent, var_dims, ...])

Converts XSO variables to xarray-simlab variables to be used in the model backend.

_make_xso_variable(label, variable)

Checks for type of variable defined and calls _convert_2_xsimlabvar function

_make_xso_parameter(label, variable)

Checks for type of variable defined and calls _convert_2_xsimlabvar function

_make_xso_forcing(label, variable)

Checks for type of variable defined and calls _convert_2_xsimlabvar function

_make_xso_flux(label, variable)

Checks for type of variable defined and calls _convert_2_xsimlabvar function

_make_xso_index(label, variable)

Checks for type of variable defined and calls _convert_2_xsimlabvar function

_create_xsimlab_var_dict(cls_vars)

Parses through attributes defined in xso.component decorated class

_create_forcing_dict(cls, var_dict)

Parses var_dict and extracts forcing setup function

_create_index_dict(cls, var_dict)

Parses var_dict and extracts index setup function

_initialize_process_vars(cls, vars_dict)

Parses vars_dict of xso.component decorated class, and

_create_flux_inputargs_dict(cls, vars_dict)

Creates a dictionary to parse the input arguments to a flux function.

_initialize_fluxes(cls, vars_dict)

Parses flux variables and methods in xso.component decorated class

_initialize_forcings(cls, forcing_dict)

Parses xso.forcing variables and methods defined in xso.component decorated class

_initialize_indexes(cls, index_dict)

Initializes xso.index variables defined in xso.component decorated class.

_get_init_stage(vars_dict)

Returns the initialization stage of the component

_create_new_cls(cls, cls_dict, init_stage)

Method to initialize XSO component with appropriate parent class

component([cls])

A component decorator that adds everything needed to use the class

Attributes

_make_xsimlab_vars

xso.component._create_variables_dict(process_cls)[source]

Get all phydra variables declared in a component. Exclude attr.Attribute objects that are not XSO specific.

xso.component._convert_2_xsimlabvar(var, intent='in', var_dims=None, value_store=False, groups=None, description_label='', attrs=True)[source]

Converts XSO variables to xarray-simlab variables to be used in the model backend.

Function receives variable as attr in _make_xsimlab_vars function and extracts description, dimensions and metadata, then passes it and additional arguments through xarray-simlab’s xs.variable function.

Parameters:
  • var (attr._Make.Attribute) – XSO variable defined in object decorated with xso.component()

  • intent (str ('in' or 'out')) – passed along, defines variable as receiving input from another component or being initialized within this component.

  • var_dims (tuple or str) – Defines dimensionality of created xsimlab variable, can be singular string or tuple of strings.

  • value_store (bool) – When true, the ouput of variable is stored to xsimlab variable. Adds ‘time’ dimension.

  • groups (str) – When defined, the variable output can be referenced via xarray simlabs group variable in other XSO components.

  • description_label (str) – Description stored with Xarray Dataset created by xsimlab.

  • attrs (bool) – If true, attrs defined in variable metadata are passed along to xsimlab variable function.

Returns:

attr class handled by Xarray-simlab, the functional foundation of XSO

Return type:

xs.variable

xso.component._make_xso_variable(label, variable)[source]

Checks for type of variable defined and calls _convert_2_xsimlabvar function accordingly. Returns dict with label and xsimlab variable as key/value pairs.

xso.component._make_xso_parameter(label, variable)[source]

Checks for type of variable defined and calls _convert_2_xsimlabvar function accordingly. Returns dict with label and xsimlab variable as key/value pairs.

xso.component._make_xso_forcing(label, variable)[source]

Checks for type of variable defined and calls _convert_2_xsimlabvar function accordingly. Returns dict with label and xsimlab variable as key/value pairs.

xso.component._make_xso_flux(label, variable)[source]

Checks for type of variable defined and calls _convert_2_xsimlabvar function accordingly. Returns dict with label and xsimlab variable as key/value pairs.

xso.component._make_xso_index(label, variable)[source]

Checks for type of variable defined and calls _convert_2_xsimlabvar function accordingly. Returns dict with label and xsimlab variable as key/value pairs.

xso.component._make_xsimlab_vars
xso.component._create_xsimlab_var_dict(cls_vars)[source]

Parses through attributes defined in xso.component decorated class and extracts those relevant for XSO.

These are initialized as xsimlab variables and returned in dict to xso.component decorated class.

xso.component._create_forcing_dict(cls, var_dict)[source]

Parses var_dict and extracts forcing setup function

xso.component._create_index_dict(cls, var_dict)[source]

Parses var_dict and extracts index setup function

xso.component._initialize_process_vars(cls, vars_dict)[source]

Parses vars_dict of xso.component decorated class, and initializes defined variables and methods with model backend.

xso.component._create_flux_inputargs_dict(cls, vars_dict)[source]

Creates a dictionary to parse the input arguments to a flux function.

xso.component._initialize_fluxes(cls, vars_dict)[source]

Parses flux variables and methods in xso.component decorated class and registers them with the model backend.

xso.component._initialize_forcings(cls, forcing_dict)[source]

Parses xso.forcing variables and methods defined in xso.component decorated class and registers them with the model backend.

xso.component._initialize_indexes(cls, index_dict)[source]

Initializes xso.index variables defined in xso.component decorated class.

xso.component._get_init_stage(vars_dict)[source]

Returns the initialization stage of the component attempts to automatically determine init stage from implemented variable types and group arguments

Parameters:

vars_dict – dictionary of variables in component

Returns:

init stage

xso.component._create_new_cls(cls, cls_dict, init_stage)[source]

Method to initialize XSO component with appropriate parent class from xso.backendcomps, which defines initialisation stage and inherits from Context class.

xso.component.component(cls=None)[source]

A component decorator that adds everything needed to use the class as a XSO component. It is a wrapper for the xarray-simlab process decorator.

A component represents a logical unit with the model, and usually implements:

  • A set of XSO variables, defined as class attributes, e.g. xso.variable, xso.parameter,

xso.forcing or xso.flux. - One or more methods that can be functions defining a xso.flux or a xso.forcing.

Parameters:

cls (class, optional) – Allows applying this decorator either as @xso.component or @xso.component(*args).

Returns:

cls – The decorated class that is a fully functional xso.component.

Return type:

class