Exporting existing mask from S3_Sl_L1_RBT product with snappy

Hello guys!

I’m reading from 3 days now about snappy. I want to write a script that will help me to export 2 masks for a snow map, those masks are cloud_an_visible and confindence_an_snow. I wrote a script that selects me one mask (e.g cloud_an_visible) and when i print it show me a result with mask info. I want to export the 2 masks as geotiff. I 'm using snappy in jupyter notebook from anaconda with python 2.7.

I know that i do something wrong but i can’t get what?

import sys 
import snappy
import jpy
from snappy import ProductIO
from snappy import Mask
import numpy as np
import matplotlib.pyplot as plt

Mask = jpy.get_type('org.esa.snap.core.datamodel.Mask')
file = snappy.File('G:\S3A_SL_1_RBT____20180705T085813_20180705T090113_20180706T144547_0179_033_107_2160_LN2_O_NT_003.SEN3/xfdumanifest.xml')
p =ProductIO.readProduct(file,'Sen3_SLSTRL1B_500m')
mask_group = p.getMaskGroup()

mymask =  p.getMaskGroup().get('cloud_an_visible')
h = p.getSceneRasterHeight()
w = p.getSceneRasterWidth()
data = np.zeros(w * h, np.uint32)
mymask = jpy.cast(mymask, Mask)


ProductIO.writeProduct(mymask, 'E:\test.tif', 'GeoTIFF-BigTIFF') 

**Results are:**


RuntimeError: no matching Java method overloads found

I’m looking for a way to export the mask to .tif as well. Does anyone have a solution for this?

The above code is not working because the Mask is not a product and can not be written by ProductIO.

Instead a subset should be created which only contains the mask.
Often masks are based on flag bands and cannot exist without this flag band.
Then this band can be converted from a mask into a band by using the BandMaths operator by using the mask name as expression. Actually when using the BandMaths no subset is needed. Just write the result of the BandMaths operation. It could be that the latitude longitude bands are also written to the output file. If so, the data needs to be reprojected before writing.

1 Like