API Reference

Parameters

class paramtools.Parameters(initial_state=None, array_first=None)[source]
adjust(params_or_path, raise_errors=True)[source]

Deserialize and validate parameter adjustments. params_or_path can be a file path or a dict that has not been fully deserialized. The adjusted values replace the current values stored in the corresponding parameter attributes.

Raises:

marshmallow.exceptions.ValidationError if data is not valid.

ParameterUpdateException if dimension values do not match at
least one existing value item’s corresponding dimension values.
clear_state()[source]

Reset the state of the Parameters instance.

from_array(param, array=None)[source]

Convert NumPy array to a Value object.

Returns:
Value object (shape: [{“value”: val, dims:…}])
Raises:
InconsistentDimensionsException: Value objects do not have consistent
dimensions.
set_state(**dims)[source]

Sets state for the Parameters instance. The state, dim_mesh, and parameter attributes are all updated with the new state.

Raises:
ValidationError if the dims kwargs contain dimensions that are not
specified in schema.json or if the dimension values fail the validator set for the corresponding dimension in schema.json.
specification(use_state=True, meta_data=False, include_empty=False, **dims)[source]

Query value(s) of all parameters along dimensions specified in dims. If use_state is True, the current state is updated with dims. If meta_data is True, then parameter attributes are included, too. If include_empty is True, then values that do not match the query dimensions set with self._state or dims will be included and set to an empty list.

Returns: serialized data of shape
{“param_name”: [{“value”: val, “dim0”: …, }], …}
to_array(param)[source]

Convert a Value object to an n-dimensional array. The list of Value objects must span the specified parameter space. The parameter space is defined by inspecting the dimension validators in schema.json and the state attribute of the Parameters instance.

Returns: n-dimensional NumPy array.

Raises:
InconsistentDimensionsException: Value objects do not have consistent
dimensions.
SparseValueObjectsException: Value object does not span the
entire space specified by the Order object.
view_state()[source]

Access the dimension state of the Parameters instance.

Fields

class paramtools.contrib.fields.Bool_(truthy=None, falsy=None, **kwargs)[source]

Implements “bool” Type property for parameter values. Defined as numpy.bool_ type

np_type

alias of numpy.bool_

num_type

alias of numpy.bool_

class paramtools.contrib.fields.Boolean(truthy=None, falsy=None, **kwargs)[source]

Implements “bool” Type property for properties except for parameter values.

np_type

alias of builtins.bool

class paramtools.contrib.fields.Date(format=None, **kwargs)[source]

Implements “date” Type property.

np_type

alias of datetime.date

class paramtools.contrib.fields.Float(allow_nan=False, as_string=False, **kwargs)[source]

Implements “float” Type property for properties except for parameter values.

np_type

alias of builtins.float

class paramtools.contrib.fields.Float64(as_string=False, **kwargs)[source]

Implements “float” Type property for parameter values. Defined as numpy.float64 type

np_type

alias of numpy.float64

num_type

alias of numpy.float64

class paramtools.contrib.fields.Int64(as_string=False, **kwargs)[source]

Implements “int” Type property for parameter values. Defined as numpy.int64 type

np_type

alias of numpy.int64

num_type

alias of numpy.int64

class paramtools.contrib.fields.Integer(strict=False, **kwargs)[source]

Implements “int” Type property for properties except for parameter values.

np_type

alias of builtins.int

class paramtools.contrib.fields.MeshFieldMixin[source]

Provides method for accessing contrib.validate validators’ mesh methods

class paramtools.contrib.fields.Str(default=<marshmallow.missing>, attribute=None, data_key=None, error=None, validate=None, required=False, allow_none=None, load_only=False, dump_only=False, missing=<marshmallow.missing>, error_messages=None, **metadata)[source]

Implements “str” Type property.

np_type

alias of builtins.object

Validate

class paramtools.contrib.validate.DateRange(min=None, max=None, error_min=None, error_max=None, step=None)[source]

Implements “date_range” Validator object. Behaves like Range, except values are ensured to be datetime.date type and mesh has special logic for dates.

class paramtools.contrib.validate.OneOf(choices, labels=None, error=None)[source]

Implements “choice” Validator object.

class paramtools.contrib.validate.Range(min=None, max=None, error_min=None, error_max=None, step=None)[source]

Implements “range” Validator object.