Skip to content

Commit

Permalink
populate item with processing datetimes (#63)
Browse files Browse the repository at this point in the history
* populate item with processing datetimes
* use community landsat schema
  • Loading branch information
Phil Varner authored Nov 9, 2023
1 parent 73e518b commit f568472
Show file tree
Hide file tree
Showing 18 changed files with 277 additions and 237 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

### Added

- Populate item with processing datetime field `landsat:product_generated` ([#63](https://github.com/stactools-packages/landsat/pull/63))

### Changed

- Replace use of externally-hosted Landsat Extension <https://landsat.usgs.gov/stac/landsat-extension/v1.1.1/schema.json> with community Landsat Extension <https://stac-extensions.github.io/landsat/v2.0.0/schema.json> ([#63](https://github.com/stactools-packages/landsat/pull/63))

## [0.4.1] - 2023-08-20

### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
- STAC extensions used:
- [classification](https://github.com/stac-extensions/classification)
- [eo](https://github.com/stac-extensions/eo)
- [landsat](https://landsat.usgs.gov/stac/landsat-extension/v1.1.1/schema.json)
- [landsat](https://stac-extensions.github.io/landsat/v2.0.0/schema.json)
- [proj](https://github.com/stac-extensions/projection/)
- [raster](https://github.com/stac-extensions/raster)
- [scientific](https://github.com/stac-extensions/scientific)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
"https://landsat.usgs.gov/stac/landsat-extension/v1.1.1/schema.json",
"https://stac-extensions.github.io/landsat/v2.0.0/schema.json",
"https://stac-extensions.github.io/classification/v1.0.0/schema.json",
"https://stac-extensions.github.io/scientific/v1.0.0/schema.json"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
"https://landsat.usgs.gov/stac/landsat-extension/v1.1.1/schema.json",
"https://stac-extensions.github.io/landsat/v2.0.0/schema.json",
"https://stac-extensions.github.io/classification/v1.0.0/schema.json",
"https://stac-extensions.github.io/scientific/v1.0.0/schema.json"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
"https://landsat.usgs.gov/stac/landsat-extension/v1.1.1/schema.json",
"https://stac-extensions.github.io/landsat/v2.0.0/schema.json",
"https://stac-extensions.github.io/classification/v1.0.0/schema.json",
"https://stac-extensions.github.io/scientific/v1.0.0/schema.json"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
"https://landsat.usgs.gov/stac/landsat-extension/v1.1.1/schema.json",
"https://stac-extensions.github.io/landsat/v2.0.0/schema.json",
"https://stac-extensions.github.io/classification/v1.0.0/schema.json",
"https://stac-extensions.github.io/scientific/v1.0.0/schema.json"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
"https://landsat.usgs.gov/stac/landsat-extension/v1.1.1/schema.json",
"https://stac-extensions.github.io/landsat/v2.0.0/schema.json",
"https://stac-extensions.github.io/classification/v1.0.0/schema.json",
"https://stac-extensions.github.io/scientific/v1.0.0/schema.json"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
"https://landsat.usgs.gov/stac/landsat-extension/v1.1.1/schema.json",
"https://stac-extensions.github.io/landsat/v2.0.0/schema.json",
"https://stac-extensions.github.io/classification/v1.0.0/schema.json",
"https://stac-extensions.github.io/scientific/v1.0.0/schema.json"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
"https://landsat.usgs.gov/stac/landsat-extension/v1.1.1/schema.json",
"https://stac-extensions.github.io/landsat/v2.0.0/schema.json",
"https://stac-extensions.github.io/classification/v1.0.0/schema.json",
"https://stac-extensions.github.io/scientific/v1.0.0/schema.json"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
"https://landsat.usgs.gov/stac/landsat-extension/v1.1.1/schema.json",
"https://stac-extensions.github.io/landsat/v2.0.0/schema.json",
"https://stac-extensions.github.io/classification/v1.0.0/schema.json",
"https://stac-extensions.github.io/scientific/v1.0.0/schema.json"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
"https://landsat.usgs.gov/stac/landsat-extension/v1.1.1/schema.json",
"https://stac-extensions.github.io/landsat/v2.0.0/schema.json",
"https://stac-extensions.github.io/classification/v1.0.0/schema.json",
"https://stac-extensions.github.io/scientific/v1.0.0/schema.json"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
"https://landsat.usgs.gov/stac/landsat-extension/v1.1.1/schema.json",
"https://stac-extensions.github.io/landsat/v2.0.0/schema.json",
"https://stac-extensions.github.io/classification/v1.0.0/schema.json",
"https://stac-extensions.github.io/scientific/v1.0.0/schema.json"
],
Expand Down
5 changes: 4 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ pre-commit
pytest
pytest-cov
vcrpy
types-python-dateutil
types-python-dateutil
# AttributeError: module 'urllib3.connectionpool' has no attribute 'VerifiedHTTPSConnection'
# if urllib3 2.x is installed on python 3.9
urllib3<2
3 changes: 2 additions & 1 deletion src/stactools/landsat/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ class Sensor(Enum):


LANDSAT_EXTENSION_SCHEMA = (
"https://landsat.usgs.gov/stac/landsat-extension/v1.1.1/schema.json"
"https://stac-extensions.github.io/landsat/v2.0.0/schema.json"
)

CLASSIFICATION_EXTENSION_SCHEMA = (
"https://stac-extensions.github.io/classification/v1.0.0/schema.json" # noqa
)
Expand Down
23 changes: 21 additions & 2 deletions src/stactools/landsat/mtl_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from lxml import etree
from lxml.etree import _Element as lxmlElement
from pyproj import Geod
from pystac.utils import map_opt, str_to_datetime
from pystac.utils import datetime_to_str, map_opt, str_to_datetime
from stactools.core.io import ReadHrefModifier, read_text
from stactools.core.io.xml import XmlElement
from stactools.core.projection import transform_from_bbox
Expand Down Expand Up @@ -273,9 +273,15 @@ def wrs_path(self) -> str:
def wrs_row(self) -> str:
return self._get_text("IMAGE_ATTRIBUTES/WRS_ROW").zfill(3)

@property
def product_generated(self) -> Optional[datetime]:
return self._product_generated(
"LEVEL2_PROCESSING_RECORD"
) or self._product_generated("LEVEL1_PROCESSING_RECORD")

@property
def landsat_metadata(self) -> Dict[str, Any]:
return {
d = {
"landsat:cloud_cover_land": self._get_float(
"IMAGE_ATTRIBUTES/CLOUD_COVER_LAND"
),
Expand All @@ -292,6 +298,12 @@ def landsat_metadata(self) -> Dict[str, Any]:
"landsat:scene_id": self.scene_id,
}

pg = self.product_generated
if pg:
d["landsat:product_generated"] = datetime_to_str(pg)

return d

@property
def level1_radiance(self) -> Dict[str, Dict[str, Optional[float]]]:
"""Gets the scale (mult) and offset (add) values for generating TOA
Expand All @@ -317,6 +329,13 @@ def level1_radiance(self) -> Dict[str, Dict[str, Optional[float]]]:
mult_add[band]["add"] = self._float_or_none(value)
return mult_add

def _product_generated(self, path: str) -> Optional[datetime]:
v = self._root.find_text(f"{path}/DATE_PRODUCT_GENERATED")
if v:
return str_to_datetime(v)
else:
return None

@classmethod
def from_file(
cls,
Expand Down
Loading

0 comments on commit f568472

Please sign in to comment.