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

fix issue #69 Warn.zeropadding for islands #70

Merged
merged 7 commits into from
Apr 14, 2023

Conversation

ThomasRoosli
Copy link
Collaborator

This pull requests fixes #69
the function Warn.zeropadding was adopted to now deal with cases where the inputed non-rectangular map contains several non touching areas like islands. This produced an IndexError before. A test is added to check that such islands are handled correctly.
As it was already the case beforehand, the function assumes that the inputed non-rectangular map contains lat and lon values, that can be accurately represented as a regular grid. It now also checks for this assumption with a maximally allowed relative error in terms of grid resolution. This check is also tested.

@chahank chahank requested a review from leonie-villiger March 7, 2023 20:32
Copy link
Collaborator

@leonie-villiger leonie-villiger left a comment

Choose a reason for hiding this comment

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

Thanks for extending the warn.zeropadding functionality to island!

  • I found a Ctrl+C error in your check whether latitudes are represented accurately enough.
  • The rest are minor comments. Personally I like to have a comment above every block of code to ensure easy understanding of the code. But this might not correspond to the conventions?
  • You have added test for the two new functionalities: (1) zeropadding for islands (i.e., patchy fields in general); (2) check for spatially sufficiently resolved input values. Thus, testing looks fine to me.

After fixing the Ctrl+C error and having considered whether to adopt the minor comments or not, we can merge the branch.

climada_petals/engine/warn.py Show resolved Hide resolved
climada_petals/engine/warn.py Outdated Show resolved Hide resolved
climada_petals/engine/warn.py Outdated Show resolved Hide resolved
climada_petals/engine/warn.py Outdated Show resolved Hide resolved

i = ((lat - min(lat)) / abs(grid_res_lat)).astype(int)
j = ((lon - min(lon)) / abs(grid_res_lon)).astype(int)
map_rec = np.zeros((len(un_y), len(un_x)))
map_rec[i, j] = val

xx, yy = np.meshgrid(un_x, un_y)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Linter suggests to rename xx and yy. Maybe he approves more of un_x_flat, un_y_flat?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I removed these two intermediate variables. Now we got rid of two Linter issues.

ThomasRoosli and others added 5 commits April 13, 2023 15:52
Co-authored-by: leonie-villiger <87335708+leonie-villiger@users.noreply.github.com>
check_lat was calculated using the lon variables due to a copying error. This was corrected and it is now calculated correctly using the lat variables

Co-authored-by: leonie-villiger <87335708+leonie-villiger@users.noreply.github.com>
@ThomasRoosli
Copy link
Collaborator Author

Thanks Leonie, for the very well done review. Do you have time to check my changes?

@leonie-villiger
Copy link
Collaborator

Your changes resolve the spotted issues and the code is clear and comprehensible. In this regard, all good to merge! However, when checking the test_warn.py again I noted that both, test_zeropadding and test_zeropadding_island, only check the returned reduced_matrix but not the returned coord. Should the opportunity be taken to complete the two tests with testing coord? What do you think?

@ThomasRoosli
Copy link
Collaborator Author

Good catch, I added some asserts for coord as well. I am now merging without further review. Thanks alot for your suggestions and for your approval.

@ThomasRoosli ThomasRoosli merged commit 422baba into develop Apr 14, 2023
@ThomasRoosli ThomasRoosli deleted the feature/warn_zeropadding_fix branch April 14, 2023 08:11
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