Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ViewExtension handles NaN values for viewing_angles correctly, release prep for 0.6.2 #156

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ 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.

## [0.6.2] - 2024-01-08

### Fixed

- ViewExtension handles NaN values for viewing_angles correctly.

## [0.6.1] - 2024-01-04

### Fixed
Expand Down Expand Up @@ -119,6 +125,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Upgrade to stactools 0.2.1.a2 (supporting PySTAC 1.0.0)

<!-- [Unreleased]: <https://github.com/stactools-packages/sentinel2/compare/v0.4.2..main> -->
[0.6.2]: <https://github.com/stactools-packages/sentinel2/compare/v0.6.1..v0.6.2>
[0.6.1]: <https://github.com/stactools-packages/sentinel2/compare/v0.6.0..v0.6.1>
[0.6.0]: <https://github.com/stactools-packages/sentinel2/compare/v0.5.0..v0.6.0>
[0.5.0]: <https://github.com/stactools-packages/sentinel2/compare/v0.4.2..v0.5.0>
Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@ build-backend = "setuptools.build_meta"
[tool.ruff]
line-length = 88
select = ["E", "F", "I"]

# pyproject.toml
[tool.pytest.ini_options]
filterwarnings = [
"error",
"ignore::antimeridian.FixWindingWarning",
]
1 change: 1 addition & 0 deletions scripts/create_expected.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"S2A_MSIL2A_20190212T192651_N0212_R013_T07HFE_20201007T160857",
"S2A_MSIL1C_20210908T042701_N0301_R133_T46RER_20210908T070248",
"S2B_MSIL2A_20191228T210519_N0212_R071_T01CCV_20201003T104658",
"S2A_OPER_MSI_L2A_TL_VGS1_20220401T110010_A035382_T34LBQ-no-tileDataGeometry",
]

root = Path(__file__).parents[1]
Expand Down
2 changes: 1 addition & 1 deletion src/stactools/sentinel2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ def register_plugin(registry):
registry.register_subcommand(commands.create_sentinel2_command)


__version__ = "0.6.1"
__version__ = "0.6.2"
22 changes: 20 additions & 2 deletions src/stactools/sentinel2/stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from pystac.extensions.projection import ProjectionExtension
from pystac.extensions.raster import DataType, RasterBand, RasterExtension
from pystac.extensions.sat import OrbitState, SatExtension
from pystac.extensions.view import SCHEMA_URI as VIEW_EXT_URI
from pystac.extensions.view import ViewExtension
from pystac.utils import now_to_rfc3339_str
from shapely.geometry import mapping as shapely_mapping
Expand Down Expand Up @@ -196,8 +197,14 @@ def create_item(

# View Extension
view = ViewExtension.ext(item, add_if_missing=True)
view.azimuth = mean([v.azimuth for v in metadata.viewing_angles.values()])
view.incidence_angle = mean([v.zenith for v in metadata.viewing_angles.values()])

if all(not math.isnan(v.azimuth) for v in metadata.viewing_angles.values()):
view.azimuth = mean([v.azimuth for v in metadata.viewing_angles.values()])

if all(not math.isnan(v.zenith) for v in metadata.viewing_angles.values()):
view.incidence_angle = mean(
[v.zenith for v in metadata.viewing_angles.values()]
)

# both sun_azimuth and sun_zenith can be NaN, so don't set
# when that is the case
Expand All @@ -207,6 +214,17 @@ def create_item(
if (msz := metadata.sun_zenith) and not math.isnan(msz):
view.sun_elevation = 90 - msz

if all(
x is None
for x in [
view.azimuth,
view.incidence_angle,
view.sun_azimuth,
view.sun_elevation,
]
):
item.stac_extensions.remove(VIEW_EXT_URI)

# Sentinel-2 Extension
item.stac_extensions.append(SENTINEL2_EXTENSION_SCHEMA)
item.properties.update(metadata.metadata_dict)
Expand Down
Loading