Commit 3d87f5b1 authored by Rashad Kanavath's avatar Rashad Kanavath
Browse files

Python: fix hashbang line for python3

parent cd9aad2f
#!/usr/bin/env python
#!/usr/bin/env python3
# This script computes NOBS.tif, the number of clear observations to compute the SCD, SMOD and SOD syntheses
# In HAL the dependencies are loaded with module load lis/develop
# Author: Simon Gascoin
......@@ -29,5 +29,3 @@ with rasterio.Env():
with rasterio.open("{}/NOBS_{}.tif".format(outdir,outfile), 'w', **profile) as dst:
dst.write(S.astype(rasterio.uint16), 1)
#!/usr/bin/env python
#!/usr/bin/env python3
# This script computes the Permanent snow area AKA "PSL" in CoSIMS from annnual snow map outputs
# The PSL of a given year is defined as pixels where snow was always observed when possible from May 01 to Sep 01 of this year
# In HAL the dependencies are loaded with module load lis/develop
......@@ -9,7 +9,7 @@ import numpy as np
import os,sys
import numpy as np
# input file is input_dates.txt
# input file is input_dates.txt
# Example: f="/work/OT/siaa/Theia/Neige/SNOW_ANNUAL_MAP_LIS_1.5/S2_with_L8_Densification//T32TNS_20170901_20180831/tmpdir/multitemp_cloud_mask.vrt"
f=sys.argv[1]
......@@ -30,7 +30,7 @@ snow = srcSnow.read(range(idx,n))
obs = srcObs.read(range(idx,n))
# pixels in p are either snow (1), cloud (1) or no snow (0)
p=snow+obs
# PSL corresponds to pixels always flagged as snow or cloud
# PSL corresponds to pixels always flagged as snow or cloud
PSL=np.all(p,axis=0)
# output file suffix
......@@ -46,4 +46,3 @@ with rasterio.Env():
with rasterio.open("{}/PSL_{}.tif".format(fdir,outfile), 'w', **profile) as dst:
dst.write(PSL.astype(rasterio.uint8), 1)
#!/usr/bin/env python
#!/usr/bin/env python3
# This script computes the snow onset date (SOD) and the snow melt-out date (SMOD) from a stack of daily snow maps
# The dates are given in number of days since the first day of the synthesis (usually September 01)
# In HAL the dependencies are loaded with module load lis/develop
......@@ -9,12 +9,12 @@ import numpy as np
import itertools,operator,sys,os
# input file is the interpolated daily raster (1=snow,0=nosnow)
# 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
# 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)
# memory heavy, load all raster bands in memory
# 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(list(range(1,365)))
......@@ -41,9 +41,8 @@ with rasterio.Env():
with rasterio.open("{}/SMOD_{}".format(os.path.split(f)[0],os.path.split(f)[1]), 'w', **profile) as dst:
dst.write(SMOD.astype(rasterio.uint16), 1)
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")
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#=========================================================================
#
......@@ -287,5 +287,3 @@ if __name__== "__main__":
logging.basicConfig(stream=sys.stdout, level=logging.INFO, format=\
'%(asctime)s - %(filename)s:%(lineno)s - %(levelname)s - %(message)s')
main()
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#=========================================================================
#
......@@ -299,5 +299,3 @@ if __name__== "__main__":
logging.basicConfig(stream=sys.stdout, level=logging.INFO, format=\
'%(asctime)s - %(filename)s:%(lineno)s - %(levelname)s - %(message)s')
main()
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
......@@ -53,7 +53,7 @@ conf_template = {"general":{"pout":"",
"rm_snow_inside_cloud_min_area":5000},
"fsc": {
"dofsc": False,
"fscToc_Eq": "1.45*ndsi-0.01",
"fscToc_Eq": "1.45*ndsi-0.01",
"fscOg_Eq": "fscToc/(1-tcd)",
"tcd": "",
"cosims_mode": False
......@@ -179,8 +179,8 @@ LANDSAT8_LASRC_parameters = {"mode":"lasrc",
"dem":".*\.tif",
"shadow_in_mask":8,
"shadow_out_mask":8,
"all_cloud_mask":224, # cloud with high confidence (32+(64+128))
"high_cloud_mask":800, # cloud and high cloud with high confidence (32 + (512+256))
"all_cloud_mask":224, # cloud with high confidence (32+(64+128))
"high_cloud_mask":800, # cloud and high cloud with high confidence (32 + (512+256))
"rf":8}
mission_parameters = {"S2":S2_parameters,\
......@@ -257,8 +257,8 @@ def read_product(inputPath, mission):
# Use in case of SEN2COR to handle differences between maja and sen2cor encoding
if 'mode' in params:
conf_json["general"]["mode"] = params["mode"]
return conf_json
else:
logging.error(inputPath + " doesn't exist.")
......@@ -308,11 +308,11 @@ def main():
group_cloud.add_argument("-red_darkcloud", type=int)
group_cloud.add_argument("-red_backtocloud", type=int)
group_cloud.add_argument("-strict_cloud_mask", type=str2bool, help="true/false")
group_fsc = parser.add_argument_group('fsc', 'fractional snow cover parameters')
group_fsc.add_argument("-fsc", type=str, help="path to tree cover density file, automatically activates sets fsc: dofsc to true")
group_fsc.add_argument("-cosims_mode", action='store_true', help="CoSIMS mode : Generate CoSIMS formatted outputs.")
group_water_mask = parser.add_argument_group('water_mask', 'water mask parameters')
group_water_mask.add_argument("-water_mask_path", type=str, help="Path to a raster or a shapefile")
group_water_mask.add_argument("-water_mask_raster_value", type=int, action='append', help="If the input water_mask_path is a raster, you can specify all the values corresponding " + \
......@@ -325,7 +325,7 @@ def main():
outputPath = os.path.abspath(args.outputPath)
sentinel2Acronyms = ['S2', 'SENTINEL2', 'S2A', 'S2B']
# Test if it is a MAJA output products (generated with MAJA processor version XX)
# FIXME: This detection based on directory substring detection is very week and error prone
# FIXME: use a factory and detect by using xml metadata
......@@ -428,14 +428,14 @@ def main():
if not jsonData["inputs"].get("dem"):
logging.error("No DEM found!")
return 1
if args.fsc:
jsonData["fsc"]["dofsc"] = True
jsonData["fsc"]["tcd"] = os.path.abspath(args.fsc)
jsonData["fsc"]["cosims_mode"] = args.cosims_mode
else:
jsonData["fsc"]["dofsc"] = False
if args.water_mask_path is not None:
jsonData["water_mask"]["apply"] = True
suffix = args.water_mask_path.split('.')[-1].lower()
......
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
......@@ -27,17 +27,17 @@ def main(argv):
#load json_file from json files
with open(json_file) as json_data_file:
data = json.load(json_data_file)
general = data["general"]
pout = general.get("pout")
log = general.get("log", True)
if log:
sys.stdout = open(op.join(pout, "stdout.log"), 'w')
sys.stderr = open(op.join(pout, "stderr.log"), 'w')
cloud_removal.run(data)
if __name__ == "__main__":
if len(sys.argv) != 2 :
show_help()
......
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
......
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
......
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import sys
import numpy as np
from s2snow import cloud_removal
......
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import sys
import numpy as np
from s2snow import cloud_removal
......
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
......@@ -18,5 +18,5 @@ def main(argv):
if __name__ == "__main__":
# Set logging level and format.
logging.basicConfig(stream=sys.stdout, level=logging.INFO, format='%(asctime)s - %(filename)s:%(lineno)s - %(levelname)s - %(message)s')
main(sys.argv)
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
......@@ -21,5 +21,5 @@ def main(argv):
if __name__ == "__main__":
# Set logging level and format.
logging.basicConfig(stream=sys.stdout, level=logging.INFO, format='%(asctime)s - %(filename)s:%(lineno)s - %(levelname)s - %(message)s')
main(sys.argv)
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
......
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#=========================================================================
#
......@@ -30,16 +30,16 @@ def main(argv):
json_file = argv[0]
snow_mask = argv[1]
cloud_mask = argv[2]
# Load json_file from json files
with open(json_file) as json_data_file:
data = json.load(json_data_file)
#dummy json
sd = snow_detector.snow_detector(data)
#
sd.pass1_5(snow_mask, cloud_mask, 1, 0.85)
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#=========================================================================
#
......@@ -30,7 +30,7 @@ def load_histo(histo_path):
#print(v[:,1])
#print(v[:,2])
#b = np.zeros(6).reshape(2, 3)
#print(fsnow_rate)
print(fsnow_rate[0])
print(fsnow_rate)
......@@ -59,10 +59,10 @@ def print_histo(histo_path):
plt.bar(dem, v[:,1], width=width, color="red", label="all")
plt.bar([i+0.25*width for i in dem], v[:,2], width=0.5*width, color="blue", alpha=1. , label="snow")
plt.xticks(dem+width/2.,
plt.xticks(dem+width/2.,
[i for i in dem] )
plt.legend()
plt.legend()
plt.show()
def main():
......@@ -73,7 +73,7 @@ def main():
(opts, args) = parser.parse_args()
if opts.histo_path is None:
if opts.histo_path is None:
print("A mandatory option is missing\n")
parser.print_help()
exit(-1)
......@@ -82,4 +82,3 @@ def main():
if __name__ == '__main__':
main()
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