Commit 9d590d89 authored by Lozac'h Loic's avatar Lozac'h Loic

Sync depot

parents a8bb2a6b e954db38
......@@ -77,7 +77,7 @@ def exmos_pipeline(argsformat, mos1, mos2, ref, out):
app0.SetParameterString("interpolator","nn")
app0.SetParameterString("inr",ref)
app0.Execute()
print("debug app0")
app1 = otbApplication.Registry.CreateApplication("Superimpose")
app1.SetParameterString("inm",mos2)
......@@ -143,8 +143,8 @@ if __name__ == "__main__":
continue
bname = os.path.basename(file).split(".")[0]
splitbname = bname.split("_")
acqdate = splitbname[-1].split("T")[0]
acqtime = splitbname[-1].split("T")[1]
acqdate = splitbname[4].split("T")[0]
acqtime = splitbname[4].split("T")[1]
outfilebase = os.path.join(abspathout,"_".join(splitbname[:3])+"_"+tileid+"_"+acqdate+"T"+acqtime)
......@@ -153,6 +153,9 @@ if __name__ == "__main__":
if len(l) == 2 :
dejafait.append(indir[l[0]])
dejafait.append(indir[l[1]])
in1 = os.path.join(indir[l[0]], "Sigma0_VV.img")
in2 = os.path.join(indir[l[1]], "Sigma0_VV.img")
outfile = outfilebase +"_VV.TIF"
......@@ -167,7 +170,7 @@ if __name__ == "__main__":
outfile = outfilebase +"_THETA.TIF"
exmos_pipeline(args.format, in1, in2, args.inref, outfile)
dejafait.append(indir[l[0]])
dejafait.append(indir[l[1]])
......
......@@ -6,7 +6,7 @@ Created on Wed Aug 28 13:55:34 2019
@author: llozach
"""
import os,datetime
import os,datetime, math
import argparse
import otbApplication
......@@ -27,6 +27,7 @@ def search_files(directory='.', extension='tif', resolution='NDVI'):
return images
def create_mask(ndvi,mask):
app1 = otbApplication.Registry.CreateApplication("BandMath")
app1.AddParameterStringList("il",ndvi)
app1.SetParameterString("out", mask)
......@@ -35,36 +36,96 @@ def create_mask(ndvi,mask):
app1.ExecuteAndWriteOutput()
def concate_images(listinputimg, pixeltype, output):
apps=[]
for img in listinputimg:
app0 = otbApplication.Registry.CreateApplication("Superimpose")
app0.SetParameterString("inm", img)
app0.SetParameterString("out", "supimp.tif")
app0.SetParameterString("inr", listinputimg[0])
app0.SetParameterString("interpolator", "nn")
app0.Execute()
apps.append(app0)
print('---\nConcatenation to {}...'.format(output))
appConcat = otbApplication.Registry.CreateApplication("ConcatenateImages")
appConcat.SetParameterStringList("il", listinputimg)
for a in apps:
appConcat.AddImageToParameterInputImageList("il",a.GetParameterOutputImage("out"))
appConcat.SetParameterString("out", output)
appConcat.SetParameterOutputImagePixelType("out", pixeltype)
#appConcat.SetParameterOutputImagePixelType("out", pixeltype)
appConcat.Execute()
return appConcat
def monthrange(start_date, end_date):
# print("MonthRange: "+str (math.floor((end_date - start_date).days/31)))
# for n in range(int (math.floor((end_date - start_date).days/31))+1):
# yield start_date + datetime.timedelta(days=n*31)
qannee = end_date.year - start_date.year
dmois = end_date.month +12*(qannee) - start_date.month
yield start_date
anneesuiv = start_date.year
for m in range(dmois-1):
m+=1
moissuiv = (start_date.month + m) % 12
if moissuiv == 0 :
moissuiv = 12
if moissuiv == 1 :
anneesuiv = anneesuiv+1
yield datetime.date(anneesuiv,moissuiv,1)
def create_outputdates(startdate, enddate, listinput_date):
stdate = datetime.date(int(startdate[:4]),int(startdate[4:6]),15)
eddate = datetime.date(int(enddate[:4]),int(enddate[4:6]),15)
yield end_date
def create_outputdates(listinput_date):
# stdate = datetime.date(int(startdate[:4]),int(startdate[4:6]),1)
# eddate = datetime.date(int(enddate[:4]),int(enddate[4:6]),15)
inst = datetime.date(int(listinput_date[0][:4]),int(listinput_date[0][4:6]),int(listinput_date[0][6:8]))
ined = datetime.date(int(listinput_date[-1][:4]),int(listinput_date[-1][4:6]),int(listinput_date[-1][6:8]))
if (stdate < inst or eddate > ined):
print("Error: Output dates provided are outside the images time serie.")
exit
if (stdate >= eddate):
print("Error: Output dates provided are not valid.")
exit
if inst.day > 15:
stdate = datetime.date(inst.year,inst.month +1,1)
else:
stdate = datetime.date(inst.year,inst.month,15)
if ined.day >= 15:
eddate = datetime.date(ined.year,ined.month,15)
else:
eddate = datetime.date(ined.year,ined.month,1)
exformat = "%Y%m%d"
print("Start date: "+stdate.strftime(exformat))
print("End date: "+eddate.strftime(exformat))
outputdates=[]
outputdates.append(stdate.strftime(exformat))
#outputdates.append(stdate.strftime(exformat))
procd = stdate
dstep = datetime.timedelta(weeks=4)
while procd < eddate:
procd = procd + dstep
procd = datetime.date(procd.year,procd.month,15)
outputdates.append(procd.strftime(exformat))
for dstep in monthrange(stdate, eddate):
procd = dstep
if dstep == stdate:
if stdate.day == 1:
outputdates.append(procd.strftime(exformat))
procd = datetime.date(dstep.year,dstep.month,15)
outputdates.append(procd.strftime(exformat))
else:
outputdates.append(procd.strftime(exformat))
elif dstep == eddate:
if eddate.day == 1:
outputdates.append(procd.strftime(exformat))
else:
procd = datetime.date(dstep.year,dstep.month,1)
outputdates.append(procd.strftime(exformat))
procd = datetime.date(dstep.year,dstep.month,15)
outputdates.append(procd.strftime(exformat))
else:
procd = datetime.date(dstep.year,dstep.month,1)
outputdates.append(procd.strftime(exformat))
procd = datetime.date(dstep.year,dstep.month,15)
outputdates.append(procd.strftime(exformat))
return outputdates
......@@ -77,8 +138,6 @@ if __name__ == "__main__":
""")
parser.add_argument('-ndvidir', action='store', required=True, help='Directory containing time serie NDVI to be gapfilled')
parser.add_argument('-startdate', action='store', required=True, help='Start date for output gapfilled NDVIs (first date in input must be before), ex. 201809')
parser.add_argument('-enddate', action='store', required=True, help='End date for output gapfilled NDVIs (last date in input must be after), ex. 201908')
parser.add_argument('-outmaskdir', action='store', required=True, help='Output directory for NDVIs mask used for gapfilling')
parser.add_argument('-interpolation', choices=['linear', 'spline'], default='linear', required=False, help='Interpolation mode for OTB ImageTimeSeriesGapFilling')
parser.add_argument('-outdir', action='store', required=True, help='Output directory for time serie gapfilled NDVIs image')
......@@ -108,7 +167,7 @@ if __name__ == "__main__":
listinput_img = [row[1] for row in parameters]
listinput_mask = [row[2] for row in parameters]
listoutput_date = create_outputdates(args.startdate, args.enddate, listinput_date)
listoutput_date = create_outputdates(listinput_date)
inputdatesfile = os.path.join(args.ndvidir,"InputDates.txt")
outputdatesfile = os.path.join(args.ndvidir,"OutputDates.txt")
......@@ -124,10 +183,44 @@ if __name__ == "__main__":
# Concatenate
print("Concatenate NDVI files : ")
[print(" "+nm) for nm in listinput_img]
appConcatImg = concate_images(listinput_img, otbApplication.ImagePixelType_uint8, "tempimg.tif")
#appConcatImg = concate_images(listinput_img, otbApplication.ImagePixelType_uint8, "tempimg.tif")
apps=[]
for img in listinput_img:
app0 = otbApplication.Registry.CreateApplication("Superimpose")
app0.SetParameterString("inm", img)
app0.SetParameterString("out", "supimp.tif")
app0.SetParameterString("inr", listinput_img[0])
app0.SetParameterString("interpolator", "nn")
app0.Execute()
apps.append(app0)
appConcatImg = otbApplication.Registry.CreateApplication("ConcatenateImages")
for a in apps:
appConcatImg.AddImageToParameterInputImageList("il",a.GetParameterOutputImage("out"))
# appConcatImg.SetParameterStringList("il", listinput_img)
appConcatImg.SetParameterString("out", "tempimg.tif")
appConcatImg.Execute()
print("Concatenate MASK files : ")
[print(" "+nm) for nm in listinput_mask]
appConcatMask = concate_images(listinput_mask, otbApplication.ImagePixelType_uint8, "tempmask.tif")
#appConcatMask = concate_images(listinput_mask, otbApplication.ImagePixelType_uint8, "tempmask.tif")
appsm=[]
for img in listinput_mask:
app0 = otbApplication.Registry.CreateApplication("Superimpose")
app0.SetParameterString("inm", img)
app0.SetParameterString("out", "supimp.tif")
app0.SetParameterString("inr", listinput_img[0])
app0.SetParameterString("interpolator", "nn")
app0.Execute()
appsm.append(app0)
appConcatMask = otbApplication.Registry.CreateApplication("ConcatenateImages")
for a in appsm:
appConcatMask.AddImageToParameterInputImageList("il",a.GetParameterOutputImage("out"))
# appConcatMask.SetParameterStringList("il", listinput_mask)
appConcatMask.SetParameterString("out", "tempmask.tif")
appConcatMask.Execute()
# Gapfill
print("Gapfilled NDVIs from input dates in "+inputdatesfile+" : ")
......
......@@ -733,6 +733,10 @@ if __name__ == "__main__":
print("Error: Exception on sarmode")
exit
if os.path.exists(output):
print(output+" already exists! Passing...")
continue
print("using: \n"+sarvv+" \n"+sarth+" \n"+ndvi+" \n"+output)
short_pipeline(normalize_proj_and_extend())
......@@ -740,8 +744,8 @@ if __name__ == "__main__":
elif args.pipeline == 'stack' :
if not os.path.isdir(args.ndvidir):
print("erreur "+args.ndvidir+" n'est pas un dossier")
exit
print("erreur "+args.ndvidir+" n'est pas un dossier")
exit
ndvis=[]
ndvis=search_files(args.ndvidir)
......
......@@ -25,7 +25,7 @@ RUN export uid=1001 gid=1001 && \
# Download Snap + Sen2Cor
# ----------------------------------------------------------------------------
RUN cd /home/lozach/esa-snap \
&& wget http://step.esa.int/downloads/6.0/installers/esa-snap_sentinel_unix_6_0.sh \
&& wget http://step.esa.int/downloads/7.0/installers/esa-snap_sentinel_unix_7_0.sh \
&& wget http://step.esa.int/thirdparties/sen2cor/2.8.0/Sen2Cor-02.08.00-Linux64.run
# ----------------------------------------------------------------------------
......@@ -33,9 +33,9 @@ RUN cd /home/lozach/esa-snap \
# ----------------------------------------------------------------------------
RUN cd /home/lozach/esa-snap \
&& chown -R lozach:lozach /home/lozach \
&& chmod +x esa-snap_sentinel_unix_6_0.sh \
&& chmod +x esa-snap_sentinel_unix_7_0.sh \
&& chmod +x Sen2Cor-02.08.00-Linux64.run \
&& echo "\n\n/home/lozach/esa-snap/snap\n\nn\n\nn\n" | sudo -u lozach ./esa-snap_sentinel_unix_6_0.sh \
&& echo "\n\n/home/lozach/esa-snap/snap\n\nn\n\nn\n" | sudo -u lozach ./esa-snap_sentinel_unix_7_0.sh \
&& sudo -u lozach ./Sen2Cor-02.08.00-Linux64.run
......
FROM mdl4eo/otbtf1.6:nouser
FROM mdl4eo/otbtf1.6
MAINTAINER Loic Lozach <loic.lozach[at]irstea[dot]fr>
......@@ -12,6 +12,7 @@ RUN cd /work/otb/otb/Modules/Remote \
&& cd /work/otb/build/OTB/build \
&& cmake /work/otb/otb \
-DModule_AgriSoilMoisture=ON \
-DModule_OTBTemporalGapFilling=ON \
&& cd /work/otb/build/ \
&& make -j $(grep -c ^processor /proc/cpuinfo)
......
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