Skip to content

Reorganize ecm_prep.py #473

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Reorganize ecm_prep.py #473

wants to merge 6 commits into from

Conversation

aspeake
Copy link
Collaborator

@aspeake aspeake commented Mar 10, 2025

Fixes #438

Improve encapsulation of ecm_prep.py by breaking out code into other modules. Only the main() function in ecm_prep.py exists outside of a class now. Below is a summary of changes.

  • New scout/utils.py module
    • with new class JsonIO containing json file handling methods previously in ecm_prep.Utils
    • with class MyEncoder that was previously stored in ecm_prep.py
    • with new class PrintFormat containing output format methods previously stored in ecm_prep.py (eg, verboseprint())
      • share the method PrintFormat.verboseprint in ecm_prep.py and in run.py
  • New scout/ecm_prep_vars.py module
    • with class UsefulVars previously in ecm_prep.py
    • with class UsefulInputFiles previously in ecm_prep.py
    • with class EPlusMapDicts previously in ecm_prep.py
  • New class ECMUtils class in ecm_prep.py to store static methods
  • New class ECMPrep class in ecm_prep.py to store static methods for altering Measure and MeasurePackage instances
    • contains prepare_measures(), prepare_packages(), and split_clean_data()
  • Remove unused EPlusGlobals class and associated tests
  • Move breakout_mseg() to an instance method of the Measure class

To-do in a future PR

  • Break up ecm_prep.main(), limiting this function to just managing the ecm_prep workflow
  • New subpackage scout/ecm_prep/ which contains:
    • ecm_prep_vars.py
    • ecm_prep_args.py
    • ecm_prep_utils.py - NEW module containing ecm_prep.Utils
    • ecm_prep_measure.py - NEW module containing class Measure
    • ecm_prep_package.py - NEW module containing class Package
    • ecm_prep.py - the entry point for preparing ECMs, contains main(), prepare_measures, prepare_packages and other workflow-related functions
  • Since ecm_prep.py is a little more buried, it would be nice to add an entry point scout ecm_prep that calls scout/ecm_prep/ecm_prep.py`

@aspeake aspeake added this to the v1.2.0 milestone Mar 10, 2025
@aspeake aspeake self-assigned this Mar 10, 2025
@aspeake aspeake marked this pull request as ready for review March 11, 2025 21:53
@aspeake aspeake force-pushed the ecm_prep_reorg branch 2 times, most recently from d12e4c2 to d217f1e Compare March 18, 2025 23:42
@aspeake aspeake force-pushed the ecm_prep_reorg branch 2 times, most recently from 295bcab to d244b6f Compare April 11, 2025 23:06
@@ -5455,12 +5452,12 @@ def main(opts: argparse.NameSpace): # noqa: F821
try:
elec_carb = elec_cost_carb['CO2 intensity of electricity']['data']
elec_cost = elec_cost_carb['End-use electricity price']['data']
fmt = True # Boolean for indicating data key substructure
format_data = True # Boolean for indicating data key substructure
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable fmt conflicted with the imported class fmt

@classmethod
def load_json(cls, filepath: Path) -> dict:
"""Loads data from a .json file
class ECMUtils:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class is similar to ECMPrep, but ECMPrep is meant to store methods that update Measure and MeasurePackage instances. It might make sense to merge the two since they both contain common static methods used throughout the module.

@aspeake aspeake requested a review from jtlangevin April 17, 2025 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Restructure ecm_prep.py
1 participant