Skip to content
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

Allow passing generic kwargs for IO operations. #21

Merged
merged 5 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ package_dir =
= src
packages = find_namespace:
install_requires =
stactools == 0.2.1
stactools == 0.4.3

[options.packages.find]
where = src
8 changes: 5 additions & 3 deletions src/stactools/sentinel1/grd/metadata_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,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(
Expand All @@ -85,7 +87,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(
Expand Down
5 changes: 3 additions & 2 deletions src/stactools/sentinel1/grd/product_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ class ProductMetadataError(Exception):


def get_shape(meta_links: MetadataLinks,
read_href_modifier: Optional[ReadHrefModifier]) -> List[int]:
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)
Expand Down
12 changes: 9 additions & 3 deletions src/stactools/sentinel1/grd/stac.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import os
from typing import Optional
from typing import Any, Optional

import pystac
from pystac.extensions.eo import EOExtension
Expand All @@ -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.

Expand All @@ -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,
Expand Down Expand Up @@ -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
})
Expand Down