Commit 505ba2ed authored by Germain Salgues's avatar Germain Salgues
Browse files

UPDATE: Fix issue #4 and #36, snow_all: bit 5: all_cloud, bit 6: slope flag

parent cec26863
......@@ -37,6 +37,8 @@ NB: To build DEM data download the SRTM files corresponding to the study area an
* 2nd bit: Snow mask after pass2
* 3rd bit: Clouds detected at pass0
* 4th bit: Clouds refined at pass0
* 5th bit: Clouds initial (all_cloud)
* 6th bit: Slope flag (optional 1: bad slope correction)
For example if you want to get the snow from pass1 and clouds detected from pass1 you need to do:
```python
......
......@@ -93,6 +93,8 @@ S2_parameters = {"multi":10,
"swir_bandNumber":1,
"cloud_mask":".*CLM_R2.*\.tif$",
"dem":".*ALT_R2\.TIF$",
"div_mask":".*MG2_R2.*\.tif$",
"div_slope_thres":64,
"shadow_in_mask":32,
"shadow_out_mask":64,
"all_cloud_mask":1,
......@@ -107,6 +109,8 @@ Take5_parameters = {"multi":1,
"swir_band":".*ORTHO_SURF_CORR_PENTE.*\.TIF$",
"swir_bandNumber":4,
"cloud_mask":".*NUA.*\.TIF$",
"div_mask":".*DIV.*\.TIF$",
"div_slope_thres":8,
"dem":".*\.tif",
"shadow_in_mask":64,
"shadow_out_mask":128,
......@@ -122,6 +126,8 @@ L8_parameters = {"multi":1,
"swir_band":".*ORTHO_SURF_CORR_PENTE.*\.TIF$",
"swir_bandNumber":6,
"cloud_mask":".*NUA.*\.TIF$",
"div_mask":".*DIV.*\.TIF$",
"div_slope_thres":8,
"dem":".*\.tif",
"shadow_in_mask":64,
"shadow_out_mask":128,
......@@ -193,6 +199,15 @@ def read_product(inputPath, mission):
else:
logging.warning("No DEM found within product!")
# Check optional div mask parameters to access slope correction flags
if "div_mask" in params and "div_slope_thres" in params:
div_mask_tmp = findFiles(inputPath, params["div_mask"])
if div_mask_tmp:
conf_json["inputs"]["div_mask"] = div_mask_tmp[0]
conf_json["inputs"]["div_slope_thres"] = params["div_slope_thres"]
else:
logging.warning("div_mask was not found, the slope correction flag will be ignored")
conf_json["cloud"]["shadow_in_mask"] = params["shadow_in_mask"]
conf_json["cloud"]["shadow_out_mask"] = params["shadow_out_mask"]
conf_json["cloud"]["all_cloud_mask"] = params["all_cloud_mask"]
......@@ -279,7 +294,7 @@ def main():
logging.info("THEIA Sentinel product detected.")
jsonData = read_product(inputPath, "S2")
elif "Take5" in inputPath:
logging.info("THEIA Sentinel product detected.")
logging.info("THEIA Take5 product detected.")
jsonData = read_product(inputPath, "Take5")
elif "LANDSAT8" in inputPath:
logging.info("THEIA LANDSAT8 product detected.")
......
......@@ -211,6 +211,8 @@ The other output files are rather useful for the expert evaluation and troublesh
\item bit 2: snow (pass 2)
\item bit 3: clouds (pass 1)
\item bit 4: clouds (pass 2)
\item bit 5: clouds (initial all cloud)
\item bit 6: slope flag (optional bad slope correction flag)
\end{itemize}
\item a metadata file (*METADATA.XML)
......
......@@ -89,8 +89,8 @@ def compute_cloud_mask(img_in, img_out, cloudmaskvalue, \
logging.error("Parameters img_in, img_out \
and cloudmaskvalue are required")
def compute_snow_mask(pass1, pass2, cloud_pass1, cloud_refine, out, \
ram=None, out_type=None):
def compute_snow_mask(pass1, pass2, cloud_pass1, cloud_refine, initial_clouds, \
out, slope_flag=None, ram=None, out_type=None):
""" Create and configure the Compute Cloud Snow application
using otb.Registry.CreateApplication("ComputeSnowMask")
......@@ -99,7 +99,9 @@ def compute_snow_mask(pass1, pass2, cloud_pass1, cloud_refine, out, \
pass2 -- the input pass2 image
cloud_pass1 -- the input cloud pass1 image
cloud_refine -- the input cloud refine image
initial_clouds -- the inital all cloud image
out -- the output image
slope_flag -- the status of the slope
ram -- the ram limitation (not mandatory)
out_type -- the output image pixel type (not mandatory)
"""
......@@ -109,6 +111,7 @@ def compute_snow_mask(pass1, pass2, cloud_pass1, cloud_refine, out, \
logging.info("pass2 = " + pass2)
logging.info("cloud_pass1 = " + cloud_pass1)
logging.info("cloud_refine = " + cloud_refine)
logging.info("initial_clouds = " + initial_clouds)
logging.info("out = " + out)
snowMaskApp = otb.Registry.CreateApplication("ComputeSnowMask")
......@@ -116,7 +119,11 @@ def compute_snow_mask(pass1, pass2, cloud_pass1, cloud_refine, out, \
snowMaskApp.SetParameterString("pass2", pass2)
snowMaskApp.SetParameterString("cloudpass1", cloud_pass1)
snowMaskApp.SetParameterString("cloudrefine", cloud_refine)
snowMaskApp.SetParameterString("initialallcloud", initial_clouds)
snowMaskApp.SetParameterString("out", out)
if slope_flag is not None:
logging.info("slope_flag = " + slope_flag)
snowMaskApp.SetParameterString("slopeflag", slope_flag)
if ram is not None:
logging.info("ram = " + str(ram))
snowMaskApp.SetParameterString("ram", str(ram))
......@@ -126,7 +133,7 @@ def compute_snow_mask(pass1, pass2, cloud_pass1, cloud_refine, out, \
return snowMaskApp
else:
logging.error("Parameters pass1, pass2, cloud_pass1, \
cloud_refine and out are required")
cloud_refine, initial_clouds and out are required")
def band_mathX(il, out, exp, ram=None, out_type=None):
""" Create and configure the band math application
......
......@@ -103,6 +103,22 @@ class snow_detector:
self.dem = str(inputs.get("dem"))
self.cloud_init = str(inputs.get("cloud_mask"))
## Get div mask if available
self.slope_mask_path = None
if inputs.get("div_mask") and inputs.get("div_slope_thres"):
self.div_mask = str(inputs.get("div_mask"))
self.div_slope_thres = inputs.get("div_slope_thres")
self.slope_mask_path = op.join(self.path_tmp, "bad_slope_correction_mask.tif")
# Extract the bad slope correction flag
bandMathSlopeFlag = band_math([self.div_mask],
self.slope_mask_path,
"im1b1>="+str(self.div_slope_thres)+"?1:0",
self.ram,
otb.ImagePixelType_uint8)
bandMathSlopeFlag.ExecuteAndWriteOutput()
bandMathSlopeFlag = None
# bands paths
gb_path_extracted = extract_band(inputs, "green_band", self.path_tmp, self.nodata)
rb_path_extracted = extract_band(inputs, "red_band", self.path_tmp, self.nodata)
......@@ -778,7 +794,9 @@ class snow_detector:
self.pass2_path,
self.cloud_pass1_path,
self.cloud_refine_path,
self.all_cloud_path,
self.snow_all_path,
self.slope_mask_path,
self.ram,
otb.ImagePixelType_uint8)
app.ExecuteAndWriteOutput()
......
......@@ -59,6 +59,14 @@ public:
SetParameterDescription( "cloudrefine", "Input cloud refine image");
MandatoryOn("cloudrefine");
AddParameter(ParameterType_InputImage, "slopeflag", "slope flag image");
SetParameterDescription( "slopeflag", "Input slope flag image");
MandatoryOff("slopeflag");
AddParameter(ParameterType_InputImage, "initialallcloud", "initial all cloud image");
SetParameterDescription( "initialallcloud", "Input initial all cloud image");
MandatoryOn("initialallcloud");
AddRAMParameter();
AddParameter(ParameterType_OutputImage, "out", "Output image");
......@@ -68,6 +76,8 @@ public:
SetDocExampleParameterValue("pass2", "pass2.tif");
SetDocExampleParameterValue("cloudpass1", "cloud_pass1.tif");
SetDocExampleParameterValue("cloudrefine", "cloud_refine.tif");
SetDocExampleParameterValue("slopeflag", "slope_flag.tif");
SetDocExampleParameterValue("initialallcloud", "all_clouds.tif");
SetDocExampleParameterValue("out", "output_mask.tif");
}
......@@ -87,12 +97,19 @@ public:
InputImageType::Pointer img_pass2 = GetParameterImage<InputImageType>("pass2");
InputImageType::Pointer img_cloud_pass1 = GetParameterImage<InputImageType>("cloudpass1");
InputImageType::Pointer img_cloud_refine = GetParameterImage<InputImageType>("cloudrefine");
InputImageType::Pointer img_all_cloud = GetParameterImage<InputImageType>("initialallcloud");
m_SnowMaskFilter = SnowMaskFilterType::New();
m_SnowMaskFilter->SetInput(0, img_pass1);
m_SnowMaskFilter->SetInput(1, img_pass2);
m_SnowMaskFilter->SetInput(2, img_cloud_pass1);
m_SnowMaskFilter->SetInput(3, img_cloud_refine);
m_SnowMaskFilter->SetInput(4, img_all_cloud);
if(IsParameterEnabled("slopeflag")){
InputImageType::Pointer img_slope_flag = GetParameterImage<InputImageType>("slopeflag");
m_SnowMaskFilter->SetInput(5, img_slope_flag);
}
// Set the output image
SetParameterOutputImage("out", m_SnowMaskFilter->GetOutput());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment