-
Notifications
You must be signed in to change notification settings - Fork 313
Converting 3d pyresampling ravel/rearrange logic to handle nd arrays. #1457
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
Open
ZachHoppinen
wants to merge
13
commits into
insarlab:main
Choose a base branch
from
ZachHoppinen:hoppinen-nd-geocoding
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
cff324c
Convering 3d pyresampling ravel/rearrange login to handle nd arrays. …
ZachHoppinen a823efc
simply restore_from_resample to just find spatial dims from data isnt…
ZachHoppinen 52db046
add in single newline for CI/CD end-of-file fixer
ZachHoppinen 7f1000b
and another newline space at the end of the .gitignore
ZachHoppinen 7ce1343
remove tab at end of resample file...
ZachHoppinen 9e21aeb
remove row/col key words from all tests
ZachHoppinen 84cbecd
remove trailing white space in resample.py
ZachHoppinen 1c94e90
cleaning remaining trailing white spaces
ZachHoppinen a8412c1
remove unused import in tests and sorting
ZachHoppinen 354dd63
sorting imports in tests....
ZachHoppinen d9117d0
using scott's advice to fix pre-commit errors of extra new line in im…
ZachHoppinen 613f9e1
remove changes to .gitignore
ZachHoppinen a7bf4c5
Merge branch 'main' into hoppinen-nd-geocoding
yunjunz 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 hidden or 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 |
|---|---|---|
|
|
@@ -133,3 +133,6 @@ dmypy.json | |
|
|
||
| # Pyre type checker | ||
| .pyre/ | ||
|
|
||
| # vscode | ||
| .vscode/ | ||
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,188 @@ | ||
| import pytest | ||
|
|
||
| import numpy as np | ||
| # from mintpy.objects.resample import resample | ||
| from mintpy.utils.utils0 import move_spatial_dimension, flatten_for_resample, restore_from_resample | ||
|
|
||
| def test_geocode_3d(): | ||
| pass | ||
|
ZachHoppinen marked this conversation as resolved.
Outdated
ZachHoppinen marked this conversation as resolved.
Outdated
|
||
|
|
||
| def test_geocode_4d(): | ||
| pass | ||
| # res_obj = resample(lut_file=lookupFile, | ||
| # src_file=file, | ||
| # SNWE=None, | ||
| # lalo_step=None) | ||
| # res_obj.open() | ||
| # res_obj.prepare() | ||
|
|
||
| # data = np.random.rand(3, 4, 20, 30) | ||
|
|
||
| # res_obj.run_resample(src_data=data, box_ind=0) | ||
|
|
||
| def test_flatten_for_resample_2d(): | ||
| data = np.random.rand(20, 30) | ||
|
|
||
| out = flatten_for_resample(data) | ||
|
|
||
| assert out.shape == (20, 30) | ||
| np.testing.assert_array_equal(out, data) | ||
|
|
||
| def test_flatten_for_resample_3d(): | ||
| data = np.random.rand(20, 30, 5) | ||
|
|
||
| out = flatten_for_resample(data) | ||
|
|
||
| assert out.shape == (20, 30, 5) | ||
| np.testing.assert_array_equal(out, data) | ||
|
|
||
| def test_flatten_for_resample_4d(): | ||
| data = np.random.rand(20, 30, 5, 4) | ||
|
|
||
| out = flatten_for_resample(data) | ||
|
|
||
| assert out.shape == (20, 30, 20) # 5 * 4 | ||
| np.testing.assert_array_equal(out.reshape(20, 30, 5, 4), data) | ||
|
|
||
| def test_restore_from_resample_2d(): | ||
| rows, cols = 20, 30 | ||
| data = np.random.rand(rows, cols) | ||
|
|
||
| out = restore_from_resample( | ||
| data, | ||
| rows=rows, | ||
| cols=cols, | ||
| non_spatial_shape=() | ||
| ) | ||
|
|
||
| assert out.shape == (rows, cols) | ||
| np.testing.assert_array_equal(out, data) | ||
|
|
||
| def test_restore_from_resample_3d(): | ||
| rows, cols = 20, 30 | ||
| non_spatial_shape = (5,) | ||
| data = np.random.rand(rows, cols, 5) | ||
|
|
||
| out = restore_from_resample( | ||
| data, | ||
| rows=rows, | ||
| cols=cols, | ||
| non_spatial_shape=non_spatial_shape | ||
| ) | ||
|
|
||
| assert out.shape == (20, 30, 5) | ||
| np.testing.assert_array_equal(out, data) | ||
|
|
||
| def test_restore_from_resample_4d(): | ||
| rows, cols = 20, 30 | ||
| non_spatial_shape = (5, 4) | ||
| data = np.random.rand(rows, cols, 20) # 5 * 4 | ||
|
|
||
| out = restore_from_resample( | ||
| data, | ||
| rows=rows, | ||
| cols=cols, | ||
| non_spatial_shape=non_spatial_shape | ||
| ) | ||
|
|
||
| assert out.shape == (20, 30, 5, 4) | ||
| np.testing.assert_array_equal(out.reshape(20, 30, 20), data) | ||
|
|
||
| @pytest.mark.parametrize( | ||
| "shape", | ||
| [ | ||
| (20, 30), # 2D | ||
| (20, 30, 5), # 3D | ||
| (20, 30, 5, 4), # 4D | ||
| (20, 30, 2, 3, 4), # 5D | ||
| ], | ||
| ) | ||
| def test_flatten_restore_roundtrip(shape): | ||
| data = np.random.rand(*shape) | ||
| rows, cols = shape[:2] | ||
| non_spatial_shape = shape[2:] | ||
|
|
||
| flat = flatten_for_resample(data) | ||
| restored = restore_from_resample( | ||
| flat, | ||
| rows=rows, | ||
| cols=cols, | ||
| non_spatial_shape=non_spatial_shape | ||
| ) | ||
|
|
||
| np.testing.assert_array_equal(restored, data) | ||
|
|
||
| def test_restore_from_resample_invalid_shape(): | ||
| rows, cols = 20, 30 | ||
| data = np.random.rand(rows, cols, 10) | ||
|
|
||
| with pytest.raises(ValueError): | ||
| restore_from_resample( | ||
| data, | ||
| rows=rows, | ||
| cols=cols, | ||
| non_spatial_shape=(3, 4) # 12 != 10 | ||
| ) | ||
|
|
||
| def test_move_spatial_dimension_2d_front_and_back(): | ||
| # shape: (time, row, col) | ||
| arr = np.zeros((20, 30)) | ||
|
|
||
| front = move_spatial_dimension(arr, to_front=True) | ||
| assert front.shape == (20, 30) | ||
|
|
||
| back = move_spatial_dimension(front, to_front=False) | ||
| assert back.shape == arr.shape | ||
|
|
||
| # ensure data integrity | ||
| np.testing.assert_array_equal(back, arr) | ||
|
|
||
| def test_move_spatial_dimension_3d_front_and_back(): | ||
| # shape: (time, row, col) | ||
| arr = np.zeros((5, 20, 30)) | ||
|
|
||
| front = move_spatial_dimension(arr, to_front=True) | ||
| assert front.shape == (20, 30, 5) | ||
|
|
||
| back = move_spatial_dimension(front, to_front=False) | ||
| assert back.shape == arr.shape | ||
|
|
||
| # ensure data integrity | ||
| np.testing.assert_array_equal(back, arr) | ||
|
|
||
| def test_move_spatial_dimension_4d_front_and_back(): | ||
| # shape: (time, band, row, col) | ||
| arr = np.random.rand(3, 4, 20, 30) | ||
|
|
||
| front = move_spatial_dimension(arr, to_front=True) | ||
| assert front.shape == (20, 30, 3, 4) | ||
|
|
||
| back = move_spatial_dimension(front, to_front=False) | ||
| assert back.shape == arr.shape | ||
|
|
||
| np.testing.assert_array_equal(back, arr) | ||
|
|
||
| @pytest.mark.parametrize( | ||
| "shape", | ||
| [ | ||
| (20, 30), # 2D | ||
| (20, 30, 5), # 3D | ||
| (20, 30, 5, 4), # 4D | ||
| (20, 30, 2, 3, 4), # 5D | ||
| ], | ||
| ) | ||
| @pytest.mark.parametrize("to_front", [True, False]) | ||
| def test_move_spatial_dimension_roundtrip(shape, to_front): | ||
| data = np.random.rand(*shape) | ||
|
|
||
| # Move spatial dimensions | ||
| moved = move_spatial_dimension(data, to_front=to_front) | ||
|
|
||
| # Invert the move | ||
| restored = move_spatial_dimension(moved, to_front=not to_front) | ||
|
|
||
| # Shape should match original | ||
| assert restored.shape == data.shape | ||
|
|
||
| # Values should match original exactly | ||
| np.testing.assert_array_equal(restored, data) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.