-
Notifications
You must be signed in to change notification settings - Fork 28
Ccaradon/sdr 2025 r4 fix timeseries plots #428
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
Merged
rHorsey
merged 19 commits into
ccaradon/sdr_2025_r4
from
ccaradon/sdr_2025_r4_fix_timeseries_plots
Jan 7, 2026
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
bbdd582
Setting up testing runs
ChristopherCaradonna cf4fd58
progress
ChristopherCaradonna 14316b4
Plotting updates - works for measure comparisons, but needs cleanup
ChristopherCaradonna 4185c1d
Move AWS/S3 methods to comstock.py
ChristopherCaradonna 7f605d1
Move S3 retrieval methods to comstock.py
ChristopherCaradonna 50b35fd
works with both states and counties but not yet multiple at one time
ChristopherCaradonna d529345
refactor code to accommodate multiple state/county queries together f…
ChristopherCaradonna f234281
Update compare_upgrades-test_timeseries_plots.py
ChristopherCaradonna 6e878d5
Add AMI plot functionality and some cleanup
ChristopherCaradonna 2854224
Adds warning if an applicability list for timeseries is empty instead…
ChristopherCaradonna 5b49d3e
Merge branch 'ccaradon/sdr_2025_r4' into ccaradon/sdr_2025_r4_fix_tim…
ChristopherCaradonna 925eccb
Merge branch 'ccaradon/sdr_2025_r4' into ccaradon/sdr_2025_r4_fix_tim…
ChristopherCaradonna d64e60a
Update postprocessing/comstockpostproc/plotting_mixin.py
ChristopherCaradonna 9d337a2
Update postprocessing/comstockpostproc/comstock.py
ChristopherCaradonna 1014b95
Update postprocessing/comstockpostproc/plotting_mixin.py
ChristopherCaradonna 3ef0577
Update postprocessing/comstockpostproc/plotting_mixin.py
ChristopherCaradonna 14650c5
PR review updates
ChristopherCaradonna 168b72c
Merge branch 'ccaradon/sdr_2025_r4_fix_timeseries_plots' of https://g…
ChristopherCaradonna 043aec3
Various updates from PR comments
ChristopherCaradonna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
postprocessing/compare_upgrades-test_timeseries_plots.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| #!/usr/bin/env python3 | ||
| # -*- coding: utf-8 -*- | ||
|
|
||
| import logging | ||
| import comstockpostproc as cspp | ||
|
|
||
| logging.basicConfig(level='INFO') # Use DEBUG, INFO, or WARNING | ||
| logger = logging.getLogger(__name__) | ||
|
|
||
| def main(): | ||
| # ComStock run | ||
| comstock = cspp.ComStock( | ||
| s3_base_dir='com-sdr', # If run not on S3, download results_up**.parquet manually | ||
| comstock_run_name='pump_v9', # Name of the run on S3 | ||
| comstock_run_version='pump_v9', # Use whatever you want to see in plot and folder names | ||
| comstock_year=2018, # Typically don't change this | ||
| athena_table_name=None, # Typically don't change this | ||
| truth_data_version='v01', # Typically don't change this | ||
| buildstock_csv_name='buildstock.csv', # Download buildstock.csv manually | ||
| acceptable_failure_percentage=0.05, # Can increase this when testing and high failure are OK | ||
| drop_failed_runs=True, # False if you want to evaluate which runs failed in raw output data | ||
| color_hex='#0072B2', # Color used to represent this run in plots | ||
| skip_missing_columns=True, # False if you want to ensure you have all data specified for export | ||
| reload_from_cache=False, # True if CSV already made and want faster reload times | ||
| include_upgrades=True, # False if not looking at upgrades | ||
| upgrade_ids_to_skip=[], # Use [1, 3] etc. to exclude certain upgrades | ||
| make_timeseries_plots=False, | ||
| timeseries_locations_to_plot={ | ||
| 'MN': 'Minnesota', # specify location (either county ID or state ID) and corresponding name for plots and folders. | ||
| #'MA':'Massachusetts', | ||
| #'OR': 'Oregon', | ||
| #'LA': 'Louisiana', | ||
| #'AZ': 'Arizona', | ||
| #'TN': 'Tennessee', | ||
| ('MA', 'NH', 'CT', 'VT', 'RI'): 'New England', # example of multiple states together - using tuples as keys | ||
| #'G4900350': 'Salt Lake City', | ||
| #'G2500250': 'Boston', # if specifying a county, you must export county level data to S3 | ||
| #'G4804530': 'Austin', | ||
| ('G2500250', 'G4804530'):'Baustin' # multiple counties together - using tuples as keys | ||
| }, | ||
|
|
||
| upgrade_ids_for_comparison={} # Use {'<Name you want for comparison run folder>':[0,1,2]}; add as many upgrade IDs as needed, but plots look strange over 5 | ||
| #output_dir = 's3://oedi-data-lake/nrel-pds-building-stock/end-use-load-profiles-for-us-building-stock/2025/comstock_amy2018_release_1' | ||
| ) | ||
|
|
||
| # Stock Estimation for Apportionment: | ||
| stock_estimate = cspp.Apportion( | ||
| stock_estimation_version='2025R3', # Only updated when a new stock estimate is published | ||
| truth_data_version='v01', # Typically don't change this | ||
| reload_from_cache=False, # Set to "True" if you have already run apportionment and would like to keep consistant values between postprocessing runs. | ||
| #output_dir = 's3://oedi-data-lake/nrel-pds-building-stock/end-use-load-profiles-for-us-building-stock/2025/comstock_amy2018_release_1' | ||
| ) | ||
|
|
||
| # Scale ComStock runs to the 'truth data' from StockE V3 estimates using bucket-based apportionment | ||
| base_sim_outs = comstock.get_sim_outs_for_upgrade(0) | ||
| comstock.create_allocated_weights(stock_estimate, base_sim_outs, reload_from_cache=False) | ||
|
|
||
| # CBECS | ||
| cbecs = cspp.CBECS( | ||
| cbecs_year=2018, # 2012 and 2018 currently available | ||
| truth_data_version='v01', # Typically don't change this | ||
| color_hex='#009E73', # Color used to represent CBECS in plots | ||
| reload_from_csv=False # True if CSV already made and want faster reload times | ||
| ) | ||
|
|
||
| # Scale ComStock to CBECS 2018 AND remove non-ComStock buildings from CBECS | ||
| base_sim_outs = comstock.get_sim_outs_for_upgrade(0) | ||
| alloc_wts = comstock.get_allocated_weights() | ||
| comstock.create_allocated_weights_scaled_to_cbecs(cbecs, base_sim_outs, alloc_wts, remove_non_comstock_bldg_types_from_cbecs=True) | ||
|
|
||
| # Add utility bills onto allocated weights | ||
| for upgrade_id in comstock.upgrade_ids_to_process: | ||
| # up_sim_outs = comstock.get_sim_outs_for_upgrade(upgrade_id) | ||
| # up_alloc_wts = comstock.get_allocated_weights_scaled_to_cbecs_for_upgrade(upgrade_id) | ||
| comstock.create_allocated_weights_plus_util_bills_for_upgrade(upgrade_id) | ||
|
|
||
| # Specify geo exports | ||
|
|
||
| # county resolution, files by state and county | ||
| county_resolution = { | ||
| 'geo_top_dir': 'by_state_and_county', | ||
| 'partition_cols': { | ||
| comstock.STATE_ABBRV: 'state', | ||
| comstock.COUNTY_ID: 'county', | ||
| }, | ||
| 'aggregation_levels': [comstock.COUNTY_ID], # , comstock.COUNTY_ID], # Full tract resolution (agg=in.nhgis_tract_gisjoin) | ||
| 'data_types': ['full'], | ||
| 'file_types': ['parquet'], | ||
| } | ||
|
|
||
| # state level resolution, one single national file | ||
| state_resolution = { | ||
| 'geo_top_dir': 'national_by_state', | ||
| 'partition_cols': {}, | ||
| 'aggregation_levels': [[comstock.STATE_ABBRV, comstock.CZ_ASHRAE]], | ||
| 'data_types': ['full'], # other options: 'detailed', 'basic' **If using multiple options, order must go from more detailed to less detailed. | ||
| 'file_types': ['parquet'], # other options:'parquet' | ||
| } | ||
|
|
||
ChristopherCaradonna marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # specify the export level | ||
| # IMPORTANT: if making county level timeseries plots, must export county level data to S3. This does not occur automatically. | ||
| geo_exports = [county_resolution] #county_resolution | ||
|
|
||
| for geo_export in geo_exports: | ||
| for upgrade_id in comstock.upgrade_ids_to_process: | ||
| #if upgrade_id == 0: | ||
| # continue | ||
| #comstock.export_metadata_and_annual_results_for_upgrade(upgrade_id, [geo_export]) | ||
|
|
||
| # Also write to S3 if making timeseries plots | ||
| if comstock.make_timeseries_plots: # TODO: force geo exports to county data if couunty timeseries is requested. | ||
| s3_dir = f"s3://{comstock.s3_base_dir}/{comstock.comstock_run_name}/{comstock.comstock_run_name}" | ||
| s3_output_dir = comstock.setup_fsspec_filesystem(s3_dir, aws_profile_name=None) | ||
| comstock.export_metadata_and_annual_results_for_upgrade(upgrade_id=upgrade_id, geo_exports=[geo_export], output_dir=s3_output_dir) | ||
|
|
||
| # write select results to S3 for Athena/Glue when needed for timeseries plots | ||
| if comstock.make_timeseries_plots: | ||
| s3_dir = f"s3://{comstock.s3_base_dir}/{comstock.comstock_run_name}/{comstock.comstock_run_name}" | ||
ChristopherCaradonna marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| database = "enduse" | ||
ChristopherCaradonna marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| crawler_name = comstock.comstock_run_name # used to set name of crawler, cannot include slashes | ||
ChristopherCaradonna marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| workgroup = "eulp" # Athena workgroup to use | ||
ChristopherCaradonna marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| glue_service_role = "service-role/AWSGlueServiceRole-default" | ||
ChristopherCaradonna marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Export parquet files to S3 for Athena/Glue | ||
| comstock.create_sightglass_tables(s3_location=f"{s3_dir}/metadata_and_annual_results_aggregates", | ||
| dataset_name=crawler_name, | ||
| database_name=database, | ||
| glue_service_role=glue_service_role) | ||
| comstock.fix_timeseries_tables(crawler_name, database) | ||
| comstock.create_views(crawler_name, database, workgroup) | ||
|
|
||
| # Create measure run comparisons; only use if run has measures | ||
| comparison = cspp.ComStockMeasureComparison(comstock, timeseries_locations_to_plot=comstock.timeseries_locations_to_plot, make_comparison_plots = comstock.make_comparison_plots, make_timeseries_plots = comstock.make_timeseries_plots) | ||
ChristopherCaradonna marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Export dictionaries corresponding to the exported columns | ||
| #comstock.export_data_and_enumeration_dictionary() | ||
|
|
||
| # Code to execute the script | ||
| if __name__=="__main__": | ||
ChristopherCaradonna marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| main() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.