Commit 56acd4be authored by Tristan Klempka's avatar Tristan Klempka
Browse files

ENH: add s2 test and first support of s2 format

parent ca08bcde
{
"general":{
"pout":"/home/klempkat/let-it-snow/muscate/output",
"nodata":-10000,
"ram":1024,
"nb_threads":1,
"generate_vector":false,
"preprocessing":false,
"log":true
},
"inputs":{
"green_band": {
"path": "/home/grizonnetm/Data-Neige/MUSCATE/SENTINEL2A_20160217-111843-605_L2A_T29RNQ_D_V1-0/SENTINEL2A_20160217-111843-605_L2A_T29RNQ_D_V1-0_FRE_B3.tif",
"noBand": 1
},
"red_band": {
"path": "/home/grizonnetm/Data-Neige/MUSCATE/SENTINEL2A_20160217-111843-605_L2A_T29RNQ_D_V1-0/SENTINEL2A_20160217-111843-605_L2A_T29RNQ_D_V1-0_FRE_B4.tif",
"noBand": 1
},
"swir_band": {
"path": "/home/grizonnetm/Data-Neige/MUSCATE/SENTINEL2A_20160217-111843-605_L2A_T29RNQ_D_V1-0/SENTINEL2A_20160217-111843-605_L2A_T29RNQ_D_V1-0_FRE_B11.tif",
"noBand": 1
},
"dem":"/home/grizonnetm/Data-Neige/MUSCATE/MNT_S2_N2/S2__TEST_AUX_REFDE2_T29RNQ_0001_1.0/S2__TEST_AUX_REFDE2_T29RNQ_0001/S2__TEST_AUX_REFDE2_T29RNQ_0001.DBL.DIR/S2__TEST_AUX_REFDE2_T29RNQ_0001_ALT_R2.TIF",
"cloud_mask":"/home/grizonnetm/Data-Neige/MUSCATE/SENTINEL2A_20160217-111843-605_L2A_T29RNQ_D_V1-0/MASKS/SENTINEL2A_20160217-111843-605_L2A_T29RNQ_D_V1-0_CLM_R2.tif"
},
"cloud":
{
"shadow_mask":64,
"all_cloud_mask":0,
"high_cloud_mask":32,
"rf":8,
"red_darkcloud":650,
"red_backtocloud":100
},
"snow":{
"dz":100,
"ndsi_pass1":0.4,
"red_pass1":200,
"ndsi_pass2":0.15,
"red_pass2":120,
"fsnow_lim":0.1,
"fsnow_total_lim":0.001
}
}
......@@ -140,6 +140,7 @@ class snow_detector :
gb_dataset = gdal.Open(gb_path, GA_ReadOnly)
gb_path_extracted=op.join(self.path_tmp, "green_band_extracted.tif")
if gb_dataset.RasterCount > 1:
print "extracting band"
call_subprocess(["gdal_translate", "-of","GTiff","-ot","Int16","-a_nodata", str(self.nodata),"-b",str(gb_no),gb_path,gb_path_extracted])
else:
copyfile(gb_path, gb_path_extracted)
......@@ -151,12 +152,11 @@ class snow_detector :
rb_dataset = gdal.Open(rb_path, GA_ReadOnly)
rb_path_extracted=op.join(self.path_tmp, "red_band_extracted.tif")
if rb_dataset.RasterCount > 1:
print "extracting band"
call_subprocess(["gdal_translate", "-of","GTiff","-ot","Int16","-a_nodata", str(self.nodata),"-b",str(rb_no),rb_path,rb_path_extracted])
else:
copyfile(rb_path, rb_path_extracted)
swir_band=inputs["swir_band"]
sb_path=swir_band["path"]
sb_no=swir_band["noBand"]
......@@ -164,12 +164,12 @@ class snow_detector :
sb_dataset = gdal.Open(sb_path, GA_ReadOnly)
sb_path_extracted=op.join(self.path_tmp, "swir_band_extracted.tif")
if sb_dataset.RasterCount > 1:
print "extracting band"
call_subprocess(["gdal_translate", "-of","GTiff","-ot","Int16","-a_nodata", str(self.nodata),"-b",str(sb_no),sb_path,sb_path_extracted])
else:
copyfile(sb_path, sb_path_extracted)
#check for same res
gb_dataset = gdal.Open(gb_path_extracted, GA_ReadOnly)
rb_dataset = gdal.Open(rb_path_extracted, GA_ReadOnly)
......@@ -179,16 +179,25 @@ class snow_detector :
rb_resolution = rb_dataset.GetGeoTransform()[1]
sb_resolution = sb_dataset.GetGeoTransform()[1]
#test if different reso
gb_path_resampled=op.join(self.path_tmp, "green_band_resampled.tif")
rb_path_resampled=op.join(self.path_tmp, "red_band_resampled.tif")
sb_path_resampled=op.join(self.path_tmp, "swir_band_resampled.tif")
if not gb_resolution == rb_resolution == sb_resolution:
#gdalwarp to max reso
print "setting resolution"
max_res = max(gb_resolution, rb_resolution, sb_resolution)
call_subprocess(["gdalwarp","-r","cubic","-tr", str(max_res),str(max_res),gb_path,gb_path])
call_subprocess(["gdalwarp","-r","cubic","-tr", str(max_res),str(max_res),rb_path,rb_path])
call_subprocess(["gdalwarp","-r","cubic","-tr", str(max_res),str(max_res),sb_path,sb_path])
print str(max_res)
call_subprocess(["gdalwarp", "-overwrite","-r","cubic","-tr", str(max_res),str(max_res),gb_path_extracted,gb_path_resampled])
call_subprocess(["gdalwarp", "-overwrite","-r","cubic","-tr", str(max_res),str(max_res),rb_path_extracted,rb_path_resampled])
call_subprocess(["gdalwarp", "-overwrite","-r","cubic","-tr", str(max_res),str(max_res),sb_path_extracted,sb_path_resampled])
else:
gb_path_resampled=gb_path_extracted
rb_path_resampled=rb_path_extracted
sb_path_resampled=sb_path_extracted
#build vrt
self.img=op.join(self.path_tmp, "grs.vrt")
call_subprocess(["gdalbuildvrt","-separate", self.img, gb_path_extracted, rb_path_extracted, sb_path_extracted])
call_subprocess(["gdalbuildvrt","-separate", self.img, gb_path_resampled, rb_path_resampled, sb_path_resampled])
#Set bands parameters
self.nGreen=1
......
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