Skip to content

Commit cbb3805

Browse files
committed
OPTIM: Only loop on useful constellations in Reader
1 parent 056fc8e commit cbb3805

3 files changed

Lines changed: 95 additions & 25 deletions

File tree

‎CHANGES.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- OPTIM: Don't use `rasters.read` when computing the default extent, use the `rasterio`'s dataset directly to ensure nothing is loaded into memory even with cloud-stored data
77
- OPTIM: Save in memory the files path listed in the Reader to avoid relisting them for every constellation check
88
- OPTIM: Don't compute several times the UTM bands when loading masks if the band is already available
9+
- OPTIM: Only loop on useful constellations in Reader (and add several template constellations such as Landsat)
910
- CI: Remove duplicated test
1011
- CI: Several speed-ups
1112

‎eoreader/products/optical/landsat_product.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,11 @@ def _get_path(self, band_id: str) -> AnyPathType:
257257

258258
return prod_path
259259

260+
def _get_constellation(self) -> Constellation:
261+
"""Getter of the constellation"""
262+
landsat_id = self.split_name[0][-1]
263+
return getattr(Constellation, f"L{landsat_id}")
264+
260265
def _set_pixel_size(self) -> None:
261266
"""
262267
Set product default pixel size (in meters)

‎eoreader/reader.py‎

Lines changed: 89 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,15 @@ class Constellation(ListEnum):
256256
Not a real constellation, only used for regex.
257257
"""
258258

259+
LANDSAT = "Landsat"
260+
"""Landsat (not a real constellation, but used for template for Landsat products)"""
261+
259262
SPOT45 = "Spot-4/5"
260263
"""SPOT-4/5 (not a real constellation, but used as a template for SPOT4/5 products)"""
261264

265+
SPOT67 = "Spot-6/7"
266+
"""SPOT-6/7 (not a real constellation, but used as a template for SPOT6/7 products)"""
267+
262268
VANTOR = "Vantor"
263269
"""Vantor (not a real constellation, but used as a template for every Vantor products)"""
264270

@@ -280,9 +286,11 @@ def get_real_constellations(cls):
280286
cls.S2_SIN,
281287
cls.S1_RTC_ASF,
282288
cls.S1_RTC_MPC,
289+
cls.LANDSAT,
283290
cls.VANTOR,
284291
cls.MAXAR,
285292
cls.SPOT45,
293+
cls.SPOT67,
286294
cls.CUSTOM,
287295
cls.SATELLOGIC,
288296
]
@@ -306,14 +314,14 @@ def is_real_constellation(cls, const: Constellation):
306314
_ALEPH1_REGEX = r"\d{8}_\d{6}_\w{3,}_L(0|1[ABCD])(_SR|)(_MS|)_\d{6,}"
307315

308316
CONSTELLATION_REGEX = {
309-
Constellation.VENUS: r"VENUS-XS_\d{8}-\d{6}-\d{3}_L2A_[A-Z0-9_-]+",
310317
Constellation.S1: r"S1[ABCD]_(IW|EW|SM|WV|S\d)_(RAW|SLC|GRD|OCN)[FHM_]_[0-2]S[SD][HV]_\d{8}T\d{6}_\d{8}T\d{6}_\d{6}_.{11}(_COG|)",
311318
Constellation.S2: r"S2[ABCD]_MSIL(1C|2A)_\d{8}T\d{6}_N\d{4}_R\d{3}_T\d{2}\w{3}_\d{8}T\d{6}",
312319
# Element84 : S2A_31UDQ_20230714_0_L2A, Sinergise: 0 or 1...
313320
Constellation.S2_E84: r"S2[ABCD]_\d{2}\w{3}_\d{8}_\d_L(1C|2A)",
314321
Constellation.S2_THEIA: r"SENTINEL2[ABCD]_\d{8}-\d{6}-\d{3}_L(2A|1C)_T\d{2}\w{3}_[CDH](_V\d-\d|)",
315322
Constellation.S3_OLCI: r"S3[ABCD]_OL_[012]_\w{6}_\d{8}T\d{6}_\d{8}T\d{6}_\d{8}T\d{6}_\w{17}_\w{3}_[OFDR]_(NR|ST|NT)_\d{3}",
316323
Constellation.S3_SLSTR: r"S3[ABCD]_SL_[012]_\w{6}_\d{8}T\d{6}_\d{8}T\d{6}_\d{8}T\d{6}_\w{17}_\w{3}_[OFDR]_(NR|ST|NT)_\d{3}",
324+
Constellation.LANDSAT: r"L[OTCEM]0[1-9]_(L1(GT|TP|GS)|L2(SP|SR))_\d{6}_\d{8}_\d{8}_\d{2}_(RT|T1|T2)",
317325
Constellation.L9: r"L[OTC]09_(L1(GT|TP)|L2(SP|SR))_\d{6}_\d{8}_\d{8}_\d{2}_(RT|T1|T2)",
318326
Constellation.L8: r"L[OTC]08_(L1(GT|TP)|L2(SP|SR))_\d{6}_\d{8}_\d{8}_\d{2}_(RT|T1|T2)",
319327
Constellation.L7: r"LE07_(L1(GT|TP|GS)|L2(SP|SR))_\d{6}_\d{8}_\d{8}_\d{2}_(RT|T1|T2)",
@@ -342,6 +350,7 @@ def is_real_constellation(cls, const: Constellation):
342350
r"(_(HH|VV|VH|HV)){1,4}_S(LC|GX|GF|CN|CW|CF|CS|SG|PG)(_\d{6}_\d{4}_\d{8}|)",
343351
Constellation.PLD: r"IMG_PHR1[AB]_(P|MS|PMS|MS-N|MS-X|PMS-N|PMS-X)_\d{3}",
344352
Constellation.PNEO: r"IMG_\d+_PNEO\d_(PMS-FS|MS-FS|PMS|MS|P)",
353+
Constellation.SPOT67: r"IMG_SPOT[67]_(P|MS|PMS|MS-N|MS-X|PMS-N|PMS-X)_\d{3}_\w",
345354
Constellation.SPOT7: r"IMG_SPOT7_(P|MS|PMS|MS-N|MS-X|PMS-N|PMS-X)_\d{3}_\w",
346355
Constellation.SPOT6: r"IMG_SPOT6_(P|MS|PMS|MS-N|MS-X|PMS-N|PMS-X)_\d{3}_\w",
347356
Constellation.SPOT45: r"SPVIEW_.+",
@@ -372,6 +381,7 @@ def is_real_constellation(cls, const: Constellation):
372381
Constellation.S1_RTC_ASF: r"S1[ABCD]_(IW|EW|SM|WV|S\d)_\d{8}T\d{6}_[DS][VH][PRO]_RTC\d{2}_.*",
373382
Constellation.ALEPH1: _ALEPH1_REGEX,
374383
Constellation.SATELLOGIC: _ALEPH1_REGEX,
384+
Constellation.VENUS: r"VENUS-XS_\d{8}-\d{6}-\d{3}_L2A_[A-Z0-9_-]+",
375385
}
376386

377387
_VANTOR_MTD_REGEX = r"\d{2}\w{3}\d{8}-.*.TIL"
@@ -393,6 +403,7 @@ def is_real_constellation(cls, const: Constellation):
393403
Constellation.S2_THEIA: rf"{CONSTELLATION_REGEX[Constellation.S2_THEIA]}_MTD_ALL\.xml",
394404
Constellation.S3_OLCI: r"Oa\d{2}_radiance.nc",
395405
Constellation.S3_SLSTR: r"S\d_radiance_an.nc",
406+
Constellation.LANDSAT: rf"{CONSTELLATION_REGEX[Constellation.LANDSAT]}_MTL\.txt",
396407
Constellation.L9: rf"{CONSTELLATION_REGEX[Constellation.L9]}_MTL\.txt",
397408
Constellation.L8: rf"{CONSTELLATION_REGEX[Constellation.L8]}_MTL\.txt",
398409
Constellation.L7: rf"{CONSTELLATION_REGEX[Constellation.L7]}_MTL\.txt",
@@ -425,6 +436,7 @@ def is_real_constellation(cls, const: Constellation):
425436
},
426437
Constellation.PLD: r"DIM_PHR1[AB]_(P|MS|PMS|MS-N|MS-X|PMS-N|PMS-X)_\d{15}_(SEN|PRJ|ORT|MOS)_.{10,}\.XML",
427438
Constellation.PNEO: r"DIM_PNEO\d_(\w+_|)\d{15}_(PMS-FS|MS-FS|PMS|MS|P)_(SEN|PRJ|ORT|MOS)_.{8,}(-.{4,}-.{4,}-.{4,}-.{12,}|_._._._.)\.XML",
439+
Constellation.SPOT67: r"DIM_SPOT[67]_(P|MS|PMS|MS-N|MS-X|PMS-N|PMS-X)_\d{15}_(SEN|PRJ|ORT|MOS)_.{10,}\.XML",
428440
Constellation.SPOT7: r"DIM_SPOT7_(P|MS|PMS|MS-N|MS-X|PMS-N|PMS-X)_\d{15}_(SEN|PRJ|ORT|MOS)_.{10,}\.XML",
429441
Constellation.SPOT6: r"DIM_SPOT6_(P|MS|PMS|MS-N|MS-X|PMS-N|PMS-X)_\d{15}_(SEN|PRJ|ORT|MOS)_.{10,}\.XML",
430442
Constellation.VIS1: r"DIM_VIS1_(PSH|MS4|PAN)_\d{14}_(PRJ|ORTP)_S\d{5,}_\d{4}_Meta\.xml",
@@ -784,7 +796,7 @@ def _open_path(
784796
else:
785797
prod = None
786798
if constellation is None:
787-
const_list = CONSTELLATION_REGEX.keys()
799+
const_list = unique_constellations()
788800
else:
789801
# Manage other products which have the same constellation in them
790802
if constellation == Constellation.S2:
@@ -1024,6 +1036,75 @@ def is_filename_valid(product_path: AnyPathStrType, regex: list | re.Pattern) ->
10241036
return is_valid
10251037

10261038

1039+
def _is_vantor(constellation: Constellation) -> bool:
1040+
return constellation in [
1041+
Constellation.QB02,
1042+
Constellation.GE01,
1043+
Constellation.WV01,
1044+
Constellation.WV02,
1045+
Constellation.WV03,
1046+
Constellation.WV04,
1047+
Constellation.WVLG,
1048+
Constellation.VANTOR,
1049+
Constellation.MAXAR,
1050+
]
1051+
1052+
1053+
def _is_landsat(constellation: Constellation) -> bool:
1054+
return constellation in [
1055+
Constellation.L1,
1056+
Constellation.L2,
1057+
Constellation.L3,
1058+
Constellation.L4,
1059+
Constellation.L5,
1060+
Constellation.L7,
1061+
Constellation.L8,
1062+
Constellation.L9,
1063+
]
1064+
1065+
1066+
def _is_spot67(constellation: Constellation) -> bool:
1067+
return constellation in [
1068+
Constellation.SPOT6,
1069+
Constellation.SPOT7,
1070+
]
1071+
1072+
1073+
def _is_spot45(constellation: Constellation) -> bool:
1074+
return constellation in [
1075+
Constellation.SPOT4,
1076+
Constellation.SPOT5,
1077+
Constellation.SPOT45,
1078+
]
1079+
1080+
1081+
def _is_aleph1(constellation: Constellation) -> bool:
1082+
return constellation in [
1083+
Constellation.SATELLOGIC,
1084+
Constellation.ALEPH1,
1085+
]
1086+
1087+
1088+
def unique_constellations() -> list:
1089+
unique_const = []
1090+
for const in CONSTELLATION_REGEX:
1091+
if _is_vantor(const) and Constellation.VANTOR not in unique_const:
1092+
unique_const.append(Constellation.VANTOR)
1093+
# Lansat constellations
1094+
elif _is_landsat(const) and Constellation.LANDSAT not in unique_const:
1095+
unique_const.append(Constellation.LANDSAT)
1096+
# SPOT-6/7 constellations
1097+
elif _is_spot67(const) and Constellation.SPOT67 not in unique_const:
1098+
unique_const.append(Constellation.SPOT67)
1099+
# SPOT-4/5 constellations
1100+
elif _is_spot45(const) and Constellation.SPOT45 not in unique_const:
1101+
unique_const.append(Constellation.SPOT45)
1102+
elif _is_aleph1(const) and Constellation.ALEPH1 not in unique_const:
1103+
unique_const.append(Constellation.ALEPH1)
1104+
1105+
return unique_const
1106+
1107+
10271108
def create_product(
10281109
product_path: AnyPathStrType,
10291110
archive_path: AnyPathStrType,
@@ -1050,40 +1131,23 @@ def create_product(
10501131

10511132
# Channel correctly the constellations to their generic files (just in case)
10521133
# Vantor-like constellations
1053-
if constellation in [
1054-
Constellation.QB02,
1055-
Constellation.GE01,
1056-
Constellation.WV01,
1057-
Constellation.WV02,
1058-
Constellation.WV03,
1059-
Constellation.WV04,
1060-
Constellation.WVLG,
1061-
]:
1134+
if _is_vantor(constellation):
10621135
sat_class = "vantor_product"
10631136
constellation = None # All product names are the same, so assess it with MTD
10641137
# Lansat constellations
1065-
elif constellation in [
1066-
Constellation.L1,
1067-
Constellation.L2,
1068-
Constellation.L3,
1069-
Constellation.L4,
1070-
Constellation.L5,
1071-
Constellation.L7,
1072-
Constellation.L8,
1073-
Constellation.L9,
1074-
]:
1138+
elif _is_landsat(constellation):
10751139
sat_class = "landsat_product"
10761140
# SPOT-6/7 constellations
1077-
elif constellation in [Constellation.SPOT6, Constellation.SPOT7]:
1141+
elif _is_spot67(constellation):
10781142
sat_class = "spot67_product"
10791143
# SPOT-4/5 constellations
1080-
elif constellation in [Constellation.SPOT4, Constellation.SPOT5]:
1144+
elif _is_spot45(constellation):
10811145
sat_class = "spot45_product"
1146+
elif _is_aleph1(constellation):
1147+
sat_class = "aleph1_product"
10821148
elif constellation in [Constellation.S2_SIN]:
10831149
sat_class = "s2_product"
10841150
kwargs["is_sinergise"] = True
1085-
elif constellation in [Constellation.SATELLOGIC]:
1086-
sat_class = "aleph1_product"
10871151

10881152
# Manage both optical and SAR
10891153
try:

0 commit comments

Comments
 (0)