From be267b36b9248fee21b8ba0f6832b364fc7a7cda Mon Sep 17 00:00:00 2001 From: sharkinsspatial Date: Fri, 11 Nov 2022 19:15:01 -0600 Subject: [PATCH 1/4] Use kwargs patched version of stactools for testing. --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 99a5359..403a216 100644 --- a/setup.cfg +++ b/setup.cfg @@ -30,7 +30,7 @@ package_dir = = src packages = find_namespace: install_requires = - stactools == 0.2.1 + stactools @ git+https://github.com/sharkinsspatial/stactools.git@kwargs_subclass [options.packages.find] where = src From 4bdb5f5e49e76f6e928e13d384afaa91118c18e2 Mon Sep 17 00:00:00 2001 From: sharkinsspatial Date: Fri, 11 Nov 2022 19:33:30 -0600 Subject: [PATCH 2/4] Pass kwargs. --- src/stactools/sentinel1/grd/metadata_links.py | 8 +++++--- src/stactools/sentinel1/grd/product_metadata.py | 9 ++++++--- src/stactools/sentinel1/grd/stac.py | 12 +++++++++--- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/stactools/sentinel1/grd/metadata_links.py b/src/stactools/sentinel1/grd/metadata_links.py index dad9c7f..4615e35 100644 --- a/src/stactools/sentinel1/grd/metadata_links.py +++ b/src/stactools/sentinel1/grd/metadata_links.py @@ -63,12 +63,14 @@ class MetadataLinks: def __init__(self, granule_href: str, read_href_modifier: Optional[ReadHrefModifier] = None, - archive_format: Format = Format.SAFE) -> None: + archive_format: Format = Format.SAFE, + **kwargs) -> None: self.granule_href = granule_href self.href = os.path.join(granule_href, "manifest.safe") self.archive_format = archive_format - self.manifest = XmlElement.from_file(self.href, read_href_modifier) + self.manifest = XmlElement.from_file(self.href, read_href_modifier, + **kwargs) data_object_section = self.manifest.find("dataObjectSection") if data_object_section is None: raise ManifestError( @@ -83,7 +85,7 @@ def __init__(self, "productInfo.json") self.product_info = json.loads( stactools.core.io.read_text(self.product_info_href, - read_href_modifier)) + read_href_modifier, **kwargs)) self.filename_map = self.product_info["filenameMap"] file_location_list = self._data_object_section.findall( diff --git a/src/stactools/sentinel1/grd/product_metadata.py b/src/stactools/sentinel1/grd/product_metadata.py index 5d4d94a..187230e 100644 --- a/src/stactools/sentinel1/grd/product_metadata.py +++ b/src/stactools/sentinel1/grd/product_metadata.py @@ -13,10 +13,13 @@ class ProductMetadataError(Exception): pass -def get_shape(meta_links: MetadataLinks, - read_href_modifier: Optional[ReadHrefModifier]) -> List[int]: +def get_shape( + meta_links: MetadataLinks, + read_href_modifier: Optional[ReadHrefModifier], + **kwargs: Any +) -> List[int]: links = meta_links.create_product_asset() - root = XmlElement.from_file(links[0][1].href, read_href_modifier) + root = XmlElement.from_file(links[0][1].href, read_href_modifier, **kwargs) x_size = int(root.findall(".//numberOfSamples")[0].text) y_size = int(root.findall(".//numberOfLines")[0].text) diff --git a/src/stactools/sentinel1/grd/stac.py b/src/stactools/sentinel1/grd/stac.py index ea4645a..51581a9 100644 --- a/src/stactools/sentinel1/grd/stac.py +++ b/src/stactools/sentinel1/grd/stac.py @@ -1,6 +1,6 @@ import logging import os -from typing import Optional +from typing import Optional, Any import pystac from pystac.extensions.eo import EOExtension @@ -23,6 +23,7 @@ def create_item( granule_href: str, read_href_modifier: Optional[ReadHrefModifier] = None, archive_format: Format = Format.SAFE, + **kwargs: Any, ) -> pystac.Item: """Create a STC Item from a Sentinel-1 GRD scene. @@ -40,7 +41,12 @@ def create_item( pystac.Item: An item representing the Sentinel-1 GRD scene. """ - metalinks = MetadataLinks(granule_href, read_href_modifier, archive_format) + metalinks = MetadataLinks( + granule_href, + read_href_modifier, + archive_format, + **kwargs, + ) product_metadata = ProductMetadata( metalinks.product_metadata_href, @@ -76,7 +82,7 @@ def create_item( item.common_metadata.constellation = SENTINEL_CONSTELLATION # s1 properties - shape = get_shape(metalinks, read_href_modifier) + shape = get_shape(metalinks, read_href_modifier, **kwargs) item.properties.update({ **product_metadata.metadata_dict, "s1:shape": shape }) From b82c6bdf0e74941c7f5a582cd9b0ea3fb817acdd Mon Sep 17 00:00:00 2001 From: sharkinsspatial Date: Thu, 12 Jan 2023 17:23:33 -0600 Subject: [PATCH 3/4] Use new stactools release containing kwargs passing. --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 403a216..c90c558 100644 --- a/setup.cfg +++ b/setup.cfg @@ -30,7 +30,7 @@ package_dir = = src packages = find_namespace: install_requires = - stactools @ git+https://github.com/sharkinsspatial/stactools.git@kwargs_subclass + stactools == 0.4.3 [options.packages.find] where = src From ad6b3d412c18003258d8b00d9b33391187c379e4 Mon Sep 17 00:00:00 2001 From: sharkinsspatial Date: Thu, 12 Jan 2023 17:51:56 -0600 Subject: [PATCH 4/4] isort fixes which were not applied when calling ./scripts/format. --- src/stactools/sentinel1/grd/product_metadata.py | 8 +++----- src/stactools/sentinel1/grd/stac.py | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/stactools/sentinel1/grd/product_metadata.py b/src/stactools/sentinel1/grd/product_metadata.py index cc45c6b..acacc17 100644 --- a/src/stactools/sentinel1/grd/product_metadata.py +++ b/src/stactools/sentinel1/grd/product_metadata.py @@ -13,11 +13,9 @@ class ProductMetadataError(Exception): pass -def get_shape( - meta_links: MetadataLinks, - read_href_modifier: Optional[ReadHrefModifier], - **kwargs: Any -) -> List[int]: +def get_shape(meta_links: MetadataLinks, + read_href_modifier: Optional[ReadHrefModifier], + **kwargs: Any) -> List[int]: links = meta_links.create_product_asset() root = XmlElement.from_file(links[0][1].href, read_href_modifier, **kwargs) diff --git a/src/stactools/sentinel1/grd/stac.py b/src/stactools/sentinel1/grd/stac.py index 51581a9..0ab5647 100644 --- a/src/stactools/sentinel1/grd/stac.py +++ b/src/stactools/sentinel1/grd/stac.py @@ -1,6 +1,6 @@ import logging import os -from typing import Optional, Any +from typing import Any, Optional import pystac from pystac.extensions.eo import EOExtension