BaseModels
EnBaseModel
¶
Bases: BaseModel
Pydantic subclass for special configurations and utility methods.
This class extends the functionality of the BaseModel provided by Pydantic. It incorporates additional configurations and utility methods, such as cleaning up empty attributes and building keyword arguments for an oemof energy system component.
Attributes:
Name | Type | Description |
---|---|---|
model_config |
Configuration dictionary that allows arbitrary types and specifies how additional attributes are handled. |
Source code in ensys/common/basemodel.py
build_kwargs(energysystem)
¶
Builds a dictionary of keyword arguments for an oemof energy system component based on the attributes of the current object. The function processes the object's attributes, transforming and mapping them into a format compatible with oemof components. Special handling is performed for attributes such as inputs, outputs, and conversion factors to properly map these to the provided energy system. Attributes of certain types are converted with their respective methods if necessary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
energysystem
|
EnergySystem
|
The energy system instance to which the object belongs, used to resolve references and convert attributes to oemof-compatible formats. |
required |
Returns:
Type | Description |
---|---|
dict[str, dict]
|
A dictionary of formatted keyword arguments suitable for creating the corresponding oemof component. |
Source code in ensys/common/basemodel.py
remove_empty()
¶
Removes attributes with None
values from the object.
This method iterates through all attributes of the object and identifies
those with a value of None
. It collects these attributes into a list
and then removes them from the object. This helps in cleaning up empty
or irrelevant data within the object's state.
Returns:
Type | Description |
---|---|
object
|
The modified object with |
Raises:
Type | Description |
---|---|
AttributeError
|
If an attribute cannot be deleted for any reason. |