Preprocessing for S1 can not for loop using Snappy

S1 GRD products are preprocessed using Snappy. The first loop can be finished successfully. But there is error in the second loop. Is it out of memorys? I can not find the reason.
code:
import os
import sys
from snappy import GPF
from snappy import ProductIO
from snappy import HashMap
from snappy import jpy
import subprocess
import time

HashMap = jpy.get_type(‘java.util.HashMap’)
parameters = HashMap()

class prepro_s1(object):

def __init__(self,files,filename):
    
    self.fs = files
    
    self.fn = filename

def read(self):

    return ProductIO.readProduct(self.fs)
    

def write(self):
    ProductIO.writeProduct(self.fs, self.fn, "BEAM-DIMAP")

def apply_orbit_file(self):   
    parameters.put("Orbit State Vectors", "Sentinel Precise (Auto Download)")
    parameters.put("Polynomial Degree", 3)    
    return GPF.createProduct("Apply-Orbit-File", parameters, self.fs)



def calibration_GRDH(self):
    parameters.put('Polarisation','VH,VV')
    parameters.put('output Sigma0 band',True)
    return GPF.createProduct("Calibration", parameters, self.fs)



def speckle_Filter(self):

    parameters.put('sourceBands','Sigma0_VH,Sigma0_VV')
    parameters.put('Filter','Refined Lee')
    return GPF.createProduct("speckle-filter", parameters, self.fs)



def terrain_correction(self):
    parameters.put("Source Bands","Sigma0_VH,Sigma0_VV")
    parameters.put("Digital Elevation Model","SRTM 3Sec (Auto Download)")
    parameters.put("DEM Resampling Method","BILINEAR_INTERPOLATION")
    parameters.put("Image Resampling Method","BILINEAR_INTERPOLATION")
    parameters.put("Pixel Spacing (m)",10.0)
    parameters.put("Pixel Spacing (deg)",0.0000898315284119)
    parameters.put("Map Projection","WGS84(DD)")
    parameters.put("Mask out areas without elevation",True)
    parameters.put("Selected source band",True)
    return GPF.createProduct("Terrain-Correction", parameters, self.fs)

################################################################################

inpath = r’F:\data’
outpath = r’F:\result’
files = os.listdir(inpath)
for filename in files:
print (filename)

outfiles = os.path.join(outpath,filename[17:25])
ff = outfiles + '.data'
if os.path.exists(ff):
    print ('%s exists'% ff)
    continue
               
file_name = os.path.join(inpath,filename)
 

prepro_sentinel1 = prepro_s1(file_name,outfiles)
print('Reading SAR data')
product_s = prepro_sentinel1.read()


prepro_sentinel1 = prepro_s1(product_s ,outfiles)
print('Apply Orbit File')
product_orbit = prepro_sentinel1.apply_orbit_file()


prepro_sentinel1 = prepro_s1(product_orbit ,outfiles)
print('calibration')
product_calibr = prepro_sentinel1.calibration_GRDH()


prepro_sentinel1 = prepro_s1(product_calibr ,outfiles)
print('speckle Filter')
product_speckle = prepro_sentinel1.speckle_Filter()

prepro_sentinel1 = prepro_s1(product_speckle ,outfiles)
print ('terrain correction')
product_tc = prepro_sentinel1.terrain_correction()



prepro_sentinel1 = prepro_s1(product_tc,outfiles)
print ('write ')
prepro_sentinel1.write()

Hi,
you need to reinitialize the parameters in all your methods: apply_orbit_file, calibration_GRDH… In the first loop is not a problem because there are not invalid parameters, but when calling the second time, you have already some parameters that produce errors in the CalibrationOp (the SourceBand parameter that you define in Speckle filter or terrain correction), since there are bands which don’t exist yet.

1 Like

I had reinitialized the parameters. ‘filename’ is different from the last one.
the code :
files = os.listdir(inpath)
for filename in files:
outfiles = os.path.join(outpath,filename[17:25])
prepro_sentinel1 = prepro_s1(file_name,outfiles)

Sorry, I meant

parameters = HashMap()

before puting the parameters for every operator.

Thanks. It is successful for looping.

Hello! I have the same problem. How did you do that? How to reinitialize parameters for every operation?
Thank you in advance!

Use of Snappy for processing is discouraged due to the degraded performance. Have you considered using snapista instead?

GitHub - snap-contrib/snapista: SNAP GPT thin layer for Python