Skip to content
This repository has been archived by the owner on May 27, 2022. It is now read-only.

refactor: move all logic within functions or if block #26

Merged
merged 1 commit into from
Dec 2, 2021

Conversation

danielolsen
Copy link
Collaborator

@danielolsen danielolsen commented Dec 1, 2021

Pull Request doc

Purpose

Move all logic within functions or an if __name__ == "__main__": block, so that the module can still be run as a script or can be looped without needing to modify the code, and to enable more granular testing of lower-level functions.

What the code is doing

  • A new main function is added, which orchestrates all of the lower-level functions.
  • An hourly_fits_df input is added to the temp_to_energy function so that this function no longer relies on a module-scope variable (there may be more places where similar parameters need to be added, this was the only one that jumped out at me so far).
    Several variables were only defined within module scope and not passed to analysis functions that needed them; these parameters have now been made explicit.
  • Launching the main function with 'default' value is moved within an if __name__ == "__main__": block, so the module can be run as a script like before, or the new main function could be called within a loop to go through many different zones.

Testing

Not tested yet, since I'm still working through an error I'm getting when I tried to run the original code (may be a local issue on my end). Will update when I can test successfully before and after the refactor. EDIT: tested, output CSVs evaluate as identical.

Time estimate

15 minutes.

@danielolsen danielolsen self-assigned this Dec 1, 2021
Copy link
Collaborator

@BainanXia BainanXia left a comment

Choose a reason for hiding this comment

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

LGTM

@danielolsen danielolsen force-pushed the daniel/zone_profile_gen branch from 0745e22 to e233753 Compare December 2, 2021 00:59
@danielolsen
Copy link
Collaborator Author

I figured out the error I was getting on my end that was preventing testing. Now that the error is resolved, I've filled in the remaining variables that needed to be passed to the lower-level functions and this is tested to produce an identical output CSV (at least for LADWP in 2019).

Copy link
Collaborator

@evanpatz evanpatz left a comment

Choose a reason for hiding this comment

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

Looks good!

@danielolsen danielolsen merged commit 92462fe into evan/zone_profile_gen Dec 2, 2021
mbwaite added a commit that referenced this pull request Jan 25, 2022
* feat: puma latitude and longitude added to puma_data dataframe

* feat: puma latitude/longitude csv to be appeneded to puma_data

* feat: national pumas and balanacing authorities shapefiles

* feat: zone profile generator

* refactor: linting

* refactor: linting

* refactor: replace while loop in bkpt_scale() with a sorting method

* refactor: move all logic within functions or if block (#26)

* refactor: simplify hourly_load_fit and improve pandas 1.3 compatibility (#27)

* zone_profile_gen.py updates from Evan - puma.area error fix, cooling equations update, zonal_data() refactor, wb/db fit update, profile year added

* feat: updated min daily number of load/temp points to fit to from 8 to 10

* feat: folder for generated profiles

* feat: folder for zone day hour coefficients

* feat: hourly fits graphs, profile stats export

* "profiles, hourly fits, and profile graphs"

* graphs

* profiles for zones in NY, CA, and TX. update to zone_profile_generator to account for puma_data year update

* linting

* linting

* feat: add wetbulb temp and darkness fraction functions to era5_data_a… (#29)

* feat: add wetbulb temp and darkness fraction functions to era5_data_agg.py, now renamed weather_data_agg.py

* chore: code style cleanup

* chore: import sorting

* chore: linting fixes

Co-authored-by: Daniel Olsen <[email protected]>

* Mike/weather write fix (#30)

* fix: reference const.state_list

* refactor: save dark_frac output to local files

* refactor: save temps_wetbulb to local files

* chore: remove unused state_list

* style: linting fixes with black

* fix: remove 2010 reference for cdd65

* chore: update puma_data

* refactor: use base_year from const.py

* refactor: rename load_year to base_year

* Yinbo/zone profile gen refactor (#32)

* Fix: create output folders if the address is not exist on local machine; Refactor: add plot_boolean to control whether or not plot result profiles

* test

* style: style correction using 'black'

* style:switch the order of package importing

* style

* chore: change os.path.exists to os.path.isdir in order to avoid same file names

* chore: add docstring

* style: docstring style fixed

Co-authored-by: danielolsen <[email protected]>
Co-authored-by: Daniel Olsen <[email protected]>
Co-authored-by: mbwaite <[email protected]>
Co-authored-by: yinboHU <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants