Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Sen2Chain
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ESPACE-DEV
Sen2Chain
Commits
9749ac2b
Commit
9749ac2b
authored
4 years ago
by
pascal.mouquet_ird.fr
Browse files
Options
Downloads
Patches
Plain Diff
New NDR function more generic to compute indices, new IRECI
parent
7dddbec5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#30
failed
4 years ago
Stage: test
Changes
2
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
sen2chain/indices.py
+95
-139
95 additions, 139 deletions
sen2chain/indices.py
sen2chain/indices_functions.py
+259
-297
259 additions, 297 deletions
sen2chain/indices_functions.py
with
354 additions
and
436 deletions
sen2chain/indices.py
+
95
−
139
View file @
9749ac2b
...
@@ -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_nd
vi
(
nir
_path
=
self
.
l2a_product
.
b08_10m
,
create_raw_nd
r
(
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_nd
wimcf
(
nir
_path
=
self
.
l2a_product
.
b0
8
_10m
,
create_raw_nd
r
(
b1
_path
=
self
.
l2a_product
.
b0
3
_10m
,
green
_path
=
self
.
l2a_product
.
b0
3
_10m
,
b2
_path
=
self
.
l2a_product
.
b0
8
_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
):
"""
"""
ND
R = (B1-B2) / (B1+B2
)
ND
WI(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
():
ndwi
mcf_path
=
(
out_path
/
self
.
indice_raw
)
ndwi
gao_name
=
(
out_path
/
self
.
indice_raw
)
else
:
else
:
ndwi
mcf_path
=
(
out_path
/
self
.
indice_filename
)
ndwi
gao_name
=
(
out_path
/
self
.
indice_filename
)
create_masked_indice
(
indice_path
=
ndwi
mcf_path
,
create_masked_indice
(
indice_path
=
ndwi
gao_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
N
dwi
Gao
(
Indice
):
class
Mn
dwi
(
Indice
):
"""
"""
NDWI
(Gao) = (NIR
-SWIR) / (
NIR
+SWIR)
M
NDWI
= (GREEN
-SWIR) / (
GREEN
+SWIR)
NIR
: band 0
8
GREEN
: band 0
3
SWIR: band 11
SWIR: band 11
"""
"""
name
=
"
NDWI
GAO
"
name
=
"
M
NDWI
"
filename_template
=
"
{product_identifier}_NDWI
GAO
{ext}
"
filename_template
=
"
{product_identifier}_
M
NDWI{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_nd
wigao
(
nir
_path
=
self
.
l2a_product
.
b0
8
_10m
,
create_raw_nd
r
(
b1
_path
=
self
.
l2a_product
.
b0
3
_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
():
ndwi
gao
_name
=
(
out_path
/
self
.
indice_raw
)
m
ndwi_name
=
(
out_path
/
self
.
indice_raw
)
else
:
else
:
ndwi
gao
_name
=
(
out_path
/
self
.
indice_filename
)
m
ndwi_name
=
(
out_path
/
self
.
indice_filename
)
create_masked_indice
(
indice_path
=
ndwi
gao
_name
,
create_masked_indice
(
indice_path
=
m
ndwi_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
):
"""
"""
M
ND
WI
= (
GREEN-SWIR) / (GREEN+SWIR
)
ND
RE
= (
NIR - REDEDGE) / (NIR + REDEDGE
)
GREEN
: band 0
3
NIR
: band 0
8
SWIR
: band
11
REDEDGE
: band
05
"""
"""
name
=
"
M
ND
WI
"
name
=
"
ND
RE
"
filename_template
=
"
{product_identifier}_
M
ND
WI
{ext}
"
filename_template
=
"
{product_identifier}_ND
RE
{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_
m
nd
wi
(
green
_path
=
self
.
l2a_product
.
b0
3
_10m
,
create_raw_nd
r
(
b1
_path
=
self
.
l2a_product
.
b0
8
_10m
,
swir
_path
=
self
.
l2a_product
.
b
11
_20m
,
b2
_path
=
self
.
l2a_product
.
b
05
_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
():
m
nd
wi
_name
=
(
out_path
/
self
.
indice_raw
)
nd
re
_name
=
(
out_path
/
self
.
indice_raw
)
else
:
else
:
m
nd
wi
_name
=
(
out_path
/
self
.
indice_filename
)
nd
re
_name
=
(
out_path
/
self
.
indice_filename
)
create_masked_indice
(
indice_path
=
m
nd
wi
_name
,
create_masked_indice
(
indice_path
=
nd
re
_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.
Click to expand it.
sen2chain/indices_functions.py
+
259
−
297
View file @
9749ac2b
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment