Obtaining sigma (backscatter) from Sentinel 1 subset


#1

I need to obtain sigma0 (backscatter) from the subset of Sentinel-1 GRDH product.

Could you tell me:

  • If I should firstly subset or calculate sigma0 or it does not matter? In my further work I need only sigma0 cropped to the area of my interest.
  • how can I create subset? As I can see there’s createSubset method, but I can’t find any usage example. As I can see the second argument should be the “Rectangle” object (how should I initialize this object in Python/snappy?? Will this object use coordinates in WGS84?)
  • how can I calculate sigma0? I know that in the SNAP desktop, I can accomplish that through Radar --> Radiometric --> Calibrate, but I can’t find appropriate option in documentation

Obviously I checked examples:


#2

I am also looking for the snappy codes only for the SAR Calibration (from SLC to sigma0). Thanks


#3

I discovered that within the ‘Help’ for calibration operator, there’s a full name provided which we need to execute this plugin from Python.

However, I have an issue with starting my sigma0 calculation
My current code:

file1 = '/home/someone/S1A_IW_GRDH_1SDV_20160509T043538_20160509T043603_011177_010E0F_2700.zip'

import os.path
import snappy
from snappy import ProductIO
from snappy import Product
from snappy import ProductData
from snappy import ProductUtils

jpy = snappy.jpy

if os.path.exists(file1):
    # Read sourceProduct and get information needed to create target product:
    sourceProduct = snappy.ProductIO.readProduct(file1)
    width = sourceProduct.getSceneRasterWidth()
    height = sourceProduct.getSceneRasterHeight()
    #Create target product:
    targetProduct = Product('FLH_Product', 'FLH_Type', width, height)
    targetBand = targetProduct.addBand('FLH', ProductData.TYPE_FLOAT32)
    ProductUtils.copyGeoCoding(sourceProduct, targetProduct)
    targetProduct.setProductWriter(ProductIO.getProductWriter('GeoTIFF'))
    # Use calibration operator - I've taken "org.esa.s1tbx.calibration.gpf.CalibrationOp" from the help window
    CalibrationOp = jpy.get_type("org.esa.s1tbx.calibration.gpf.CalibrationOp")
    CalOp = CalibrationOp()
    CalOp.setSourceProduct(sourceProduct)
    CalOp.setTargetProduct(targetProduct)
    #### HERE I DO NOT KNOW HOW TO EXECUTE this operator
    #### When I try to execute: 'doExecute' or 'execute' methods, I receive an error message
    targetProduct.closeIO()


#4

Have a look at the snappy_subset.py in the examples folder in the snappy directory. There you can see how to use an operator.
In general you don’t need to create the target product. It is created by the operator.
sub_product = op.getTargetProduct()

I adapt you code here. It is probably not fully correct but you will get the idea.

if os.path.exists(file1):
    # Read sourceProduct
    sourceProduct = snappy.ProductIO.readProduct(file1)
    # Use calibration operator - I've taken "org.esa.s1tbx.calibration.gpf.CalibrationOp" from the help window
    CalibrationOp = jpy.get_type("org.esa.s1tbx.calibration.gpf.CalibrationOp")
    CalOp = CalibrationOp()
    CalOp.setSourceProduct(sourceProduct)
    CalOp.setParameter('doSomethng', True)

    targetProduct = CalOp.getTargetProduct()
    snappy.ProductIO.writeProduct(result, '/path/toFile.dim', 'BEAM-DIMAP')

Instead of creating the operator instance directly it would be better to use GPF as I have written in the other post. Aggregation and Interpolation of Sentinel products - should I use snappy or GDAL tools?
You can also have a look at my other recent posts. They are also somehow related.


#5

@marpet Thanks. When I try to run your code, I get following message repeated numerous times:
java.lang.OutOfMemoryError: Java heap space

I’ve tried to repeat this commeand and after two
java.lang.OutOfMemoryError: Java heap space
I get:
RuntimeError: java.lang.OutOfMemoryError: GC overhead limit exceeded


#6

I think you need to edit the snappy.ini as described here: ‘GC overhead limit exceeded’ runtime error using 'Terrain-Correction' in python


#7

@marpet It doesn’t work for me.

I edited both snappy.ini in

~/.snap/snap-python/snappy
~/.snap/snap-python/build/lib.linux-x86_64-2.7/snappy

and edited/uncommented following line (I have 8 GB of RAM):

java_max_mem: 6G

I even restart my computer, but it doesn’t help.

Each time when I try (I use code which I commited here, I receive:

java.lang.OutOfMemoryError: Java heap space

RuntimeError Traceback (most recent call last)
in ()
----> 1 getSigma(SentinelFile)

in getSigma(SentinelFile)
48 newFile=newFilepath(SentinelFile, “calibrated”)
49 print("Starting writing to the file: " + newFile)
—> 50 snappy.ProductIO.writeProduct(targetProduct, newFile, ‘BEAM-DIMAP’)
51 return newFile
52

RuntimeError: java.lang.OutOfMemoryError: Java heap space

I’m able to accomplish calibration in ESA SNAP desktop:

Might it be related with Java version?

I have:

java -showversion
openjdk version “1.8.0_91”
OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-0ubuntu4~16.04.1-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)


#8

Your code looks good. Even though I would switch to GPF.createProduct().
Is the same operation working when you do it in the desktop app? I know that working with S1 data can be memory consuming.
Maybe one thing. When using the operator directly you should call op.setParameterDefaultValues(). This will ensure that parameters are initialised with default values, If they have default values. This is ensured by the framework if you use GPF.
However, this is probably not a problem in your case.


#9

@marpet Yes, this operation works in desktop app - I edited my question to provide an example.

Regarding rewriting to GPF.createProduct() - could you provide me an example/suggestion. Will this help with mentioned errors?


#10

@marpet It seems thatjava_max_mem settings from~/.snap/snap-python/snappy/snappy.ini does not work.

I typed ‘export _JAVA_OPTIONS=-Xmx4096m’ in my shell and then run my script.
Now I do not get a > java.lang.OutOfMemoryError exception.


#11

Hello Kedzior,
I’m a beginner to use snap+python,
I need to calibrate Sentinel-1 data.
Finally, do you have succeeded to run your script?
Please, can you share your your script?
Thanks


#12

you don’t need any script, just run the Calibration module (Menu > Radar > Radiometric > Calibration) on your Sentinel-1 data in order to convert them into Sigma0.


#13

Thank you ABraun,
But I have many images to calibrate. So, I would link snap with a python (snappy) to do that in an iterative process.


#14

that is an option, yes. But you can also simply create a graph file in SNAP (read > calibrate > write) and apply it on multiple images using the batch processing menu.


#15

Here it turned out to be working.


Strange. However, finally you made it :+1:


#16

@marpet
Where we have to code this? In SNAP or somewhere else? Please also tell how to get backscatter values using python script?


Backscatter values of sentinel-1A image using python
#17

it is basically just loading the data and applying the calibration operator.
Have you seen this topic: Snappy: Where to start?

Here is the main documentation: https://senbox.atlassian.net/wiki/spaces/SNAP/pages/50855941/Configure+Python+to+use+the+SNAP-Python+snappy+interface


#18

@ABraun
I want python code to obtain backscatter values.


#19

As I said above, you need to install the snappy library first and then load the data into python as explained in the documentation above.
How data can be loaded is described here: https://github.com/senbox-org/snap-examples/blob/master/snap-engine-python-scripts/src/main/python/snippets.py

The second step is to call the calibration tool from python.


#20

@ABraun
While I am writing the code given above I am getting an error like: ImportError: cannot import name ProductIO. I have installed snappy. What should I have to do?