Skip to content

Commit

Permalink
LINT: use new ruff guidelines
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-braun committed Dec 16, 2024
1 parent bf9b8f1 commit f75c10d
Show file tree
Hide file tree
Showing 79 changed files with 496 additions and 568 deletions.
2 changes: 1 addition & 1 deletion CI/SCRIPTS/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
""" Tests modules """
"""Tests modules"""
2 changes: 1 addition & 1 deletion CI/SCRIPTS/test_bands.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Script testing EOReader bands """
"""Script testing EOReader bands"""

from CI.scripts_utils import READER, opt_path, reduce_verbosity, s3_env
from eoreader.bands import BLUE, YELLOW
Expand Down
2 changes: 1 addition & 1 deletion CI/SCRIPTS/test_custom.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Testing custom stacks. """
"""Testing custom stacks."""

import logging
import os
Expand Down
2 changes: 1 addition & 1 deletion CI/SCRIPTS/test_end_to_end.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Script testing EOReader satellites in an end-to-end manner. """
"""Script testing EOReader satellites in an end-to-end manner."""

import logging
import os
Expand Down
2 changes: 1 addition & 1 deletion CI/SCRIPTS/test_index.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Script testing EOReader index """
"""Script testing EOReader index"""

import logging
import os
Expand Down
6 changes: 3 additions & 3 deletions CI/SCRIPTS/test_others.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Other tests. """
"""Other tests."""

import os
import sys
Expand Down Expand Up @@ -347,7 +347,7 @@ def test_bands():
sb = SarBandMap()
sb.map_bands(map_dic)

for key, val in map_dic.items():
for key, _ in map_dic.items():
assert key in sb._band_map
assert sb._band_map[key].id == map_dic[key]

Expand All @@ -369,7 +369,7 @@ def test_bands():
ob = SpectralBandMap()
ob.map_bands(map_dic)

for key, val in map_dic.items():
for key, _ in map_dic.items():
assert key in ob._band_map
assert ob._band_map[key].id == map_dic[key]

Expand Down
11 changes: 4 additions & 7 deletions CI/SCRIPTS/test_satellites.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
""" Script testing EOReader satellites in a push routine """
"""Script testing EOReader satellites in a push routine"""

import contextlib
import logging
import os
import sys
Expand Down Expand Up @@ -442,16 +443,12 @@ def _test_core(
check_geometry(prod, "footprint", tmp_dir)

if hasattr(prod, "wgs84_extent"):
try:
with contextlib.suppress(NotImplementedError):
prod.wgs84_extent()
except NotImplementedError:
pass

if hasattr(prod, "_fallback_wgs84_extent"):
try:
with contextlib.suppress(NotImplementedError):
prod._fallback_wgs84_extent()
except NotImplementedError:
pass

# Get the bands we want to stack / load
stack_bands = [band for band in possible_bands if prod.has_band(band)]
Expand Down
36 changes: 21 additions & 15 deletions CI/SCRIPTS/test_stac_items.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Script testing EOReader ingestion of STAC Items """
"""Script testing EOReader ingestion of STAC Items"""

import logging
import os
Expand Down Expand Up @@ -50,13 +50,16 @@ def _test_core(

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(requester_pays=True):
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(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 @@ -73,13 +76,16 @@ def test_s2_l2a_e84():

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(requester_pays=True):
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(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
2 changes: 1 addition & 1 deletion CI/SCRIPTS_WEEKLY/test_all_sat_end_to_end_on_disk.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Script testing EOReader satellites in a push routine """
"""Script testing EOReader satellites in a push routine"""

import logging
import os
Expand Down
2 changes: 1 addition & 1 deletion CI/SCRIPTS_WEEKLY/test_broken_s2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Testing broken S2 products weekly. """
"""Testing broken S2 products weekly."""

import logging

Expand Down
2 changes: 1 addition & 1 deletion CI/SCRIPTS_WEEKLY/test_custom.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Testing custom stacks weekly """
"""Testing custom stacks weekly"""

import logging

Expand Down
2 changes: 1 addition & 1 deletion CI/SCRIPTS_WEEKLY/test_index.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Script testing EOReader index weekly."""
"""Script testing EOReader index weekly."""

import logging
import os
Expand Down
2 changes: 1 addition & 1 deletion CI/SCRIPTS_WEEKLY/test_satellites.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Script testing EOReader satellites weekly """
"""Script testing EOReader satellites weekly"""

import logging
import os
Expand Down
44 changes: 22 additions & 22 deletions CI/SCRIPTS_WEEKLY/test_stac_creation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
""" Script testing the creaction of STAC Items from EOReader Products. """
"""Script testing the creaction of STAC Items from EOReader Products."""

import contextlib
import logging
import os
import sys
Expand Down Expand Up @@ -149,10 +150,7 @@ def _test_core(
list(prod.extent().to_crs(WGS84).bounds.values[0]),
"item.bbox",
)
if prod.is_ortho:
geometry_fct = prod.footprint
else:
geometry_fct = prod.extent
geometry_fct = prod.footprint if prod.is_ortho else prod.extent

compare(
item.geometry,
Expand Down Expand Up @@ -249,14 +247,12 @@ def _test_core(

if prod.sensor_type == SensorType.OPTICAL:
prod: OpticalProduct
try:
with contextlib.suppress(KeyError):
compare(
item.properties[EO_CC],
prod.get_cloud_cover(),
f"{EO_CC} (item.properties)",
)
except KeyError:
pass

sun_az, sun_zen = prod.get_mean_sun_angles()
sun_el = 90 - sun_zen
Expand Down Expand Up @@ -302,17 +298,22 @@ def _test_core(
existing_bands = prod.get_existing_bands()
nof_assets = len(existing_bands)

if is_not_s2:
if NARROW_NIR in existing_bands:
nof_assets -= 1 # remove NARROW NIR, except for S2
if is_not_s2 and prod.constellation != Constellation.S3_OLCI:
if VRE_1 in existing_bands and VRE_2 in existing_bands:
nof_assets -= 1 # remove one VRE, except for S2 and S3 OLCI
if VRE_1 in existing_bands and VRE_3 in existing_bands:
nof_assets -= 1 # remove one VRE, except for S2 and S3 OLCI
if prod.instrument == LandsatInstrument.TM:
if TIR_1 in existing_bands and TIR_2 in existing_bands:
nof_assets -= 1 # remove one TIR for TM data
if is_not_s2 and NARROW_NIR in existing_bands:
nof_assets -= 1 # remove NARROW NIR, except for S2
elif (
is_not_s2
and prod.constellation != Constellation.S3_OLCI
and VRE_1 in existing_bands
and VRE_2 in existing_bands
or VRE_3 in existing_bands
):
nof_assets -= 1 # remove one VRE, except for S2 and S3 OLCI
if (
prod.instrument == LandsatInstrument.TM
and TIR_1 in existing_bands
and TIR_2 in existing_bands
):
nof_assets -= 1 # remove one TIR for TM data
else:
prod: SarProduct
existing_bands = prod._get_raw_bands()
Expand Down Expand Up @@ -343,14 +344,13 @@ def _test_core(

eo_band = band.extra_fields[EO_BANDS][0]
compare(eo_band["name"], prod_band.name, f"{EO_BANDS} name")
try:
with contextlib.suppress(KeyError):
compare(
eo_band["common_name"],
prod_band.common_name.value,
f"{EO_BANDS} common_name",
)
except KeyError:
pass

compare(
eo_band["description"],
prod_band.description,
Expand Down
36 changes: 21 additions & 15 deletions CI/SCRIPTS_WEEKLY/test_stac_items.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Script testing EOReader ingestion of STAC Items """
"""Script testing EOReader ingestion of STAC Items"""

import logging
import os
Expand Down Expand Up @@ -68,13 +68,16 @@ def _test_core(

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(requester_pays=True):
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(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 @@ -91,13 +94,16 @@ def test_s2_l2a_e84():

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(requester_pays=True):
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(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
2 changes: 1 addition & 1 deletion CI/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
""" Tests modules """
"""Tests modules"""
8 changes: 4 additions & 4 deletions CI/scripts_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Utils module for scripts """
"""Utils module for scripts"""

import logging
import os
Expand Down Expand Up @@ -47,11 +47,11 @@ def get_ci_db_dir() -> AnyPathType:
try:
# CI
return AnyPath(get_db3_path(), "CI", "eoreader")
except NotADirectoryError:
except NotADirectoryError as exc:
# Windows
db_path = AnyPath(r"//ds2/database03/CI/eoreader")
if not db_path.is_dir():
raise NotADirectoryError("Impossible to find get_ci_db_dir")
raise NotADirectoryError("Impossible to find get_ci_db_dir") from exc

return db_path

Expand Down Expand Up @@ -148,7 +148,7 @@ def broken_s2_path():


def s3_env(*args, **kwargs):
return unistra.s3_env(use_s3_env_var=CI_EOREADER_S3, *args, **kwargs)
return unistra.s3_env(*args, use_s3_env_var=CI_EOREADER_S3, **kwargs)


def compare(to_be_checked, ref, topic):
Expand Down
1 change: 1 addition & 0 deletions eoreader/bands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
>>> NDVI
<function NDVI at 0x00000261F6FFA950>
"""

# flake8: noqa
from eoreader.bands.bands import Band, BandMap

Expand Down
7 changes: 1 addition & 6 deletions eoreader/bands/band_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,7 @@ def corresponding_despeckle(cls, band: "SarBandNames"):
Returns:
SarBandNames: Despeckled band
"""
if cls.is_despeckle(band):
dspk = band
else:
dspk = cls.from_value(f"{band.name}_DSPK")

return dspk
return band if cls.is_despeckle(band) else cls.from_value(f"{band.name}_DSPK")

@classmethod
def corresponding_speckle(cls, band: "SarBandNames"):
Expand Down
4 changes: 2 additions & 2 deletions eoreader/bands/bands.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2024, SERTIT-ICube - France, https://sertit.unistra.fr/
# This file is part of eoreader project
# https://github.com/sertit/eoreader
Expand All @@ -14,7 +13,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
""" Bands """
"""Bands"""

# Lines too long
# pylint: disable=C0301
import copy
Expand Down
Loading

0 comments on commit f75c10d

Please sign in to comment.