Skip to content

Commit af88579

Browse files
authored
Implement inheritance of field names for structures based on supertypes (based on Issue #31) (#33)
* Implement inheritance of field names for structures based on supertypes: - utils function necessary for inheritance - changes to update_descriptive_names! to add inheritance step - Changes to descriptive_names.yml; removing redundant descriptive names and adding descriptive names to supertypes. * Moved tests for descriptive_names to own file
1 parent 2e14ac9 commit af88579

9 files changed

Lines changed: 362 additions & 163 deletions

File tree

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ SparseVariables = "2749762c-80ed-4b14-8f33-f0736679b02b"
2626
TimeStruct = "f9ed5ce0-9f41-4eaa-96da-f38ab8df101c"
2727
XLSX = "fdbf4ff8-1666-58a4-91e7-1b58723a45e0"
2828
YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"
29+
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
2930

3031
[weakdeps]
3132
EnergyModelsGeography = "3f775d88-a4da-46c4-a2cc-aa9f16db6708"
@@ -58,3 +59,4 @@ TimeStruct = "0.9"
5859
XLSX = "0.10"
5960
YAML = "0.4"
6061
julia = "1.10"
62+
InteractiveUtils = "1"

src/EnergyModelsGUI.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ using Colors
2323
# To format numbers with @sprintf
2424
using Printf
2525

26+
# To retrieve supertypes
27+
using InteractiveUtils
28+
2629
# Use GLMakie front end to visualize the GUI figure
2730
using GLMakie
2831

src/descriptive_names.yml

Lines changed: 20 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -3,127 +3,60 @@
33
structures:
44
# EnergyModelsBase
55
## node.jl
6-
StorCapOpex:
6+
AbstractStorageParameters:
77
capacity: "Installed capacity"
88
opex_var: "Relative variable operating expense per energy unit"
99
opex_fixed: "Relative fixed operating expense per installed capacity"
1010

11-
StorCap:
12-
capacity: "Installed capacity"
13-
14-
StorCapOpexVar:
15-
capacity: "Installed capacity"
16-
opex_var: "Relative variable operating expense per energy unit"
17-
18-
StorCapOpexFixed:
19-
capacity: "Installed capacity"
20-
opex_fixed: "Relative fixed operating expense per installed capacity"
21-
22-
StorOpexVar:
23-
opex_var: "Relative variable operating expense per energy unit"
24-
25-
RefSource:
26-
cap: "Installed capacity"
27-
opex_var: "Relative variable operating expense per energy unit produced"
28-
opex_fixed: "Relative fixed operating expense per installed capacity"
29-
30-
RefNetworkNode:
11+
Node:
3112
cap: "Installed capacity"
3213
opex_var: "Relative variable operating expense per energy unit produced"
3314
opex_fixed: "Relative fixed operating expense per installed capacity"
3415

35-
RefSink:
16+
Sink:
3617
cap: "Demand"
3718
penalty:
3819
surplus: "Penalties for surplus"
3920
deficit: "Penalties for deficits"
4021

4122
# EnergyModelsGeography
4223
## mode.jl
43-
RefDynamic:
44-
trans_cap: "Capacity of the transmission mode"
45-
trans_loss: "Relative loss of the transported resource during transmission"
46-
opex_var: "Relative variable operating expense per energy unit transported"
47-
opex_fixed: "Relative fixed operating expense per installed capacity"
48-
49-
RefStatic:
50-
trans_cap: "Capacity of the transmission mode"
51-
trans_loss: "Relative loss of the transported resource during transmission"
52-
opex_var: "Relative variable operating expense per energy unit transported"
53-
opex_fixed: "Relative fixed operating expense per installed capacity"
54-
55-
PipeSimple:
56-
consumption_rate: "Rate at which the resource is consumed, as a ratio of the volume of the resource going into the inlet"
24+
TransmissionMode:
5725
trans_cap: "Capacity of the transmission mode"
5826
trans_loss: "Relative loss of the transported resource during transmission"
5927
opex_var: "Relative variable operating expense per energy unit transported"
6028
opex_fixed: "Relative fixed operating expense per installed capacity"
61-
62-
PipeLinepackSimple:
6329
consumption_rate: "Rate at which the resource is consumed, as a ratio of the volume of the resource going into the inlet"
64-
trans_cap: "Capacity of the transmission mode"
65-
trans_loss: "Relative loss of the transported resource during transmission"
66-
opex_var: "Relative variable operating expense per energy unit transported"
67-
opex_fixed: "Relative fixed operating expense per installed capacity"
6830

6931
# EnergyModelsInvestment
7032
## investment_data.jl
71-
NoStartInvData:
72-
capex: "Capital costs for investing in a capacity"
73-
max_inst: "Maximum installed capacity in a strategic period"
74-
75-
StartInvData:
33+
AbstractInvData:
7634
capex: "Capital costs for investing in a capacity"
7735
max_inst: "Maximum installed capacity in a strategic period"
7836
initial: "Initial capacity in the first strategic period"
7937

8038
## investment_mode.jl
39+
Investment:
40+
min_add: "Minimum added capacity in a strategic period"
41+
max_add: "Maximum added capacity in a strategic period"
42+
increment: "Used increment for discrete investments"
43+
capex_offset: "Offset for the CAPEX in a strategic period"
8144
FixedInvestment:
8245
cap: "Capacity used for the fixed investments"
8346

8447
BinaryInvestment:
8548
cap: "Capacity used for the binary investments"
8649

87-
DiscreteInvestment:
88-
increment: "Used increment for discrete investments"
89-
90-
ContinuousInvestment:
91-
min_add: "Minimum added capacity in a strategic period"
92-
max_add: "Maximum added capacity in a strategic period"
93-
94-
SemiContinuousInvestment:
95-
min_add: "Minimum added capacity in a strategic period"
96-
max_add: "Maximum added capacity in a strategic period"
97-
98-
SemiContinuousOffsetInvestment:
99-
max_add: "Maximum added capacity in a strategic period"
100-
min_add: "Minimum added capacity in a strategic period"
101-
capex_offset: "Offset for the CAPEX in a strategic period"
102-
10350
## lifetime_mode.jl
104-
StudyLife:
105-
lifetime: "Chosen lifetime of the technology"
106-
107-
PeriodLife:
108-
lifetime: "Chosen lifetime of the technology"
109-
110-
RollingLife:
51+
LifetimeMode:
11152
lifetime: "Chosen lifetime of the technology"
11253

11354
# EnergyModelsRenewableProducers
11455
## datastructures.jl
115-
NonDisRES:
116-
cap: "Installed capacity"
56+
AbstractNonDisRES:
11757
profile: "Power production profile as a ratio of installed capacity"
118-
opex_var: "Relative variable operating expense per energy unit produced"
119-
opex_fixed: "Relative fixed operating expense per installed capacity"
120-
121-
HydroStor:
122-
level_init: "Initial stored energy in the dam"
123-
level_inflow: "Inflow of power per operational period"
124-
level_min: "Minimum fraction of the reservoir capacity required"
12558

126-
PumpedHydroStor:
59+
HydroStorage:
12760
level_init: "Initial stored energy in the dam"
12861
level_inflow: "Inflow of power per operational period"
12962
level_min: "Minimum fraction of the reservoir capacity required"
@@ -141,17 +74,17 @@ structures:
14174
opex_var: "Variable operational costs per water flow"
14275
opex_fixed: "Fixed operational costs"
14376

144-
HydroGenerator:
145-
cap: "Installed discharge or power capacity"
77+
HydroUnit:
14678
opex_var: "Variable operational costs per energy unit produced"
14779
opex_fixed: "Fixed operational costs"
14880

81+
HydroGenerator:
82+
cap: "Installed discharge or power capacity"
83+
14984
HydroPump:
15085
cap: "Installed pumping capacity"
151-
opex_var: "Variable operational costs per energy unit produced"
152-
opex_fixed: "Fixed operational costs"
15386

154-
CycleLife:
87+
AbstractBatteryLife:
15588
stack_cost: "Relative cost for replacing a battery stack"
15689

15790
# EnergyModelsHeat
@@ -162,22 +95,9 @@ structures:
16295

16396
## node.jl
16497
HeatPump:
165-
cap: "Installed capacity"
16698
t_source: "Heat source temperature"
16799
t_sink: "Heat sink temperature"
168100
eff_carnot: "Carnot Efficiency"
169-
opex_var: "Variable operating expense per energy unit produced"
170-
opex_fixed: "Fixed operating expense per installed capacity"
171-
172-
HeatExchanger:
173-
cap: "Installed capacity"
174-
opex_var: "Variable operating expense per energy unit produced"
175-
opex_fixed: "Fixed operating expense per installed capacity"
176-
177-
DirectHeatUpgrade:
178-
cap: "Installed capacity"
179-
opex_var: "Variable operating expense per energy unit produced"
180-
opex_fixed: "Fixed operating expense per installed capacity"
181101

182102
## resource.jl
183103
ResourceHeat:
@@ -186,52 +106,27 @@ structures:
186106

187107
# EnergyModelsHydrogen
188108
## node.jl
189-
Electrolyzer:
190-
cap: "Installed capacity"
191-
opex_var: "Variable operating expense per capacity used"
192-
opex_fixed: "Fixed operating expense per installed capacity"
193-
stack_replacement_cost: "Replacement cost of electrolyzer stacks"
194-
195-
SimpleElectrolyzer:
196-
cap: "Installed capacity"
109+
AbstractElectrolyzer:
197110
opex_var: "Variable operating expense per capacity used"
198-
opex_fixed: "Fixed operating expense per installed capacity"
199111
stack_replacement_cost: "Replacement cost of electrolyzer stacks"
200112

201113
CommitParameters:
202114
opex: "Operating cost per installed capacity and operational duration"
203115
time: "Minimum time node must remain in a state before transitioning"
204116

205-
RampBi:
206-
up: "Maximum positive rate of change of a node"
207-
down: "Maximum negative rate of change of a node"
208-
209-
RampUp:
117+
AbstractRampParameters:
210118
up: "Maximum positive rate of change of a node"
211-
212-
RampDown:
213119
down: "Maximum negative rate of change of a node"
214120

215-
Reformer:
216-
cap: "Installed capacity"
217-
opex_var: "Variable operating expense per capacity usage"
218-
opex_fixed: "Fixed operating expense per installed capacity"
219-
220121
# EnergyModelsCO2
221122
CO2Source:
222-
cap: "Installed capacity"
223123
opex_var: "Variable operating expense per energy unit produced"
224-
opex_fixed: "Fixed operating expense"
225124

226125
RefNetworkNodeRetrofit:
227-
cap: "Installed capacity"
228126
opex_var: "Variable operating expense per energy unit produced"
229-
opex_fixed: "Fixed operating expense"
230127

231128
CCSRetroFit:
232-
cap: "Installed capacity"
233129
opex_var: "Variable operating expense per unit of CO₂ captured"
234-
opex_fixed: "Fixed operating expense"
235130

236131

237132
variables:

src/utils_GUI/GUI_utils.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -625,16 +625,19 @@ function update_descriptive_names!(gui::GUI)
625625
joinpath(@__DIR__, "..", "descriptive_names.yml"); dicttype = Dict{Symbol,Any},
626626
)
627627

628-
# Get a dictionary of installed packages
629-
installed_packages = installed()
628+
# Get a dictionary of loaded packages
629+
loaded_packages = loaded()
630630

631631
# Filter packages with names matching the pattern "EnergyModels*"
632-
emx_packages = filter(pkg -> occursin(r"EnergyModels", pkg), keys(installed_packages))
633-
634-
# Search through EMX packages if icons are available there
632+
emx_packages = filter(pkg -> occursin(r"EnergyModels", pkg), loaded_packages)
633+
# apply inheritances for fetching descriptive names
634+
# create a dictionary were the keys are all the types defined in emx_packages and the values are the types they inherit from
635+
emx_supertypes_dict = get_supertypes(emx_packages)
636+
inherit_descriptive_names_from_supertypes!(descriptive_names, emx_supertypes_dict)
635637
for package emx_packages
636638
package_path::Union{String,Nothing} = dirname(dirname(Base.find_package(package)))
637639
if !isnothing(package_path)
640+
# check for presence of file to extend descriptive names
638641
path_to_descriptive_names_ext = joinpath(
639642
package_path, "ext", "EMGUIExt", "descriptive_names.yml",
640643
)

src/utils_gen/structures_utils.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ function installed()
1414
return installs
1515
end
1616

17+
"""
18+
function loaded()
19+
20+
Get a list of loaded packages.
21+
"""
22+
loaded() = [String(n) for n names(Main, imported = true) if getfield(Main, n) isa Module]
23+
1724
"""
1825
place_nodes_in_circle(total_nodes::Int64, current_node::Int64, r::Float32, xₒ::Float32, yₒ::Float32)
1926

0 commit comments

Comments
 (0)