Skip to content

Commit a5457d6

Browse files
authored
Fix miscellaneous bugs and enhance colors (#49)
* Add colors for resources * Fix arbitrary radius calculation bug * Fix issue when topology is not defined properly * Fix missing investments in transmission modes in the investment overview * Fix formatting, update NEWS.md and figures.
1 parent d296246 commit a5457d6

9 files changed

Lines changed: 89 additions & 22 deletions

File tree

NEWS.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Release notes
22

3+
## Version 0.7.1 (2026-04-24)
4+
5+
### Bugfix
6+
7+
* Fix bug that resulted in arbitrary evaluated lat-lon coordinates for children of `Area`s due to the arbitrary default radius of 1.0 if not provided by the design `.yml` input files. The bug is resolved by first computing minimal distance between areas and letting the new radius be a third of this distance.
8+
* Fix issue when the transmissions/links is not properly defined (e.g., `from` or `to` objects not sharing resource).
9+
* Fix missing investments in transmission modes in the Investment overview.
10+
11+
### Enhancements
12+
13+
* Add more colors for resources aliases.
14+
315
## Version 0.7.0 (2026-04-17)
416

517
### Breaking changes

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "EnergyModelsGUI"
22
uuid = "737a7361-d3b7-40e9-b1ac-59bee4c5ea2d"
3-
version = "0.7.0"
3+
version = "0.7.1"
44
authors = ["Jon Vegard Venås <JonVegard.Venas@sintef.no>", "Dimitri Pinel <Dimitri.Pinel@sintef.no>", "Magnus Askeland <Magnus.Askeland@sintef.no>", "Shweta Tiwari <Shweta.Tiwari@sintef.no>"]
55

66
[deps]

docs/src/figures/EMI_geography.png

-5.02 KB
Loading
-684 Bytes
Loading

ext/EMGExt/EMGExt.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,14 @@ Map types to header symbols for saving results.
189189
"""
190190
EMGUI._type_to_header(::Type{<:TransmissionMode}) = :element
191191

192+
"""
193+
EMGUI.get_inv_objs(obj::Transmission)
194+
195+
Get the objects for which investment information should be stored for a given `Transmission`.
196+
This includes obj itself but also its modes.
197+
"""
198+
EMGUI.get_inv_objs(obj::Transmission) = [obj, modes(obj)...]
199+
192200
############################################################################################
193201
## From info_axis_utils.jl
194202
"""

src/colors.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Power: "#045993" # blue
44
power: "#045993" # blue
55
Hydrogen: "#009DAD" # cyan
66
H2: "#009DAD" # cyan
7+
H₂: "#009DAD" # cyan
78
Cooling: "#00DBDB" # aqua
89
Resource: "#C059A1" # pink
910
Waste: "#DB6000" # orange
@@ -12,11 +13,17 @@ WarmWater: "#75499C" # purple
1213
ResourceCarrier: "#C059A1" # pink
1314
Biomass: "#118011" # green
1415
NG: "#B88505" # goldenrod
16+
CH₄: "#B88505" # goldenrod
17+
CH4: "#B88505" # goldenrod
18+
Methane: "#B88505" # goldenrod
1519
Oil: "#DBB500" # gold
1620
ResourceEmit: "#606060" # gray
1721
CO2: "#606060" # gray
1822
CO₂: "#606060" # gray
1923
Coal: "#6D392E" # brown
2024
Water: "#bfefff" # sky blue
2125
HeatLT: "#fbdfb0" # :navajowhite
22-
HeatHT: "#e78582" # :lightcoral
26+
HeatHT: "#e78582" # :lightcoral
27+
Ammonia: "#007C79" # dark teal
28+
NH3: "#007C79" # dark teal
29+
NH₃: "#007C79" # dark teal

src/setup_topology.jl

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ function EnergySystemDesign(
3232
icon::String = "",
3333
parent::AbstractGUIObj = NothingDesign(),
3434
level::Int64 = 0,
35+
radius::Float32 = 0.1f0,
3536
)
3637
# Create the path to the file where existing design is stored (if any)
3738
file::String = design_file(system, design_path)
@@ -43,6 +44,28 @@ function EnergySystemDesign(
4344
Dict()
4445
end
4546

47+
if isa(system, SystemGeo)
48+
# Collect all (lon, lat) coordinates from elements that have them
49+
coords = [
50+
Point2f(element.lon, element.lat)
51+
for element get_children(system)
52+
]
53+
54+
# Compute all pairwise distances
55+
min_dist = Inf
56+
for i 1:(length(coords)-1)
57+
for j (i+1):length(coords)
58+
dist = l2_norm(coords[i] - coords[j])
59+
if dist < min_dist
60+
min_dist = dist
61+
end
62+
end
63+
end
64+
65+
# Set radius to a third of the minimal distance such that expanded nodes do not overlap
66+
radius = min_dist / 3
67+
end
68+
4669
# Complete the `id_to_color_map` if some products are lacking (this is done by choosing
4770
# colors for the lacking `Resource`s that are most distinct to the existing set of colors)
4871
if !issubset(get_products(system), keys(id_to_color_map))
@@ -98,7 +121,7 @@ function EnergySystemDesign(
98121
xy = xy_parent
99122
else # place nodes in a circle around the parents availability node
100123
xy = place_nodes_in_circle(
101-
nodes_count, current_node, 1.0f0, xy_parent,
124+
nodes_count, current_node, radius, xy_parent,
102125
)
103126
current_node += 1
104127
end
@@ -119,6 +142,7 @@ function EnergySystemDesign(
119142
icon = find_icon(this_sys, id_to_icon_map),
120143
parent = design,
121144
level = level + 1,
145+
radius = radius,
122146
),
123147
)
124148
end

src/utils_GUI/GUI_utils.jl

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,15 @@ get_values(vals::JuMP.Containers.DenseAxisArray, ts::Vector) = Array(value.(vals
501501
get_values(vals::DataFrame, ts::Vector) = vals[in.(vals.t, Ref(ts)), :val]
502502
get_values(vals::TimeProfile, ts::Vector) = vals[ts]
503503

504+
"""
505+
get_inv_objs(obj::AbstractElement)
506+
507+
Get the objects for which investment information should be stored for a given `AbstractElement`.
508+
By default, this is just the element itself, but for some elements (e.g., `Transmission`) it can
509+
be relevant to also store the investment information of related objects (e.g., its modes).
510+
"""
511+
get_inv_objs(obj::AbstractElement) = [obj]
512+
504513
"""
505514
get_investment_times(gui::GUI, max_inst::Float64)
506515
@@ -516,29 +525,32 @@ function get_investment_times(gui::GUI, max_inst::Float64)
516525
period_labels = get_var(gui, :periods_labels)
517526
model = get_model(gui)
518527
for component get_root_design(gui)
519-
element = get_element(component)
528+
# Ensure to include both the component itself and its modes (in case of a transmission) when checking for investments
529+
elements = get_inv_objs(get_element(component))
520530
investment_times = String[]
521531
investment_capex = Float64[]
522-
for (i, t) enumerate(𝒯ᴵⁿᵛ)
523-
for investment_indicator investment_indicators # important not to use shorthand loop syntax here due to the break command (exiting both loops in that case)
524-
sym = Symbol(investment_indicator)
525-
if haskey(model, sym) &&
526-
!isempty(model[sym]) &&
527-
element axes(model[sym])[1]
528-
val = value(model[sym][element, t])
529-
if val > get_var(gui, :tol) * max_inst
530-
capex::Float64 = 0.0
531-
for capex_field capex_fields
532-
capex_key = Symbol(capex_field[1])
533-
if haskey(model, capex_key) &&
534-
element axes(model[capex_key])[1]
535-
capex += value(model[capex_key][element, t])
532+
for element elements
533+
for (i, t) enumerate(𝒯ᴵⁿᵛ)
534+
for investment_indicator investment_indicators # important not to use shorthand loop syntax here due to the break command (exiting both loops in that case)
535+
sym = Symbol(investment_indicator)
536+
if haskey(model, sym) &&
537+
!isempty(model[sym]) &&
538+
element axes(model[sym])[1]
539+
val = value(model[sym][element, t])
540+
if val > get_var(gui, :tol) * max_inst
541+
capex::Float64 = 0.0
542+
for capex_field capex_fields
543+
capex_key = Symbol(capex_field[1])
544+
if haskey(model, capex_key) &&
545+
element axes(model[capex_key])[1]
546+
capex += value(model[capex_key][element, t])
547+
end
536548
end
549+
t_str = split(period_labels[i], " ")[1]
550+
push!(investment_times, t_str)
551+
push!(investment_capex, capex)
552+
break # Do not add the capex again for other elements in investment_indicators
537553
end
538-
t_str = split(period_labels[i], " ")[1]
539-
push!(investment_times, t_str)
540-
push!(investment_capex, capex)
541-
break # Do not add the capex again for other elements in investment_indicators
542554
end
543555
end
544556
end

src/utils_GUI/topo_axis_utils.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ function connect!(gui::GUI, connection::Connection, two_way::Bool)
229229
any(style == inv_linestyle for style linestyles) ? [inv_linestyle] : [:solid]
230230
else
231231
colors = get_colors(connection)
232+
if isempty(colors)
233+
@warn "No resources transmitted for connection $(get_element(connection).id). Skipping."
234+
return
235+
end
232236
no_colors = length(colors)
233237
linestyle = linestyles
234238
end

0 commit comments

Comments
 (0)