Skip to content

Commit 3248929

Browse files
committed
Fix tests
1 parent d4f52cf commit 3248929

3 files changed

Lines changed: 53 additions & 9 deletions

File tree

ci/on_push/test_satellites.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ def core(prod_path, possible_bands, tmpdir, **kwargs):
498498

499499
test_optical_constellations_cases = [
500500
pytest.param("*S2*_MSI*_N7*", {}, id="s2_after_04_00"),
501-
pytest.param("*S2*_MSI*_N02*", {}, id="s2_before_04_00"),
501+
pytest.param("*S2*_MSI*_N0209*", {}, id="s2_before_04_00"),
502502
pytest.param("*SENTINEL2*", {}, id="s2_theia"),
503503
pytest.param("*S2A_39KZU*", {}, id="s2_cloud"),
504504
pytest.param("*S3*_OL_1_*", {}, id="s3_olci"),
@@ -599,6 +599,6 @@ def test_invalid():
599599

600600

601601
@s3_env
602-
def test_s2_before_04_00(eoreader_tests_path):
602+
def test_s2_after_04_00(eoreader_tests_path):
603603
"""Function testing the support of Sentinel-2 constellation"""
604-
_test_core_optical("*S2*_MSI*_N0209*", eoreader_tests_path.tmpdir)
604+
_test_core_optical("*S2*_MSI*_N7*", eoreader_tests_path.tmpdir)

ci/scripts_utils.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,25 +200,32 @@ def decorator(function):
200200
@wraps(function)
201201
def s3_env_wrapper(*args, **kwargs):
202202
with rasterio.Env(
203-
# Set to TRUE or EMPTY_DIR to avoid listing all files in the directory once a single file is opened (this is highly recommended).
204-
GDAL_DISABLE_READDIR_ON_OPEN=True,
205-
# # Size of the default block cache, can be set in byte, MB, or as a percentage of available main, memory.
206-
# GDAL_CACHEMAX=gdal_cachemax_bytes, # => doesn't seem to improve anything, in fact slows down things a bit
207203
# Global cache size for downloads in bytes, defaults to 16 MB.
208204
CPL_VSIL_CURL_CACHE_SIZE=mo_to_bytes(200),
205+
#
209206
# Enable / disable per-file caching by setting to TRUE or FALSE.
210207
VSI_CACHE=True,
208+
#
211209
# Per-file cache size in bytes
212210
VSI_CACHE_SIZE=mo_to_bytes(5),
211+
#
213212
# When set to YES, this attempts to download multiple range requests in parallel, reusing the same TCP connection
214213
GDAL_HTTP_MULTIPLEX=True,
214+
#
215215
# Gives the number of initial bytes GDAL should read when opening a file and inspecting its metadata.
216216
GDAL_INGESTED_BYTES_AT_OPEN=ko_to_bytes(32),
217217
GDAL_HTTP_VERSION=2,
218+
#
218219
# Tells GDAL to merge consecutive range GET requests.
219220
GDAL_HTTP_MERGE_CONSECUTIVE_RANGES="YES",
221+
#
222+
# -- useless by experience --
223+
# Size of the default block cache, can be set in byte, MB, or as a percentage of available main, memory.
224+
# GDAL_CACHEMAX=gdal_cachemax_bytes, # => doesn't seem to improve anything, in fact slows down things a bit
220225
# Number of threads GDAL can use for block reads and (de)compression, set to ALL_CPUS to use all available cores.
221-
# GDAL_NUM_THREADS="ALL_CPUS", # => doesn't seem to improve anything, in fact slows down things
226+
# GDAL_NUM_THREADS="ALL_CPUS", # => doesn't seem to improve anything, in fact slows down things
227+
# Set to TRUE or EMPTY_DIR to avoid listing all files in the directory once a single file is opened (this is highly recommended).
228+
# GDAL_DISABLE_READDIR_ON_OPEN=True, # => seems to have drawbacks especially for s2
222229
):
223230
return unistra.s3_env(
224231
function(*args, **kwargs), use_s3_env_var=CI_EOREADER_S3

eoreader/utils.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,44 @@
5353
DEFAULT_NOF_BANDS_IN_CHUNKS = 1
5454
UINT16_NODATA = rasters.UINT16_NODATA
5555

56-
read_bit_array = rasters.read_bit_array
56+
57+
# Workaround for now, remove this asap
58+
def read_bit_array(
59+
bit_mask: Union[xr.DataArray, np.ndarray], bit_id: Union[list, int]
60+
) -> Union[np.ndarray, list]:
61+
"""
62+
Read 8 bit arrays as a succession of binary masks.
63+
64+
Forces array to :code:`np.uint8`.
65+
66+
See :py:func:`rasters.read_bit_array`.
67+
68+
Args:
69+
bit_mask (np.ndarray): Bit array to read
70+
bit_id (int): Bit ID of the slice to be read
71+
Example: read the bit 0 of the mask as a cloud mask (Theia)
72+
73+
Returns:
74+
Union[np.ndarray, list]: Binary mask or list of binary masks if a list of bit_id is given
75+
"""
76+
if misc.compare_version("sertit", "1.47.0", ">="):
77+
return rasters.read_bit_array(bit_mask, bit_id)
78+
else:
79+
# Suppress nan nodata and convert back to original dtype if known
80+
81+
if isinstance(bit_mask, np.ndarray):
82+
bit_mask = np.nan_to_num(bit_mask)
83+
elif isinstance(bit_mask, xr.DataArray):
84+
orig_dtype = bit_mask.encoding.get("dtype")
85+
bit_mask = bit_mask.fillna(0).data
86+
if orig_dtype is not None and bit_mask.dtype != orig_dtype:
87+
bit_mask = bit_mask.astype(orig_dtype)
88+
89+
else:
90+
bit_mask = bit_mask.fillna(0)
91+
from sertit import rasters_rio
92+
93+
return rasters_rio.read_bit_array(bit_mask, bit_id)
5794

5895

5996
def get_src_dir() -> AnyPathType:

0 commit comments

Comments
 (0)