Snappy SARSim-Terrain-Correction -- RuntimeError: java.lang.NullPointerException


#1

Hi all, I am new to using snappy and am running into a null pointer error. I am trying to pre-process many images within a folder, and all of the code functions when the SARSim-Terrain-Correction is removed from the process.

What I want to know is: did I code something incorrectly for this error to occur? When I run the same process in the graph GUI it produces an output. The error I am receiving is for the line that is supposed to write the SARSim-Terrain-Correction. The error is as follows :

Here is my script:

import gc
import os
import snappy
from snappy import ProductIO
from snappy import GPF

GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis()
HashMap = snappy.jpy.get_type(‘java.util.HashMap’)
path = “E:\snappy test\”
for folder in os.listdir(path):
output = path + folder + “\”
timestamp = folder.split("")[4]
date = timestamp[:8]
sentinel_1 = snappy.ProductIO.readProduct(output + “\manifest.safe”)
print sentinel_1
pols = [‘VH’, ‘VV’]
for p in pols:
polarization = p
loop_number =+ 1
print “Loop number:” , loop_number
#
#SAR-SIMULATION
#
print “Initiating SAR-Simulation…”
parameters = HashMap()
parameters.put(‘sourceBands’, "Intensity
" + polarization)
parameters.put(‘demName’, “External DEM”)
parameters.put(‘externalDEMFile’, ‘E:\RemovedForPrivacy’)
parameters.put(‘demResamplingMethod’, “BICUBIC_INTERPOLATION”)
print “Parameters defined…”
SARsim = output + date + “SS” + polarization
target_0 = GPF.createProduct(“SAR-Simulation”, parameters, sentinel_1)
ProductIO.writeProduct(target_0, SARsim, ‘BEAM-DIMAP’)
print "SAR-Simulation complete for " + folder + " " + p
#
#CROSS-CORRELATION
#
print “Initiating Cross-Correlation”
SARsimulation = ProductIO.readProduct(SARsim + “.dim”)
parameters = HashMap()
parameters.put(‘sourceBands’, “Simulated_Intensity” and “Intensity_” + polarization)
parameters.put(‘numGCPtoGenerate’, 2000)
print “Parameters defined…”
CrossCor = output + date + “SS_CC” + polarization
target_1 = GPF.createProduct(“Cross-Correlation”, parameters, SARsimulation)
ProductIO.writeProduct(target_1, CrossCor, ‘BEAM-DIMAP’)
print "Cross-Correlation complete for " + folder + " " + p
#
#SARSim-TERRAIN-CORRECTION
#
print “Initiating SARSim-Terrain-Correction…”
CrossCorrelation = ProductIO.readProduct(CrossCor + “.dim”)
parameters = HashMap()
parameters.put(‘sourceBands’, “Simulated_Intensity” and “Intensity_” + polarization)
parameters.put(‘alignToStandardGrid’, False)
parameters.put(‘applyRadiometricNormalization’, True)
parameters.put(‘imgResamplingMethod’, “BILINEAR_INTERPOLATION”)
parameters.put(‘incidenceAngleForSigma0’, “Use local incidence angle from DEM”)
parameters.put(‘mapProjection’, “AUTO:42001”)
parameters.put(‘openResidualsFile’, True)
parameters.put(‘saveLocalIncidenceAngle’, True)
parameters.put(‘saveProjectedLocalIncidenceAngle’, True)
parameters.put(‘saveSelectedSourceBand’, False)
parameters.put(‘saveSigmaNought’, True)
print “Parameters defined…”
SSTerrainCor = output + date + “SS_CC_TC” + polarization
target_2 = GPF.createProduct(“SARSim-Terrain-Correction”, parameters, CrossCorrelation)
ProductIO.writeProduct(target_2, SSTerrainCor, ‘BEAM-DIMAP’) #this is where the error is traced to
print "SARSim-Terrain-Correction complete for " + folder + " " + p
#
#SUBSET
#
print “Initiating Subset…”
WKTReader = snappy.jpy.get_type(‘com.vividsolutions.jts.io.WKTReader’)
wkt = “POLYGON (())” #removed for privacy reasons
geom = WKTReader().read(wkt)
parameters = HashMap()
parameters.put(‘copyMetadata’, True)
parameters.put(‘sourceBands’, “Sigma0_{polarization}_ use_local_inci_angle_from_dem”)
parameters.put(‘geoRegion’, geom)
print “Parameters defined…”
subset = output + date + “SS_CC_TC_subset” + polarization
target_3 = GPF.createProduct(“Subset”, parameters, SSTerrainCor)
snappy.ProductIO.writeProduct(target_3, subset, ‘BEAM-DIMAP’)
print "Subset complete for " + folder + " " + p
#
#SPECKLE-FILTER
#
print “Initiating Speckle-Filter…”
subs = ProductIO.readProduct(subset + “.dim”)
parameters = HashMap()
parameters.put(‘sourceBands’, “Sigma0_{polarization}_ use_local_inci_angle_from_dem” and
“Sigma0_” + polarization and “localIncidenceAngle” and
“projectedLocalIncidenceAngle”)
parameters.put(‘filter’, “Gamma Map”)
parameters.put(‘windowSize’, “7x7”)
print “Parameters defined…”
SpecFil = output + date + “SS_CC_TC_subset_SF” + polarization
target_4 = GPF.createProduct(“Speckle-Filter”, parameters, subs)
print "Speckle-filter complete for " + folder + " " + p
print “Image " + folder + " " + polarization + " complete.”

Thank you!


#2

I think the SARSim-Terrain-Correction and Cross-Correlation operators do not have the sourceBands parameter.
Also, I think the way you concatenate string by and does not work.
parameters.put('sourceBands', "Simulated_Intensity" and "Intensity_" + polarization)
Probably better is:
parameters.put('sourceBands', "Simulated_Intensity,Intensity_" + polarization)

Maybe this fixes your script already, but I see that you use GPF in an inefficient way.
You write every step to disk and read it in again. This slows down the processing dramatically.
You can pass the output of one createProduct(....) call as input to the next one.
I’ve shown how to do it in this post:


#3

Thank you for the clarification @marpet,

I have fixed what you mentioned, my code is running now! However, the Speckle-Filer seems not to be getting applied. I have switched my “windowSize” parameter to “filterSizeX” and “filterSizeY”.

#
#SPECKLE-FILTER
#
print "Initiating Speckle-Filter..."
parameters = HashMap()
parameters.put('filter', "Gamma Map")
parameters.put('filterSizeX', 7)
parameters.put('filtersizeY', 7)
parameters.put('sourceBands', "Intensity_{0},Amplitude_{0}".format(polarization))
print "Parameters defined..."
SpecFil = output + date + "_SF_" + polarization
target_4 = GPF.createProduct("Speckle-Filter", parameters, sentinel_1)
print "Speckle-filter complete for " + folder + " " + p
print "Image " + folder + " " + polarization + " complete."

#4

I looked into it, and it is filtering the image. However, the image that is produced by this filtering process is less filtered than the produced in the manual output. I have checked many times to ensure that all of the parameters are the same. Do you have any idea of what could be causing this?


#5

I’m not an expert for SAR processing but by looking at the processor GUI is see that
the parameter Estimate Equivalent Number of Looks is set to true. And you haven’t set this in your script. By default it is disabled.
Try

parameters.put('estimateENL', True)

#6

Thank you for your quick response, I saw this as well and I changed it, however it did not fix the problem. In addition I have added the other defaults as well. Here is the most recent update to my code:

print "Initiating Speckle-Filter..."
parameters = HashMap()
parameters.put('filter', "Gamma Map")
parameters.put('estimateENL', True)
parameters.put('filterSizeX', 7)
parameters.put('filterSizeY', 7)
parameters.put('numLooksStr', "1")
parameters.put('sourceBands', "Intensity_{0},Amplitude_{0}".format(polarization))
parameters.put('targetWindowStr', "3x3")
parameters.put('windowSize', "7x7")
print "Parameters defined..."
SpecFil = output + date + "_SF2_" + polarization
target_4 = GPF.createProduct("Speckle-Filter", parameters, sentinel_1)
print "Speckle-filter complete for " + folder + " " + p

#7

Maybe @lveci or @cwong can say something about this behaviour.


#8

Hello again,

Just another update: I tried running Lee Sigma instead of Gamma Map to check if I could reproduce the errors I was getting. I found that there is no difference between Lee Sigma manually done and when it is run through the code. Both the images are filtered correctly. I did this for both S1 and R2 images. Could this be an issue with the way the Gamma Map SF is set up in snappy?

Thanks for your time.


#9

Nikolic, it would be very helpful if you could post some of your results once the TC has completed. I originally was running into the same error you list at the start of your post. I solved it, but my output is all 0 values. I’m trying to troubleshoot and am finding that there is very little discussion of the TC results, so any feedback would be helpful, if you have the time.

Thank you very much,
Jessie