Set band unit with snappy

Hello,

I am using snappy for multitemp filtering a stack of 7 images, .tif format… I have the error :

RuntimeError: org.esa.snap.core.gpf.OperatorException: band band_1 requires a unit

This is a metadata problem for sure but with the SNAP interface I can set the unit into the properties of the image.

Does someone have any idea how to change this with snappy?
(I already tried to reproject the image with snappy but nothing changes)

Thanks

Reprojecting doesn’t change the unit.

The code should lokk simiar to this:

product = ProductIO.readProduct(...)
product.getBand('BandName').setUnit('db')

You can also use
product.getBandAt(0).setUnit(‘db’)

yes, it is really good answer thanks you @marpet Check this article to get more about it.

Hello @marpet, I applied the following code and tried to convert the intensity of the calibrated data from linear to decibel; however, it did not work. Can you please tell me what went wrong and whether I need to change the intensity to decibel as long as I perform other pre-processing operations on that data?

Blockquote
#radiometric calibration
parameters = HashMap()
parameters.put(‘sourceBands’, ‘Intensity_’ + polarisation)
parameters.put(‘selectedPolarisations’, polarisation)
parameters.put(‘outputSigmaBand’, True)
parameters.put(‘outputGammaBand’, False)
parameters.put(‘outputBetaBand’, False)
parameters.put(‘outputImageScaleInDb’, False)
calibration = snappy.GPF.createProduct(‘Calibration’, parameters, source_file)
print(“Radiometric Calibration Completed”)
snappy.ProductIO.writeProduct(calibration,‘processed/’+source_filename+"_cal",“BEAM-DIMAP”)
print(“Radiometric Calibrated File Saved”)
print(list(source_file.getBandNames()))
calibration.getBand(‘Sigma0_VV’).setUnit(‘db’)
print(list(source_file.getBandNames()))

Printed Output
Radiometric Calibration Completed
Radiometric Calibrated File Saved
[‘Sigma0_VV’]
[‘Sigma0_VV’]

** I have also tried by setting parameters.put(‘outputImageScaleInDb’, False) to True but it didn’t work.

@Samira.h @josh09dmello @mengdahl @arnab @css @falahfakhri @antonio19812 @johngan

I’m not of much help here. I don’t know SAR processing. I’m more into the optical part.
Maybe @lveci can help or some else?
You say it is not working. But what is not working? The values are not converted after processing?

@marpet yes, it remained the same as before. I am trying to get the total amount of water in the s1 data. The histogram that I am trying to generate remained the same as before. @lveci, can you please help me out with this?

@Samira.h @josh09dmello @mengdahl @arnab @css @falahfakhri @antonio19812 @johngan

Performed Radiometric Calibration
Performed Speckle Filtering

and then the following.

Blockquote
band=source_file.getBand(‘Sigma0_VV’)
w=band.getRasterWidth()
h=band.getRasterHeight()
print(w,h,wh)
band_data=np.zeros(w
h,np.float32)
print(band_data)
band.readPixels(0,0,w,h,band_data)
print(band_data)
band_data.shape=h*w
print(band_data)
plt.hist(np.asarray(band_data, dtype=‘float’), bins=2048, range=[0.004, 0.3], normed=True)
plt.show()

I am trying to find out the water body amount with this program.