ship detection output

This is related to using snappy python for ship detection in Sentinel-1 imagery. The algorithm itself works fine. At the end, I am saving the entire output as beam-dimap file with the following command

snappy.ProductIO.writeProduct(…, … , ‘BEAM-DIMAP’)

Among others, that includes a .csv file with ship detection data (latitude, longitude, ship width, ship length, etc.). This csv file (ShipDetections.csv) is compact sized and saved in the subfolder for vector data. I want to know whether it is possible to save this csv file only (rather than the entire output as beam-dimap). This would be much more efficient in terms of computational resources.

Hello Claus,

I think it is currently not possible to just store the csv file at least not straight forward. The current implementation does not allow it.

As a strange workaround you could do the following. I write the code without testing it. So it might contain some errors and some gaps ‘…’, but the general approach should be clear.

// ship_detection = GPF.createProduct('Object-Discrimination', ...)
// after creating the ship_detection product you need to iterate over all bands and acquire the data.
// This triggers the actual computation.
bands = ship_detection.getBands()
for band in bands:

// Now you can get the VectorDataNode
vdn = ship_detection.getgetVectorDataGroup().get('ShipDetections')

vdnWriter = jpy.get_type('org.esa.snap.core.dataio.geometry.VectorDataNodeWriter')
writer =vdnWriter()
writer.write(vdn, File('Path_to_location.csv'))

Maybe someone else has an easier idea. Maybe @lveci or @jun_lu?

1 Like

A workaround for problems like this is to create a temporary store in RAM big enough to store the full BEAM-DIMAP file, save data you will need in the future (e.g., .csv, .dim for metadata, and perhaps additional processing history details) to permanent storage, and erase the RAM store.

When testing the above, the line vdn = ship_detection.getgetVectorDataGroup().get(‘ShipDetections’)
gave the following error AttributeError: ‘org.esa.snap.core.datamodel.Product’ object has no attribute ‘getgetVectorDataGroup’

I typed one get to much. Sorry.
It should be:

vdn = ship_detection.getVectorDataGroup().get(‘ShipDetections’)

The line “writer.write(vdn, File(‘Path_to_location.csv’))” still gives some error. The first error was “NameError: global name ‘File’ is not defined”. Following that, we changed the line to “writer.write(vdn, ‘Path_to_location.csv’)”. The next error was “RuntimeError: no matching Java method overloads found”.

I’m not sure if this causes the error, but you have to replace Path_to_location.csv with your personal target directory and filename.

We did that.

Before using File like this you need to import it.

from snappy import File

Or you can write snappy.File(‘Path_to_location.csv’)