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

FIX: optimization of by-date feature extraction (still temp).

parent 928db6ff
......@@ -633,22 +633,18 @@ def createS1Features(fld, base_name='S1series', out_fld=None, features=None, con
feat.append(otb.Registry.CreateApplication('BandMathX'))
feat[-1].SetParameterStringList('il', lst_vh)
feat[-1].SetParameterString('exp', expr)
if by_date:
feat[-1].Execute()
else:
feat[-1].SetParameterString('out', vh_out)
feat[-1].SetParameterOutputImagePixelType('out', otb.ImagePixelType_int16)
feat[-1].ExecuteAndWriteOutput()
feat[-1].SetParameterString('out', vh_out)
feat[-1].SetParameterOutputImagePixelType('out', otb.ImagePixelType_int16)
feat[-1].ExecuteAndWriteOutput()
feat.append(otb.Registry.CreateApplication('BandMathX'))
feat[-1].SetParameterStringList('il', lst_vv)
feat[-1].SetParameterString('exp', expr)
if by_date:
feat[-1].Execute()
else:
feat[-1].SetParameterString('out', vv_out)
feat[-1].SetParameterOutputImagePixelType('out', otb.ImagePixelType_int16)
feat[-1].ExecuteAndWriteOutput()
feat[-1].SetParameterString('out', vv_out)
feat[-1].SetParameterOutputImagePixelType('out', otb.ImagePixelType_int16)
feat[-1].ExecuteAndWriteOutput()
feat_out = [vh_out, vv_out]
if features is not None and 'ratio' in features:
expr = '{' + ';'.join(['1000 * im1b%d / (im2b%d + 1e-6)' % (i + 1, i + 1) for i in range(len(lst_vh))]) + '}'
......@@ -656,25 +652,27 @@ def createS1Features(fld, base_name='S1series', out_fld=None, features=None, con
feat[-1].AddImageToParameterInputImageList('il', feat[0].GetParameterOutputImage('out'))
feat[-1].AddImageToParameterInputImageList('il', feat[1].GetParameterOutputImage('out'))
feat[-1].SetParameterString('exp', expr)
if by_date:
feat[-1].Execute()
else:
ratio_out = out_fld + os.sep + base_name + '_vh_vv_ratio_series.tiff'
feat[-1].SetParameterString('out', ratio_out)
feat[-1].SetParameterOutputImagePixelType('out', otb.ImagePixelType_int16)
feat[-1].ExecuteAndWriteOutput()
ratio_out = out_fld + os.sep + base_name + '_vh_vv_ratio_series.tiff'
feat[-1].SetParameterString('out', ratio_out)
feat[-1].SetParameterOutputImagePixelType('out', otb.ImagePixelType_int16)
feat[-1].ExecuteAndWriteOutput()
feat_out.append(ratio_out)
# optimization needed to avoid recomputation of the whole multi-temp stack at each date production
# so far, per-feature stack is written prior to per-date extraction
if by_date:
i = 1
cc = []
for d in dates_vh:
stack_out = out_fld + os.sep + base_name + '_' + d + '_feat.tif'
cc.append(otb.Registry.CreateApplication('BandMathX'))
[cc[-1].AddImageToParameterInputImageList('il', x.GetParameterOutputImage('out')) for x in feat]
#[cc[-1].AddImageToParameterInputImageList('il', x.GetParameterOutputImage('out')) for x in feat]
cc[-1].SetParameterStringList('il', feat_out)
cc[-1].SetParameterString('exp', '{' + ';'.join(['im%db%d' % (t,i) for t in range(1,len(feat)+1)]) + '}')
cc[-1].SetParameterString('out', stack_out)
cc[-1].SetParameterOutputImagePixelType('out', otb.ImagePixelType_int16)
cc[-1].ExecuteAndWriteOutput()
i += 1
return
......
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