Skip to content

Commit

Permalink
apply more suggestions from review
Browse files Browse the repository at this point in the history
  • Loading branch information
hrodmn committed Nov 19, 2024
1 parent d403377 commit 538ac16
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
10 changes: 10 additions & 0 deletions src/stactools/glad_glclu2020/commands.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import warnings
from typing import Optional

import click
Expand Down Expand Up @@ -70,6 +71,15 @@ def create_collection_command(
if collection_type == "annual"
else CollectionIDs.GLAD_GLCLU2020_CHANGE
)

if not (sample_asset_href or media_type):
warnings.warn(
"No sample_asset_href or media_type provided. "
f"Defaulting to {MediaType.GEOTIFF} media type.",
category=UserWarning,
)
media_type = MediaType.GEOTIFF.value

media_type_enum = MediaType(media_type) if media_type else None

collection = stac.create_collection(
Expand Down
11 changes: 6 additions & 5 deletions src/stactools/glad_glclu2020/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

COLLECTION_START_DATETIME = datetime(2000, 1, 1, tzinfo=timezone.utc)
COLLECTION_END_DATETIME = datetime(2020, 12, 31, 23, 59, 59, tzinfo=timezone.utc)
COLLECTION_BBOX = (-180.0, -60.0, 180.0, 80.0)

DEFAULT_HREF_FORMAT = "https://storage.googleapis.com/earthenginepartners-hansen/GLCLU2000-2020/v2/{year}/{loc}.tif"

Expand Down Expand Up @@ -225,7 +226,7 @@ def build_collection(
title=self.title,
description=self.description,
extent=Extent(
SpatialExtent([[-180.0, 80.0, 180.0, -80.0]]),
SpatialExtent([list(COLLECTION_BBOX)]),
TemporalExtent(
[
[
Expand Down Expand Up @@ -255,8 +256,8 @@ def build_collection(
href=(
"https://glad.umd.edu/sites/default/files/styles/projects/public/datasets_glulc.jpg?itok=bxS-HPMi"
),
media_type=MediaType.PNG,
title=self.title,
media_type=MediaType.JPEG,
title="Thumbnail",
roles=["thumbnail"],
)
},
Expand All @@ -282,13 +283,13 @@ def build_collection(
Link(
rel=RelType.LICENSE,
target="https://creativecommons.org/licenses/by/4.0/",
media_type="text/html",
media_type=MediaType.HTML,
title="CC-BY-4.0 license",
),
Link(
rel="documentation",
target=COLLECTION_HOMEPAGE,
media_type="text/html",
media_type=MediaType.HTML,
title="GLAD GLCLU Access Page",
),
Link(
Expand Down
17 changes: 17 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,20 @@ def test_create_item(
item = Item.from_file(path)
assert item.assets[ASSET_NAME].media_type == media_type
item.validate()


def test_create_collection_no_media_type_or_sample(tmp_path: Path) -> None:
"""Test warning if no media_type or sample_asset_href provided"""
path = str(tmp_path / "collection.json")
runner = CliRunner()
with pytest.warns(UserWarning, match="No sample_asset_href or media_type provided"):
result = runner.invoke(
command,
[
"create-collection",
"--type",
"annual",
path,
],
)
assert result.exit_code == 0, "\n{}".format(result.output)

0 comments on commit 538ac16

Please sign in to comment.