Skip to content

Commit

Permalink
Remove the requirement for a 9 parameter transform, including test of…
Browse files Browse the repository at this point in the history
… S1 STAC
  • Loading branch information
alexgleith authored and jeremyh committed Jun 29, 2021
1 parent e26245e commit 0ab44d1
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion eodatasets3/dataset.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ properties:
type: array
items:
type: number
minItems: 9
minItems: 6
maxItems: 9
required:
- shape
Expand Down
16 changes: 9 additions & 7 deletions eodatasets3/serialise.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,17 @@ def _structure_as_stac_props(d, t):


def _structure_as_affine(d: Tuple, t):
if len(d) != 9:
raise ValueError(f"Expected 9 coefficients in transform. Got {d!r}")
if len(d) not in [6, 9]:
raise ValueError(f"Expected 6 or 9 coefficients in transform. Got {d!r}")

if tuple(d[-3:]) != (0.0, 0.0, 1.0):
raise ValueError(
f"Nine-element affine should always end in [0, 0, 1]. Got {d!r}"
)
if len(d) == 9:
if tuple(d[-3:]) != (0.0, 0.0, 1.0):
raise ValueError(
f"Nine-element affine should always end in [0, 0, 1]. Got {d!r}"
)
d = [*d[:-3]]

return Affine(*d[:-3])
return Affine(*d)


def _unstructure_as_stac_props(v: StacPropertyView):
Expand Down
14 changes: 14 additions & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path
from typing import Dict, Callable

import json
import pytest

from eodatasets3 import serialise
Expand Down Expand Up @@ -31,6 +32,13 @@
/ "LS8_OLITIRS_STD-MD_P00_LC80840720742017365LGN00_084_072-074_20180101T004644Z20180101T004824_1"
)

# Manually converted from a S1 STAC document
S1_EO3_PATH: Path = (
Path(__file__).parent
/ "data"
/ "s1_rtc_021EE1_N00E001_2019_09_13_metadata_eo3.json"
)


WOFS_PATH: Path = Path(__file__).parent / "data" / "wofs"

Expand All @@ -47,6 +55,12 @@ def relative_offset(base, offset):
return offset


@pytest.fixture
def sentinel1_eo3() -> Path:
with open(S1_EO3_PATH) as f:
return json.load(f)


@pytest.fixture
def l1_ls8_folder(tmp_path: Path) -> Path:
return _make_copy(L8_INPUT_PATH, tmp_path)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"$schema": "https://schemas.opendatacube.org/dataset", "id": "1505d39c-9a51-50cf-a5e1-53e0908fb691", "crs": "epsg:4326", "grids": {"default": {"shape": [5000, 5000], "transform": [1.0, 0.0002, 0.0, 1.0, 0.0, -0.0002]}}, "product": {"name": "s1_rtc"}, "properties": {"datetime": "2019-09-13T18:16:05.317374Z", "dtr:start_datetime": "2019-09-13T18:16:05.317374Z", "dtr:end_datetime": "2019-09-13T18:16:34.334266Z", "eo:constellation": "sentinel-1", "eo:instrument": "C-SAR", "eo:platform": "sentinel-1b", "proj:epsg": 4326, "odc:region_code": "N00E001", "odc:product": "s1_rtc", "odc:processing_datetime": "2021-06-01T22:03:33.069607Z", "sar:instrument_mode": "IW", "sar:frequency_band": "C", "sar:center_frequency": 5.405, "sar:polarizations": ["VV", "VH"], "sar:product_type": "RTC", "sar:observation_direction": "right", "sat:orbit_state": "ascending", "sat:relative_orbit": 146, "sat:absolute_orbit": 18022, "odc:file_format": "GeoTIFF"}, "measurements": {"vv": {"path": "s1_rtc_021EE1_N00E001_2019_09_13_VV.tif"}, "area": {"path": "s1_rtc_021EE1_N00E001_2019_09_13_AREA.tif"}, "vh": {"path": "s1_rtc_021EE1_N00E001_2019_09_13_VH.tif"}, "angle": {"path": "s1_rtc_021EE1_N00E001_2019_09_13_ANGLE.tif"}, "mask": {"path": "s1_rtc_021EE1_N00E001_2019_09_13_MASK.tif"}}, "lineage": {}, "accessories": {"metadata": {"path": "s1_rtc_021EE1_N00E001_2019_09_13_metadata.xml"}}, "label": "N00E001_2019_09_13_021EE1", "geometry": {"type": "Polygon", "coordinates": [[[1.512839816070727, 1.0], [1.0, 1.0], [1.0, 0.4830833032494046], [1.5941492779129824, 0.6106073585853442], [1.512839816070727, 1.0]]]}}
4 changes: 4 additions & 0 deletions tests/integration/test_serialise.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
from tests.common import dump_roundtrip


def test_stac_to_eo3_serialise(sentinel1_eo3):
dump_roundtrip(sentinel1_eo3)


def test_valid_document_works(tmp_path: Path, example_metadata: Dict):
generated_doc = dump_roundtrip(example_metadata)

Expand Down

0 comments on commit 0ab44d1

Please sign in to comment.