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()
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')
@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
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.
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
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.
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.
@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?
There is another python package called snappy, it is therefore important to install snappy with the procedure mentioned above. For example, running “pip install snappy” will load the wrong package.
Are you sure you installed the package in the correct python installation? Sometimes, there are several installed on the computer, e.g. when you use ArcGIS.
Maybe a colleague can help you to configure snappy.