Call graphs from eesyplan methods#479
Conversation
8b96118 to
db15e10
Compare
db15e10 to
e2e4a81
Compare
Fetches timeseries data from database based on foreignkeys and rebuilds the original datapackage structure
e2e4a81 to
21a33ef
Compare
Bachibouzouk
left a comment
There was a problem hiding this comment.
Thanks for tackling this @paulapreuss - I think it looks nice. However I would wait that the PR oemof/oemof-datapackage#4 is merged (or check that with this version of oemof-datapackage it still works as expected)
| # TODO this sankey implementation does not allow for single timesteps | ||
| # if ts is not None: | ||
| # ts = int(ts) | ||
| rebuilt_dp = add_timeseries_to_database_datapackage(scenario) |
There was a problem hiding this comment.
I am wondering whether we should add this as a method of the Scenario model. However this might add confusion if there are too many methods to get a datapackage or a jsonified datapackage from the Scenario. Because then one has to be sure where the datapackages comes from, from the DB or generated on the fly. And what if the user changed some components without resimulating and would like to export this as a datapackage.
If we decide to go for the method I would
rebuilt_dp = scenario.rebuilt_datapackage() and this method should return an error message if the datapackage attribute wasn't present (or it could generate it on the fly)
There was a problem hiding this comment.
You're right, I think it makes a lot of sense to add this as a Scenario method instead.
| qs = FancyResults.objects.filter(simulation=scenario.simulation) | ||
|
|
||
| if qs.exists(): | ||
| flows = { | ||
| (asset, bus): json.loads(flow_data) | ||
| for asset, bus, flow_data in qs.values_list("asset", "bus", "flow_data") | ||
| } | ||
| flows_df = pd.DataFrame(flows) | ||
| flows_df.index = scenario.get_timestamps()[: len(flows_df)] | ||
| fig, links_df = eesyplan_graphs.sankey(flows=flows_df, es=es) |
There was a problem hiding this comment.
In the future we should then get all this from the results datapackage I guess
|
I updated the EZP simulation server with |
|
Not sure about why, but now with these changes I get an |
| if qs.exists(): | ||
| flows = { | ||
| (asset, bus): json.loads(flow_data) | ||
| for asset, bus, flow_data in qs.values_list( |
There was a problem hiding this comment.
This will always list asset on the first line and bus on the second line of the multiIndex column. I think now it is better to save the results as a jsonified datapackage and use
from oemof.eesyplan.datapackage.energy_system import (
create_energy_system_from_dp,
)
from oemof.eesyplan import import_results
from oemof.eesyplan.postprocessing.graphs import sankey
energy_system = create_energy_system_from_dp(es_dp_path)
results = import_results(destination_path, energy_system)
fig, links_df = sankey(results["flow"], title="Test Sankey")
There was a problem hiding this comment.
So you would add a datapackage_results and store it? I guess here it is mostly a question of how much slower (or not slower at all?) doing import_results for each graph might be compared to fetching ònly the relevant columns from the more structured database object.
There was a problem hiding this comment.
This is why I might also want to store the graphs as dict/json within the datapackage under the folder graph
Goal
Notes:
Scenarioinstead ofSimulationto not have to worry about if a simulation object already existsstore_database_recordtoto_jsonified_datapackagemethod instead of calling again withn_timestamps=0to only build the datapackage once and strip the timeseries instead of building twice (once for simulation and once for db)EnergySystemcan be rebuilt from db datapackage after repopulating with Timeseries values