-
Notifications
You must be signed in to change notification settings - Fork 22
geocode SLC integration test #46
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
Merged
Merged
Changes from 20 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
6b02edd
initial commit for geocode SLC unit test
LiangJYu fd880ed
download test data from zenodo
LiangJYu 9f0b607
added docstrings, more descriptive variable names, internet check
LiangJYu 97c4461
Merge branch 'main' into geocode_slc_unit_test
LiangJYu 2984d49
run integration test in circleci
LiangJYu 1abbfe4
adding pytest as requirement
LiangJYu 92daa0f
adding pytest to docker specfile
LiangJYu 0164652
another attempt to run pytest in ci
LiangJYu ebfea34
yet another attempt to run pytest in ci
LiangJYu 13cb5b2
applying suggestion from rtburns
LiangJYu 7a5655c
docker command tweak
LiangJYu 6442402
fix entry point
LiangJYu cd70f7c
remove entry point
LiangJYu 6e3069c
fix path
LiangJYu 8eff671
activate environment
LiangJYu 175ab31
init bash
LiangJYu c65ace4
bash path not needed
LiangJYu 17a70ff
docker command fix
LiangJYu dbf457b
adding attr to specifile
LiangJYu 7e34b3f
fix typo in url
LiangJYu 35cb9e8
Merge remote-tracking branch 'upstream/main' into geocode_slc_unit_test
LiangJYu 5b4dc91
updated specfile
LiangJYu 07c83e4
account for multiburst, new burst ID, geocode entire burst
LiangJYu b30f823
use main instead of tag because of missing features
LiangJYu 18c9cb4
clone hhtps not ssh
LiangJYu 4ddf5f8
template yaml
LiangJYu aa1540c
Merge branch 'main' into geocode_slc_unit_test
LiangJYu 8e10100
update unit tests for smaller dataset
LiangJYu 88f0487
parallel test data download
LiangJYu d438b58
update specifile
LiangJYu dd2e841
remove unused imports
LiangJYu e693f51
more comments/docstrings
LiangJYu aeb64ac
cleaner mp pool
LiangJYu 3f72ad3
fix docstring
LiangJYu b95f45c
load just the slice not EVERYTHING
LiangJYu 8953342
Merge branch 'geocode_slc_unit_test' of github.com:LiangJYu/COMPASS i…
LiangJYu dd7b5e1
clarity in file related variable
LiangJYu fa33f64
fix typo in path
LiangJYu 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
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
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,64 @@ | ||
| import os | ||
| import pathlib | ||
| import pytest | ||
| import requests | ||
| import types | ||
|
|
||
| from s1reader.s1_orbit import check_internet_connection | ||
|
|
||
| def download_if_needed(local_path): | ||
LiangJYu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # check if test inputs and reference files exists; download if not found. | ||
| if os.path.isfile(local_path): | ||
| return | ||
|
|
||
| check_internet_connection() | ||
|
|
||
| dataset_url = 'https://zenodo.org/record/6954753/files/' | ||
| dst_dir, file_name = os.path.split(local_path) | ||
| print(dst_dir, file_name) | ||
| os.makedirs(dst_dir, exist_ok=True) | ||
| target_url = f'{dataset_url}/{file_name}' | ||
| with open(local_path, 'wb') as f: | ||
| f.write(requests.get(target_url).content) | ||
|
|
||
| @pytest.fixture(scope="session") | ||
| def test_paths(): | ||
| test_paths = types.SimpleNamespace() | ||
|
|
||
| burst_id = 't71_151200_iw1' | ||
| b_date = '20200511' | ||
|
|
||
| # get test working directory | ||
| test_path = pathlib.Path(__file__).parent.resolve() | ||
|
|
||
| # set other paths relative to working directory | ||
| test_data_path = f'{test_path}/data' | ||
| out_path = f'{test_path}/gburst' | ||
|
|
||
| # paths for template and actual runconfig | ||
| gslc_template_path = f'{test_data_path}/geo_cslc_s1_template.yaml' | ||
| test_paths.gslc_cfg_path = f'{test_data_path}/geo_cslc_s1.yaml' | ||
|
|
||
| # read runconfig template, replace pieces, write to runconfig | ||
| with open(gslc_template_path, 'r') as f_template, \ | ||
| open(test_paths.gslc_cfg_path, 'w') as f_cfg: | ||
| cfg = f_template.read().replace('@TEST_PATH@', str(test_path)).\ | ||
| replace('@DATA_PATH@', test_data_path).\ | ||
| replace('@BURST_ID@', burst_id) | ||
| f_cfg.write(cfg) | ||
|
|
||
| # output geocoded SLC paths | ||
| test_paths.test_gslc = f'{out_path}/{burst_id}/{b_date}/{burst_id}_{b_date}_VV.slc' | ||
|
|
||
| # reference geocoded SLC paths | ||
| test_paths.ref_gslc = f'{test_data_path}/reference/ref_compass_gslc.slc' | ||
|
|
||
| # check for files and download as needed | ||
| test_files = ['S1A_IW_SLC__1SSV_20200511T135117_20200511T135144_032518_03C421_7768.zip', | ||
| 'orbits/S1A_OPER_AUX_POEORB_OPOD_20210318T120818_V20200510T225942_20200512T005942.EOF', | ||
| 'test_dem.tiff', 'reference/ref_compass_gslc.hdr', | ||
| 'reference/ref_compass_gslc.slc'] | ||
| for test_file in test_files: | ||
| download_if_needed(f'{test_data_path}/{test_file}') | ||
|
|
||
| return test_paths | ||
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,50 @@ | ||
| import numpy as np | ||
| import numpy.testing as npt | ||
| from osgeo import gdal | ||
|
|
||
| from compass import s1_geocode_slc | ||
| from compass.utils.geo_runconfig import GeoRunConfig | ||
|
|
||
|
|
||
| def gdal_get_arr(f): | ||
| ''' | ||
| extract numpy array from GDAL supported raster | ||
|
|
||
| Parameters | ||
| ---------- | ||
| f: str | ||
| path the GDAL supported raster | ||
|
|
||
| Returns | ||
| ------- | ||
| _: np.ndarray | ||
| array extracted from GDAL supported raster | ||
| ''' | ||
| ds = gdal.Open(f, gdal.GA_ReadOnly) | ||
| arr = np.array([]) | ||
| if ds is not None: | ||
| arr = ds.GetRasterBand(1).ReadAsArray() | ||
| return arr | ||
|
|
||
| def test_geocode_slc_run(test_paths): | ||
LiangJYu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ''' | ||
| run s1_geocode_slc to ensure it does not crash | ||
| ''' | ||
| # load yaml to cfg | ||
| cfg = GeoRunConfig.load_from_yaml(test_paths.gslc_cfg_path, | ||
| workflow_name='s1_cslc_geo') | ||
|
|
||
| # pass cfg to s1_geocode_slc | ||
| s1_geocode_slc.run(cfg) | ||
|
|
||
| def test_geocode_slc_validate(test_paths): | ||
LiangJYu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ''' | ||
| check if computed results match golden dataset | ||
| ''' | ||
| # load test output | ||
| test_arr = gdal_get_arr(test_paths.test_gslc) | ||
|
|
||
| # load reference output | ||
| ref_arr = gdal_get_arr(test_paths.ref_gslc) | ||
|
|
||
| npt.assert_array_equal(test_arr, ref_arr) | ||
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.