Skip to content

Commit

Permalink
Merge branch 'main' into fork-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
pixalytics committed May 18, 2024
2 parents 71ecc68 + e89599d commit bacd004
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 37 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ci:
autoupdate_schedule: monthly
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks.git
rev: v4.5.0
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -25,7 +25,7 @@ repos:
- id: flake8

- repo: 'https://github.com/psf/black'
rev: 24.3.0
rev: 24.4.2
hooks:
- id: black

Expand Down
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

## 0.21.2 (2024-mm-dd)

- ENH: `to_str` and `to_band`: add a `as_list` argument defaulting to `True`. When set as False, return a str from `to_str` and a band from `to_band` ([#138](https://github.com/sertit/eoreader/issues/138)). Thanks @jsetty!
- FIX: Fix issue with geocoding with unzipped `Sentinel-3 OLCI` product ([#137](https://github.com/sertit/eoreader/issues/137))
- FIX: Fix iceye product when extent file (*.kml) not found ([#135](https://github.com/sertit/eoreader/pull/135))
- FIX: Add missing `pystac[validation]` in setup.py
- CI: Fix S3 endpoint management with `sertit==1.37.0`

## 0.21.1 (2024-04-03)

Expand Down
6 changes: 4 additions & 2 deletions CI/SCRIPTS/test_stac_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ def test_s2_l1c_e84():
"""Function testing the support of Sentinel-2 L1C constellation processed by E84 and linked via a STAC URL"""
with tempenv.TemporaryEnvironment(
{
"AWS_S3_ENDPOINT": "s3.us-west-2.amazonaws.com",
"AWS_SECRET_ACCESS_KEY": os.getenv("AWS_S3_AWS_SECRET_ACCESS_KEY"),
"AWS_ACCESS_KEY_ID": os.getenv("AWS_S3_AWS_ACCESS_KEY_ID"),
}
), s3.temp_s3(endpoint="s3.us-west-2.amazonaws.com", requester_pays=True):
), s3.temp_s3(requester_pays=True):
_test_core(
"https://earth-search.aws.element84.com/v1/collections/sentinel-2-l1c/items/S2B_29SLD_20231121_0_L1C",
Constellation.S2,
Expand All @@ -75,10 +76,11 @@ def test_l9_e84():
"""Function testing the support of Landsat-9 constellation processed by E84 and linked via a STAC URL"""
with tempenv.TemporaryEnvironment(
{
"AWS_S3_ENDPOINT": "s3.us-west-2.amazonaws.com",
"AWS_SECRET_ACCESS_KEY": os.getenv("AWS_S3_AWS_SECRET_ACCESS_KEY"),
"AWS_ACCESS_KEY_ID": os.getenv("AWS_S3_AWS_ACCESS_KEY_ID"),
}
), s3.temp_s3(endpoint="s3.us-west-2.amazonaws.com", requester_pays=True):
), s3.temp_s3(requester_pays=True):
_test_core(
"https://earth-search.aws.element84.com/v1/collections/landsat-c2-l2/items/LC09_L2SP_095022_20231119_02_T2",
Constellation.L9,
Expand Down
6 changes: 4 additions & 2 deletions CI/SCRIPTS_WEEKLY/test_stac_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ def test_s2_l1c_e84():
"""Function testing the support of Sentinel-2 L1C constellation processed by E84 and linked via a STAC URL"""
with tempenv.TemporaryEnvironment(
{
"AWS_S3_ENDPOINT": "s3.us-west-2.amazonaws.com",
"AWS_SECRET_ACCESS_KEY": os.getenv("AWS_S3_AWS_SECRET_ACCESS_KEY"),
"AWS_ACCESS_KEY_ID": os.getenv("AWS_S3_AWS_ACCESS_KEY_ID"),
}
), s3.temp_s3(endpoint="s3.us-west-2.amazonaws.com", requester_pays=True):
), s3.temp_s3(requester_pays=True):
_test_core(
"https://earth-search.aws.element84.com/v1/collections/sentinel-2-l1c/items/S2B_29SLD_20231121_0_L1C",
Constellation.S2,
Expand All @@ -93,10 +94,11 @@ def test_l9_e84():
"""Function testing the support of Landsat-9 constellation processed by E84 and linked via a STAC URL"""
with tempenv.TemporaryEnvironment(
{
"AWS_S3_ENDPOINT": "s3.us-west-2.amazonaws.com",
"AWS_SECRET_ACCESS_KEY": os.getenv("AWS_S3_AWS_SECRET_ACCESS_KEY"),
"AWS_ACCESS_KEY_ID": os.getenv("AWS_S3_AWS_ACCESS_KEY_ID"),
}
), s3.temp_s3(endpoint="s3.us-west-2.amazonaws.com", requester_pays=True):
), s3.temp_s3(requester_pays=True):
_test_core(
"https://earth-search.aws.element84.com/v1/collections/landsat-c2-l2/items/LC09_L2SP_095022_20231119_02_T2",
Constellation.L9,
Expand Down
9 changes: 5 additions & 4 deletions CI/scripts_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
from typing import Callable

import tempenv
from sertit import AnyPath, s3
from sertit.s3 import USE_S3_STORAGE
from sertit import AnyPath, s3, unistra
from sertit.types import AnyPathType
from sertit.unistra import (
UNISTRA_S3_ENPOINT,
Expand Down Expand Up @@ -44,7 +43,7 @@ def get_ci_db_dir() -> AnyPathType:
"""
if int(os.getenv(CI_EOREADER_S3, 0)):
# ON S3
s3.define_s3_client(default_endpoint=UNISTRA_S3_ENPOINT)
unistra.define_s3_client()
return AnyPath("s3://sertit-eoreader-ci")
else:
# ON DISK
Expand Down Expand Up @@ -98,7 +97,9 @@ def get_db_dir() -> AnyPathType:
Returns:
str: Database directory
"""
with tempenv.TemporaryEnvironment({USE_S3_STORAGE: os.getenv(CI_EOREADER_S3, "0")}):
with tempenv.TemporaryEnvironment(
{s3.USE_S3_STORAGE: os.getenv(CI_EOREADER_S3, "0")}
):
return get_geodatastore()


Expand Down
74 changes: 47 additions & 27 deletions eoreader/bands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,9 @@ def is_dem(dem: Any) -> bool:
return is_valid


def to_band(to_convert: Union[list, BandNames, str]) -> list:
def to_band(
to_convert: Union[list, BandNames, str], as_list: bool = True
) -> Union[list, BandNames]:
"""
Convert a string (or real value) to any alias, band or index.
Expand All @@ -414,11 +416,8 @@ def to_band(to_convert: Union[list, BandNames, str]) -> list:
list: converted values
"""
if not isinstance(to_convert, list):
to_convert = [to_convert]

band_list = []
for tc in to_convert:
def convert_to_band(tc) -> BandNames:
band_or_idx = None
# Try legit types
if isinstance(tc, str):
Expand Down Expand Up @@ -447,22 +446,35 @@ def to_band(to_convert: Union[list, BandNames, str]) -> list:

# Store it
if band_or_idx:
band_list.append(band_or_idx)
return band_or_idx
else:
if tc == "GREEN1":
from sertit import logs

logs.deprecation_warning(
"`GREEN1` is deprecated in favor of `GREEN_1`. `GREEN1` will be removed in a future release."
)
band_list.append(GREEN_1)
return GREEN1
else:
raise _ite(f"Unknown band or index: {tc}")

return band_list


def to_str(to_convert: Union[list, BandNames, str]) -> list:
if as_list:
band_list = []
if not isinstance(to_convert, list):
to_convert = [to_convert]
for tc in to_convert:
tc_band = convert_to_band(tc=tc)
band_list.append(tc_band)
return band_list
else:
if isinstance(to_convert, list):
raise _ite(f"Set as_list=True(default) for list arguments")
return convert_to_band(to_convert)


def to_str(
to_convert: Union[list, BandNames, str], as_list: bool = True
) -> Union[list, str]:
"""
Convert a string (or real value) to any alias, band or index.
Expand All @@ -479,19 +491,27 @@ def to_str(to_convert: Union[list, BandNames, str]) -> list:
Returns:
list: str bands
"""
if not isinstance(to_convert, list):
to_convert = [to_convert]

bands_str = []
for tc in to_convert:
if isinstance(tc, str):
band_str = tc
else:
try:
band_str = tc.name
except AttributeError:
band_str = tc.__name__

bands_str.append(band_str)

return bands_str
if as_list:
if not isinstance(to_convert, list):
to_convert = [to_convert]

bands_str = []
for tc in to_convert:
if isinstance(tc, str):
band_str = tc
else:
try:
band_str = tc.name
except AttributeError:
band_str = tc.__name__

bands_str.append(band_str)
return bands_str
else:
if isinstance(to_convert, list):
raise _ite(f"Set as_list=True(default) for list arguments")
try:
band_str = tc.name
except AttributeError:
band_str = tc.__name__
return band_str
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"validators",
"methodtools",
"dicttoxml",
"pystac[validation]",
],
classifiers=[
"Development Status :: 5 - Production/Stable",
Expand Down

0 comments on commit bacd004

Please sign in to comment.