diff --git a/sen2chain/multi_processing.py b/sen2chain/multi_processing.py index a5549d03d9a211087ae55c3db6906fe50d979cd7..079157260ffd6484d1479ea34bdaa010244adf05 100644 --- a/sen2chain/multi_processing.py +++ b/sen2chain/multi_processing.py @@ -74,11 +74,19 @@ def multi_cld_ver_pro_iter_repro(l2a_ver_pro_iter_repro): cm_version = l2a_ver_pro_iter_repro[1] probability = l2a_ver_pro_iter_repro[2] iterations = l2a_ver_pro_iter_repro[3] - reprocess = l2a_ver_pro_iter_repro[4] + cld_shad = l2a_ver_pro_iter_repro[4] + cld_med_prob = l2a_ver_pro_iter_repro[5] + cld_hi_prob = l2a_ver_pro_iter_repro[6] + thin_cir = l2a_ver_pro_iter_repro[7] + reprocess = l2a_ver_pro_iter_repro[8] try: l2a.compute_cloud_mask(cm_version = cm_version, probability = probability, iterations = iterations, + cld_shad = cld_shad, + cld_med_prob = cld_med_prob, + cld_hi_prob = cld_hi_prob, + thin_cir = thin_cir, reprocess = reprocess) except: pass diff --git a/sen2chain/products.py b/sen2chain/products.py index 0a985829aa88a02c5c490b7edafa73e315adddee..6e51674f27657a8022d6b1a1a0290a6723dca739 100755 --- a/sen2chain/products.py +++ b/sen2chain/products.py @@ -528,6 +528,9 @@ class L2aProduct(Product): """ if cm_version == "cm003": logger.info("Computing cloudmask version {}, probability {}%, iteration(s) {}: {}".format(cm_version, probability, iterations, self.identifier)) + elif cm_version == "cm004": + logger.info("Computing cloudmask version {}, ITER {}, SHAD {}, MED-PRB {}, HI-PRB {}, CIRR {}: {}"\ + .format(cm_version, iterations, cld_shad, cld_med_prob, cld_hi_prob, thin_cir, self.identifier)) else: logger.info("Computing cloudmask version {}: {}".format(cm_version, self.identifier)) diff --git a/sen2chain/tiles.py b/sen2chain/tiles.py index 925cae3974438b74ccba97d1d05542a9f3ee301c..64bbdf43c8d3ca18e54e0508861ddf9814bb2d3b 100644 --- a/sen2chain/tiles.py +++ b/sen2chain/tiles.py @@ -168,11 +168,23 @@ class CloudMaskList(ProductsList): def params(self, probability: int = 1, iterations: int = 5, + cld_shad: bool = True, + cld_med_prob: bool = True, + cld_hi_prob: bool = True, + thin_cir: bool = True, ): filtered = CloudMaskList() for k, v in self._dict.items(): if "_CM003" in k: - if "-PRB" + str(probability) + "-ITER" + str(iterations) in k: + if "-PRB" + str(probability) + \ + "-ITER" + str(iterations) in k: + filtered[k] = {"date": v["date"], "cloud_cover": v["cloud_cover"]} + elif "_CM004" in k: + if "-CSH" + str(int(cld_shad)) + \ + "-CMP" + str(int(cld_med_prob)) + \ + "-CHP" + str(int(cld_hi_prob)) + \ + "-TCI" + str(int(thin_cir)) + \ + "-ITER" + str(iterations) in k: filtered[k] = {"date": v["date"], "cloud_cover": v["cloud_cover"]} else: filtered[k] = {"date": v["date"], "cloud_cover": v["cloud_cover"]} @@ -467,12 +479,22 @@ class Tile: cm_version: str = "cm001", probability: int = 1, iterations: int = 5, + cld_shad: bool = True, + cld_med_prob: bool = True, + cld_hi_prob: bool = True, + thin_cir: bool = True, ) -> "ProductsList": """Returns tile's L2A products that don't have a cloud mask as a ProductsList.""" prods_list = ProductsList() missings_l2a_set = set(self.l2a.products) - {(re.findall(r"(S2.+)_CM.+.jp2", identifier)[0] + ".SAFE") \ for identifier in getattr(self.cloudmasks, cm_version).\ - params(probability = probability, iterations = iterations).\ + params(probability = probability, + iterations = iterations, + cld_shad = cld_shad, + cld_med_prob = cld_med_prob, + cld_hi_prob = cld_hi_prob, + thin_cir = thin_cir, + ).\ products} for prod in missings_l2a_set: prods_list[prod] = {"date": self._products["l2a"][prod].date, @@ -596,6 +618,10 @@ class Tile: cm_version: str = "cm001", probability: int = 1, iterations: int = 5, + cld_shad: bool = True, + cld_med_prob: bool = True, + cld_hi_prob: bool = True, + thin_cir: bool = True, reprocess: bool = False, date_min: str = None, date_max: str = None, @@ -612,18 +638,24 @@ class Tile: """ if not reprocess: - cld_l2a_process_list = list([p.identifier, cm_version, probability, iterations, reprocess] \ + cld_l2a_process_list = list([p.identifier, cm_version, probability, iterations, + cld_shad, cld_med_prob, cld_hi_prob, thin_cir, reprocess] \ for p in self.cloudmasks_missing(cm_version = cm_version, probability = probability, iterations = iterations, + cld_shad = cld_shad, + cld_med_prob = cld_med_prob, + cld_hi_prob = cld_hi_prob, + thin_cir = thin_cir, )\ .filter_dates(date_min = date_min, date_max = date_max)) else: - cld_l2a_process_list = list([p.identifier, cm_version, probability, iterations, reprocess] \ + cld_l2a_process_list = list([p.identifier, cm_version, probability, iterations, + cld_shad, cld_med_prob, cld_hi_prob, thin_cir, reprocess] \ for p in self.l2a.filter_dates(date_min = date_min, date_max = date_max)) if cld_l2a_process_list: logger.info("{} l2a products to process:".format(len(cld_l2a_process_list))) - logger.info("{}".format(cld_l2a_process_list)) + #~ logger.info("{}".format(cld_l2a_process_list)) cld_version_probability_iterations_reprocessing_multiprocessing(cld_l2a_process_list, nb_proc=nb_proc) else: logger.info("All cloud masks already computed")