Commit b0d5a970 authored by Gaetano Raffaele's avatar Gaetano Raffaele
Browse files

Temporal smoothing (Savitzky Golay) script (pre).

parent 6643f164
......@@ -3,7 +3,7 @@ import datetime
import os
import subprocess
def temporalSmoothing(fld,template='MOD13Q1.006__250m_16_days_NDVI_',date_pos=34,date_len=7,date_jul=True,ext='tif',sgdeg=4,sgrad=6):
def temporalSmoothing(fld,template='MOD13Q1.006__250m_16_days_NDVI_',date_pos=34,date_len=7,date_jul=True,ext='tif',sgdeg=4,sgrad=6,clip_valid=23,clip_both_sides=True):
lst = sorted(glob.glob(fld + '/' + template + '*.' + ext))
......@@ -19,5 +19,20 @@ def temporalSmoothing(fld,template='MOD13Q1.006__250m_16_days_NDVI_',date_pos=34
cmd += [f]
cmd += ['-dates',fld+'/dates.txt','-out',fld+'/SmoothedSeries.tif','uint16','-interp','sg','-interp.sg.deg',str(sgdeg),'-interp.sg.rad',str(sgrad)]
#print cmd
subprocess.call(cmd)
\ No newline at end of file
#subprocess.call(cmd)
if clip_valid > 0:
cmd = ['otbcli_BandMathX', '-il', fld+'/SmoothedSeries.tif', '-out', 'ClippedSmoothedSeries.tif','uint16','-exp']
clip_end = len(lst)
if clip_both_sides:
clip_end -= clip_valid
with open(fld + '/dates.clipped.txt','wb') as cdf:
with open(fld + '/dates.txt','rb') as df:
dts = df.readlines()
expr = []
for n in range(clip_valid,clip_end+1):
expr.append('im1b'+str(n+1))
cdf.write(dts[n])
cmd += ['{' + ';'.join(expr) + '}']
print cmd
#subprocess.call(cmd)
\ No newline at end of file
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