diff --git a/CHANGELOG.md b/CHANGELOG.md index 8403df5b..ae927f8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [PEP 440](https://www.python.org/dev/peps/pep-0440/) and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.7.1] +### Added +* insar_tops_burst now validates burst pair granule names. ## [0.7.0] ### Added diff --git a/images/coverage.svg b/images/coverage.svg index dd6df127..2fad913a 100644 --- a/images/coverage.svg +++ b/images/coverage.svg @@ -15,7 +15,7 @@ coverage coverage - 61% - 61% + 62% + 62% diff --git a/src/hyp3_isce2/burst.py b/src/hyp3_isce2/burst.py index 56806749..ebaebccf 100644 --- a/src/hyp3_isce2/burst.py +++ b/src/hyp3_isce2/burst.py @@ -380,3 +380,38 @@ def get_burst_params(scene_name: str) -> BurstParams: polarization=results[0].properties['polarization'], burst_number=results[0].properties['burst']['burstIndex'], ) + + +def validate_bursts(reference_name: str, secondary_name: str) -> None: + """Check whether the reference and secondary bursts are valid. + + Args: + reference_scene: The reference burst name. + secondary_scene: The secondary burst name. + + Returns: + None + """ + ref_split = reference_name.split('_') + sec_split = secondary_name.split('_') + + ref_burst_id = ref_split[1] + sec_burst_id = sec_split[1] + + ref_polarization = ref_split[4] + sec_polarization = sec_split[4] + + if ref_burst_id != sec_burst_id: + raise ValueError( + f'The reference and secondary burst IDs are not the same: {ref_burst_id} and {sec_burst_id}.' + ) + + if ref_polarization != sec_polarization: + raise ValueError( + f'The reference and secondary polarizations are not the same: {ref_polarization} and {sec_polarization}.' + ) + + if ref_polarization != "VV" and ref_polarization != "HH": + raise ValueError( + f'{ref_polarization} polarization is not currently supported, only VV and HH.' + ) diff --git a/src/hyp3_isce2/insar_tops_burst.py b/src/hyp3_isce2/insar_tops_burst.py index 5bf85a01..95942301 100644 --- a/src/hyp3_isce2/insar_tops_burst.py +++ b/src/hyp3_isce2/insar_tops_burst.py @@ -28,6 +28,7 @@ get_isce2_burst_bbox, get_product_name, get_region_of_interest, + validate_bursts ) from hyp3_isce2.dem import download_dem_for_isce2 from hyp3_isce2.logging import configure_root_logger @@ -416,6 +417,7 @@ def main(): log.info('Begin ISCE2 TopsApp run') reference_scene, secondary_scene = oldest_granule_first(args.granules[0], args.granules[1]) + validate_bursts(reference_scene, secondary_scene) swath_number = int(reference_scene[12]) range_looks, azimuth_looks = [int(looks) for looks in args.looks.split('x')] diff --git a/tests/test_burst.py b/tests/test_burst.py index 76da92c3..7c789e1b 100644 --- a/tests/test_burst.py +++ b/tests/test_burst.py @@ -168,3 +168,25 @@ def test_get_burst_params_multiple_results(): with pytest.raises(ValueError, match=r'.*found multiple results.*'): burst.get_burst_params('there are multiple copies of this burst') mock_search.assert_called_once_with(product_list=['there are multiple copies of this burst']) + + +def test_validate_bursts(): + burst.validate_bursts( + 'S1_030349_IW1_20230808T171601_VV_4A37-BURST', + 'S1_030349_IW1_20230820T171602_VV_5AC3-BURST' + ) + with pytest.raises(ValueError, match=r'.*polarizations are not the same.*'): + burst.validate_bursts( + 'S1_215032_IW2_20230802T144608_VV_7EE2-BURST', + 'S1_215032_IW2_20230721T144607_HH_B3FA-BURST' + ) + with pytest.raises(ValueError, match=r'.*burst IDs are not the same.*'): + burst.validate_bursts( + 'S1_030349_IW1_20230808T171601_VV_4A37-BURST', + 'S1_030348_IW1_20230820T171602_VV_5AC3-BURST' + ) + with pytest.raises(ValueError, match=r'.*only VV and HH.*'): + burst.validate_bursts( + 'S1_030349_IW1_20230808T171601_VH_4A37-BURST', + 'S1_030349_IW1_20230820T171602_VH_5AC3-BURST' + )