Skip to content

Commit

Permalink
Merge pull request #68 from digitalearthpacific/zero-pad-and-https-by…
Browse files Browse the repository at this point in the history
…-default

Make zero padding tile ids and https hrefs default
  • Loading branch information
jessjaco authored Oct 9, 2024
2 parents e40fd98 + 8de5990 commit 2e272f7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
4 changes: 2 additions & 2 deletions dep_tools/namers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(
version: str,
time: str,
prefix: str = "dep",
zero_pad_numbers: bool = False,
zero_pad_numbers: bool = True,
):
self.sensor = sensor
self.dataset_id = dataset_id
Expand Down Expand Up @@ -86,7 +86,7 @@ def __init__(
version: str,
time: str,
prefix: str = "dep",
zero_pad_numbers: bool = False,
zero_pad_numbers: bool = True,
):
super().__init__(
sensor=sensor,
Expand Down
6 changes: 3 additions & 3 deletions dep_tools/stac_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(
itempath: DepItemPath,
remote: bool = True,
collection_url_root: str = "https://stac.staging.digitalearthpacific.org/collections",
make_hrefs_https: bool = False,
make_hrefs_https: bool = True,
**kwargs,
):
self._itempath = itempath
Expand Down Expand Up @@ -52,7 +52,7 @@ def get_stac_item(
data: DataArray | Dataset,
remote: bool = True,
collection_url_root: str = "https://stac.staging.digitalearthpacific.org/collections",
make_hrefs_https: bool = False,
make_hrefs_https: bool = True,
**kwargs,
) -> Item | str:
prefix = Path("./")
Expand All @@ -65,7 +65,7 @@ def get_stac_item(
if make_hrefs_https:
# E.g., https://dep-public-prod.s3.us-west-2.amazonaws.com/
prefix = URL(
f"https://{getattr(itempath, 'bucket')}.s3/us-west-2.amazonaws.com"
f"https://{getattr(itempath, 'bucket')}.s3.us-west-2.amazonaws.com"
)
else:
# E.g., s3://dep-public-prod/
Expand Down
3 changes: 2 additions & 1 deletion tests/test_get_stac_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ def stac_item():
dataset_id="wofs",
version="1.0.0",
time="2021-01-01",
zero_pad_numbers=False,
)
tif = itempath.path("12,34", asset_name="wofs")
test_xr = rioxarray.open_rasterio(tif).to_dataset(name="wofs")
item = get_stac_item(
itempath=itempath,
item_id="12,34",
data=test_xr,
remote=False,
remote=False
)

return item
Expand Down
19 changes: 16 additions & 3 deletions tests/test_namers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
time = "2045"
testItemPath = DepItemPath(sensor, dataset_id, version, time)
paddedItemPath = DepItemPath(sensor, dataset_id, version, time, zero_pad_numbers=True)
nonPaddedItemPath = DepItemPath(sensor, dataset_id, version, time, zero_pad_numbers=False)

item_id = "001,002"
asset_name = "mean"
Expand Down Expand Up @@ -47,16 +48,28 @@ def test_padded_format_item_id_string():


def test_format_item_id_iterable():
assert testItemPath._format_item_id(("66", "23"), "_") == "66_23"
assert testItemPath._format_item_id(("66", "23"), "_") == "066_023"


def test_format_item_id_iterable_int():
assert testItemPath._format_item_id((66, 23), "_") == "66_23"
assert testItemPath._format_item_id((66, 23), "_") == "066_023"


def test_format_item_id_list_as_string():
assert testItemPath._format_item_id("001,002", "_") == "001_002"


def test_format_item_id_string():
assert testItemPath._format_item_id("66", "_") == "66"
assert testItemPath._format_item_id("66", "_") == "066"


def test_non_padded_format_item_id_iterable():
assert nonPaddedItemPath._format_item_id(("66", "23"), "_") == "66_23"


def test_non_padded_format_item_id_iterable_int():
assert nonPaddedItemPath._format_item_id((66, 23), "_") == "66_23"


def test_non_padded_format_item_id_list_as_string():
assert nonPaddedItemPath._format_item_id("001,002", "_") == "001_002"

0 comments on commit 2e272f7

Please sign in to comment.