Hello !
In SNAP, when I use the Ocean Object Detection pipeline on Sentinel-1 imagery to extract ship in sea, I get a product that contains a “Mask” directory where I can find the detected ships.
When I use the same pipeline in python code with snappy, I’m unable to retrieve the mask at the output of the GPF.createProduct(‘Object-Discrimination’, …) operation.
Even if I write the product in BEAM-DIMAP format and then open it on SNAP, there is no Mask directory that can be find.
Here is my code (I try to decompose the different operator since I have a problem when calculating the all pipeline at once. Once the AdaptiveThreshold reach, the code runs forever, I have to re-run the code from the last product save to reach the end of the pipeline) :
from snappy import HashMap, GPF, Product, ProductIO, ProductUtils
fileName = "S1B_IW_GRDH_1SDV_20200620T084112_20200620T084137_022115_029F80_B189"
def ApplyOrbitFile(inpt, outpt) :
source = ProductIO.readProduct(inpt)
print(source)
params = HashMap()
params.put('orbitType', 'Sentinel Precise (Auto Download)')
params.put('polyDegree', '3')
params.put('continueOnFail', 'false')
target = GPF.createProduct('Apply-Orbit-File', params, source)
ProductIO.writeProduct(target, outpt, 'BEAM-DIMAP')
def LandSeaMask(inpt, outpt) :
source = ProductIO.readProduct(inpt)
print(source)
params = HashMap()
params.put('useSRTM', True)
params.put('landMask', True)
params.put('shorelineExtension', '10')
params.put('sourceBands', 'Intensity_VV')
target = GPF.createProduct('Land-Sea-Mask', params, source)
ProductIO.writeProduct(target, outpt, 'BEAM-DIMAP')
def Calibration(inpt, outpt) :
source = ProductIO.readProduct(inpt)
print(source)
params = HashMap()
params.put('outputSigmaBand', True)
params.put('sourceBands', 'Intensity_VV')
params.put('selectedPolarisations', 'VV')
target = GPF.createProduct('Calibration', params, source)
ProductIO.writeProduct(target, outpt, 'BEAM-DIMAP')
def AdaptiveThreshold(inpt, outpt) :
source = ProductIO.readProduct(inpt)
print(source)
params = HashMap()
params.put('targetWindowSizeInMeter', '30')
params.put('guardWindowSizeInMeter', '500.0')
params.put('backgroundWindowSizeInMeter', '800.0')
params.put('pfa', '12.5')
target = GPF.createProduct('AdaptiveThresholding', params, source)
ProductIO.writeProduct(target, outpt, 'BEAM-DIMAP')
def ObjectDiscrimination(inpt, outpt) :
source = ProductIO.readProduct(inpt)
print(source)
params = HashMap()
params.put('minTargetSizeInMeter', '30')
params.put('maxTargetSizeInMeter', '600')
target = GPF.createProduct('Object-Discrimination', params, source)
ProductIO.writeProduct(target, outpt, 'BEAM-DIMAP')
def WriteProduct(inpt, outpt) :
source = ProductIO.readProduct(inpt)
print(source)
params = HashMap()
params.put('file', inpt)
target = GPF.createProduct('Write', params, source)
ProductIO.writeProduct(target, outpt, 'BEAM-DIMAP')
if __name__ == "__main__" :
source = fileName+'.zip'
orbit = 'orbitApplied.dim'
landSeaMask = 'landSeaMask.dim'
calibration = 'calibration.dim'
adaptiveThreshold = 'adaptiveThreshold.dim'
objectDiscrimination = 'objectDiscrimination.dim'
target = 'prod.dim'
"""ApplyOrbitFile(source, orbit)
LandSeaMask(orbit, landSeaMask)
Calibration(landSeaMask, calibration)
AdaptiveThreshold(calibration, adaptiveThreshold)"""
ObjectDiscrimination(adaptiveThreshold, objectDiscrimination)
WriteProduct(objectDiscrimination, target)
Thank you in advance !
Théo V.