Add structure for moving report.gms to Python - #142
Conversation
…from e_report.gms
… wrong for stress periods before the final year
| (dfs['tran_flow_all_rep'] * g['hours'] / dfs['tran_cap_energy']).groupby(['r','rr','trtype','t']).sum() | ||
| / g['hours'].sum() | ||
| ) | ||
| ## NOTE: We here assume that all solve years use the same total weighting for stress |
There was a problem hiding this comment.
The method on main is off for years before the last year; see #146. This implementation fixes it and is self-consistent when stress periods are always weighted at 6 hours per solve year, but if #146 is fixed as suggested, we should instead use hours_h(allh,t) here to make it future-proof in case we switch to nonuniform stress period weights.
bsergi
left a comment
There was a problem hiding this comment.
Looks good to me. I added one small fix to get the logging working again.
Do you have any concerns about memory usage as we add more ouputs here? We already read in the whole gdx so it might be fine but wasn't sure.
You noted that the outputs.h5 file is unchanged--is that saying that you ran the new diff_outputs() function and didn't come up with any differences between this branch and main?
| CO2_TRANSPORT_INV_out(r,rr,t)$tmodel_new(t) = CO2_TRANSPORT_INV.l(r,rr,t) ; | ||
| CO2_SPURLINE_INV_out(r,cs,t)$[tmodel_new(t)$csfeas(cs)] = CO2_SPURLINE_INV.l(r,cs,t) ; | ||
|
|
||
| CO2_FLOW_out(r,rr,h,t)$[(ord(r) < ord(rr))$tmodel_new(t)] = CO2_FLOW.l(r,rr,h,t) + CO2_FLOW.l(rr,r,h,t) ; |
There was a problem hiding this comment.
Shouldn't this be CO2_FLOW.l(r,rr,h,t) - CO2_FLOW.l(rr,r,h,t) ;? The sum is used in eq_co2_transport_caplimit which makes sense, but if the goal is to just get flows for r < rr region pairs but preserve direction then I would think the second term should be negative as is done with the tran_flow_rep calculation. Not sure who is the lead on CO2 these days but might be worth checking with them.
If this is a bug it might make sense to just flag this in an issue and address it in a separate PR since the goal of this one is just to do the reporting and have it match what we have. If we did want to address here I think we would just to agg='net' over in report_calcs.py.
There was a problem hiding this comment.
I guess there is the net flow calculation below which is what I was expecting, so maybe this one is fine.
There was a problem hiding this comment.
Yeah I'm not sure why it's here; the number of permutations doesn't really seem necessary, but because the net flow is also included, it seems intentional to have both. It might be used to identify hours where the pipeline capacity is binding. I figured I'd leave it for parity with the existing outputs, and it could maybe be cleaned up as part of #2.
Co-authored-by: Brian Sergi <bsergi@nlr.gov>
Summary
Following in the vein of #61 and #139, this PR adds a structure for moving the calculations in
report.gmsto Python and uses it for a couple blocks of outputs as examples.Technical details
Implementation notes
The proposed structure is:
report_data.csv(inreeds/core/terminus){case}/outputs/results.gdxreport_dump.pycalls a newreport_calcs.main(), which returns a dictionary of output parameters calculated in Python. These parameters then get written to{case}/outputs/{param}.csvand/or{case}/outputs/outputs.h5, as usual.report_calcs.main()has some helper functions for common operations at the top, followed by blocks of calculations for the different types of outputs.Some notes given the current mix of standards:
report.gmstoreport_calcs.pyare listed in a block comment at the top ofreport.gms, so searching for them will turn up both scripts.report.gmswill not show up in{case}/outputs/rep_{case}.gdx{case}/outputs/outputs.h5is unchangedreport_calcs.pyAdditional changes
A new
reeds.results.diff_outputs()function has been added. This function works likegdxdiffbut foroutputs.h5files, and can be used to do a global comparison of outputs between pairs of cases.Validation, testing, and comparison report(s)
Zero change for the USA_defaults case: results-v20260708_mainK0_USA_defaults,v20260709_reportK0_USA_defaults.pptx
Checklist for author
Details to double-check
General information to guide review
Did you use LLM tools (chatbot or copilot) in the preparation of this PR? If so, describe how
No