Skip to content

Commit f3d58cc

Browse files
Convert costs 2015 to new data structure (#4153)
* move costs 2015 data structure to dataclass * Ensure vname is a string in cost 2015 * delete unnecessary comments/docstrings --------- Co-authored-by: Timothy Nunn <timothy.nunn@ukaea.uk>
1 parent 75f0aae commit f3d58cc

6 files changed

Lines changed: 784 additions & 1024 deletions

File tree

process/core/init.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from process.data_structure.buildings_variables import init_buildings_variables
2222
from process.data_structure.ccfe_hcpb_module import init_ccfe_hcpb_module
2323
from process.data_structure.constraint_variables import init_constraint_variables
24-
from process.data_structure.cost_2015_variables import init_cost_2015_variables
2524
from process.data_structure.cost_variables import init_cost_variables
2625
from process.data_structure.cs_fatigue_variables import init_cs_fatigue_variables
2726
from process.data_structure.current_drive_variables import init_current_drive_variables
@@ -301,7 +300,6 @@ def init_all_module_vars():
301300
init_cs_fatigue_variables()
302301
init_blanket_library()
303302
init_dcll_module()
304-
init_cost_2015_variables()
305303
init_power_variables()
306304
init_neoclassics_variables()
307305

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
@@ -703,7 +703,7 @@ def costs(self, value: CostsProtocol):
703703
def models(self) -> tuple[Model, ...]:
704704
# At the moment, this property just returns models that implement the Model interface.
705705
# Eventually every Model will comply and then this method can be used as the caller/outputter!
706-
return (self.water_use,)
706+
return (self.water_use, self._costs_2015)
707707

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

0 commit comments

Comments
 (0)