From be3d81bbe96cb3b737bf3a8179e9f0c9f1bc1548 Mon Sep 17 00:00:00 2001 From: Andrew Player Date: Tue, 15 Oct 2024 16:42:12 -0400 Subject: [PATCH 1/9] add relative orbit check for srg time series --- apps/api/src/hyp3_api/validation.py | 18 ++++++++++++++++++ job_spec/SRG_TIME_SERIES.yml | 3 ++- tests/test_api/test_validation.py | 17 +++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/apps/api/src/hyp3_api/validation.py b/apps/api/src/hyp3_api/validation.py index 6d9ff9646..d99cb0bb7 100644 --- a/apps/api/src/hyp3_api/validation.py +++ b/apps/api/src/hyp3_api/validation.py @@ -179,6 +179,24 @@ def check_granules_intersecting_bounds(job, granule_metadata): ) +def check_same_relative_orbits(job, granule_metadata): + relative_orbit_numbers = [] + for granule in granule_metadata: + name = granule['name'].split('_') + absolute_orbit = name[7] + if name[0] == 'S1A': + relative_orbit = str(((int(absolute_orbit) - 73) % 175) + 1) + else: + relative_orbit = str(((int(absolute_orbit) - 27) % 175) + 1) + if not relative_orbit_numbers: + relative_orbit_numbers.append(relative_orbit) + else: + if relative_orbit not in relative_orbit_numbers: + raise GranuleValidationError( + f'The relative orbit number for {granule["name"]} does not match the previous granules: {relative_orbit} is not {relative_orbit_numbers[0]}.' + ) + + def convert_single_burst_jobs(jobs: list[dict]) -> list[dict]: jobs = deepcopy(jobs) for job in jobs: diff --git a/job_spec/SRG_TIME_SERIES.yml b/job_spec/SRG_TIME_SERIES.yml index 2cfe31af0..c081bf8c4 100644 --- a/job_spec/SRG_TIME_SERIES.yml +++ b/job_spec/SRG_TIME_SERIES.yml @@ -38,7 +38,8 @@ SRG_TIME_SERIES: example: -116.583 validators: [ check_bounds_formatting, - check_granules_intersecting_bounds + check_granules_intersecting_bounds, + check_same_relative_orbits ] cost_profiles: DEFAULT: diff --git a/tests/test_api/test_validation.py b/tests/test_api/test_validation.py index 410d01d77..534039409 100644 --- a/tests/test_api/test_validation.py +++ b/tests/test_api/test_validation.py @@ -536,3 +536,20 @@ def test_check_granules_intersecting_bounds(): validation.check_granules_intersecting_bounds(job_with_specified_bounds, invalid_granule_metadata) with raises(validation.GranuleValidationError, match=error_pattern): validation.check_granules_intersecting_bounds(job_with_default_bounds, invalid_granule_metadata) + + +def check_same_relative_orbits(): + valid_granule_metadata = [ + {'name': 'S1A_IW_RAW__0SDV_20201015T161622_20201015T161654_034809_040E95_AF3C'}, + {'name': 'S1A_IW_RAW__0SDV_20200816T161620_20200816T161652_033934_03EFCE_5730'}, + {'name': 'S1B_IW_RAW__0SDV_20200810T161537_20200810T161610_022863_02B66A_F7D7'}, + {'name': 'S1B_IW_RAW__0SDV_20200623T161535_20200623T161607_022163_02A10F_7FD6'} + ] + invalid_granule_metadata = valid_granule_metadata + invalid_granule_metadata.append( + {'name': 'S1B_IW_RAW__0SDV_20200623T161535_20200623T161607_012345_02A10F_7FD6'} # 23 + ) + validation.check_same_relative_orbits({}, valid_granule_metadata) + error_pattern = r'.*S1B_IW_RAW__0SDV_20200623T161535_20200623T161607_012345_02A10F_7FD6 does not match the previous granules: 23 is not 87.*' + with raises(validation.GranuleValidationError, match=error_pattern): + validation.check_same_relative_orbits({}, invalid_granule_metadata) From 4e4d024cf61f17b9b174d7fd3cc9799aec6536d1 Mon Sep 17 00:00:00 2001 From: Andrew Player Date: Tue, 15 Oct 2024 16:44:12 -0400 Subject: [PATCH 2/9] remove else --- apps/api/src/hyp3_api/validation.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/apps/api/src/hyp3_api/validation.py b/apps/api/src/hyp3_api/validation.py index d99cb0bb7..9980f9383 100644 --- a/apps/api/src/hyp3_api/validation.py +++ b/apps/api/src/hyp3_api/validation.py @@ -190,11 +190,10 @@ def check_same_relative_orbits(job, granule_metadata): relative_orbit = str(((int(absolute_orbit) - 27) % 175) + 1) if not relative_orbit_numbers: relative_orbit_numbers.append(relative_orbit) - else: - if relative_orbit not in relative_orbit_numbers: - raise GranuleValidationError( - f'The relative orbit number for {granule["name"]} does not match the previous granules: {relative_orbit} is not {relative_orbit_numbers[0]}.' - ) + if relative_orbit not in relative_orbit_numbers: + raise GranuleValidationError( + f'The relative orbit number for {granule["name"]} does not match the previous granules: {relative_orbit} is not {relative_orbit_numbers[0]}.' + ) def convert_single_burst_jobs(jobs: list[dict]) -> list[dict]: From c02c4eb4f43596b8cbaea7032790304bee4580d6 Mon Sep 17 00:00:00 2001 From: Andrew Player Date: Tue, 15 Oct 2024 16:48:40 -0400 Subject: [PATCH 3/9] refactor --- apps/api/src/hyp3_api/validation.py | 5 +++-- tests/test_api/test_validation.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/api/src/hyp3_api/validation.py b/apps/api/src/hyp3_api/validation.py index 9980f9383..bb6cea021 100644 --- a/apps/api/src/hyp3_api/validation.py +++ b/apps/api/src/hyp3_api/validation.py @@ -190,9 +190,10 @@ def check_same_relative_orbits(job, granule_metadata): relative_orbit = str(((int(absolute_orbit) - 27) % 175) + 1) if not relative_orbit_numbers: relative_orbit_numbers.append(relative_orbit) - if relative_orbit not in relative_orbit_numbers: + if relative_orbit not in relative_orbit_numbers: raise GranuleValidationError( - f'The relative orbit number for {granule["name"]} does not match the previous granules: {relative_orbit} is not {relative_orbit_numbers[0]}.' + f'Relative orbit number for {granule["name"]} does not match that of the previous granules: ' + f'{relative_orbit} is not {relative_orbit_numbers[0]}.' ) diff --git a/tests/test_api/test_validation.py b/tests/test_api/test_validation.py index 534039409..b936653e2 100644 --- a/tests/test_api/test_validation.py +++ b/tests/test_api/test_validation.py @@ -550,6 +550,6 @@ def check_same_relative_orbits(): {'name': 'S1B_IW_RAW__0SDV_20200623T161535_20200623T161607_012345_02A10F_7FD6'} # 23 ) validation.check_same_relative_orbits({}, valid_granule_metadata) - error_pattern = r'.*S1B_IW_RAW__0SDV_20200623T161535_20200623T161607_012345_02A10F_7FD6 does not match the previous granules: 23 is not 87.*' + error_pattern = r'.*23 is not 87.*' with raises(validation.GranuleValidationError, match=error_pattern): validation.check_same_relative_orbits({}, invalid_granule_metadata) From 54d898f4b6723ff419d827124625ad73cd89a0ad Mon Sep 17 00:00:00 2001 From: Andrew Player Date: Tue, 15 Oct 2024 16:50:41 -0400 Subject: [PATCH 4/9] list to number --- apps/api/src/hyp3_api/validation.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/api/src/hyp3_api/validation.py b/apps/api/src/hyp3_api/validation.py index bb6cea021..466ea95ee 100644 --- a/apps/api/src/hyp3_api/validation.py +++ b/apps/api/src/hyp3_api/validation.py @@ -180,7 +180,7 @@ def check_granules_intersecting_bounds(job, granule_metadata): def check_same_relative_orbits(job, granule_metadata): - relative_orbit_numbers = [] + relative_orbit_number = None for granule in granule_metadata: name = granule['name'].split('_') absolute_orbit = name[7] @@ -188,12 +188,12 @@ def check_same_relative_orbits(job, granule_metadata): relative_orbit = str(((int(absolute_orbit) - 73) % 175) + 1) else: relative_orbit = str(((int(absolute_orbit) - 27) % 175) + 1) - if not relative_orbit_numbers: - relative_orbit_numbers.append(relative_orbit) - if relative_orbit not in relative_orbit_numbers: + if not relative_orbit_number: + relative_orbit_number = relative_orbit + if relative_orbit != relative_orbit_number: raise GranuleValidationError( f'Relative orbit number for {granule["name"]} does not match that of the previous granules: ' - f'{relative_orbit} is not {relative_orbit_numbers[0]}.' + f'{relative_orbit} is not {relative_orbit_number}.' ) From 5c564897d8e26efd0e45525f6fd93686f9174b13 Mon Sep 17 00:00:00 2001 From: Andrew Player Date: Tue, 15 Oct 2024 16:52:13 -0400 Subject: [PATCH 5/9] flake8 --- apps/api/src/hyp3_api/validation.py | 2 +- tests/test_api/test_validation.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/api/src/hyp3_api/validation.py b/apps/api/src/hyp3_api/validation.py index 466ea95ee..2beab0651 100644 --- a/apps/api/src/hyp3_api/validation.py +++ b/apps/api/src/hyp3_api/validation.py @@ -190,7 +190,7 @@ def check_same_relative_orbits(job, granule_metadata): relative_orbit = str(((int(absolute_orbit) - 27) % 175) + 1) if not relative_orbit_number: relative_orbit_number = relative_orbit - if relative_orbit != relative_orbit_number: + if relative_orbit != relative_orbit_number: raise GranuleValidationError( f'Relative orbit number for {granule["name"]} does not match that of the previous granules: ' f'{relative_orbit} is not {relative_orbit_number}.' diff --git a/tests/test_api/test_validation.py b/tests/test_api/test_validation.py index b936653e2..6a32aefc4 100644 --- a/tests/test_api/test_validation.py +++ b/tests/test_api/test_validation.py @@ -547,7 +547,7 @@ def check_same_relative_orbits(): ] invalid_granule_metadata = valid_granule_metadata invalid_granule_metadata.append( - {'name': 'S1B_IW_RAW__0SDV_20200623T161535_20200623T161607_012345_02A10F_7FD6'} # 23 + {'name': 'S1B_IW_RAW__0SDV_20200623T161535_20200623T161607_012345_02A10F_7FD6'} ) validation.check_same_relative_orbits({}, valid_granule_metadata) error_pattern = r'.*23 is not 87.*' From 1ef5d156b85524a26593ceb046a2a27035c9d58f Mon Sep 17 00:00:00 2001 From: Andrew Player Date: Tue, 15 Oct 2024 17:05:06 -0400 Subject: [PATCH 6/9] refactor --- apps/api/src/hyp3_api/validation.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/apps/api/src/hyp3_api/validation.py b/apps/api/src/hyp3_api/validation.py index 2beab0651..382ebac8e 100644 --- a/apps/api/src/hyp3_api/validation.py +++ b/apps/api/src/hyp3_api/validation.py @@ -182,12 +182,10 @@ def check_granules_intersecting_bounds(job, granule_metadata): def check_same_relative_orbits(job, granule_metadata): relative_orbit_number = None for granule in granule_metadata: - name = granule['name'].split('_') - absolute_orbit = name[7] - if name[0] == 'S1A': - relative_orbit = str(((int(absolute_orbit) - 73) % 175) + 1) - else: - relative_orbit = str(((int(absolute_orbit) - 27) % 175) + 1) + name_split = granule['name'].split('_') + absolute_orbit = name_split[7] + offset = 73 if name_split[0] == 'S1A' else 27 + relative_orbit = str(((int(absolute_orbit) - offset) % 175) + 1) if not relative_orbit_number: relative_orbit_number = relative_orbit if relative_orbit != relative_orbit_number: From 168472450ee70d972e6dabad4e680a39fea24946 Mon Sep 17 00:00:00 2001 From: Andrew Player Date: Tue, 15 Oct 2024 17:08:50 -0400 Subject: [PATCH 7/9] add relative orbit check to srg_gslc --- job_spec/SRG_GSLC.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/job_spec/SRG_GSLC.yml b/job_spec/SRG_GSLC.yml index 26609f537..ccff7c84e 100644 --- a/job_spec/SRG_GSLC.yml +++ b/job_spec/SRG_GSLC.yml @@ -38,7 +38,8 @@ SRG_GSLC: example: -116.583 validators: [ check_bounds_formatting, - check_granules_intersecting_bounds + check_granules_intersecting_bounds, + check_same_relative_orbits ] cost_profiles: DEFAULT: From 4666beaf06d03fc967c4e4a05ed58f16c121e608 Mon Sep 17 00:00:00 2001 From: Andrew Player Date: Tue, 15 Oct 2024 17:23:24 -0400 Subject: [PATCH 8/9] add reference for relative orbit calc --- apps/api/src/hyp3_api/validation.py | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/api/src/hyp3_api/validation.py b/apps/api/src/hyp3_api/validation.py index 382ebac8e..60e80edb6 100644 --- a/apps/api/src/hyp3_api/validation.py +++ b/apps/api/src/hyp3_api/validation.py @@ -184,6 +184,7 @@ def check_same_relative_orbits(job, granule_metadata): for granule in granule_metadata: name_split = granule['name'].split('_') absolute_orbit = name_split[7] + # "Relationship between relative and absolute orbit numbers": https://sentiwiki.copernicus.eu/web/s1-products offset = 73 if name_split[0] == 'S1A' else 27 relative_orbit = str(((int(absolute_orbit) - offset) % 175) + 1) if not relative_orbit_number: From 15c7813d32e07b75eed47ef67c5c99cc1d1a3d07 Mon Sep 17 00:00:00 2001 From: Andrew Player Date: Wed, 16 Oct 2024 14:23:43 -0400 Subject: [PATCH 9/9] refactor --- apps/api/src/hyp3_api/validation.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/api/src/hyp3_api/validation.py b/apps/api/src/hyp3_api/validation.py index 60e80edb6..4355f71f6 100644 --- a/apps/api/src/hyp3_api/validation.py +++ b/apps/api/src/hyp3_api/validation.py @@ -180,19 +180,19 @@ def check_granules_intersecting_bounds(job, granule_metadata): def check_same_relative_orbits(job, granule_metadata): - relative_orbit_number = None + previous_relative_orbit = None for granule in granule_metadata: name_split = granule['name'].split('_') absolute_orbit = name_split[7] # "Relationship between relative and absolute orbit numbers": https://sentiwiki.copernicus.eu/web/s1-products offset = 73 if name_split[0] == 'S1A' else 27 - relative_orbit = str(((int(absolute_orbit) - offset) % 175) + 1) - if not relative_orbit_number: - relative_orbit_number = relative_orbit - if relative_orbit != relative_orbit_number: + relative_orbit = ((int(absolute_orbit) - offset) % 175) + 1 + if not previous_relative_orbit: + previous_relative_orbit = relative_orbit + if relative_orbit != previous_relative_orbit: raise GranuleValidationError( f'Relative orbit number for {granule["name"]} does not match that of the previous granules: ' - f'{relative_orbit} is not {relative_orbit_number}.' + f'{relative_orbit} is not {previous_relative_orbit}.' )