Skip to content

Commit 4399f17

Browse files
author
Jon Vegard Venås
authored
Fix miscellaneous bugs and miscellaneous improvements (#22)
* Fix bug when length(get_products(system)) == length(id_to_color_map) but when get_products(system) is not a subset of keys(id_to_color_map). This case did not expand id_to_color_map correctly. * Add the EnergyModelsGUI package in the Project.toml file in the examples folder. * Added more descriptive names for EnergyModelsHeat and EnergyModelsHydrogen in the descriptive_names.yml file and performed a cleanup of the file. Also added colors for the HeatLT and HeatHT resources. * Order the colors (by id) in the Resources legend and move boundaries for countries just above the ocean layer. * Add missing description of the case_name option in the GUI-function. * Fix default placements of the nodes in a uniform circle (when coordinates are not provided). * Only create the design-folder if needed
1 parent f527ad1 commit 4399f17

8 files changed

Lines changed: 276 additions & 235 deletions

File tree

NEWS.md

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

3+
## Version 0.5.13 (2025-06-02)
4+
5+
### Bugfix
6+
7+
* Fix bug when `length(get_products(system)) == length(id_to_color_map)` but when `get_products(system)` is not a subset of `keys(id_to_color_map)`. This case did not expand `id_to_color_map` correctly.
8+
* Add missing description of the `case_name` option in the `GUI`-function.
9+
* Add the `EnergyModelsGUI` package in the `Project.toml` file in the examples folder.
10+
11+
### Enhancement
12+
13+
* Added more descriptive names for `EnergyModelsHeat` and `EnergyModelsHydrogen` and add a colors for the `HeatLT` and `HeatHT` resources.
14+
15+
### Adjustment
16+
* Order the colors (by id) in the Resources legend.
17+
* Move boundaries for countries just above the ocean layer.
18+
* Fix default placements of the nodes in a uniform circle (when coordinates are not provided).
19+
* Only create the design-folder if needed.
20+
321
## Version 0.5.12 (2025-03-09)
422

523
### Enhancement

Project.toml

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

66
[deps]
77
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"

examples/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[deps]
22
EnergyModelsBase = "5d7e687e-f956-46f3-9045-6f5a5fd49f50"
3+
EnergyModelsGUI = "737a7361-d3b7-40e9-b1ac-59bee4c5ea2d"
34
EnergyModelsGeography = "3f775d88-a4da-46c4-a2cc-aa9f16db6708"
45
EnergyModelsInvestments = "fca3f8eb-b383-437d-8e7b-aac76bb2004f"
56
EnergyModelsRenewableProducers = "b007c34f-ba52-4995-ba37-fffe79fbde35"

src/colors.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ ResourceEmit: "#606060" # gray
1717
CO2: "#606060" # gray
1818
CO₂: "#606060" # gray
1919
Coal: "#6D392E" # brown
20-
Water: "#bfefff" # sky blue
20+
Water: "#bfefff" # sky blue
21+
HeatLT: "#fbdfb0" # :navajowhite
22+
HeatHT: "#e78582" # :lightcoral

src/descriptive_names.yml

Lines changed: 231 additions & 223 deletions
Large diffs are not rendered by default.

src/setup_GUI.jl

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ data stored as key-value pairs. This dictionary is corresponding to the the old
3030
main window.
3131
- **`fontsize::Int64=12`** is the general fontsize.
3232
- **`plot_widths::Tuple{Int64,Int64}=(1920, 1080)`** is the resolution of the window.
33+
- **`case_name::String = ""`** provides a tag for the window title.
3334
- **`scale_tot_opex::Bool=false`** multiplies total OPEX quantities with the duration of the strategic period.
3435
- **`scale_tot_capex::Bool=false`** divides total CAPEX quantities with the duration of the strategic period.
3536
- **`colormap::Vector=Makie.wong_colors()`** is the colormap used for plotting results.
@@ -292,7 +293,7 @@ function create_makie_objects(vars::Dict, design::EnergySystemDesign)
292293
# Create GeoMakie plotable object
293294
countries = GeoMakie.to_multipoly(countries_geo_json.geometry)
294295
end
295-
poly!(
296+
countries_plot = poly!(
296297
ax,
297298
countries;
298299
color = :honeydew,
@@ -301,6 +302,7 @@ function create_makie_objects(vars::Dict, design::EnergySystemDesign)
301302
strokewidth = 0.5,
302303
inspectable = false,
303304
)
305+
Makie.translate!(countries_plot, 0, 0, -1)
304306
ocean_coords = [(180, -90), (-180, -90), (-180, 90), (180, 90)]
305307
ocean = poly!(
306308
ax,
@@ -310,7 +312,7 @@ function create_makie_objects(vars::Dict, design::EnergySystemDesign)
310312
strokecolor = :gray50,
311313
inspectable = false,
312314
)
313-
Makie.translate!(ocean, 0, 0, -1)
315+
Makie.translate!(ocean, 0, 0, -2)
314316
else # The design does not use the EnergyModelsGeography package: Create a simple Makie axis
315317
ax = Axis(
316318
gridlayout_topology_ax[1, 1];
@@ -362,16 +364,26 @@ function create_makie_objects(vars::Dict, design::EnergySystemDesign)
362364

363365
# Create legend to explain the available resources in the design model
364366
markers::Vector{Makie.Scatter} = Vector{Makie.Scatter}(undef, 0)
365-
for color collect(values(design.id_to_color_map))
367+
368+
# Create an ordered list of colors (based on their id)
369+
color_mat =
370+
hcat(collect(keys(design.id_to_color_map)), collect(values(design.id_to_color_map)))
371+
perm = sortperm(lowercase.(color_mat[:, 1]))
372+
sorted_color_mat = color_mat[perm, :]
373+
374+
# Create markers for colors in legend
375+
for color sorted_color_mat[:, 2]
366376
push!(
367377
markers,
368378
scatter!(ax, Point2f((0, 0)); marker = :rect, color = color, visible = false),
369379
) # add invisible dummy markers to be put in the legend box
370380
end
381+
382+
# Add the legend to the axis
371383
topo_legend = axislegend(
372384
ax,
373385
markers,
374-
collect(keys(design.id_to_color_map)),
386+
sorted_color_mat[:, 1],
375387
"Resources";
376388
position = :rt,
377389
labelsize = vars[:fontsize],

src/setup_topology.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function EnergySystemDesign(
4343

4444
# Complete the `id_to_color_map` if some products are lacking (this is done by choosing
4545
# colors for the lacking `Resource`s that are most distinct to the existing set of colors)
46-
if !(length(get_products(system)) == length(id_to_color_map))
46+
if !issubset(get_products(system), keys(id_to_color_map))
4747
id_to_color_map = set_colors(get_products(system), id_to_color_map)
4848
end
4949

@@ -87,7 +87,6 @@ function EnergySystemDesign(
8787
if element == get_ref_element(system)
8888
x = parent_x
8989
y = parent_y
90-
nodes_count -= 1
9190
else # place nodes in a circle around the parents availability node
9291
x, y = place_nodes_in_circle(
9392
nodes_count, current_node, 1, parent_x, parent_y,

src/utils_gen/structures_utils.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,6 @@ function design_file(system::AbstractSystem, path::String)
166166
if isempty(path)
167167
return ""
168168
end
169-
if !isdir(path)
170-
mkpath(path)
171-
end
172169
return joinpath(path, "$(get_parent(system)).yml")
173170
end
174171

@@ -233,6 +230,10 @@ Save the x,y-coordinates of `design_dict` to a .yml file at location and filenam
233230
`file`.
234231
"""
235232
function save_design(design_dict::Dict, file::String)
233+
design_dir = dirname(file)
234+
if !isdir(design_dir)
235+
mkpath(design_dir)
236+
end
236237
return YAML.write_file(file, design_dict)
237238
end
238239

@@ -242,7 +243,7 @@ end
242243
links::Vector{Link},
243244
area_links::Vector{Link},
244245
area_nodes::Vector{EMB.Node},
245-
indices::Vector{Int
246+
indices::Vector{Int},
246247
)
247248
248249
Recursively find all nodes connected (directly or indirectly) to `node` in a system of `links`

0 commit comments

Comments
 (0)