Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create function to plot #191

Closed
3 of 4 tasks
Tracked by #97
abelsiqueira opened this issue Oct 25, 2023 · 11 comments · Fixed by #360
Closed
3 of 4 tasks
Tracked by #97

Create function to plot #191

abelsiqueira opened this issue Oct 25, 2023 · 11 comments · Fixed by #360
Assignees
Labels
Type: addition Add something that doesn't exist Zone: export & visualisation How data leaves model & is visualised
Milestone

Comments

@abelsiqueira
Copy link
Member

abelsiqueira commented Oct 25, 2023

Create a function to create graph plots and attach information to the graph.
Check https://github.com/JuliaGraphs/NetworkLayout.jl or https://github.com/JuliaGraphs/GraphPlot.jl

The following functions for plots will be added:

  • time series for a single flow
  • graph with flow values
  • balance (stacked bar charts) for assets
  • time series for all flows?
@abelsiqueira abelsiqueira mentioned this issue Oct 25, 2023
11 tasks
@abelsiqueira abelsiqueira added Type: addition Add something that doesn't exist Zone: data & import Interfacing between database and Julia labels Oct 25, 2023
@clizbe clizbe self-assigned this Oct 26, 2023
@clizbe
Copy link
Member

clizbe commented Oct 30, 2023

I started playing with this, but if someone else wants to tackle it while I'm gone, go ahead.

@clizbe clizbe removed their assignment Oct 30, 2023
@clizbe clizbe self-assigned this Nov 8, 2023
@clizbe
Copy link
Member

clizbe commented Nov 9, 2023

I've made the first graph and am working on the second.
I would like to scale the thickness of the connecting lines by the total capacity (initial+investment) and maybe the same for the size (or color) of the nodes - or maybe just labels.

But I can't figure out how to get this data. It means adding a Dict and a DenseAxis Array:
image

@clizbe
Copy link
Member

clizbe commented Nov 9, 2023

I found a function "merge" that can add Dicts based on their keys, but it doesn't recognize a DenseAxisArray:
image

@abelsiqueira
Copy link
Member Author

Indeed, there is no way to nicely sum these because they are different structures but also because they are not indexed on the same sets.

parameters.flows_unit_capacity is indexed on F and solution.flows_investment is indexed on Fi.

So you have to iterate on the flows and aggregate these based on what you want.

If you want all flows_unit_capacity, and if they are investable, add the solution, then you can do.

total = copy(parameters.flows_unit_capacity)
for f in sets.flows
    if parameters.flows_investable[f]
        total[f] += solution.flows_investment[f]
    end
end

And a += b is the same as a = a + b.

@clizbe
Copy link
Member

clizbe commented Nov 10, 2023

Yes that's exactly what I need, thanks!
But also I think this is something we'll want in the output, so it might make sense to put this is post-processing, or otherwise change the structure of the data. 🤔

@clizbe
Copy link
Member

clizbe commented Nov 10, 2023

Is there a way to ask the graph where it's connections are FROM and TO? Because now I have this data in a Dict{Tuple{String, String}, Float64} but the gplot parameter edgelinewidth is expecting just a Vector that somehow matches the order of the flows in the graph.

@clizbe
Copy link
Member

clizbe commented Nov 10, 2023

Google seems to suggest we use a MetaGraph or MetaGraphsNext which would allow node names and weights?
https://discourse.julialang.org/t/identifying-nodes-in-a-graph/41498

@datejada
Copy link
Member

Is there a way to ask the graph where it's connections are FROM and TO? Because now I have this data in a Dict{Tuple{String, String}, Float64} but the gplot parameter edgelinewidth is expecting just a Vector that somehow matches the order of the flows in the graph.

From the graph structure, something like this will give you the id and the name:

for e  edges(graph)
   from_asset_id = e.src
   from_asset_name = sets.assets[e.src]
   to_asset_id = e.dst
   to_asset_name = sets.assets[e.dst]
end

If you are using the F set, then something like this should work too:

for f  F
   from_asset_name = f[1]
   to_asset_name = f[2]
end

Depending on the information in your function, one option will be more straightforward.

@abelsiqueira, any comment, suggestion or thoughts? Thanks!

@clizbe clizbe added this to the M2 - End June milestone Dec 11, 2023
@clizbe clizbe mentioned this issue Dec 13, 2023
4 tasks
@clizbe
Copy link
Member

clizbe commented Dec 14, 2023

With the new data format, I would like to show a directed graph with:

  • Node names with capacity values (done)
  • Export flows with capacity (normal directed graph)
  • Import flows with capacity (reverse directed graph)

I know how to calculate the export/import caps for flow A->B, but how can I get the reverse direction arrows onto the same graph to label with the import capacity? The graph just thinks there's 1 arrow that can have a positive or negative flow - but I need to show two arrows with their own capacities.

@clizbe
Copy link
Member

clizbe commented Dec 14, 2023

I could do a non-directed graph and make the labeled capacity be a different color for export/import (or display on a different part of the line), but I think having double arrows is the better solution.

@abelsiqueira
Copy link
Member Author

You will need to create a separate graph for that, since the one we have is indeed only from A to B (unless explicitly declared from B to A in the csv as well).

Here is how to construct one such graph using the existing graph:

graph
dgraph = DiGraph(nv(graph)) # Creates a graph with the same number of vertices
for e in edges(graph)
    add_edge!(dgraph, e.src, e.dst)
    add_edge!(dgraph, e.dst, e.src)
end

The thing is, dgraph is NOT a MetaGraph. So using dgraph[u, v].some_field will not work, so you have to get those properties from graph. Let me know if you need more info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: addition Add something that doesn't exist Zone: export & visualisation How data leaves model & is visualised
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants