BaseModels
EnBaseModel
¶
Bases: BaseModel
Specialized Pydantic BaseModel for managing energy system components.
This class extends the functionality of Pydantic's BaseModel by adding methods for removing empty attributes and building keyword arguments for oemof.solph components. It is designed for applications in energy systems modeling, particularly when working with the oemof.solph framework. The class provides utility methods to handle energy system components, including proper management of complex data structures and configurations.
Source code in backend/app/ensys/common/basemodel.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
Config
¶
Configuration class for customizing behavior of Pydantic objects.
This class is used to specify custom configuration options for Pydantic models, particularly for enabling support for arbitrary data types like pandas DataFrame and pandas Series, as well as allowing additional keyword arguments (**kwargs) to be passed to Pydantic's BaseModel instances.
Attributes:
Name | Type | Description |
---|---|---|
arbitrary_types_allowed |
Enables support for arbitrary data types that are not natively supported by Pydantic by default, such as pandas DataFrames or pandas Series. |
|
extra |
Specifies the extra attributes or fields behavior in Pydantic models. Setting this to 'allow' permits passing extra **kwargs that are not explicitly defined in Pydantic BaseModel. |
Source code in backend/app/ensys/common/basemodel.py
build_kwargs(energysystem)
¶
Builds keyword arguments for creating oemof.solph components from the provided EnergySystem and the attributes of the instance. Special handling is implemented for specific attributes like "inputs", "outputs", "conversion_factors", "nonconvex", "nominal_value", and "nominal_storage_capacity" to properly handle their conversion or dependency on the provided EnergySystem.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
energysystem
|
EnergySystem
|
An instance of the oemof.solph.EnergySystem class used to resolve dependencies and references for creating keyword arguments. |
required |
Returns:
Type | Description |
---|---|
dict[str, dict]
|
A dictionary containing keyword arguments for initializing oemof.solph components, with special attributes processed and mapped accordingly. |
Source code in backend/app/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. |