diff --git a/sen2chain/cloud_mask.py b/sen2chain/cloud_mask.py index 125baa95ad784f5597196cf6bf6ead004ec9567f..490c305913c19fc2025d3f9c559d156c731fa8a6 100755 --- a/sen2chain/cloud_mask.py +++ b/sen2chain/cloud_mask.py @@ -14,11 +14,12 @@ from shapely.ops import transform import rasterio from rasterio.features import shapes, rasterize import numpy as np -from typing import Mapping, Sequence, AbstractSet, List, Set, Dict, Tuple, Optional, Union +import gdal import otbApplication +# type annotations +from typing import Mapping, Sequence, AbstractSet, List, Set, Dict, Tuple, Optional, Union + from .config import Config -import gdal -import os LOGGER = logging.getLogger(__name__) @@ -253,13 +254,16 @@ def create_cloud_mask_v2(cloud_mask: Union[str, pathlib.PosixPath], out_path="./ LOGGER.info("Creating cloud-mask_v2") out_temp_path = Path(Config().get("temp_path")) -# LOGGER.info(out_temp_path) -# LOGGER.info(str(out_temp_path)) - out_bin = str(out_temp_path) + '/temp_bin.tif' - out_erode = str(out_temp_path) + '/temp_erode.tif' - out_dilate = str(out_temp_path) + '/temp_dilate.tif' - - # Seuillage du masque nuage SEN2COR + # LOGGER.info(out_temp_path) + # LOGGER.info(str(out_temp_path)) + # ATTENTION, si jamais des traitements en parallèle: les fichiers + # temporaires auront le même nom => conflits + # à utiliser uniquement pour des tests + out_bin = str(out_temp_path / "temp_bin.tif") + out_erode = str(out_temp_path / "temp_erode.tif") + out_dilate = str(out_temp_path / "temp_dilate.tif") + + # Seuillage du masque nuage Sen2Cor CLD_seuil = 25 BandMath = otbApplication.Registry.CreateApplication("BandMath") BandMath.SetParameterStringList("il", [str(cloud_mask)]) @@ -299,11 +303,11 @@ def create_cloud_mask_v2(cloud_mask: Union[str, pathlib.PosixPath], out_path="./ # Enregistrement JP2000 src_ds = gdal.Open(out_dilate) driver = gdal.GetDriverByName("JP2OpenJPEG") - dst_ds = driver.CreateCopy(str(out_path), src_ds, options=['CODEC=JP2', 'QUALITY=100', 'REVERSIBLE=YES', 'YCBCR420=NO']) + dst_ds = driver.CreateCopy(str(out_path), src_ds, options=["CODEC=JP2", "QUALITY=100", "REVERSIBLE=YES", "YCBCR420=NO"]) dst_ds = None src_ds = None #os.remove(out_bin) #os.remove(out_erode) #os.remove(out_dilate) - +