Skip to content
Snippets Groups Projects
Commit 9749ac2b authored by pascal.mouquet_ird.fr's avatar pascal.mouquet_ird.fr
Browse files

New NDR function more generic to compute indices, new IRECI

parent 7dddbec5
No related branches found
No related tags found
No related merge requests found
Pipeline #30 failed
...@@ -13,9 +13,9 @@ import os ...@@ -13,9 +13,9 @@ import os
# type annotations # type annotations
from typing import Union, List from typing import Union, List
from .indices_functions import (create_raw_ndvi, create_raw_ndre, create_raw_ndwigao, create_raw_ndwimcf, from .indices_functions import (create_raw_ndr, create_raw_ireci,
#~ create_raw_ndvi, create_raw_ndre, create_raw_ndwigao, create_raw_ndwimcf, create_raw_mndwi
create_raw_bigr, create_raw_birnir, create_raw_bibg, create_raw_bigr, create_raw_birnir, create_raw_bibg,
create_raw_mndwi, create_raw_ndr,
create_masked_indice, index_tiff_2_jp2) create_masked_indice, index_tiff_2_jp2)
from .colormap import matplotlib_colormap_to_rgb, create_colormap, create_rvb from .colormap import matplotlib_colormap_to_rgb, create_colormap, create_rvb
...@@ -66,7 +66,6 @@ class Ndvi(Indice): ...@@ -66,7 +66,6 @@ class Ndvi(Indice):
ext = ".jp2" ext = ".jp2"
ext_raw = ".tif" ext_raw = ".tif"
colormap = cm.RdYlGn colormap = cm.RdYlGn
# _colors_table_path = functions_data_path = Path("../share/data/RdYlGn.lut")
def __init__(self, l2a_product_object, cm_product_object): def __init__(self, l2a_product_object, cm_product_object):
if (l2a_product_object or cm_product_object) is None: if (l2a_product_object or cm_product_object) is None:
...@@ -75,10 +74,8 @@ class Ndvi(Indice): ...@@ -75,10 +74,8 @@ class Ndvi(Indice):
self.l2a_product = l2a_product_object self.l2a_product = l2a_product_object
self.cm_product = cm_product_object self.cm_product = cm_product_object
# output path
self.out_path = None self.out_path = None
# filenames
self.indice_stem = self.filename_template.format(product_identifier=self.l2a_product.identifier, ext="") self.indice_stem = self.filename_template.format(product_identifier=self.l2a_product.identifier, ext="")
self.indice_filename = self.indice_stem + self.ext self.indice_filename = self.indice_stem + self.ext
self.indice_raw = self.indice_stem + self.ext_raw self.indice_raw = self.indice_stem + self.ext_raw
...@@ -100,11 +97,12 @@ class Ndvi(Indice): ...@@ -100,11 +97,12 @@ class Ndvi(Indice):
if (out_path / self.indice_filename).exists() and not reprocess: if (out_path / self.indice_filename).exists() and not reprocess:
logger.info("{} already exists".format(self.indice_filename)) logger.info("{} already exists".format(self.indice_filename))
else: else:
create_raw_ndvi(nir_path=self.l2a_product.b08_10m, create_raw_ndr(b1_path=self.l2a_product.b08_10m,
vir_path=self.l2a_product.b04_10m, b2_path=self.l2a_product.b04_10m,
out_path=(out_path / self.indice_raw)) out_path=(out_path / self.indice_raw))
index_tiff_2_jp2(img_path=(out_path / self.indice_raw), index_tiff_2_jp2(img_path=(out_path / self.indice_raw),
out_path=(out_path / self.indice_filename)) out_path=(out_path / self.indice_filename),
quality = 20)
if nodata_clouds: if nodata_clouds:
if not self.cm_product.path.exists(): if not self.cm_product.path.exists():
...@@ -112,11 +110,6 @@ class Ndvi(Indice): ...@@ -112,11 +110,6 @@ class Ndvi(Indice):
masked_indice_filename = self.indice_stem + "_" + self.cm_product.suffix + self.ext masked_indice_filename = self.indice_stem + "_" + self.cm_product.suffix + self.ext
masked_indice_raw = self.indice_stem + "_" + self.cm_product.suffix + self.ext_raw masked_indice_raw = self.indice_stem + "_" + self.cm_product.suffix + self.ext_raw
#~ if self.l2a_product.user_cloud_mask is None:
#~ raise ValueError("Cloud mask does not exist")
#~ masked_indice_filename = self.indice_stem + "_MASKED" + self.ext
#~ masked_indice_raw = self.indice_stem + "_MASKED" + self.ext_raw
if (out_path / masked_indice_filename).exists() and not reprocess: if (out_path / masked_indice_filename).exists() and not reprocess:
logger.info("{} already exists".format(masked_indice_filename)) logger.info("{} already exists".format(masked_indice_filename))
else: else:
...@@ -128,7 +121,8 @@ class Ndvi(Indice): ...@@ -128,7 +121,8 @@ class Ndvi(Indice):
cloud_mask_path=self.cm_product.path, cloud_mask_path=self.cm_product.path,
out_path=(out_path / masked_indice_raw)) out_path=(out_path / masked_indice_raw))
index_tiff_2_jp2(img_path=(out_path / masked_indice_raw), index_tiff_2_jp2(img_path=(out_path / masked_indice_raw),
out_path=(out_path / masked_indice_filename)) out_path=(out_path / masked_indice_filename),
quality = 20)
os.remove(str(out_path / masked_indice_raw)) os.remove(str(out_path / masked_indice_raw))
try: try:
...@@ -146,24 +140,11 @@ class Ndvi(Indice): ...@@ -146,24 +140,11 @@ class Ndvi(Indice):
logger.info("{} already exists".format(quicklook_filename)) logger.info("{} already exists".format(quicklook_filename))
else: else:
logger.info("creating quicklook") logger.info("creating quicklook")
# create_colormap(raster=(self.out_path / self.indice_filename),
# cloud_mask=self.l2a_product.user_cloud_mask,
# # lut_dict=get_colormap(self._colors_table_path.absolute()),
# lut_dict=cmap, clouds_color="white",
# out_path=(self.out_path / quicklook_filename))
#~ create_colormap2(raster=(self.out_path / self.indice_filename),
#~ cloud_mask=self.l2a_product.user_cloud_mask,
#~ # lut_dict=get_colormap(self._colors_table_path.absolute()),
#~ lut_dict=cmap, clouds_color="white",
#~ out_path=(self.out_path / quicklook_filename))
create_rvb(raster=(self.out_path / self.indice_filename), create_rvb(raster=(self.out_path / self.indice_filename),
cloud_mask=self.cm_product.path, cloud_mask=self.cm_product.path,
# lut_dict=get_colormap(self._colors_table_path.absolute()),
lut_dict=cmap, clouds_color="white", lut_dict=cmap, clouds_color="white",
out_path=(self.out_path / quicklook_filename)) out_path=(self.out_path / quicklook_filename))
#~ IndiceProduct(identifier = self.indice_filename).init_md()
#~ IndiceProduct(identifier = masked_indice_filename).init_md()
#~ IndiceProduct(identifier = quicklook_filename).init_md()
class NdwiMcf(Indice): class NdwiMcf(Indice):
""" """
...@@ -176,7 +157,6 @@ class NdwiMcf(Indice): ...@@ -176,7 +157,6 @@ class NdwiMcf(Indice):
filename_template = "{product_identifier}_NDWIMCF{ext}" filename_template = "{product_identifier}_NDWIMCF{ext}"
ext = ".jp2" ext = ".jp2"
ext_raw = ".tif" ext_raw = ".tif"
#~ colormap = cm.RdYlBu
colormap = cm.colors.LinearSegmentedColormap.from_list("", ["green", "white", "blue"]) colormap = cm.colors.LinearSegmentedColormap.from_list("", ["green", "white", "blue"])
...@@ -187,10 +167,8 @@ class NdwiMcf(Indice): ...@@ -187,10 +167,8 @@ class NdwiMcf(Indice):
self.l2a_product = l2a_product_object self.l2a_product = l2a_product_object
self.cm_product = cm_product_object self.cm_product = cm_product_object
# output path
self.out_path = None self.out_path = None
# filenames
self.indice_stem = self.filename_template.format(product_identifier=self.l2a_product.identifier, ext="") self.indice_stem = self.filename_template.format(product_identifier=self.l2a_product.identifier, ext="")
self.indice_filename = self.indice_stem + self.ext self.indice_filename = self.indice_stem + self.ext
self.indice_raw = self.indice_stem + self.ext_raw self.indice_raw = self.indice_stem + self.ext_raw
...@@ -207,11 +185,12 @@ class NdwiMcf(Indice): ...@@ -207,11 +185,12 @@ class NdwiMcf(Indice):
if (out_path / self.indice_filename).exists() and not reprocess: if (out_path / self.indice_filename).exists() and not reprocess:
logger.info("{} already exists".format(self.indice_filename)) logger.info("{} already exists".format(self.indice_filename))
else: else:
create_raw_ndwimcf(nir_path=self.l2a_product.b08_10m, create_raw_ndr(b1_path=self.l2a_product.b03_10m,
green_path=self.l2a_product.b03_10m, b2_path=self.l2a_product.b08_10m,
out_path=(out_path / self.indice_raw)) out_path=(out_path / self.indice_raw))
index_tiff_2_jp2(img_path=(out_path / self.indice_raw), index_tiff_2_jp2(img_path=(out_path / self.indice_raw),
out_path=(out_path / self.indice_filename)) out_path=(out_path / self.indice_filename),
quality = 20)
if nodata_clouds: if nodata_clouds:
if not self.cm_product.path.exists(): if not self.cm_product.path.exists():
...@@ -230,7 +209,8 @@ class NdwiMcf(Indice): ...@@ -230,7 +209,8 @@ class NdwiMcf(Indice):
cloud_mask_path=self.cm_product.path, cloud_mask_path=self.cm_product.path,
out_path=(out_path / masked_indice_raw)) out_path=(out_path / masked_indice_raw))
index_tiff_2_jp2(img_path=(out_path / masked_indice_raw), index_tiff_2_jp2(img_path=(out_path / masked_indice_raw),
out_path=(out_path / masked_indice_filename)) out_path=(out_path / masked_indice_filename),
quality = 20)
os.remove(str(out_path / masked_indice_raw)) os.remove(str(out_path / masked_indice_raw))
try: try:
...@@ -254,21 +234,18 @@ class NdwiMcf(Indice): ...@@ -254,21 +234,18 @@ class NdwiMcf(Indice):
out_path=(self.out_path / quicklook_filename)) out_path=(self.out_path / quicklook_filename))
class NdwiGao(Indice):
class GenericNDR(Indice):
""" """
NDR = (B1-B2) / (B1+B2) NDWI(Gao) = (NIR-SWIR) / (NIR+SWIR)
B1: band NIR: band 08
B2: band SWIR: band 11
""" """
name = "GENERICNDR" name = "NDWIGAO"
filename_template = "{product_identifier}_GENERICNDR{ext}" filename_template = "{product_identifier}_NDWIGAO{ext}"
ext = ".jp2" ext = ".jp2"
ext_raw = ".tif" ext_raw = ".tif"
#~ colormap = cm.RdYlBu colormap = cm.RdYlBu
colormap = cm.colors.LinearSegmentedColormap.from_list("", ["red", "white", "blue"])
def __init__(self, l2a_product_object, cm_product_object): def __init__(self, l2a_product_object, cm_product_object):
if (l2a_product_object or cm_product_object) is None: if (l2a_product_object or cm_product_object) is None:
...@@ -277,10 +254,8 @@ class GenericNDR(Indice): ...@@ -277,10 +254,8 @@ class GenericNDR(Indice):
self.l2a_product = l2a_product_object self.l2a_product = l2a_product_object
self.cm_product = cm_product_object self.cm_product = cm_product_object
# output path
self.out_path = None self.out_path = None
# filenames
self.indice_stem = self.filename_template.format(product_identifier=self.l2a_product.identifier, ext="") self.indice_stem = self.filename_template.format(product_identifier=self.l2a_product.identifier, ext="")
self.indice_filename = self.indice_stem + self.ext self.indice_filename = self.indice_stem + self.ext
self.indice_raw = self.indice_stem + self.ext_raw self.indice_raw = self.indice_stem + self.ext_raw
...@@ -294,6 +269,7 @@ class GenericNDR(Indice): ...@@ -294,6 +269,7 @@ class GenericNDR(Indice):
) -> None: ) -> None:
""" process """ """ process """
self.out_path = out_path self.out_path = out_path
if (out_path / self.indice_filename).exists() and not reprocess: if (out_path / self.indice_filename).exists() and not reprocess:
logger.info("{} already exists".format(self.indice_filename)) logger.info("{} already exists".format(self.indice_filename))
else: else:
...@@ -301,9 +277,8 @@ class GenericNDR(Indice): ...@@ -301,9 +277,8 @@ class GenericNDR(Indice):
b2_path=self.l2a_product.b11_20m, b2_path=self.l2a_product.b11_20m,
out_path=(out_path / self.indice_raw)) out_path=(out_path / self.indice_raw))
index_tiff_2_jp2(img_path=(out_path / self.indice_raw), index_tiff_2_jp2(img_path=(out_path / self.indice_raw),
out_path=(out_path / self.indice_filename), out_path=(out_path / self.indice_filename),
quality = 20 quality = 20)
)
if nodata_clouds: if nodata_clouds:
if not self.cm_product.path.exists(): if not self.cm_product.path.exists():
...@@ -315,18 +290,19 @@ class GenericNDR(Indice): ...@@ -315,18 +290,19 @@ class GenericNDR(Indice):
logger.info("{} already exists".format(masked_indice_filename)) logger.info("{} already exists".format(masked_indice_filename))
else: else:
if (out_path / self.indice_raw).exists(): if (out_path / self.indice_raw).exists():
ndwimcf_path = (out_path / self.indice_raw) ndwigao_name = (out_path / self.indice_raw)
else: else:
ndwimcf_path = (out_path / self.indice_filename) ndwigao_name = (out_path / self.indice_filename)
create_masked_indice(indice_path=ndwimcf_path, create_masked_indice(indice_path=ndwigao_name,
cloud_mask_path=self.cm_product.path, cloud_mask_path=self.cm_product.path,
out_path=(out_path / masked_indice_raw)) out_path=(out_path / masked_indice_raw))
index_tiff_2_jp2(img_path=(out_path / masked_indice_raw), index_tiff_2_jp2(img_path=(out_path / masked_indice_raw),
out_path=(out_path / masked_indice_filename)) out_path=(out_path / masked_indice_filename),
#~ os.remove(str(out_path / masked_indice_raw)) quality = 20)
os.remove(str(out_path / masked_indice_raw))
try: try:
#~ os.remove(str(out_path / self.indice_raw)) os.remove(str(out_path / self.indice_raw))
logger.info("Removing {}".format(self.indice_raw)) logger.info("Removing {}".format(self.indice_raw))
except: except:
pass pass
...@@ -334,8 +310,7 @@ class GenericNDR(Indice): ...@@ -334,8 +310,7 @@ class GenericNDR(Indice):
if quicklook: if quicklook:
cmap = matplotlib_colormap_to_rgb(self.colormap, revers=False) cmap = matplotlib_colormap_to_rgb(self.colormap, revers=False)
quicklook_filename = self.indice_stem + "_" + self.cm_product.suffix + "_QL.tif" quicklook_filename = self.indice_stem + "_QUICKLOOK.tif"
if (self.out_path / quicklook_filename).exists() and not reprocess: if (self.out_path / quicklook_filename).exists() and not reprocess:
logger.info("{} already exists".format(quicklook_filename)) logger.info("{} already exists".format(quicklook_filename))
else: else:
...@@ -346,18 +321,18 @@ class GenericNDR(Indice): ...@@ -346,18 +321,18 @@ class GenericNDR(Indice):
out_path=(self.out_path / quicklook_filename)) out_path=(self.out_path / quicklook_filename))
class NdwiGao(Indice): class Mndwi(Indice):
""" """
NDWI(Gao) = (NIR-SWIR) / (NIR+SWIR) MNDWI = (GREEN-SWIR) / (GREEN+SWIR)
NIR: band 08 GREEN: band 03
SWIR: band 11 SWIR: band 11
""" """
name = "NDWIGAO" name = "MNDWI"
filename_template = "{product_identifier}_NDWIGAO{ext}" filename_template = "{product_identifier}_MNDWI{ext}"
ext = ".jp2" ext = ".jp2"
ext_raw = ".tif" ext_raw = ".tif"
colormap = cm.RdYlBu colormap = cm.BrBG
def __init__(self, l2a_product_object, cm_product_object): def __init__(self, l2a_product_object, cm_product_object):
if (l2a_product_object or cm_product_object) is None: if (l2a_product_object or cm_product_object) is None:
...@@ -366,11 +341,8 @@ class NdwiGao(Indice): ...@@ -366,11 +341,8 @@ class NdwiGao(Indice):
self.l2a_product = l2a_product_object self.l2a_product = l2a_product_object
self.cm_product = cm_product_object self.cm_product = cm_product_object
# output path
self.out_path = None self.out_path = None
# filenames
self.indice_stem = self.filename_template.format(product_identifier=self.l2a_product.identifier, ext="") self.indice_stem = self.filename_template.format(product_identifier=self.l2a_product.identifier, ext="")
self.indice_filename = self.indice_stem + self.ext self.indice_filename = self.indice_stem + self.ext
self.indice_raw = self.indice_stem + self.ext_raw self.indice_raw = self.indice_stem + self.ext_raw
...@@ -388,30 +360,32 @@ class NdwiGao(Indice): ...@@ -388,30 +360,32 @@ class NdwiGao(Indice):
if (out_path / self.indice_filename).exists() and not reprocess: if (out_path / self.indice_filename).exists() and not reprocess:
logger.info("{} already exists".format(self.indice_filename)) logger.info("{} already exists".format(self.indice_filename))
else: else:
create_raw_ndwigao(nir_path=self.l2a_product.b08_10m, create_raw_ndr(b1_path=self.l2a_product.b03_10m,
swir_path=self.l2a_product.b11_20m, b2_path=self.l2a_product.b11_20m,
out_path=(out_path / self.indice_raw)) out_path=(out_path / self.indice_raw))
index_tiff_2_jp2(img_path=(out_path / self.indice_raw), index_tiff_2_jp2(img_path=(out_path / self.indice_raw),
out_path=(out_path / self.indice_filename)) out_path=(out_path / self.indice_filename),
quality = 20)
if nodata_clouds: if nodata_clouds:
if not self.cm_product.path.exists(): if not self.cm_product.path.exists():
raise ValueError("Cloud mask does not exist") raise ValueError("Cloud mask does not exist")
masked_indice_filename = self.indice_stem + "_" + self.cm_product.suffix + self.ext masked_indice_filename = self.indice_stem + "_" + self.cm_product.suffix + self.ext
masked_indice_raw = self.indice_stem + "_" + self.cm_product.suffix + self.ext_raw masked_indice_raw = self.indice_stem + "_" + self.cm_product.suffix + self.ext_raw
if (out_path / masked_indice_filename).exists() and not reprocess: if (out_path / masked_indice_filename).exists() and not reprocess:
logger.info("{} already exists".format(masked_indice_filename)) logger.info("{} already exists".format(masked_indice_filename))
else: else:
if (out_path / self.indice_raw).exists(): if (out_path / self.indice_raw).exists():
ndwigao_name = (out_path / self.indice_raw) mndwi_name = (out_path / self.indice_raw)
else: else:
ndwigao_name = (out_path / self.indice_filename) mndwi_name = (out_path / self.indice_filename)
create_masked_indice(indice_path=ndwigao_name, create_masked_indice(indice_path=mndwi_name,
cloud_mask_path=self.cm_product.path, cloud_mask_path=self.cm_product.path,
out_path=(out_path / masked_indice_raw)) out_path=(out_path / masked_indice_raw))
index_tiff_2_jp2(img_path=(out_path / masked_indice_raw), index_tiff_2_jp2(img_path=(out_path / masked_indice_raw),
out_path=(out_path / masked_indice_filename)) out_path=(out_path / masked_indice_filename),
quality = 20)
os.remove(str(out_path / masked_indice_raw)) os.remove(str(out_path / masked_indice_raw))
try: try:
...@@ -423,33 +397,29 @@ class NdwiGao(Indice): ...@@ -423,33 +397,29 @@ class NdwiGao(Indice):
if quicklook: if quicklook:
cmap = matplotlib_colormap_to_rgb(self.colormap, revers=False) cmap = matplotlib_colormap_to_rgb(self.colormap, revers=False)
quicklook_filename = self.indice_stem + "_QUICKLOOK.tif" quicklook_filename = self.indice_stem + "_" + self.cm_product.suffix + "_QL.tif"
if (self.out_path / quicklook_filename).exists() and not reprocess: if (self.out_path / quicklook_filename).exists() and not reprocess:
logger.info("{} already exists".format(quicklook_filename)) logger.info("{} already exists".format(quicklook_filename))
else: else:
logger.info("creating quicklook") logger.info("creating quicklook")
# create_colormap(raster=(self.out_path / self.indice_filename),
# cloud_mask=self.l2a_product.user_cloud_mask,
# lut_dict=cmap, clouds_color="white",
# out_path=(self.out_path / quicklook_filename))
create_rvb(raster=(self.out_path / self.indice_filename), create_rvb(raster=(self.out_path / self.indice_filename),
cloud_mask=self.cm_product.path, cloud_mask=self.cm_product.path,
lut_dict=cmap, clouds_color="white", lut_dict=cmap, clouds_color="white",
out_path=(self.out_path / quicklook_filename)) out_path=(self.out_path / quicklook_filename))
class Mndwi(Indice): class Ndre(Indice):
""" """
MNDWI = (GREEN-SWIR) / (GREEN+SWIR) NDRE = (NIR - REDEDGE) / (NIR + REDEDGE)
GREEN: band 03 NIR: band 08
SWIR: band 11 REDEDGE: band 05
""" """
name = "MNDWI" name = "NDRE"
filename_template = "{product_identifier}_MNDWI{ext}" filename_template = "{product_identifier}_NDRE{ext}"
ext = ".jp2" ext = ".jp2"
ext_raw = ".tif" ext_raw = ".tif"
colormap = cm.BrBG colormap = cm.Spectral
def __init__(self, l2a_product_object, cm_product_object): def __init__(self, l2a_product_object, cm_product_object):
if (l2a_product_object or cm_product_object) is None: if (l2a_product_object or cm_product_object) is None:
...@@ -457,33 +427,31 @@ class Mndwi(Indice): ...@@ -457,33 +427,31 @@ class Mndwi(Indice):
else: else:
self.l2a_product = l2a_product_object self.l2a_product = l2a_product_object
self.cm_product = cm_product_object self.cm_product = cm_product_object
# output path
self.out_path = None self.out_path = None
# filenames
self.indice_stem = self.filename_template.format(product_identifier=self.l2a_product.identifier, ext="") self.indice_stem = self.filename_template.format(product_identifier=self.l2a_product.identifier, ext="")
self.indice_filename = self.indice_stem + self.ext self.indice_filename = self.indice_stem + self.ext
self.indice_raw = self.indice_stem + self.ext_raw self.indice_raw = self.indice_stem + self.ext_raw
def process_indice( def process_indice(self,
self, out_path: pathlib.PosixPath,
out_path: pathlib.PosixPath, reprocess: bool = False,
reprocess: bool = False, nodata_clouds: bool = False,
nodata_clouds: bool = False, quicklook: bool = False
quicklook: bool = False ) -> None:
) -> None:
""" process """ """ process """
self.out_path = out_path self.out_path = out_path
if (out_path / self.indice_filename).exists() and not reprocess: if (out_path / self.indice_filename).exists() and not reprocess:
logger.info("{} already exists".format(self.indice_filename)) logger.info("{} already exists".format(self.indice_filename))
else: else:
create_raw_mndwi(green_path=self.l2a_product.b03_10m, create_raw_ndr(b1_path=self.l2a_product.b08_10m,
swir_path=self.l2a_product.b11_20m, b2_path=self.l2a_product.b05_20m,
out_path=(out_path / self.indice_raw)) out_path=(out_path / self.indice_raw))
index_tiff_2_jp2(img_path=(out_path / self.indice_raw), index_tiff_2_jp2(img_path=(out_path / self.indice_raw),
out_path=(out_path / self.indice_filename)) out_path=(out_path / self.indice_filename),
quality = 20)
if nodata_clouds: if nodata_clouds:
if not self.cm_product.path.exists(): if not self.cm_product.path.exists():
...@@ -495,14 +463,15 @@ class Mndwi(Indice): ...@@ -495,14 +463,15 @@ class Mndwi(Indice):
logger.info("{} already exists".format(masked_indice_filename)) logger.info("{} already exists".format(masked_indice_filename))
else: else:
if (out_path / self.indice_raw).exists(): if (out_path / self.indice_raw).exists():
mndwi_name = (out_path / self.indice_raw) ndre_name = (out_path / self.indice_raw)
else: else:
mndwi_name = (out_path / self.indice_filename) ndre_name = (out_path / self.indice_filename)
create_masked_indice(indice_path=mndwi_name, create_masked_indice(indice_path=ndre_name,
cloud_mask_path=self.cm_product.path, cloud_mask_path=self.cm_product.path,
out_path=(out_path / masked_indice_raw)) out_path=(out_path / masked_indice_raw))
index_tiff_2_jp2(img_path=(out_path / masked_indice_raw), index_tiff_2_jp2(img_path=(out_path / masked_indice_raw),
out_path=(out_path / masked_indice_filename)) out_path=(out_path / masked_indice_filename),
quality = 20)
os.remove(str(out_path / masked_indice_raw)) os.remove(str(out_path / masked_indice_raw))
try: try:
...@@ -510,10 +479,8 @@ class Mndwi(Indice): ...@@ -510,10 +479,8 @@ class Mndwi(Indice):
logger.info("Removing {}".format(self.indice_raw)) logger.info("Removing {}".format(self.indice_raw))
except: except:
pass pass
if quicklook: if quicklook:
cmap = matplotlib_colormap_to_rgb(self.colormap, revers=False) cmap = matplotlib_colormap_to_rgb(self.colormap, revers=False)
quicklook_filename = self.indice_stem + "_" + self.cm_product.suffix + "_QL.tif" quicklook_filename = self.indice_stem + "_" + self.cm_product.suffix + "_QL.tif"
if (self.out_path / quicklook_filename).exists() and not reprocess: if (self.out_path / quicklook_filename).exists() and not reprocess:
logger.info("{} already exists".format(quicklook_filename)) logger.info("{} already exists".format(quicklook_filename))
...@@ -525,19 +492,20 @@ class Mndwi(Indice): ...@@ -525,19 +492,20 @@ class Mndwi(Indice):
out_path=(self.out_path / quicklook_filename)) out_path=(self.out_path / quicklook_filename))
class Ndre(Indice): class IRECI(Indice):
""" """
NDRE = (NIR - REDEDGE) / (NIR + REDEDGE) IRECI = (NIR-R)/(RE1/RE2)
NIR: band 783nm (B7 - 20m)
NIR: band 08 R: band 665nm (B4 - 10m)
REDEDGE: band 05 RE1: band 705nm (B5 - 20m)
RE2: band 740nm (B6 - 20m)
""" """
name = "NDRE" name = "IRECI"
filename_template = "{product_identifier}_NDRE{ext}" filename_template = "{product_identifier}_IRECI{ext}"
ext = ".jp2" ext = ".jp2"
ext_raw = ".tif" ext_raw = ".tif"
colormap = cm.Spectral colormap = cm.Spectral
def __init__(self, l2a_product_object, cm_product_object): def __init__(self, l2a_product_object, cm_product_object):
if (l2a_product_object or cm_product_object) is None: if (l2a_product_object or cm_product_object) is None:
raise ValueError("A L2aProduct and NewCloudMask objects must be provided") raise ValueError("A L2aProduct and NewCloudMask objects must be provided")
...@@ -545,10 +513,8 @@ class Ndre(Indice): ...@@ -545,10 +513,8 @@ class Ndre(Indice):
self.l2a_product = l2a_product_object self.l2a_product = l2a_product_object
self.cm_product = cm_product_object self.cm_product = cm_product_object
# output path
self.out_path = None self.out_path = None
# filenames
self.indice_stem = self.filename_template.format(product_identifier=self.l2a_product.identifier, ext="") self.indice_stem = self.filename_template.format(product_identifier=self.l2a_product.identifier, ext="")
self.indice_filename = self.indice_stem + self.ext self.indice_filename = self.indice_stem + self.ext
self.indice_raw = self.indice_stem + self.ext_raw self.indice_raw = self.indice_stem + self.ext_raw
...@@ -565,11 +531,14 @@ class Ndre(Indice): ...@@ -565,11 +531,14 @@ class Ndre(Indice):
if (out_path / self.indice_filename).exists() and not reprocess: if (out_path / self.indice_filename).exists() and not reprocess:
logger.info("{} already exists".format(self.indice_filename)) logger.info("{} already exists".format(self.indice_filename))
else: else:
create_raw_ndre(nir_path=self.l2a_product.b08_10m, create_raw_ireci(b1_path = self.l2a_product.b07_20m,
redge_path=self.l2a_product.b05_20m, b2_path = self.l2a_product.b04_10m,
out_path=(out_path / self.indice_raw)) b3_path = self.l2a_product.b05_20m,
b4_path = self.l2a_product.b06_20m,
out_path=(out_path / self.indice_raw))
index_tiff_2_jp2(img_path=(out_path / self.indice_raw), index_tiff_2_jp2(img_path=(out_path / self.indice_raw),
out_path=(out_path / self.indice_filename)) out_path=(out_path / self.indice_filename),
quality = 30)
if nodata_clouds: if nodata_clouds:
if not self.cm_product.path.exists(): if not self.cm_product.path.exists():
...@@ -588,7 +557,8 @@ class Ndre(Indice): ...@@ -588,7 +557,8 @@ class Ndre(Indice):
cloud_mask_path=self.cm_product.path, cloud_mask_path=self.cm_product.path,
out_path=(out_path / masked_indice_raw)) out_path=(out_path / masked_indice_raw))
index_tiff_2_jp2(img_path=(out_path / masked_indice_raw), index_tiff_2_jp2(img_path=(out_path / masked_indice_raw),
out_path=(out_path / masked_indice_filename)) out_path=(out_path / masked_indice_filename),
quality = 30)
os.remove(str(out_path / masked_indice_raw)) os.remove(str(out_path / masked_indice_raw))
try: try:
...@@ -609,20 +579,6 @@ class Ndre(Indice): ...@@ -609,20 +579,6 @@ class Ndre(Indice):
out_path=(self.out_path / quicklook_filename)) out_path=(self.out_path / quicklook_filename))
# A faire
class IRECI(Indice):
"""
IRECI =
"""
name = "IRECI"
filename_template = "{product_identifier}_IRECI{ext}"
ext = ".jp2"
ext_raw = ".tif"
colormap = cm.Spectral
class BIGR(Indice): class BIGR(Indice):
""" """
Brightness Index Green Red = ( (GREEN² + RED²)/2 ) ^ 0.5 Brightness Index Green Red = ( (GREEN² + RED²)/2 ) ^ 0.5
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment