Export Mask Pixels with snappy

Hello,

Is there an Export Mask Pixels gpt operator that can be used in snappy? I know of PixEx which works using geo-coordinates, however, I just want to export all pixel info contained in a Mask.

Thank you,
Jeremy

No there is no such operator for exporting the mask.
But you can simply create subset which only contains the mask and then export it. Either as NetCDF, GeoTIFF or CSV.

Thank you marpet for the response.

I applied the BandMaths operator in snappy for multiple expressions following the bandmaths example script in the snappy directory (targetBand1, targetBand2, etc…). When I write the product as a CSV file the bandmath masks are successfully exported, however, how can I get all the reflectance bands to be exported as well? ( I am using a BRR product).

thank you,
Jeremy

You can use the Merge operator.

sourceProducts = HashMap()
sourceProducts.put(“master”, source)
sourceProducts.put(“slave”, bmath_result)
parameters = HashMap()
target = GPF.createProduct(‘Merge’, parameters, sourceProducts)

hello,

I am using snappy for automating all the steps required to produce a land subsidence map. The snappy script works fine but there is one last thing I need to implement and I have not managed to do so. The last step of my script is where I export the wrapped phase into snaphu format. Below it is given only the script referred to the function of exporting the wrapped phase into snaphu.

import os
from snappy import GPF
from snappy import ProductIO
from snappy import HashMap
from snappy import jpy
HashMap = jpy.get_type('java.util.HashMap')
parameters = HashMap()

#path to the file for exporting into snaphu
path = '/home/io/ASTROSAT/ASTROSAT_Projects/Ho_Chi_Minh_subsidence/processing/Dec2016_March2017/processing/S1A_IW_SLC__1SDV_Dec2016_March2017_batch_processing.dim'

def read(filename):
return ProductIO.readProduct(filename)

def export_snaphu(product):
    parameters.put('targetFolder', 'path-to-my-folder')
    parameters.put('Statistical-cost mode', 'DEFO')
    parameters.put('Initial method', 'MCF')I still have not figured out where problem is.
    parameters.put('Number of Tile Rows', 10)
    parameters.put('Number of Tile Columns', 10)
    parameters.put('Number of Processors', 12)
    parameters.put('Row Overlap', 0)
    parameters.put('Column Overlap', 0)
    parameters.put('Tile Cost Threshold', 500)
    return GPF.createProduct("SnaphuExport", parameters, product)

  read_file = read(path)  #read the file
  snaphu = export_snaphu(read_file) #run the function for exporting the file
  snaphu.writeHeader('/home/io/ASTROSAT/ASTROSAT_Projects/Ho_Chi_Minh_subsidence/snaphu') # write the header

When we export the unwrapped phase into snaphu, the following files are generated as shown below:

When I run the script, only two files are generated. There are four files missing as shown below.

I still have not figured out where problem is.
So, How can I export the unwrapped phase into snaphu successfully using snappy?
I would appreciate any help on that
@marpet
Thank you

I’ve no experience with Snaphu. Maybe @cwong can help here?

In terms of my previous question about about exporting the wrapped phase band of the InSAR product into snaphu format using snappy. Here is my experience with it.

As I mentioned before, I have automated all steps required by SNAP toolbox for producing a subsidence map using snappy, apart from the last one which is the export of the wrapped phase into snaphu format. I was looking for a way of doing this step in snappy in order to have a fully automated script of producing the unwrapped phase and then the map subsidence.

In order to achieve that, I tried to read the JAVA code (where I am not familiar with JAVA at all) and understand the implementation of how to export the phase and coherence band from our product into the snaphu format and translate it into python code. Finally, I managed to successfully write the coherence and phase band as well as the configuration file required for snaphu. The code is given below.

source_product_path = os.path.join(DATA_PATH, 'test_snaphu', 'source_product',
                               'S1A_IW_SLC__1SDV_Dec2016_Jan2017_batch_processing.dim')
source_product = read(source_product_path)
target_product = snappy.Product(source_product.getName(), 
                           source_product.getProductType(),
                           source_product.getSceneRasterWidth(),
                           source_product.getSceneRasterHeight())
for source_band in source_product.getBands():
    band_name = source_band.getName() 
    if band_name.startswith('coh'):
         ProductUtils.copyBand(band_name, source_product, target_product, True) 
    elif bandName.startswith('Phase'):
         ProductUtils.copyBand(band_name, source_product, target_product, True)
target_product_path = os.path.join(DATA_PATH, 'test_snaphu', 'python_output',
                              'S1A_IW_SLC__1SDV_Dec2016_Jan2017_batch_processing.dim')
write(target_product, target_product_path)

I was very happy that I finally did it and now I have a fully automated script until I got the following error when running snaphu command line tool which is:

Unexpected or abnormal exit of child process 440 Abort

I changed different parameters in the configuration file, but the same error came up on the screen. Hence, I tried to export the wrapped phase to snaphu using SNAP toolbox and did the same using my script and I compared both results to see what the difference was. When I loaded the Phase_ifg_VV_24Dec2016_29Jan2017.snaphu.hdr band produced by SNAP into the SNAP toolbox I have seen the following results.

Figure 1: SNAP results

When I loaded the Phase_ifg_VV_24Dec2016_29Jan2017.snaphu.hdrband produced by my script the results were the follwoing:


Figure 2: script results

As we can see, the phase produced by SNAP and fed into snaphu for phase unwrapping, it does not make much sense to me but it seems that this is how it should be in order for snaphu to work. It is just a white image with black dots scattered around. On the other hand, the phase band produced when running the script looks fine. When we feed this phase band into snaphu it throws an error.

I have spend so much time on that but I still have not managed to properly export the coherence and phase band to be fed into snaphu. I do not know what kind of magic is happening in JAVA code and we get the image shown in figure 1, so that for snaphu to properly work. It seems there is not an easy way of exporting the wrapped phase of our product into snaphu format using snappy in order to have a fully automated script for producing the differential Interferogram.

I just wanted to share this with everyone in case there is someone else that tries to do something similar to this.
If anyone found a solution on this issue, I would appreciate if he/she could post the answer

3 Likes

Can you show how your write method looks like?
I expect that you only use ProductIO.writeProduct(…), right?
What might be not correctly written are scaling offsets and scaling factors.
I can have a look at the data if you provide it to me.
I send you a PM with the location where you can drop the data.

Hello marpet,

Thanks for your reply. The write method I used is the one you described (its is shown below).

def write(product, filename):
    ProductIO.writeProduct(product, filename, "BEAM-DIMAP")

It takes as input the GoldsteinFiltering product and as filename the location of the product where it will be saved is given.
I have already put the two SAR images I have used for this example in the ftp you have specified.

Thanks

Oh I thought you would just upload the two result files
Phase_ifg_VV_24Dec2016_29Jan2017.snaphu.hdr
Honestly, I don’t want to process the whole chain and actually, I’m not really able to do. Because I’m not a SAR expert and I don’t have snaphu at hand. But I could investigate the results and maybe I see something, what might be wrong.

sorry for the misunderstanding @marpet. I have uploaded the correct files to the ftp as you requested.
In the SNAP folder, you will find the results produced by SNAP when exporting the wrapped phase into snaphu format.
In the snappy folder, you will find the results produced by snappy. The script I have used for exporting the wrapped phase to be used in snaphu is already posted here

thanks for your help

I had a look at this.
I’m sorry to say this, but I couldn’t find any indicator regarding this problem.

Maybe the posts after this one might help:

1 Like