From d68ed11df83abffea5a1bd42e3e13987fa036d3d Mon Sep 17 00:00:00 2001 From: Forrest Williams Date: Wed, 21 Aug 2024 07:43:25 -0500 Subject: [PATCH 1/8] switch to ref/sec for insar_isce_burst_job --- CHANGELOG.md | 5 +++++ src/hyp3_sdk/hyp3.py | 28 +++++++++++++++++----------- tests/test_hyp3.py | 21 ++++++++++++++------- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c21841..6621ff0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ 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). +## [8.0.0] + +### Changed +* The `insar_isce_burst_job` so that it takes a `reference` and `secondary` scene as input, not `granule1` and `granule2`. + ## [7.0.1] ### Removed diff --git a/src/hyp3_sdk/hyp3.py b/src/hyp3_sdk/hyp3.py index 4f653cc..33422c5 100644 --- a/src/hyp3_sdk/hyp3.py +++ b/src/hyp3_sdk/hyp3.py @@ -4,7 +4,7 @@ from datetime import datetime, timezone from functools import singledispatchmethod from getpass import getpass -from typing import List, Literal, Optional, Union +from typing import Iterable, List, Literal, Optional, Union from urllib.parse import urljoin from warnings import warn @@ -424,16 +424,16 @@ def prepare_insar_job(cls, return job_dict def submit_insar_isce_burst_job(self, - granule1: str, - granule2: str, + reference: Union[str, Iterable[str]], + secondary: Union[str, Iterable[str]], name: Optional[str] = None, apply_water_mask: bool = False, looks: Literal['20x4', '10x2', '5x1'] = '20x4') -> Batch: """Submit an InSAR ISCE burst job. Args: - granule1: The first granule (scene) to use - granule2: The second granule (scene) to use + reference: The reference granule (older scene) to use + secondary: The secondary granule (younger scene) to use name: A name for the job apply_water_mask: Sets pixels over coastal waters and large inland waterbodies as invalid for phase unwrapping @@ -449,16 +449,16 @@ def submit_insar_isce_burst_job(self, @classmethod def prepare_insar_isce_burst_job(cls, - granule1: str, - granule2: str, + reference: Union[str, Iterable[str]], + secondary: Union[str, Iterable[str]], name: Optional[str] = None, apply_water_mask: bool = False, looks: Literal['20x4', '10x2', '5x1'] = '20x4') -> dict: """Prepare an InSAR ISCE burst job. Args: - granule1: The first granule (scene) to use - granule2: The second granule (scene) to use + reference: The reference granule (older scene) to use + secondary: The secondary granule (younger scene) to use name: A name for the job apply_water_mask: Sets pixels over coastal waters and large inland waterbodies as invalid for phase unwrapping @@ -468,11 +468,17 @@ def prepare_insar_isce_burst_job(cls, A dictionary containing the prepared InSAR ISCE burst job """ job_parameters = locals().copy() - for key in ['cls', 'granule1', 'granule2', 'name']: + for key in ['cls', 'reference', 'secondary', 'name']: job_parameters.pop(key) + if isinstance(reference, str): + reference = [reference] + + if isinstance(secondary, str): + secondary = [secondary] + job_dict = { - 'job_parameters': {'granules': [granule1, granule2], **job_parameters}, + 'job_parameters': {'reference': reference, 'secondary': secondary, **job_parameters}, 'job_type': 'INSAR_ISCE_BURST', } if name is not None: diff --git a/tests/test_hyp3.py b/tests/test_hyp3.py index 25086f8..4bfed2f 100644 --- a/tests/test_hyp3.py +++ b/tests/test_hyp3.py @@ -281,23 +281,30 @@ def test_prepare_insar_job(): def test_prepare_insar_isce_burst_job(): - assert HyP3.prepare_insar_isce_burst_job(granule1='my_granule1', granule2='my_granule2') == { + assert HyP3.prepare_insar_isce_burst_job(reference='ref_granule1', secondary='sec_granule2') == { 'job_type': 'INSAR_ISCE_BURST', 'job_parameters': { - 'granules': ['my_granule1', 'my_granule2'], + 'reference': ['ref_granule1'], + 'secondary': ['sec_granule2'], 'apply_water_mask': False, 'looks': '20x4', - } + }, } - assert HyP3.prepare_insar_isce_burst_job(granule1='my_granule1', granule2='my_granule2', name='my_name', - apply_water_mask=True, looks='10x2') == { + assert HyP3.prepare_insar_isce_burst_job( + reference=['ref_granule1', 'ref_granule2'], + secondary=['sec_granule1', 'sec_granule2'], + name='my_name', + apply_water_mask=True, + looks='10x2', + ) == { 'job_type': 'INSAR_ISCE_BURST', 'name': 'my_name', 'job_parameters': { - 'granules': ['my_granule1', 'my_granule2'], + 'reference': ['ref_granule1', 'ref_granule2'], + 'secondary': ['sec_granule1', 'sec_granule2'], 'apply_water_mask': True, 'looks': '10x2', - } + }, } From d2e0b9e89a13882b2d9e5f9372de62827f331089 Mon Sep 17 00:00:00 2001 From: Forrest Williams Date: Wed, 21 Aug 2024 08:11:48 -0500 Subject: [PATCH 2/8] add backwards compatibility --- CHANGELOG.md | 2 +- src/hyp3_sdk/hyp3.py | 27 +++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6621ff0..2820fb4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [8.0.0] ### Changed -* The `insar_isce_burst_job` so that it takes a `reference` and `secondary` scene as input, not `granule1` and `granule2`. +* The `insar_isce_burst_job` so that it takes a `reference` and `secondary` scene as input, not `granule1` and `granule2`. Backward compatibility in `submit_insar_isce_burst_job` is maintained for now. ## [7.0.1] diff --git a/src/hyp3_sdk/hyp3.py b/src/hyp3_sdk/hyp3.py index 33422c5..256edea 100644 --- a/src/hyp3_sdk/hyp3.py +++ b/src/hyp3_sdk/hyp3.py @@ -424,8 +424,11 @@ def prepare_insar_job(cls, return job_dict def submit_insar_isce_burst_job(self, - reference: Union[str, Iterable[str]], - secondary: Union[str, Iterable[str]], + *args, + reference: Union[str, Iterable[str]] = None, + secondary: Union[str, Iterable[str]] = None, + granule1: Optional[str] = None, + granule2: Optional[str] = None, name: Optional[str] = None, apply_water_mask: bool = False, looks: Literal['20x4', '10x2', '5x1'] = '20x4') -> Batch: @@ -434,6 +437,8 @@ def submit_insar_isce_burst_job(self, Args: reference: The reference granule (older scene) to use secondary: The secondary granule (younger scene) to use + granule1: Depreceated argument superseeded by reference + granule2: Depreceated argument superseeded by secondary name: A name for the job apply_water_mask: Sets pixels over coastal waters and large inland waterbodies as invalid for phase unwrapping @@ -444,6 +449,24 @@ def submit_insar_isce_burst_job(self, """ arguments = locals().copy() arguments.pop('self') + arguments.pop('args') + + if len(args) == 2: + warnings.warn("Positional arguments for submit_insar_isce_burst_job are now mapped to 'reference' and 'secondary'.", DeprecationWarning) + arguments['reference'] = args[0] + arguments['secondary'] = args[1] + + if arguments['granule1']: + warnings.warn("Keyword argument 'granule1' is deprecated. Use 'reference' instead.", DeprecationWarning) + arguments['reference'] = arguments['granule1'] + + if arguments['granule2']: + warnings.warn("Keyword argument 'granule2' is deprecated. Use 'secondary' instead.", DeprecationWarning) + arguments['secondary'] = arguments['granule1'] + + arguments.pop('granule1') + arguments.pop('granule2') + job_dict = self.prepare_insar_isce_burst_job(**arguments) return self.submit_prepared_jobs(prepared_jobs=job_dict) From 3940351f555ad92fee1cc11d3d63a774f226df2c Mon Sep 17 00:00:00 2001 From: Forrest Williams Date: Wed, 21 Aug 2024 08:13:17 -0500 Subject: [PATCH 3/8] fix flake8 --- src/hyp3_sdk/hyp3.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/hyp3_sdk/hyp3.py b/src/hyp3_sdk/hyp3.py index 256edea..0b1ed88 100644 --- a/src/hyp3_sdk/hyp3.py +++ b/src/hyp3_sdk/hyp3.py @@ -450,9 +450,8 @@ def submit_insar_isce_burst_job(self, arguments = locals().copy() arguments.pop('self') arguments.pop('args') - + if len(args) == 2: - warnings.warn("Positional arguments for submit_insar_isce_burst_job are now mapped to 'reference' and 'secondary'.", DeprecationWarning) arguments['reference'] = args[0] arguments['secondary'] = args[1] From eb83bd398e7eb1d7effffca1a740a9e605eb7042 Mon Sep 17 00:00:00 2001 From: Joseph H Kennedy Date: Wed, 21 Aug 2024 09:19:39 -0700 Subject: [PATCH 4/8] refactor submit and prepare insar busrt jobs --- src/hyp3_sdk/hyp3.py | 77 ++++++++++++++++++++++++-------------------- tests/test_hyp3.py | 42 ++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 35 deletions(-) diff --git a/src/hyp3_sdk/hyp3.py b/src/hyp3_sdk/hyp3.py index 0b1ed88..8e68bc7 100644 --- a/src/hyp3_sdk/hyp3.py +++ b/src/hyp3_sdk/hyp3.py @@ -424,83 +424,90 @@ def prepare_insar_job(cls, return job_dict def submit_insar_isce_burst_job(self, - *args, - reference: Union[str, Iterable[str]] = None, - secondary: Union[str, Iterable[str]] = None, - granule1: Optional[str] = None, - granule2: Optional[str] = None, + reference: Optional[Union[str, Iterable[str]]] = None, + secondary: Optional[Union[str, Iterable[str]]] = None, name: Optional[str] = None, apply_water_mask: bool = False, - looks: Literal['20x4', '10x2', '5x1'] = '20x4') -> Batch: + looks: Literal['20x4', '10x2', '5x1'] = '20x4', + *, + granule1: Optional[str] = None, + granule2: Optional[str] = None, + ) -> Batch: """Submit an InSAR ISCE burst job. Args: - reference: The reference granule (older scene) to use - secondary: The secondary granule (younger scene) to use - granule1: Depreceated argument superseeded by reference - granule2: Depreceated argument superseeded by secondary + reference: The reference granules (older scenes) to use + secondary: The secondary granules (younger scenes) to use name: A name for the job apply_water_mask: Sets pixels over coastal waters and large inland waterbodies as invalid for phase unwrapping looks: Number of looks to take in range and azimuth + granule1: Deprecated argument superseded by reference.The reference granule (older scene) to use + granule2: Deprecated argument superseded by secondary. The reference granule (older scene) to use Returns: A Batch object containing the InSAR ISCE burst job """ arguments = locals().copy() arguments.pop('self') - arguments.pop('args') - - if len(args) == 2: - arguments['reference'] = args[0] - arguments['secondary'] = args[1] - - if arguments['granule1']: - warnings.warn("Keyword argument 'granule1' is deprecated. Use 'reference' instead.", DeprecationWarning) - arguments['reference'] = arguments['granule1'] - - if arguments['granule2']: - warnings.warn("Keyword argument 'granule2' is deprecated. Use 'secondary' instead.", DeprecationWarning) - arguments['secondary'] = arguments['granule1'] - - arguments.pop('granule1') - arguments.pop('granule2') job_dict = self.prepare_insar_isce_burst_job(**arguments) return self.submit_prepared_jobs(prepared_jobs=job_dict) @classmethod def prepare_insar_isce_burst_job(cls, - reference: Union[str, Iterable[str]], - secondary: Union[str, Iterable[str]], + reference: Optional[Union[str, Iterable[str]]] = None, + secondary: Optional[Union[str, Iterable[str]]] = None, name: Optional[str] = None, apply_water_mask: bool = False, - looks: Literal['20x4', '10x2', '5x1'] = '20x4') -> dict: + looks: Literal['20x4', '10x2', '5x1'] = '20x4', + *, + granule1: Optional[str] = None, + granule2: Optional[str] = None, + ) -> dict: """Prepare an InSAR ISCE burst job. Args: - reference: The reference granule (older scene) to use - secondary: The secondary granule (younger scene) to use + Args: + reference: The reference granules (older scenes) to use + secondary: The secondary granules (younger scenes) to use name: A name for the job apply_water_mask: Sets pixels over coastal waters and large inland waterbodies as invalid for phase unwrapping looks: Number of looks to take in range and azimuth + granule1: Deprecated argument superseded by reference.The reference granule (older scene) to use + granule2: Deprecated argument superseded by secondary. The reference granule (older scene) to use Returns: A dictionary containing the prepared InSAR ISCE burst job """ - job_parameters = locals().copy() - for key in ['cls', 'reference', 'secondary', 'name']: - job_parameters.pop(key) + if reference is None: + if granule1: + warnings.warn("Keyword argument 'granule1' is deprecated. Use 'reference' instead.", DeprecationWarning) + reference = granule1 + else: + raise ValueError('Either reference and secondary or granule1 and granule2 must be provided.') + + if secondary is None: + if granule2: + warnings.warn("Keyword argument 'granule1' is deprecated. Use 'reference' instead.", DeprecationWarning) + secondary = granule2 + else: + raise ValueError('Either reference and secondary or granule1 and granule2 must be provided.') if isinstance(reference, str): reference = [reference] + if isinstance(secondary, str): secondary = [secondary] + arguments = locals().copy() + for key in ['cls', 'granule1', 'granule2', 'name']: + arguments.pop(key) + job_dict = { - 'job_parameters': {'reference': reference, 'secondary': secondary, **job_parameters}, + 'job_parameters': {**arguments}, 'job_type': 'INSAR_ISCE_BURST', } if name is not None: diff --git a/tests/test_hyp3.py b/tests/test_hyp3.py index 4bfed2f..234126a 100644 --- a/tests/test_hyp3.py +++ b/tests/test_hyp3.py @@ -3,6 +3,7 @@ from datetime import datetime, timedelta, timezone from urllib.parse import urljoin +import pytest import responses import hyp3_sdk @@ -290,6 +291,18 @@ def test_prepare_insar_isce_burst_job(): 'looks': '20x4', }, } + + assert HyP3.prepare_insar_isce_burst_job('ref_granule1', 'sec_granule2', 'job_name') == { + 'job_type': 'INSAR_ISCE_BURST', + 'name': 'job_name', + 'job_parameters': { + 'reference': ['ref_granule1'], + 'secondary': ['sec_granule2'], + 'apply_water_mask': False, + 'looks': '20x4', + }, + } + assert HyP3.prepare_insar_isce_burst_job( reference=['ref_granule1', 'ref_granule2'], secondary=['sec_granule1', 'sec_granule2'], @@ -307,6 +320,35 @@ def test_prepare_insar_isce_burst_job(): }, } + assert HyP3.prepare_insar_isce_burst_job( + ['ref_granule1', 'ref_granule2'], + ['sec_granule1', 'sec_granule2'], + name='my_name', + apply_water_mask=True, + looks='10x2', + ) == { + 'job_type': 'INSAR_ISCE_BURST', + 'name': 'my_name', + 'job_parameters': { + 'reference': ['ref_granule1', 'ref_granule2'], + 'secondary': ['sec_granule1', 'sec_granule2'], + 'apply_water_mask': True, + 'looks': '10x2', + }, + } + + with pytest.warns(DeprecationWarning): + assert HyP3.prepare_insar_isce_burst_job(granule1='ref_granule1', granule2='sec_granule2') == { + 'job_type': 'INSAR_ISCE_BURST', + 'job_parameters': { + 'reference': ['ref_granule1'], + 'secondary': ['sec_granule2'], + 'apply_water_mask': False, + 'looks': '20x4', + }, + } + + def test_deprecated_warning(): with warnings.catch_warnings(record=True) as w: From c804ad205eb97c07cb118736a6a90089e1a91453 Mon Sep 17 00:00:00 2001 From: Forrest Williams Date: Wed, 21 Aug 2024 12:54:43 -0500 Subject: [PATCH 5/8] fix flake8 --- src/hyp3_sdk/hyp3.py | 1 - tests/test_hyp3.py | 1 - 2 files changed, 2 deletions(-) diff --git a/src/hyp3_sdk/hyp3.py b/src/hyp3_sdk/hyp3.py index 8e68bc7..cd8714d 100644 --- a/src/hyp3_sdk/hyp3.py +++ b/src/hyp3_sdk/hyp3.py @@ -498,7 +498,6 @@ def prepare_insar_isce_burst_job(cls, if isinstance(reference, str): reference = [reference] - if isinstance(secondary, str): secondary = [secondary] diff --git a/tests/test_hyp3.py b/tests/test_hyp3.py index 234126a..caba43e 100644 --- a/tests/test_hyp3.py +++ b/tests/test_hyp3.py @@ -349,7 +349,6 @@ def test_prepare_insar_isce_burst_job(): } - def test_deprecated_warning(): with warnings.catch_warnings(record=True) as w: HyP3.prepare_insar_job(granule1='my_granule1', granule2='my_granule2', include_los_displacement=False) From d6ecb55f37a655cdc42117dd3734de065be18cbb Mon Sep 17 00:00:00 2001 From: Forrest Williams Date: Wed, 21 Aug 2024 13:02:35 -0500 Subject: [PATCH 6/8] fix changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2820fb4..3ba9c0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ 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). -## [8.0.0] +## [7.1.1] ### Changed * The `insar_isce_burst_job` so that it takes a `reference` and `secondary` scene as input, not `granule1` and `granule2`. Backward compatibility in `submit_insar_isce_burst_job` is maintained for now. From cb39c5a9bef52a17c7a7080a15e4f3c53f7f1783 Mon Sep 17 00:00:00 2001 From: Forrest Williams <31411324+forrestfwilliams@users.noreply.github.com> Date: Fri, 23 Aug 2024 07:25:35 -0500 Subject: [PATCH 7/8] Update CHANGELOG.md Co-authored-by: Andrew Player --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ba9c0c..2263abc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [7.1.1] ### Changed -* The `insar_isce_burst_job` so that it takes a `reference` and `secondary` scene as input, not `granule1` and `granule2`. Backward compatibility in `submit_insar_isce_burst_job` is maintained for now. +* `insar_isce_burst_job` so that it takes a `reference` and `secondary` scene as input, rather than `granule1` and `granule2`. Backward compatibility in `submit_insar_isce_burst_job` is maintained for now, but it will be broken in the future. ## [7.0.1] From 3396596c0d3ced019390a00642ad8998255fbaae Mon Sep 17 00:00:00 2001 From: Forrest Williams Date: Fri, 23 Aug 2024 08:19:30 -0500 Subject: [PATCH 8/8] remove the build package --- environment.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/environment.yml b/environment.yml index 1d1124b..5ef6c1e 100644 --- a/environment.yml +++ b/environment.yml @@ -6,7 +6,6 @@ dependencies: - python>=3.10 - pip # For packaging, and testing - - build - flake8 - flake8-import-order - flake8-blind-except