Commit 497d26fc authored by Rémi Jugier's avatar Rémi Jugier
Browse files

update python3 + OTB7 working solution

parent f91262a6
......@@ -10,12 +10,12 @@ VERSION="0.1"
def show_help():
"""Show help of the run_cloud_removal script"""
print "Usage: python run_cloud_removal.py param.json"
print "python run_cloud_removal.py version to show version"
print "python run_cloud_removal.py help to show help"
print("Usage: python run_cloud_removal.py param.json")
print("python run_cloud_removal.py version to show version")
print("python run_cloud_removal.py help to show help")
def show_version():
print VERSION
print(VERSION)
#----------------- MAIN ---------------------------------------------------
......
......@@ -12,15 +12,15 @@ VERSION = "0.1.0"
def show_help():
"""Show help of the run_snow_annual_map script"""
print "This script is used to run the snow annual map " \
+ "module that compute snow coverage onto a given date range"
print "Usage: python run_snow_annual_map.py param.json"
print "python run_snow_annual_map.py version to show version"
print "python run_snow_annual_map.py help to show help"
print("This script is used to run the snow annual map " \
+ "module that compute snow coverage onto a given date range")
print("Usage: python run_snow_annual_map.py param.json")
print("python run_snow_annual_map.py version to show version")
print("python run_snow_annual_map.py help to show help")
def show_version():
print VERSION
print(VERSION)
# ----------------- MAIN ---------------------------------------------------
......
......@@ -11,15 +11,15 @@ from s2snow.version import VERSION
def show_help():
"""Show help of the run_snow_detector script"""
print "This script is used to run the snow detector module that compute snow mask" \
+ " using OTB applications on Spot/LandSat/Sentinel-2 products from theia platform"
print "Usage: python run_snow_detector.py param.json"
print "python run_snow_detector.py version to show version"
print "python run_snow_detector.py help to show help"
print("This script is used to run the snow detector module that compute snow mask" \
+ " using OTB applications on Spot/LandSat/Sentinel-2 products from theia platform")
print("Usage: python run_snow_detector.py param.json")
print("python run_snow_detector.py version to show version")
print("python run_snow_detector.py help to show help")
def show_version():
print VERSION
print(VERSION)
# ----------------- MAIN ---------------------------------------------------
......
......@@ -12,12 +12,12 @@ import itertools,operator,sys,os
# Example: /work/OT/siaa/Theia/Neige/SNOW_ANNUAL_MAP_LIS_1.5/S2_with_L8_Densification//T31TCH_20160901_20170831/DAILY_SNOW_MASKS_T31TCH_20160901_20170831.tif
f=sys.argv[1]
src=rasterio.open(f, 'r')
print "Start compute_SOD_SMOD.py using: ",f
print("Start compute_SOD_SMOD.py using: ",f)
# memory heavy, load all raster bands in memory
# runs in 23 min in HAl with 100 Gb RAM: qsub -I -l select=1:ncpus=4:mem=100000mb -l walltime=05:00:00
# 20 Gb should be fine: qsub -I -l walltime=00:50:00 -l select=1:ncpus=1:mem=20000mb
W = src.read(range(1,365))
W = src.read(list(range(1,365)))
n=np.shape(W)[1]
m=np.shape(W)[2]
......@@ -45,5 +45,5 @@ with rasterio.Env():
with rasterio.open("{}/SOD_{}".format(os.path.split(f)[0],os.path.split(f)[1]), 'w', **profile) as dst:
dst.write(SOD.astype(rasterio.uint16), 1)
print "End of compute_SOD_SMOD.py"
print("End of compute_SOD_SMOD.py")
This diff is collapsed.
This diff is collapsed.
......@@ -40,7 +40,7 @@ def band_math(il, out, exp, ram=None, out_type=None):
bandMathApp = otb.Registry.CreateApplication("BandMath")
bandMathApp.SetParameterString("exp", exp)
for image in il:
if isinstance(image, basestring):
if isinstance(image, str):
bandMathApp.AddParameterStringList("il", image)
else:
bandMathApp.AddImageToParameterInputImageList("il", image)
......@@ -155,7 +155,7 @@ def band_mathX(il, out, exp, ram=None, out_type=None):
bandMathApp = otb.Registry.CreateApplication("BandMathX")
bandMathApp.SetParameterString("exp", exp)
for image in il:
if isinstance(image, basestring):
if isinstance(image, str):
bandMathApp.AddParameterStringList("il", image)
else:
bandMathApp.AddImageToParameterInputImageList("il", image)
......@@ -199,10 +199,14 @@ def compute_snow_line(img_dem, img_snow, img_cloud, dz, fsnowlim, fclearlim, \
snowLineApp.SetParameterFloat("fsnowlim", fsnowlim)
snowLineApp.SetParameterFloat("fclearlim", fclearlim)
snowLineApp.SetParameterInt("offset", offset)
if not isinstance(centeroffset, int):
print("WARNING: centeroffset shoud be an interger, got %s instead with value %s => converting to int"%(type(centeroffset), centeroffset))
centeroffset = int(centeroffset)
snowLineApp.SetParameterInt("centeroffset", centeroffset)
if reverse:
snowLineApp.SetParameterString("reverse", "true")
snowLineApp.SetParameterInt("reverse", 1)
else:
snowLineApp.SetParameterInt("reverse", 0)
if ram is not None:
logging.info("ram = " + str(ram))
......@@ -304,8 +308,10 @@ def compute_contour(img_in, img_out, foreground_value, fullyconnected, \
logging.info("out = " + img_out)
cloudMaskApp.SetParameterString("out", img_out)
if fullyconnected:
cloudMaskApp.SetParameterString("fullyconnected", "true")
cloudMaskApp.SetParameterInt("fullyconnected", 1)
cloudMaskApp.SetParameterString("inputmask", img_in)
else:
cloudMaskApp.SetParameterInt("fullyconnected", 0)
if ram is not None:
logging.info("ram = " + str(ram))
cloudMaskApp.SetParameterString("ram", str(ram))
......
......@@ -124,7 +124,7 @@ def step1(m2_path, m1_path, t0_path, p1_path, p2_path, output_path, ram):
def step2(t0_path, dem_path, output_path, ram):
percentage_cloud = compute_cloudpercent(t0_path)
print("cloud percent : " + str(percentage_cloud))
print(("cloud percent : " + str(percentage_cloud)))
# Perform step 2 only if cloud coverage is less than a threshold value
# (hard coded for now to 30%)
......@@ -133,7 +133,7 @@ def step2(t0_path, dem_path, output_path, ram):
if cloudpercent_condition:
# S(y,x,t) = 1 if (H(x,y) < Hsmin(t))
hs_min = compute_HSmin(t0_path, dem_path)
print("hs_min: " + str(hs_min))
print(("hs_min: " + str(hs_min)))
call(["otbcli_BandMath",
"-ram",
str(ram),
......@@ -145,7 +145,7 @@ def step2(t0_path, dem_path, output_path, ram):
"-exp",
"im1b1==205?(im2b1<" + str(hs_min) + "?0:im1b1):im1b1"])
hs_max = compute_HSmax(t0_path, dem_path)
print("hs_max: " + str(hs_max))
print(("hs_max: " + str(hs_max)))
# S(y,x,t) = 1 if (H(x,y) > Hsmax(t))
call(["otbcli_BandMath",
"-ram",
......@@ -333,7 +333,7 @@ def format_percent(array, total_cloud):
def plot_stats(array):
steps = range(0, array.shape[0])
steps = list(range(0, array.shape[0]))
TCE = array[:, 0]
TRUE = array[:, 1]
FALSE = array[:, 2]
......
......@@ -94,9 +94,9 @@ def build_dem(psrtm, pimg, pout, ram, nbThreads):
)
except subprocess.CalledProcessError as e:
print e.output
print 'Error running command: ' + str(e.cmd) + ' see above shell error'
print 'Return code: ' + str(e.returncode)
print(e.output)
print('Error running command: ' + str(e.cmd) + ' see above shell error')
print('Return code: ' + str(e.returncode))
return e.returncode
def main(argv):
......
......@@ -23,11 +23,11 @@ def main(argv):
# Find potential
if snow_percent > minsnowthreshold and cloud_percent > mincloudthreshold and snow_percent < maxsnowthreshold and cloud_percent < maxcloudthreshold :
print(root)
print("snow percent: " + str(snow_percent))
print("cloud percent: " + str(cloud_percent))
print(("snow percent: " + str(snow_percent)))
print(("cloud percent: " + str(cloud_percent)))
total_images += 1
print("total images :" + str(total_images))
print(("total images :" + str(total_images)))
if __name__ == "__main__":
if len(sys.argv) != 5:
......
......@@ -113,7 +113,7 @@ def merge_masks_at_same_date(snow_product_list, merged_snow_product, threshold=1
# the order of the images in the input list is important:
# we expect to have first the main input products
# and then the densification products
img_index = range(1, len(snow_product_list)+1)
img_index = list(range(1, len(snow_product_list)+1))
expression_merging = "".join(["(im" + str(i) + "b1<=" + str(threshold) + "?im" + str(i) + "b1:" for i in img_index])
expression_merging += "im"+str(img_index[-1])+"b1"
expression_merging += "".join([")" for i in img_index])
......@@ -209,7 +209,7 @@ class snow_annual_map():
if densification_product_dict:
# Reproject the densification products on S2 tile before going further
for densifier_product_key in densification_product_dict.keys():
for densifier_product_key in list(densification_product_dict.keys()):
for densifier_product in densification_product_dict[densifier_product_key]:
original_mask = densifier_product.get_snow_mask()
reprojected_mask = op.join(self.path_tmp,
......@@ -228,7 +228,7 @@ class snow_annual_map():
logging.debug(densifier_product.snow_mask)
# Add the products to extend the self.product_dict
if densifier_product_key in self.product_dict.keys():
if densifier_product_key in list(self.product_dict.keys()):
self.product_dict[densifier_product_key].extend(densification_product_dict[densifier_product_key])
else:
self.product_dict[densifier_product_key] = densification_product_dict[densifier_product_key]
......@@ -255,7 +255,7 @@ class snow_annual_map():
# merge products at the same date
self.resulting_snow_mask_dict={}
for key in self.product_dict.keys():
for key in list(self.product_dict.keys()):
if len(self.product_dict[key]) > 1:
merged_mask = op.join(self.path_tmp, key + "_merged_snow_product.tif")
merge_masks_at_same_date(self.product_dict[key],
......@@ -286,7 +286,7 @@ class snow_annual_map():
separate=True)
# generate the summary map
band_index = range(1, len(self.binary_cloudmask_list)+1)
band_index = list(range(1, len(self.binary_cloudmask_list)+1))
expression = "+".join(["im1b" + str(i) for i in band_index])
bandMathApp = band_math([self.multitemp_cloud_vrt],
......@@ -327,7 +327,7 @@ class snow_annual_map():
app_gap_filling = None
# generate the annual map
band_index = range(1, len(output_dates)+1)
band_index = list(range(1, len(output_dates)+1))
expression = "+".join(["im1b" + str(i) for i in band_index])
bandMathApp = band_math([img_in],
......@@ -368,7 +368,7 @@ class snow_annual_map():
if (product_type is not None) and (product_type not in product.platform):
test_result = False
if test_result:
if current_day not in product_dict.keys():
if current_day not in list(product_dict.keys()):
product_dict[current_day] = [product]
else:
product_dict[current_day].append(product)
......
......@@ -98,18 +98,18 @@ def get_raster_intersection(raster1, raster2):
Return the instersection polygon and the associated projection
"""
poly1, srs1 = get_raster_extent_as_poly(raster1)
print("poly1", poly1)
print(("poly1", poly1))
poly2, srs2 = get_raster_extent_as_poly(raster2)
print("poly2", poly2)
print(("poly2", poly2))
# convert poly2 into poly1 ProjectionRef
transform = osr.CoordinateTransformation(srs2, srs1)
poly2.Transform(transform)
print("poly2 transformed", poly2)
print(("poly2 transformed", poly2))
intersection = poly2.Intersection(poly1)
print("intersection", intersection)
print(("intersection", intersection))
#return also the srs in which is expressed the intersection
return intersection, srs1
......@@ -159,7 +159,7 @@ class snow_annual_map_evaluation(snow_annual_map):
# load required product
self.resulting_snow_mask_dict={}
for key in self.product_dict.keys():
for key in list(self.product_dict.keys()):
comparison_tag = key + "_comparison"
if len(self.product_dict[key]) > 1:
merged_mask = op.join(self.path_tmp, comparison_tag + "_merged_snow_product.tif")
......@@ -202,7 +202,7 @@ class snow_annual_map_evaluation(snow_annual_map):
# compare the two snow masks
comparision_list = []
for comparison_date in pair_dict.keys():
for comparison_date in list(pair_dict.keys()):
s2_index, comparison_index = pair_dict[comparison_date]
path_extracted = op.join(self.path_tmp, "gapfilled_s2_" + comparison_date + ".tif")
......@@ -279,7 +279,7 @@ class snow_annual_map_evaluation(snow_annual_map):
modis_stop_index = i
# generate the summary map
band_index = range(modis_start_index+1, modis_stop_index+2)
band_index = list(range(modis_start_index+1, modis_stop_index+2))
expression = "+".join(["(im1b" + str(i) + "==200?1:0)" for i in band_index])
if not op.exists(self.modis_annual_snow_map):
......
......@@ -662,7 +662,7 @@ class snow_detector:
# compute individual snow area size
(labels, label_counts)= np.unique(snowlabels, return_counts=True)
labels_area = dict(zip(labels, label_counts))
labels_area = dict(list(zip(labels, label_counts)))
logging.debug(labels_area)
logging.debug("Start loop on snow areas")
......
......@@ -145,23 +145,23 @@ def main():
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
a = snow_product("/work/OT/siaa/Theia/S2L2A/data_production_muscate_juillet2017/L2B-SNOW/SENTINEL2A_20170314-104411-573_L2B-SNOW_T31TGK_D_V1-0")
print a.get_snow_mask()
print(a.get_snow_mask())
a.extract_snow_mask(".")
print a.get_snow_mask()
print a.get_metadata()
print a.acquisition_date
print(a.get_snow_mask())
print(a.get_metadata())
print(a.acquisition_date)
b = snow_product("/work/OT/siaa/Theia/Neige/output_muscate_v2pass2red40/T31TGL/SENTINEL2A_20151230-105153-392_L2A_T31TGL_D_V1-0")
print b.get_snow_mask()
print(b.get_snow_mask())
b.extract_snow_mask(".")
print b.get_snow_mask()
print b.get_metadata()
print(b.get_snow_mask())
print(b.get_metadata())
c = snow_product("/work/OT/siaa/Theia/Neige/output_muscate_v2pass2red40/Landsat-8/D0005H0001/LANDSAT8_OLITIRS_XS_20160812_N2A_France-MetropoleD0005H0001")
print c.get_snow_mask()
print(c.get_snow_mask())
c.extract_snow_mask(".")
print c.get_snow_mask()
print c.get_metadata()
print(c.get_snow_mask())
print(c.get_metadata())
if __name__ == '__main__':
main()
......@@ -35,7 +35,7 @@ public:
SetDescription("Compute Cloud Mask application");
// Documentation
SetDocName("Application for Compute Cloud Mask");
//~ SetDocName("Application for Compute Cloud Mask");
SetDocLongDescription("This application does compute the cloud mask");
SetDocLimitations("None");
SetDocAuthors("Germain SALGUES");
......
......@@ -36,7 +36,7 @@ public:
SetDescription("Compute Contours application");
// Documentation
SetDocName("Application for Computing Contours");
//~ SetDocName("Application for Computing Contours");
SetDocLongDescription("This application does compute the contours of the final mask");
SetDocLimitations("None");
SetDocAuthors("Germain SALGUES");
......@@ -56,9 +56,8 @@ public:
MandatoryOff("backgroundvalue");
SetDefaultParameterInt("backgroundvalue", 0);
AddParameter(ParameterType_Empty, "fullyconnected", "cloud refine image");
AddParameter(ParameterType_Int, "fullyconnected", "cloud refine image");
SetParameterDescription( "fullyconnected", "Input cloud refine image");
DisableParameter("fullyconnected");
AddRAMParameter();
......@@ -94,7 +93,7 @@ public:
m_ContourFilter->SetBackgroundValue(0);
m_ContourFilter->SetBackgroundValue(GetParameterInt("backgroundvalue"));
m_ContourFilter->SetFullyConnected(IsParameterEnabled("fullyconnected"));
m_ContourFilter->SetFullyConnected(GetParameterInt("fullyconnected")==1);
// Set the output image
SetParameterOutputImage("out", m_ContourFilter->GetOutput());
......
......@@ -35,7 +35,7 @@ public:
SetDescription("Compute Snow line application");
// Documentation
SetDocName("Application to compute the snow line");
//~ SetDocName("Application to compute the snow line");
SetDocLongDescription("This application does compute the ZS value and output the histogram of snow pixels per altitude slices.");
SetDocLimitations("None");
SetDocAuthors("Manuel Grizonnet");
......
......@@ -35,7 +35,7 @@ public:
SetDescription("Compute Snow line application");
// Documentation
SetDocName("Application to compute the snow line");
//~ SetDocName("Application to compute the snow line");
SetDocLongDescription("This application does compute the ZS value and output the histogram of snow pixels per altitude slices.");
SetDocLimitations("None");
SetDocAuthors("Manuel Grizonnet");
......@@ -60,10 +60,8 @@ public:
AddParameter(ParameterType_Float, "fclearlim", "fclearlim");
SetParameterDescription("fclearlim", "fclearlim");
AddParameter(ParameterType_Empty, "reverse", "reverse");
AddParameter(ParameterType_Int, "reverse", "reverse");
SetParameterDescription("reverse", "reverse");
MandatoryOff("reverse");
DisableParameter("reverse");
AddParameter(ParameterType_Int, "offset", "offset");
SetParameterDescription("offset", "offset");
......@@ -130,7 +128,7 @@ public:
GetParameterInt("dz"),
GetParameterFloat("fsnowlim"),
GetParameterFloat("fclearlim"),
IsParameterEnabled("reverse"),
GetParameterInt("reverse")==1,
GetParameterInt("offset"),
GetParameterInt("centeroffset"),
GetParameterAsString("outhist").c_str()
......
......@@ -36,7 +36,7 @@ public:
SetDescription("Compute Snow Mask application");
// Documentation
SetDocName("Application for Compute Snow Mask");
//~ SetDocName("Application for Compute Snow Mask");
SetDocLongDescription("This application does compute the snow mask");
SetDocLimitations("None");
SetDocAuthors("Germain SALGUES");
......
......@@ -27,14 +27,14 @@ def load_histo(histo_path):
fsnow_rate=v[:,1]/(v[:,1]+v[:,2])
#print v[:,1]
#print v[:,2]
#print(v[:,1])
#print(v[:,2])
#b = np.zeros(6).reshape(2, 3)
#print fsnow_rate
print fsnow_rate[0]
print fsnow_rate
print np.shape(fsnow_rate)[0]
#print(fsnow_rate)
print(fsnow_rate[0])
print(fsnow_rate)
print(np.shape(fsnow_rate)[0])
plt.plot(np.arange(np.shape(fsnow_rate)[0]), fsnow_rate[:], 'ro')
#plt.axis([0, 6, 0, 20])
plt.show()
......@@ -50,7 +50,7 @@ def print_histo(histo_path):
#n, bins, patches = ax1.hist(v_hist, bins=50, normed=1, facecolor='green')
#plt.show()
print v
print(v)
dem=v[:,0]
width = 0.8
......@@ -74,7 +74,7 @@ def main():
(opts, args) = parser.parse_args()
if opts.histo_path is None:
print "A mandatory option is missing\n"
print("A mandatory option is missing\n")
parser.print_help()
exit(-1)
else:
......
Supports Markdown
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