Skip to content
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

Refactor: Carbon Pools Package Imports #28

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

Conversation

gtempus
Copy link
Collaborator

@gtempus gtempus commented Sep 14, 2022

As promised, I did some import investigation and cleanup.

Pull request checklist

Please check if your PR fulfills the following requirements:

  • Make sure you are requesting to pull a topic/feature/bugfix branch (right side). Don't request your master!
  • Make sure you are making a pull request against the develop branch (left side). Also you should start your branch off our develop.
  • Check the commit's or even all commits' message styles matches our requested structure.
  • Check your code additions will fail neither code linting checks nor unit test.

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

Import statements are messy and append to sys.path during loading.
Issue Number: N/A

What is the new behavior?

Imports follow PEP-8 and no longer require sys.path modification

Does this introduce a breaking change?

  • Yes
  • No

Other information

dagibbs22 and others added 17 commits August 22, 2022 16:41
* docker-compose works fine and can enter docker container locally. Haven't tried running the model with updated GDAL and Python yet.

* Successfully installs the required Python packages. Haven't tried running test tile yet.

* Runs test tile 00N_000E. Didn't check that outputs were correct but did verify that the output rasters load and have values in ArcMap.
* Froze all dependencies in `requirements.txt` to their current version.
Also, added testing folder and file but haven't tried using them yet.

* Used pylint on mp_create_carbon_pools.py. Addressed pretty much all the messages I wanted to.

* Continued delinting in create_carbon_pools. Changed all obvious print statements in mp_create_carbon_pools.py and create_carbon_pools.py to fprint. Added docstrings to each function. Testing carbon pool creation for 00N_000E seems to work fine.

* Experimenting with setting some variables as global so that I don't have to pass them as arguments: sensit_type, no_upload, save_intermediates, etc. For saving and modifying variables between files, this page seems to be helpful: https://thewebdev.info/2021/10/19/how-to-use-global-variables-between-files-in-python/#:~:text=To%20use%20global%20variables%20between%20files%20in%20Python%2C%20we%20can,reference%20the%20global%20variable%20directly.&text=We%20import%20the%20settings%20and,Then%20we%20call%20settings.

* Testing global variables with no_upload. I seem to be able to reset the global variable from run_full_model.py, including in the log. Need to make sure this is actually carrying through to uploading.

* Added global variables to constants_and_names.py and top of run_full_model.py.

* Changed run_full_model.py through carbon pool step.

* Changed carbon pool creation to use global variables. Decided to have functions pass carbon_pool_extent because it's a key parameter of carbon pool creation.

* Changed all model stages to use global variables from the command line. Still testing that I didn't break anything in local runs.

* Changed some universal_util.py functions to use the global variables instead of passing arguments to them.

* Starting to change print statements to f'' print statements throughout the model.

* Changed to f print statements for model extent and forest age category steps.

* Changed to f print statements for entire removals model.

* Changed to f print statements for carbon, emissions, and analyses. Haven't changed in universal_util or constants_and_names. Haven't checked if everything is working alright.

* Changed to f print statements for universal_util.py. Didn't change arguments to gdal commands for the most part, though.

* Used pylint on all regular model steps and run_full_model.py. Fixed most message that weren't about importing, too many variables, too many statements, or too many branches. I'll work on those structural issues later.

* Testing 00N_000E locally with linting of run_full_model.py and all model stages through net flux. Going to try running it on an ec2 instance now.

* 00N_000 works in a full local run and 00N_020E works in a full ec2 run. I've linted enough for now.
* Added a command line argument `--single-processor` or `-sp` to run_full_model.py and each model step through net flux that sets whether the tile processing is done with the multiprocessing module or not. This involved adding another if...else statement (or sometimes statements) to each step to have it use the correct processing route. Also changed readme.md to add the new argument.

* Ran 00N_000E locally for all model steps with single and multiprocessing options to make sure both still worked after this reconfiguration. Both worked.
Single processing took (no uploading of outputs): 1 hour 23 minutes
Multi-processing took (no uploading of outputs):  1 hour 11 minutes
running:
$> `python -m carbon_pools.create_carbon_pools`
succeeds in importing the modules.
So, I don't think this is necessary any longer.
PEP-8:
https://peps.python.org/pep-0008/#imports
Imports should be grouped in the following order:
1. Standard library imports.
2. Related third party imports.
3. Local application/library specific imports.
You should put a blank line between each group of imports.
running:
$> `python -m carbon_pools.create_soil_C`
succeeds in importing the modules.
So, I don't think this is necessary any longer.
PEP-8:
https://peps.python.org/pep-0008/#imports
Imports should be grouped in the following order:
1. Standard library imports.
2. Related third party imports.
3. Local application/library specific imports.
You should put a blank line between each group of imports.
running:
$> `python -m carbon_pools.mp_create_carbon_pools`
succeeds in importing the modules.
So, I don't think this is necessary any longer.
PEP-8:
https://peps.python.org/pep-0008/#imports
Explicit relative imports are an acceptable alternative to absolute imports, especially when dealing with complex package layouts where using absolute imports would be unnecessarily verbose.
PEP-8:
https://peps.python.org/pep-0008/#imports
Imports should be grouped in the following order:
1. Standard library imports.
2. Related third party imports.
3. Local application/library specific imports.
You should put a blank line between each group of imports.
PEP-8:
https://peps.python.org/pep-0008/#imports
Explicit relative imports are an acceptable alternative to absolute imports, especially when dealing with complex package layouts where using absolute imports would be unnecessarily verbose.
running:
$> `python -m carbon_pools.mp_create_soil_C`
succeeds in importing the modules.
So, I don't think this is necessary any longer.
PEP-8:
https://peps.python.org/pep-0008/#imports
Imports should be grouped in the following order:
1. Standard library imports.
2. Related third party imports.
3. Local application/library specific imports.
You should put a blank line between each group of imports.
@gtempus gtempus requested a review from dagibbs22 September 14, 2022 22:24
Base automatically changed from develop to master October 26, 2023 01:59
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.

2 participants