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

#1166 Add support for zero-padded months in SWY #1697

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

claire-simpson
Copy link

Description

Updated the regex to allow users to have zero-padded month numbers in the monthly precipitation and evapotranspiration files. Now, filenames like et0_01.tif and precip01.tif are permitted.

Fixes #1166

Checklist

  • Updated HISTORY.rst and link to any relevant issue (if these changes are user-facing)
  • Updated the user's guide (if needed)
  • Tested the Workbench UI (if relevant)

@claire-simpson claire-simpson self-assigned this Nov 25, 2024
Copy link
Contributor

@davemfish davemfish left a comment

Choose a reason for hiding this comment

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

Hi @claire-simpson , this looks like a great solution! A nice convenient little function + unit test. I had a few fairly minor comments that perhaps we can discuss, but this looks great overall.

for mo in range(1, n_months+1)]
padded_precip_dir_list = [
os.path.join("/fake/path", "Precip" + str(mo).zfill(2) + ".tif")
for mo in range(1, n_months + 1)]
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a very nice self-contained unit test!

Do you think it's worth constructing one of these lists with zero-padded numbers and one without? To demonstrate that _get_monthly_file_lists should accommodate both?

We could also consider a test that asserts a ValueError is raised in certain cases, since the function is designed with those cases in mind too.

Copy link
Author

Choose a reason for hiding this comment

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

I believe the other tests all use non-zero-padded file names so this concept does get tested - but maybe its still good to have an explicit test for this with the new regex? Happy to add this.

As for the fail cases - I'm thinking double zeros (i.e. raising ValueError on precip001.tif). Did you have anything else in mind?

@@ -659,33 +659,15 @@ def execute(args):
output_align_list = [
file_registry['lulc_aligned_path'], file_registry['dem_aligned_path']]
if not args['user_defined_local_recharge']:
precip_path_list = []
et0_path_list = []

et0_dir_list = [
os.path.join(args['et0_dir'], f) for f in os.listdir(
args['et0_dir'])]
precip_dir_list = [
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think it makes sense to do these list comprehensions within the _get_monthly_file_lists function? It seems like logically they are closely related to the rest of the code in the function, so it might be nice to encapsulate it there. And then the function would take args['et0_dir'] as a direct input.

Copy link
Author

Choose a reason for hiding this comment

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

Yep good call!


for data_type, dir_list, path_list in [
('et0', et0_dir_list, et0_path_list),
('Precip', precip_dir_list, precip_path_list)]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that we have this convenient function to use, what do you think about having the function operate on only one directory, and return one list of filepaths? In other words, instead of using this for loop here, we make two separate calls to _get_monthly_file_list from up in execute.

Copy link
Author

Choose a reason for hiding this comment

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

Yes I like this, will update

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.

Support zero-padded month numbers in SWY?
2 participants