Skip to content

Commit

Permalink
Merge pull request #150 from stactools-packages/pv/use-am-for-bbox
Browse files Browse the repository at this point in the history
use antimeridian package for creating bbox
  • Loading branch information
Phil Varner authored Dec 13, 2023
2 parents 82c2dbc + 047bc6b commit 3bf4923
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 53 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). This project attempts to match the major and minor versions of [stactools](https://github.com/stac-utils/stactools) and increments the patch number as needed.

## [Unreleased] - TBD

### Fixed

- Antimeridian-crossing scene bboxes

## Removed

- `create_item` method parameter `create_item` removed, as it was no longer used

## [0.5.0] - 2023-12-01

### Added
Expand Down Expand Up @@ -97,7 +107,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Modified Item IDs to include product discriminator ([#7](https://github.com/stactools-packages/sentinel2/pull/7))
- Upgrade to stactools 0.2.1.a2 (supporting PySTAC 1.0.0)

<!-- [Unreleased]: <https://github.com/stactools-packages/sentinel2/compare/v0.4.2..main> -->
[Unreleased]: <https://github.com/stactools-packages/sentinel2/compare/v0.4.2..main>
[0.5.0]: <https://github.com/stactools-packages/sentinel2/compare/v0.4.2..v0.5.0>
[0.4.2]: <https://github.com/stactools-packages/sentinel2/compare/v0.4.1..v0.4.2>
[0.4.1]: <https://github.com/stactools-packages/sentinel2/compare/v0.4.0..v0.4.1>
Expand Down
2 changes: 2 additions & 0 deletions scripts/create_expected.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python3

from pathlib import Path

from stactools.sentinel2 import stac
Expand Down
5 changes: 0 additions & 5 deletions src/stactools/sentinel2/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from typing import Optional

import click
from stactools.core.utils.antimeridian import Strategy
from stactools.sentinel2.constants import DEFAULT_TOLERANCE
from stactools.sentinel2.stac import create_item

Expand Down Expand Up @@ -55,15 +54,11 @@ def create_item_command(
with open(providers) as f:
additional_providers = json.load(f)

antimeridian_strategy = "split"
strategy = Strategy[antimeridian_strategy.upper()]

item = create_item(
granule_href=src,
additional_providers=additional_providers,
tolerance=tolerance,
asset_href_prefix=asset_href_prefix,
antimeridian_strategy=strategy,
)

item_path = os.path.join(dst, f"{item.id}.json")
Expand Down
16 changes: 4 additions & 12 deletions src/stactools/sentinel2/stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from shapely.validation import make_valid
from stactools.core.io import ReadHrefModifier
from stactools.core.projection import reproject_geom, transform_from_bbox
from stactools.core.utils.antimeridian import Strategy
from stactools.sentinel2.constants import (
ASSET_TO_TITLE,
BANDS_TO_ASSET_NAME,
Expand Down Expand Up @@ -82,7 +81,6 @@ class Metadata:
cloudiness_percentage: Optional[float]
extra_assets: dict[str, pystac.Asset]
geometry: dict[str, Any]
bbox: list[float]
datetime: datetime
platform: str
metadata_dict: dict[str, Any]
Expand All @@ -106,7 +104,6 @@ def create_item(
additional_providers: Optional[list[pystac.Provider]] = None,
read_href_modifier: Optional[ReadHrefModifier] = None,
asset_href_prefix: Optional[str] = None,
antimeridian_strategy: Strategy = Strategy.SPLIT,
) -> pystac.Item:
"""Create a STC Item from a Sentinel 2 granule.
Expand All @@ -120,9 +117,6 @@ def create_item(
This can be used to modify a HREF to make it readable, e.g. appending
an Azure SAS token or creating a signed URL.
asset_href_prefix: The URL prefix to apply to the asset hrefs
antimeridian_strategy (Antimeridian): Either split on -180 or
normalize geometries so all longitudes are either positive or
negative.
Returns:
pystac.Item: An item representing the Sentinel 2 scene
Expand All @@ -138,14 +132,14 @@ def create_item(
created = now_to_rfc3339_str()

# ensure that we have a valid geometry, fixing any antimeridian issues
geometry = shapely_mapping(
make_valid(shapely_shape(antimeridian.fix_shape(metadata.geometry)))
)
shapely_geometry = shapely_shape(antimeridian.fix_shape(metadata.geometry))
geometry = shapely_mapping(make_valid(shapely_geometry))
bbox = [round(v, COORD_ROUNDING) for v in antimeridian.bbox(geometry)]

item = pystac.Item(
id=metadata.scene_id,
geometry=geometry,
bbox=metadata.bbox,
bbox=bbox,
datetime=metadata.datetime,
properties={"created": created},
)
Expand Down Expand Up @@ -537,7 +531,6 @@ def metadata_from_safe_manifest(
scene_id=product_metadata.scene_id,
extra_assets=extra_assets,
geometry=product_metadata.geometry,
bbox=[round(v, COORD_ROUNDING) for v in product_metadata.bbox],
datetime=product_metadata.datetime,
platform=product_metadata.platform,
orbit_state=product_metadata.orbit_state,
Expand Down Expand Up @@ -624,7 +617,6 @@ def metadata_from_granule_metadata(
proj_bbox=granule_metadata.proj_bbox,
resolution_to_shape=granule_metadata.resolution_to_shape,
geometry=shapely_mapping(geometry),
bbox=geometry.bounds,
datetime=tileinfo_metadata.datetime,
platform=granule_metadata.platform,
image_media_type=pystac.MediaType.JPEG2000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"stac_version": "1.0.0",
"id": "S2A_T01LAC_20200717T221944_L1C",
"properties": {
"created": "2023-11-20T17:22:07.294960Z",
"created": "2023-12-13T15:10:35.662528Z",
"providers": [
{
"name": "ESA",
Expand Down Expand Up @@ -791,9 +791,9 @@
}
},
"bbox": [
-179.71667,
179.256949,
-16.351724,
180.0,
-179.70343,
-15.345454
],
"stac_extensions": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"stac_version": "1.0.0",
"id": "S2A_T01WCP_20230625T234624_L2A",
"properties": {
"created": "2023-11-20T17:22:06.726429Z",
"created": "2023-12-13T15:10:35.151115Z",
"providers": [
{
"name": "ESA",
Expand Down Expand Up @@ -1712,9 +1712,9 @@
}
},
"bbox": [
-179.0443,
178.474107,
65.67165,
180.0,
-178.96619,
66.7056
],
"stac_extensions": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"stac_version": "1.0.0",
"id": "S2A_T01WCP_20230625T234624_L2A",
"properties": {
"created": "2023-11-20T17:22:07.028165Z",
"created": "2023-12-13T15:10:35.432011Z",
"providers": [
{
"name": "ESA",
Expand Down Expand Up @@ -1710,9 +1710,9 @@
}
},
"bbox": [
-179.0443,
178.474107,
65.67165,
180.0,
-178.96619,
66.7056
],
"stac_extensions": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"stac_version": "1.0.0",
"id": "S2A_T01WCS_20230625T234624_L2A",
"properties": {
"created": "2023-11-20T17:22:07.138030Z",
"created": "2023-12-13T15:10:35.529969Z",
"providers": [
{
"name": "ESA",
Expand Down Expand Up @@ -1740,9 +1740,9 @@
}
},
"bbox": [
-179.93085,
179.0059,
68.372483,
180.0,
-179.197,
69.394461
],
"stac_extensions": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"stac_version": "1.0.0",
"id": "S2A_T01KAB_20230821T221944_L2A",
"properties": {
"created": "2023-11-20T17:22:06.799537Z",
"created": "2023-12-13T15:10:35.226345Z",
"providers": [
{
"name": "ESA",
Expand Down Expand Up @@ -1712,9 +1712,9 @@
}
},
"bbox": [
-179.72957,
179.23921,
-17.25485,
180.0,
-179.71545,
-16.247763
],
"stac_extensions": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"stac_version": "1.0.0",
"id": "S2A_OPER_MSI_L1C_TL_SGS__20181231T203637_A018414_T10SDG",
"properties": {
"created": "2023-11-20T17:22:07.346802Z",
"created": "2023-12-13T15:10:35.705354Z",
"providers": [
{
"name": "ESA",
Expand Down Expand Up @@ -721,10 +721,10 @@
}
},
"bbox": [
-123.77120008096219,
36.95538583284048,
-122.88892538947995,
37.94752813015373
-123.7712,
36.955386,
-122.888925,
37.947528
],
"stac_extensions": [
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"stac_version": "1.0.0",
"id": "S2A_OPER_MSI_L2A_TL_SGS__20181231T210250_A018414_T10SDG",
"properties": {
"created": "2023-11-20T17:22:07.092086Z",
"created": "2023-12-13T15:10:35.489434Z",
"providers": [
{
"name": "ESA",
Expand Down Expand Up @@ -1783,10 +1783,10 @@
}
},
"bbox": [
-123.77120008096219,
36.95538583284048,
-122.88892538947995,
37.94752813015373
-123.7712,
36.955386,
-122.888925,
37.947528
],
"stac_extensions": [
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"stac_version": "1.0.0",
"id": "S2A_OPER_MSI_L2A_TL_VGS1_20220401T110010_A035382_T34LBP",
"properties": {
"created": "2023-11-20T17:22:06.388489Z",
"created": "2023-12-13T15:10:34.067362Z",
"providers": [
{
"name": "ESA",
Expand Down Expand Up @@ -1783,10 +1783,10 @@
}
},
"bbox": [
18.837533655044183,
-10.048676709777588,
19.26487070909741,
-9.943916470908118
18.837534,
-10.048677,
19.264871,
-9.943916
],
"stac_extensions": [
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"stac_version": "1.0.0",
"id": "S2A_T34LBQ_20220401T090142_L2A",
"properties": {
"created": "2023-11-20T17:22:06.849436Z",
"created": "2023-12-13T15:10:35.272511Z",
"providers": [
{
"name": "ESA",
Expand Down Expand Up @@ -1796,10 +1796,10 @@
}
},
"bbox": [
18.837533655044183,
-10.048676709777588,
19.26487070909741,
-9.943916470908118
18.837534,
-10.048677,
19.264871,
-9.943916
],
"stac_extensions": [
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
Expand Down

0 comments on commit 3bf4923

Please sign in to comment.