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()