Skip to content

Commit ba88b9f

Browse files
committed
Big internal refactoring + speeding up the every day CI + fix issues with STAC products
1 parent 031b84c commit ba88b9f

30 files changed

+1979
-958
lines changed

.gitlab-ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pytest_end_to_end:
102102
- pip install pytest coverage pytest-cov pylint
103103
- pip install -e .
104104
script:
105-
- python -m pytest -v --durations=0 --cov-report term --cov-report html:${CI_PROJECT_DIR}/cov_e2e.html --cov=eoreader --cov-config=.coveragerc CI/SCRIPTS_WEEKLY/test_all_sat_end_to_end_on_disk.py --log-cli-level DEBUG --capture=tee-sys
105+
- python -m pytest -v --durations=0 --cov-report term --cov-report html:${CI_PROJECT_DIR}/cov_e2e.html --cov=eoreader --cov-config=.coveragerc CI/SCRIPTS_WEEKLY --log-cli-level DEBUG --capture=tee-sys
106106
artifacts:
107107
paths:
108108
- ${CI_PROJECT_DIR}/cov_e2e.html

CHANGES.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
- CI: Enabling pre-commit.ci and dependabot bots
2121
- CI: Update pre-commit hooks
2222
- CI: Revamping `test_satellites`
23-
- CI: Some refactoring
23+
- CI: Some refactoring and speed-ups
2424

2525
## 0.20.4 (2023-09-26)
2626

CI/SCRIPTS/test_bands.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
""" Script testing EOReader bands """
2-
from CI.SCRIPTS.scripts_utils import READER, opt_path
2+
from CI.scripts_utils import READER, opt_path, s3_env
33
from eoreader.bands import BLUE, YELLOW
44

55

6+
@s3_env
67
def test_bands_s3_olci():
78
"""Test EOReader bands for Sentinel-3 OLCI"""
89
prod_path = opt_path().joinpath(
@@ -14,6 +15,7 @@ def test_bands_s3_olci():
1415
assert list(set(prod.to_band(["Oa07", YELLOW, "YELLOW"]))) == [YELLOW]
1516

1617

18+
@s3_env
1719
def test_bands_l8():
1820
"""Test EOReader bands for Landsat-8"""
1921
prod_path = opt_path().joinpath("LC08_L1GT_023030_20200518_20200527_01_T2")

CI/SCRIPTS/test_custom.py

+3-147
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,17 @@
22
import logging
33
import os
44

5-
import numpy as np
65
import pytest
76
from rasterio.windows import Window
87
from sertit import ci
98

9+
from CI.scripts_utils import READER, dask_env, get_db_dir, others_path, s3_env
1010
from eoreader import EOREADER_NAME
11-
from eoreader.bands import (
12-
BLUE,
13-
CA,
14-
CLOUDS,
15-
GREEN,
16-
HH,
17-
HILLSHADE,
18-
NDVI,
19-
NIR,
20-
RED,
21-
RH,
22-
SWIR_1,
23-
VV,
24-
VV_DSPK,
25-
YELLOW,
26-
)
11+
from eoreader.bands import BLUE, CA, GREEN, HILLSHADE, NDVI, NIR, RED, SWIR_1
2712
from eoreader.env_vars import DEM_PATH
28-
from eoreader.exceptions import InvalidProductError, InvalidTypeError
13+
from eoreader.exceptions import InvalidTypeError
2914
from eoreader.products import SensorType
3015

31-
from .scripts_utils import READER, dask_env, get_db_dir, others_path, s3_env
32-
3316
LOGGER = logging.getLogger(EOREADER_NAME)
3417

3518
ci.reduce_verbosity()
@@ -156,133 +139,6 @@ def test_custom_optical():
156139
)
157140

158141

159-
def test_custom_sar():
160-
# SAR
161-
sar_stack = others_path() / "20210827T162210_ICEYE_SC_GRD_STK.tif"
162-
163-
# Load with all info
164-
prod_sar = READER.open(
165-
sar_stack,
166-
custom=True,
167-
sensor_type=SensorType.SAR,
168-
name="20210827T162210_ICEYE_SC_GRD",
169-
datetime="20210827T162210",
170-
constellation="ICEYE",
171-
instrument="SAR X-band",
172-
pixel_size=6.0,
173-
product_type="GRD",
174-
band_map={VV: 1, VV_DSPK: 2},
175-
)
176-
LOGGER.info(prod_sar)
177-
extent_sar = prod_sar.extent()
178-
footprint_sar = prod_sar.footprint()
179-
crs_sar = prod_sar.crs()
180-
stack_sar = prod_sar.stack([VV, VV_DSPK], prod_sar.pixel_size * 10)
181-
182-
# Errors
183-
with pytest.raises(AssertionError):
184-
prod_sar.load(NDVI)
185-
186-
# Check attributes
187-
assert stack_sar.attrs["long_name"] == "VV VV_DSPK"
188-
assert stack_sar.attrs["constellation"] == "ICEYE"
189-
assert stack_sar.attrs["constellation_id"] == "ICEYE"
190-
assert stack_sar.attrs["product_type"] == "GRD"
191-
assert stack_sar.attrs["instrument"] == "SAR X-band"
192-
assert stack_sar.attrs["acquisition_date"] == "20210827T162210"
193-
assert stack_sar.attrs["condensed_name"] == "20210827T162210_ICEYE_GRD"
194-
assert stack_sar.attrs["product_path"] == str(sar_stack)
195-
196-
# MIX
197-
sar_stack = others_path() / "20210827T162210_ICEYE_SC_GRD_STK.tif"
198-
prod_wtf = READER.open(
199-
sar_stack,
200-
custom=True,
201-
sensor_type=SensorType.SAR,
202-
band_map={HH: 1, RH: 2},
203-
name=None,
204-
product_type=None,
205-
instrument=None,
206-
datetime=None,
207-
pixel_size=6.0,
208-
)
209-
LOGGER.info(prod_wtf)
210-
extent_wtf = prod_wtf.extent()
211-
footprint_wtf = prod_wtf.footprint()
212-
crs_wtf = prod_wtf.crs()
213-
stack_wtf = prod_wtf.stack([HH, RH], prod_wtf.pixel_size * 10)
214-
215-
ci.assert_geom_equal(extent_sar, extent_wtf)
216-
ci.assert_geom_equal(footprint_sar, footprint_wtf)
217-
assert crs_sar == crs_wtf
218-
assert prod_wtf.name is not None
219-
assert prod_wtf.product_type is not None
220-
assert prod_wtf.instrument is not None
221-
222-
np.testing.assert_array_equal(stack_sar.data, stack_wtf.data)
223-
224-
225-
def test_custom_wgs84():
226-
# WGS84
227-
wgs84_stack = others_path() / "SPOT6_WGS84.tif"
228-
prod_wgs84 = READER.open(
229-
wgs84_stack,
230-
custom=True,
231-
sensor_type=SensorType.OPTICAL,
232-
name="SPOT6_WGS84",
233-
datetime="20181218T090308",
234-
constellation="SPOT6",
235-
pixel_size=1.5 * 15,
236-
instrument="NAOMI",
237-
product_type="ORT",
238-
band_map={RED: 1, GREEN: 2, BLUE: 3, NIR: 4},
239-
)
240-
LOGGER.info(prod_wgs84)
241-
242-
# Check geometries -> assert projected
243-
with pytest.raises(InvalidProductError):
244-
prod_wgs84.extent() # noqa
245-
246-
with pytest.raises(InvalidProductError):
247-
prod_wgs84.footprint() # noqa
248-
249-
with pytest.raises(InvalidProductError):
250-
prod_wgs84.crs() # noqa
251-
252-
# Read mtd
253-
root, nsp = prod_wgs84.read_mtd()
254-
assert nsp == {}
255-
assert root.findtext("name") == "SPOT6_WGS84"
256-
assert root.findtext("datetime") == "2018-12-18T09:03:08"
257-
assert root.findtext("sensor_type") == "Optical"
258-
assert root.findtext("constellation") == "Spot-6"
259-
assert root.findtext("pixel_size") == str(1.5 * 15)
260-
assert root.findtext("product_type") == "ORT"
261-
assert root.findtext("band_map") == "{'BLUE': 3, 'GREEN': 2, 'RED': 1, 'NIR': 4}"
262-
assert root.findtext("sun_azimuth") == "None"
263-
assert root.findtext("sun_zenith") == "None"
264-
assert root.findtext("orbit_direction") == "None"
265-
assert root.findtext("cloud_cover") == "None"
266-
assert root.findtext("instrument") == "NAOMI"
267-
268-
# Band paths
269-
assert prod_wgs84.get_existing_bands() == [BLUE, GREEN, RED, NIR]
270-
assert prod_wgs84.get_default_band() == BLUE
271-
for key, ppath in prod_wgs84.get_existing_band_paths().items():
272-
assert key in [BLUE, GREEN, RED, NIR]
273-
assert str(ppath) == str(wgs84_stack)
274-
275-
# Load without a list and nothing
276-
with pytest.raises(InvalidProductError):
277-
prod_wgs84.load(BLUE, size=[3863, 1049])[BLUE] # noqa
278-
279-
# Try non-available clouds and bands
280-
assert len(prod_wgs84.load([])) == 0
281-
assert not prod_wgs84.has_bands(CLOUDS)
282-
with pytest.raises(AssertionError):
283-
prod_wgs84.load(CLOUDS, YELLOW)
284-
285-
286142
def test_custom_invalid():
287143
# Invalid tests
288144
opt_stack = others_path() / "20200310T030415_WV02_Ortho_BGRN_STK.tif"

CI/SCRIPTS/test_end_to_end.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import xarray as xr
1010
from sertit import AnyPath, ci, path
1111

12-
from CI.SCRIPTS.scripts_utils import (
12+
from CI.scripts_utils import (
1313
CI_EOREADER_S3,
1414
READER,
1515
dask_env,
@@ -153,7 +153,7 @@ def _test_core(
153153

154154
for pattern_path in pattern_paths:
155155
LOGGER.info(
156-
"%s on drive %s (CI_EOREADER_S3: %s)",
156+
f"%s on drive %s ({CI_EOREADER_S3}: %s)",
157157
pattern_path.name,
158158
pattern_path.drive,
159159
os.getenv(CI_EOREADER_S3),

CI/SCRIPTS/test_index.py

+4-34
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,9 @@
66
import numpy as np
77
from sertit import ci, rasters
88

9+
from CI.scripts_utils import READER, dask_env, get_ci_data_dir, opt_path, s3_env
910
from eoreader import EOREADER_NAME
10-
from eoreader.bands import (
11-
BAI,
12-
BAIM,
13-
BAIS2,
14-
EVI,
15-
NBR,
16-
NDMI,
17-
NDVI,
18-
SAVI,
19-
VARI,
20-
AWEInsh,
21-
AWEIsh,
22-
get_eoreader_indices,
23-
)
24-
25-
from .scripts_utils import READER, dask_env, get_ci_data_dir, opt_path, s3_env
11+
from eoreader.bands import BAI, NBR, NDVI
2612

2713
LOGGER = logging.getLogger(EOREADER_NAME)
2814

@@ -44,25 +30,9 @@ def test_index():
4430
with tempfile.TemporaryDirectory() as tmp_dir:
4531
# tmp_dir = os.path.join("/mnt", "ds2_db3", "CI", "eoreader", "DATA", "INDEX")
4632
prod.output = os.path.join(tmp_dir, prod.condensed_name)
33+
idx_list = [NDVI, NBR, BAI]
4734

48-
# Load every index
49-
spyndex_list = [
50-
NDVI,
51-
NDMI,
52-
NBR,
53-
BAI,
54-
AWEIsh,
55-
AWEInsh,
56-
BAIM,
57-
BAIS2,
58-
EVI,
59-
SAVI,
60-
VARI,
61-
]
62-
LOGGER.info(f"Load selected indices (EOReader's + {spyndex_list})")
63-
idx_list = [
64-
idx for idx in spyndex_list + get_eoreader_indices() if prod.has_band(idx)
65-
]
35+
LOGGER.info(f"Load selected indices (EOReader's + {idx_list})")
6636
idx = prod.load(idx_list, pixel_size=RES)
6737

6838
for idx_name, idx_arr in idx.items():

CI/SCRIPTS/test_others.py

+27-29
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@
1111
from rasterio.windows import Window
1212
from sertit import AnyPath, ci, path, unistra
1313

14+
from CI.scripts_utils import (
15+
READER,
16+
dask_env,
17+
get_db_dir,
18+
get_db_dir_on_disk,
19+
opt_path,
20+
others_path,
21+
s3_env,
22+
sar_path,
23+
)
1424
from eoreader import utils
1525
from eoreader.bands import (
1626
AFRI_1_6,
@@ -53,17 +63,6 @@
5363
from eoreader.products import SensorType
5464
from eoreader.reader import Constellation
5565

56-
from .scripts_utils import (
57-
READER,
58-
dask_env,
59-
get_db_dir,
60-
get_db_dir_on_disk,
61-
opt_path,
62-
others_path,
63-
s3_env,
64-
sar_path,
65-
)
66-
6766
ci.reduce_verbosity()
6867

6968

@@ -294,7 +293,6 @@ def test_dems_https():
294293
xr.testing.assert_equal(dem_local[DEM], dem_remote[DEM])
295294

296295

297-
@s3_env
298296
def test_dems_S3():
299297
# Get paths
300298
prod_path = opt_path().joinpath("LC08_L1GT_023030_20200518_20200527_01_T2")
@@ -311,24 +309,24 @@ def test_dems_S3():
311309
local_path = str(get_db_dir_on_disk().joinpath(*dem_sub_dir_path))
312310

313311
# ON S3
314-
unistra.define_s3_client()
315-
s3_path = str(AnyPath("s3://sertit-geodatastore").joinpath(*dem_sub_dir_path))
316-
317-
# Loading same DEM from two different sources (one hosted locally and the other hosted on S3 compatible storage)
318-
with tempenv.TemporaryEnvironment({DEM_PATH: local_path}): # Local DEM
319-
dem_local = prod.load(
320-
[DEM],
321-
pixel_size=30,
322-
window=Window(col_off=0, row_off=0, width=100, height=100),
323-
) # Loading same DEM from two different sources (one hosted locally and the other hosted on S3 compatible storage)
324-
with tempenv.TemporaryEnvironment({DEM_PATH: s3_path}): # S3 DEM
325-
dem_s3 = prod.load(
326-
[DEM],
327-
pixel_size=30,
328-
window=Window(col_off=0, row_off=0, width=100, height=100),
329-
)
312+
with unistra.unistra_s3():
313+
s3_path = str(AnyPath("s3://sertit-geodatastore").joinpath(*dem_sub_dir_path))
314+
315+
# Loading same DEM from two different sources (one hosted locally and the other hosted on S3 compatible storage)
316+
with tempenv.TemporaryEnvironment({DEM_PATH: local_path}): # Local DEM
317+
dem_local = prod.load(
318+
[DEM],
319+
pixel_size=30,
320+
window=Window(col_off=0, row_off=0, width=100, height=100),
321+
) # Loading same DEM from two different sources (one hosted locally and the other hosted on S3 compatible storage)
322+
with tempenv.TemporaryEnvironment({DEM_PATH: s3_path}): # S3 DEM
323+
dem_s3 = prod.load(
324+
[DEM],
325+
pixel_size=30,
326+
window=Window(col_off=0, row_off=0, width=100, height=100),
327+
)
330328

331-
xr.testing.assert_equal(dem_local[DEM], dem_s3[DEM])
329+
xr.testing.assert_equal(dem_local[DEM], dem_s3[DEM])
332330

333331

334332
def test_bands():

0 commit comments

Comments
 (0)