I do phase unrwapping using snappy+snaphu in python. After snaphu export,
I use the following code for phase unrwapping. Where Folder is the path to my wrapped phase and Tempfolder is a temporary folder for writing products. All products of snaphu export are written in this folder including header information of onrwapped phase and exported ENVI files of wrapped interferogram.
Product = snappy.ProductIO.readProduct(Folder + “/” + Name + “_ifg_ml_fit.dim”)
params = HashMap()
params.put(“targetProductFile”, Folder + “/” + Name + “_ifg_ml_fit.dim”)
Product = GPF.createProduct(“snaphu-unwrapping”, params, Product)
snappy.ProductIO.writeProduct(Product, TempFolder, “ENVI”)
print(“Phase unwrapping performed successfully …”)
My main question here is the last line of the code if it is right way of writing the final product of unwrapped phase into ENVI file. Is there a better correct way of writing the final product into ENVI file to be importated into SNAP in the next step.
Thanks in advance for your guidance,
The way you are doing it is actually correct. One thing, the location to write the data to should actually be file and not a folder. So better extend the variable TempFolder with a file name. maybe derived from the product name.
And if you want to work in SNAP as next step anyway then I would suggest to save the data in BEAM-DIMAP format. The single bands will still be available as ENVI files but you have a shell for it and more ancillary data is stored.
Something like this:
FileLocation = TempFolder + "/" + Product.getName() + ".dim"
snappy.ProductIO.writeProduct(Product, FileLocation, “BEAM-DIMAP”)
Thanks for our reply.
When doing phase unrwapping in the terminal, we get an envi file.Is this dim file, unrwapphed phase? As the way you suggect to write the product to get dim file, we do not need to do snaphu import step as follows. Right?
Files = snappy.jpy.array(‘org.esa.snap.core.datamodel.Product’, 2)
Files = snappy.ProductIO.readProduct(ifg_path + “/” + Name + “.dim”)
Files = snappy.ProductIO.readProduct(glob.glob(Folder +"/"+ Name+"/UnwPhase*.hdr"))
HashMap = snappy.jpy.get_type(“java.util.HashMap”)
params = HashMap()
Product = GPF.createProduct(“SnaphuImport”, params, File)
snappy.ProductIO.writeProduct(Product, Folder + “/” + Name + “_ifg_ml_fit_unwph.dim”, “BEAM-DIMAP”)
print(“Snaphu import performed successfully …”)
The first line in the code above is to read the wrapped interferogram in dim format.
Should not it be ENVI file generated in “snaphu export” step?
Sorry, I can’t answer this. I never used snaphu.
Maybe someone else can help?
I found out that the ENVI file of the unwrapped interferogram is written to the path of $USERPROFILE and we can set up the path manually in SNAP>Tools>External Tools
I wonder how we can append the path to our desired path in python.