bluemira.codes.params
Base classes for external parameter management.
Classes
Special |
|
Simple class containing information on mapping of a bluemira parameter to one in |
Module Contents
- class bluemira.codes.params.MappedParameterFrame
Bases:
bluemira.base.parameter_frame.ParameterFrameSpecial
ParameterFramethat contains a set of parameter mappings.The mappings are intended to be used to map bluemira parameters to parameters in an external code.
See
ParameterFramefor details on how to declare parameters.- __post_init__()
Ensure mappings are as immutable as we can manage
- property defaults: dict
- Abstractmethod:
- Return type:
dict
Default values for the ParameterFrame
- classmethod from_defaults(data: dict, source: str = 'bluemira codes default') MappedParameterFrame
Create ParameterFrame with default values for external codes.
External codes are likely to have variables that are not changed often therefore in some cases sane defaults are needed.
If a default value is not found for a given mapping it is set to NaN
- Returns:
The parameter frame
- Parameters:
data (dict)
source (str)
- Return type:
- property mappings: dict[str, ParameterMapping]
- Abstractmethod:
- Return type:
dict[str, ParameterMapping]
The mappings associated with these frame’s parameters.
The keys are names of parameters in this frame, the values are
ParameterMappingobjects containing the name of the corresponding parameter in some external code.
- update_mappings(new_send_recv: dict[str, dict[Literal['send', 'recv'], bool]])
Update the mappings in this frame with new send/recv values.
- Parameters:
new_send_recv (dict[str, dict[Literal['send', 'recv'], bool]]) – The new send/recv values for all, or a subset, of the parameter mappings. Keys are parameter names (as defined in this class, not the external code), the values are a dictionary, optionally containing keys ‘send’ and/or ‘recv’. The values for the inner dictionary are a boolean.
- Raises:
CodesError – If a parameter name in the input does not match the name of a parameter in this frame.
- class bluemira.codes.params.ParameterMapping
Simple class containing information on mapping of a bluemira parameter to one in external software.
- Parameters:
name – name of mapped parameter
recv – receive data from mapped parameter (to overwrite bluemira parameter)
send – send data to mapped parameter (from bluemira parameter)
- name: str
- out_name: str | None = None
- send: bool = True
- recv: bool = True
- unit: str | None = None
- _frozen = ()
- __post_init__()
Freeze the dataclass
- to_dict() dict
Convert this object to a dictionary with attributes as values.
- Return type:
dict
- classmethod from_dict(the_dict: dict) ParameterMapping
Create a ParameterMapping using a dictionary with attributes as values.
- Parameters:
the_dict (dict)
- Return type:
- __str__()
Create a string representation of of this object which is more compact than that provided by the default __repr__ method.
- __setattr__(attr: str, value: bool | str)
Protect against additional attributes
- Parameters:
attr (str) – Attribute to set (name can only be set on init)
value (bool | str) – Value of attribute
- Raises:
KeyError – Cannot set attribute
ValueError – Attribute must be a boolean