diff --git a/python/SoilMoistureBatchExtractAndMosaic2S2Tile.py b/python/SoilMoistureBatchExtractAndMosaic2S2Tile.py index 70ce1666b1a8f4ee139ecc808f73a905c2688912..2db35c4ed3ac7a913e4ae75b713847897073c064 100755 --- a/python/SoilMoistureBatchExtractAndMosaic2S2Tile.py +++ b/python/SoilMoistureBatchExtractAndMosaic2S2Tile.py @@ -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[4].split("T")[0] - acqtime = splitbname[4].split("T")[1] + acqdate = splitbname[-1].split("T")[0] + acqtime = splitbname[-1].split("T")[1] outfilebase = os.path.join(abspathout,"_".join(splitbname[:3])+"_"+tileid+"_"+acqdate+"T"+acqtime) @@ -153,9 +153,6 @@ 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" @@ -170,7 +167,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]]) diff --git a/python/SoilMoistureNdviGapfilling.py b/python/SoilMoistureNdviGapfilling.py index 11111a57bbf9f272e0859fe9f49bba6f1790fba8..62efc928e3b95be85a898c0cc73c7ba807be3678 100755 --- a/python/SoilMoistureNdviGapfilling.py +++ b/python/SoilMoistureNdviGapfilling.py @@ -6,7 +6,7 @@ Created on Wed Aug 28 13:55:34 2019 @author: llozach """ -import os,datetime, math +import os,datetime import argparse import otbApplication @@ -27,7 +27,6 @@ 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) @@ -36,96 +35,36 @@ 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") - for a in apps: - appConcat.AddImageToParameterInputImageList("il",a.GetParameterOutputImage("out")) + appConcat.SetParameterStringList("il", listinputimg) 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) - 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) +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) 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 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) - + 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 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 - 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)) + dstep = datetime.timedelta(weeks=4) + while procd < eddate: + procd = procd + dstep + procd = datetime.date(procd.year,procd.month,15) + outputdates.append(procd.strftime(exformat)) return outputdates @@ -138,6 +77,8 @@ 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') @@ -167,7 +108,7 @@ if __name__ == "__main__": listinput_img = [row[1] for row in parameters] listinput_mask = [row[2] for row in parameters] - listoutput_date = create_outputdates(listinput_date) + listoutput_date = create_outputdates(args.startdate, args.enddate, listinput_date) inputdatesfile = os.path.join(args.ndvidir,"InputDates.txt") outputdatesfile = os.path.join(args.ndvidir,"OutputDates.txt") @@ -183,44 +124,10 @@ 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") - 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() + appConcatImg = concate_images(listinput_img, otbApplication.ImagePixelType_uint8, "tempimg.tif") print("Concatenate MASK files : ") [print(" "+nm) for nm in listinput_mask] - #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() - - - - + appConcatMask = concate_images(listinput_mask, otbApplication.ImagePixelType_uint8, "tempmask.tif") # Gapfill print("Gapfilled NDVIs from input dates in "+inputdatesfile+" : ") diff --git a/python/SoilMoisturePipeline.py b/python/SoilMoisturePipeline.py index e30d2925c78612da57cc526a454653f834516b62..8fdf527360f96fcc3f457ca8d985fcefe9f1d836 100755 --- a/python/SoilMoisturePipeline.py +++ b/python/SoilMoisturePipeline.py @@ -733,10 +733,6 @@ 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()) @@ -744,8 +740,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) diff --git a/tools/docker/esa-snap/Dockerfile b/tools/docker/esa-snap/Dockerfile index 5380353b8605d84fb8e91bce393f11e13fbcd224..f198f73b71b404fb96a6fe0d0d857f0645678efb 100755 --- a/tools/docker/esa-snap/Dockerfile +++ b/tools/docker/esa-snap/Dockerfile @@ -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/7.0/installers/esa-snap_sentinel_unix_7_0.sh \ + && wget http://step.esa.int/downloads/6.0/installers/esa-snap_sentinel_unix_6_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_7_0.sh \ + && chmod +x esa-snap_sentinel_unix_6_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_7_0.sh \ + && echo "\n\n/home/lozach/esa-snap/snap\n\nn\n\nn\n" | sudo -u lozach ./esa-snap_sentinel_unix_6_0.sh \ && sudo -u lozach ./Sen2Cor-02.08.00-Linux64.run diff --git a/tools/docker/otbtf-soilmoisture-withuser/Dockerfile b/tools/docker/otbtf-soilmoisture-withuser/Dockerfile index c9b42a069819530d59247ce51d29b7dbf4890f13..7f174a9d59e835b5d3248f457a8c1ef1134410a2 100755 --- a/tools/docker/otbtf-soilmoisture-withuser/Dockerfile +++ b/tools/docker/otbtf-soilmoisture-withuser/Dockerfile @@ -1,4 +1,4 @@ -FROM mdl4eo/otbtf1.6 +FROM mdl4eo/otbtf1.6:nouser MAINTAINER Loic Lozach <loic.lozach[at]irstea[dot]fr> @@ -12,7 +12,6 @@ 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)