-
Notifications
You must be signed in to change notification settings - Fork 124
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
added get_bounds functions for EPSG 4326 #980
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
77dbdd2
added functions and tests
ValentinGebhart 2bfe421
adapted functions and order of outputs
ValentinGebhart 7526ab3
Apply suggestions from code review Sam
ValentinGebhart 679c2ec
added tests from invalid cardinal bounds inputs
ValentinGebhart 8ad36cb
added ValueError if ISO code not recognized
ValentinGebhart 847b906
consistent naming of functions
ValentinGebhart fa258fa
updated changelog
ValentinGebhart 4faaffe
Merge branch 'develop' into feature/bounds_NESW_functions
ValentinGebhart File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2294,6 +2294,69 @@ def test_mask_raster_with_geometry(self): | |
) | ||
|
||
|
||
class TestBoundsFromUserInput(unittest.TestCase): | ||
"""Unit tests for the bounds_from_user_input function.""" | ||
|
||
def global_bounding_box(self): | ||
"""Test for 'global' area selection.""" | ||
result = u_coord.global_bounding_box() | ||
expected = (-180, -90, 180, 90) | ||
np.testing.assert_almost_equal(result, expected) | ||
|
||
def test_get_country_bounding_box(self): | ||
"""Test for a list of ISO country codes.""" | ||
result = u_coord.get_country_bounding_box( | ||
["ITA"], buffer=1.0 | ||
) # Testing with Italy (ITA) | ||
# Real expected bounds for Italy (calculated or manually known) | ||
expected = [ | ||
5.6027283120000675, | ||
34.48924388200004, | ||
19.517425977000073, | ||
48.08521494500006, | ||
] # Italy's bounding box | ||
|
||
np.testing.assert_array_almost_equal(result, expected, decimal=4) | ||
|
||
def test_bounds_from_cardinal_bounds(self): | ||
"""Test for conversion from cardinal bounds to bounds.""" | ||
np.testing.assert_array_almost_equal( | ||
u_coord.bounds_from_cardinal_bounds( | ||
northern=90, southern=-20, eastern=30, western=20 | ||
), | ||
(20, -20, 30, 90), | ||
) | ||
np.testing.assert_array_almost_equal( | ||
u_coord.bounds_from_cardinal_bounds( | ||
northern=90, southern=-20, eastern=20, western=30 | ||
), | ||
(30, -20, 380, 90), | ||
) | ||
np.testing.assert_array_almost_equal( | ||
u_coord.bounds_from_cardinal_bounds( | ||
northern=90, southern=-20, eastern=170, western=-170 | ||
), | ||
(-170, -20, 170, 90), | ||
) | ||
np.testing.assert_array_almost_equal( | ||
u_coord.bounds_from_cardinal_bounds( | ||
northern=90, southern=-20, eastern=-170, western=170 | ||
), | ||
(170, -20, 190, 90), | ||
) | ||
np.testing.assert_array_almost_equal( | ||
u_coord.bounds_from_cardinal_bounds( | ||
northern=90, southern=-20, eastern=170, western=175 | ||
), | ||
(175, -20, 530, 90), | ||
) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should add tests for invalid bounding box. |
||
def test_invalid_input_string(self): | ||
"""Test for invalid string input.""" | ||
with self.assertRaises(Exception): | ||
u_coord.get_bound("invalid_ISO") | ||
|
||
|
||
# Execute Tests | ||
if __name__ == "__main__": | ||
TESTS = unittest.TestLoader().loadTestsFromTestCase(TestFunc) | ||
|
@@ -2302,4 +2365,5 @@ def test_mask_raster_with_geometry(self): | |
TESTS.addTests(unittest.TestLoader().loadTestsFromTestCase(TestRasterMeta)) | ||
TESTS.addTests(unittest.TestLoader().loadTestsFromTestCase(TestRasterIO)) | ||
TESTS.addTests(unittest.TestLoader().loadTestsFromTestCase(TestDistance)) | ||
TESTS.addTests(unittest.TestLoader().loadTestsFromTestCase(TestBoundsFromUserInput)) | ||
unittest.TextTestRunner(verbosity=2).run(TESTS) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't it be better to simply throw an exception in case the country is not recognized?
I can't see the point of filtering out the unrecognizable countries in here. If a user runs this with a typo in one of the country names would they be upset if it fails?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I agree, this would be better. I changed it to raise a ValueError now.
My only doubt is that the function util.coordinates.get_country_geometries() existed before and if you input a list of ISO codes with one invalid code, it did NOT raise an error before (this is why I "only" added a warning). Wouldn't this be a potential problem for existing code to break down due to the error, or is it better to make aware that the input was not correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@emanuel-schmid What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. Imo, it is better to make them finally aware that their input has been wrong all the time.
We just need to add a note in the change log.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect, agreed. I'm adapting the change log accordingly.