Skip to content

Commit 7115658

Browse files
committed
move costs 2015 data structure to dataclass
1 parent 893a36c commit 7115658

6 files changed

Lines changed: 783 additions & 967 deletions

File tree

process/core/init.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from process.data_structure.buildings_variables import init_buildings_variables
2323
from process.data_structure.ccfe_hcpb_module import init_ccfe_hcpb_module
2424
from process.data_structure.constraint_variables import init_constraint_variables
25-
from process.data_structure.cost_2015_variables import init_cost_2015_variables
2625
from process.data_structure.cost_variables import init_cost_variables
2726
from process.data_structure.cs_fatigue_variables import init_cs_fatigue_variables
2827
from process.data_structure.current_drive_variables import init_current_drive_variables
@@ -302,7 +301,6 @@ def init_all_module_vars():
302301
init_cs_fatigue_variables()
303302
init_blanket_library()
304303
init_dcll_module()
305-
init_cost_2015_variables()
306304
init_power_variables()
307305
init_neoclassics_variables()
308306

process/core/model.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import abc
22
from dataclasses import dataclass, fields
33

4+
from process.data_structure.cost_2015_variables import Cost2015Data
45
from process.data_structure.water_usage_variables import WaterUseData
56

67
initialise_later = object()
@@ -9,6 +10,7 @@
910
@dataclass(kw_only=True)
1011
class DataStructure:
1112
water_use: WaterUseData = initialise_later
13+
costs_2015: Cost2015Data = initialise_later
1214

1315
def __post_init__(self):
1416
for f in fields(self):
Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,33 @@
1-
import numpy as np
2-
3-
mean_electric_output: float = None
4-
5-
annual_electric_output: float = None
6-
7-
maintenance: float = None
8-
9-
total_costs: float = None
1+
from dataclasses import dataclass, field
102

11-
s_label: list[str] = None
12-
13-
s_kref: list[float] = None
14-
15-
s_k: list[float] = None
16-
17-
s_cref: list[float] = None
3+
import numpy as np
184

19-
s_cost: list[float] = None
205

21-
s_cost_factor: list[float] = None
6+
@dataclass
7+
class Cost2015Data:
8+
mean_electric_output: float = 0.0
229

10+
annual_electric_output: float = 0.0
2311

24-
def init_cost_2015_variables():
25-
global mean_electric_output
26-
mean_electric_output = 0.0
12+
maintenance: float = 0.0
2713

28-
global annual_electric_output
29-
annual_electric_output = 0.0
14+
total_costs: float = 0.0
3015

31-
global maintenance
32-
maintenance = 0.0
16+
s_label: list[str] = field(
17+
default_factory=lambda: np.array(["not used"] * 100, dtype=object)
18+
)
3319

34-
global total_costs
35-
total_costs = 0.0
20+
s_kref: list[float] = field(default_factory=lambda: np.zeros(100, dtype=np.float64))
3621

37-
global s_label
38-
s_label = np.array(["not used"] * 100, dtype=object)
22+
s_k: list[float] = field(default_factory=lambda: np.zeros(100, dtype=np.float64))
3923

40-
global s_kref
41-
s_kref = np.zeros(100, dtype=np.float64)
24+
s_cref: list[float] = field(default_factory=lambda: np.zeros(100, dtype=np.float64))
4225

43-
global s_k
44-
s_k = np.zeros(100, dtype=np.float64)
26+
s_cost: list[float] = field(default_factory=lambda: np.zeros(100, dtype=np.float64))
4527

46-
global s_cref
47-
s_cref = np.zeros(100, dtype=np.float64)
28+
s_cost_factor: list[float] = field(
29+
default_factory=lambda: np.zeros(100, dtype=np.float64)
30+
)
4831

49-
global s_cost
50-
s_cost = np.zeros(100, dtype=np.float64)
5132

52-
global s_cost_factor
53-
s_cost_factor = np.zeros(100, dtype=np.float64)
33+
CREATE_DICTS_FROM_DATACLASS = Cost2015Data

process/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ def costs(self, value: CostsProtocol):
776776
def models(self) -> tuple[Model, ...]:
777777
# At the moment, this property just returns models that implement the Model interface.
778778
# Eventually every Model will comply and then this method can be used as the caller/outputter!
779-
return (self.water_use,)
779+
return (self.water_use, self._costs_2015)
780780

781781
def setup_data_structure(self):
782782
# This Models class should be replaced with a dataclass so we can

0 commit comments

Comments
 (0)