Can't read the dim file processing from Snappy

Dear All,

I’m sorry for the lots of questions in this some time but I’m becoming a bit desperate.

My goal is to doing this stuff with Snappy :

So I just wanted to separated the filter part and the interferogram formation just to control.

Here my code :

import sys
import os
from snappy import GPF
from snappy import ProductIO
from snappy import HashMap
from snappy import jpy
from snappy import WKTReader
import subprocess
import glob
import shutil
import gc
import time
import multiprocessing
import logging

def read_product(*args, **kwargs):
“”“Open product.
Arguments:
Accepts: .zip, .dim, unzipped .SAFE directory
*args
object from class fetchme.Product() with attribute ‘path_and_file’
**kwargs:
path_and_file
Returns:
product
Examples:
# EX1: case where argument a keyword argument
import snapme as gpt
p = gpt.read_product(path_and_file = ‘/path/file.zip’)
# EX2: case where argument is an object with attribute ‘path_and_file’
import fetchme
import snapme as gpt
obj = fetchme.Product()
p = gpt.read_product(obj)
# See native funtions available:
p.
EX: p.getName()
“””

#logging.info(‘reading product’)

# case if args agument passed
if len(args) > 0 and hasattr(args[0], 'path_and_file'):
    pnf = args[0].path_and_file

# case if keyword agument passed
if len(kwargs) > 0 and 'path_and_file' in kwargs:
    pnf = kwargs['path_and_file']

product = ProductIO.readProduct(pnf)

return product

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

def get_name(obj):
r = obj.getName()
return

def write_product(obj, f_out=None, p_out=None, fmt_out=None):

if f_out is None:
    f_out = get_name(obj)

if p_out is None:
    p_out = '../data/'
else:
    p_out = os.path.join(p_out, '')  # add trailing slash if missing (os independent)

if fmt_out is None:
    ext = '.dim'
    fmt_out = 'BEAM-DIMAP'
else:
    ext = ''

logging.info('saving product')

# print(p_out + f_out + ext)
# print(fmt_out)
# return
ProductIO.writeProduct(obj, p_out + f_out + ext, fmt_out)

#os.chdir(r’/Users/clement.goldmann/SAR_docker’)
def write_product2(obj, filename):
ProductIO.writeProduct(obj, filename , “BEAM-DIMAP”)

def topsar_split(product, IW):
# Hashmap is used to provide access to all JAVA operators
HashMap = jpy.get_type(‘java.util.HashMap’)
parameters = HashMap()
parameters.put(‘subswath’, ‘IW2’)
parameters.put(‘selectedPolarisations’, ‘VV’)
parameters.put(‘firstBurstIndex’, 1)
parameters.put(‘lastBurstIndex’, 3)
return GPF.createProduct(“TOPSAR-Split”, parameters, product)

def apply_orbit_file(product):
HashMap = jpy.get_type(‘java.util.HashMap’)
parameters = HashMap()
parameters.put(“Orbit State Vectors”, “Sentinel Precise (Auto Download)”)
parameters.put(“Polynomial Degree”, 3)
parameters.put(“continueOnFail”, True)
return GPF.createProduct(“Apply-Orbit-File”, parameters, product)

def back_geocoding(product):
HashMap = jpy.get_type(‘java.util.HashMap’)
parameters = HashMap()
parameters.put(“Digital Elevation Model”, “SRTM 3Sec (Auto Download)”)
parameters.put(“DEM Resampling Method”, “BICUBIC_INTERPOLATION”)
parameters.put(“Resampling Type”, “BISINC_5_POINT_INTERPOLATION”)
parameters.put(“Mask out areas with no elevation”, True)
parameters.put(“Output Deramp and Demod Phase”, True)
return GPF.createProduct(“Back-Geocoding”, parameters, product)

def EnhancedSpectralDiversity(product):
parameters = HashMap()
parameters.put(“Registration Window Width”, 512)
parameters.put(“Registration Window Height”, 512)
parameters.put(“Search Window Accuracy in Azimuth Direction”, 16)
parameters.put(“Search Window Accuracy in Range Direction”, 16)
parameters.put(“Window oversampling factor”, 128)
parameters.put(“Cross-Correlation Threshold”, 0.1)
parameters.put(“cohThreshold”, 0.3)
parameters.put(“numBlocksPerOverlap”, 10)
parameters.put(“esdEstimator”, ‘Periodogram’)
parameters.put(“weightFunc”, ‘Inv Quadratic’)
parameters.put(“temporalBaselineType”, ‘Number of images’)
parameters.put(“maxTemporalBaseline”, 4)
parameters.put(“integrationMethod”, ‘L1 and L2’)
parameters.put(“doNotWriteTargetBands”, False)
parameters.put(“useSuppliedRangeShift”, False)
parameters.put(“overallRangeShift”, 0.0)
parameters.put(“useSuppliedAzimuthShift”,False)
parameters.put(“overallAzimuthShift”,0.0)
return GPF.createProduct(‘Enhanced-Spectral-Diversity’, parameters, product)

def interferogram(product):
HashMap = jpy.get_type(‘java.util.HashMap’)
parameters = HashMap()
parameters.put(“Subtract flat-earth phase”, True)
parameters.put(“Degree of "Flat Earth" polynomial”, 5)
parameters.put(“Number of "Flat Earth" estimation points”, 501)
parameters.put(“Orbit interpolation degree”, 3)
parameters.put(“Include coherence estimation”, True)
parameters.put(“Square Pixel”, True)
parameters.put(“Independent Window Sizes”, False)
parameters.put(“Coherence Azimuth Window Size”, 2)
parameters.put(“Coherence Range Window Size”, 10)
return GPF.createProduct(“Interferogram”, parameters, product)

def topsar_deburst(product):
HashMap = jpy.get_type(‘java.util.HashMap’)
parameters = HashMap()
parameters.put(“Polarisations”, “VV”)
return GPF.createProduct(“TOPSAR-Deburst”, parameters, product)

def FirststepSAR(filename_1, filename_2):

print('Reading SAR data')
product_1 = read(filename_1)
product_2 = read(filename_2)
print('TOPSAR-Split')
product_TOPSAR_1 = topsar_split(product_1, 'IW2')
product_TOPSAR_2 = topsar_split(product_2, 'IW2')

print('Applying precise orbit files')
product_orbitFile_1 = apply_orbit_file(product_TOPSAR_1)
product_orbitFile_2 = apply_orbit_file(product_TOPSAR_2)

print('back geocoding')

backGeocoding = back_geocoding([product_orbitFile_1, product_orbitFile_2])

print('ESD')

ESD = EnhancedSpectralDiversity(backGeocoding)

print('interferogram generation')
interferogram_formation = interferogram(backGeocoding)

print('TOPSAR_deburst')
TOPSAR_deburst = topsar_deburst(interferogram_formation)

write_product2(TOPSAR_deburst, 'S1A_IW2_SLC__20230122_20230215_Orb_Stack.dim')

print('Operation successfull')

and I run this one :

from DefineSar import FirststepSAR

FirststepSAR(“S1A_IW_SLC__1SDV_20230122T111531_20230122T111559_046895_059FB4_89F7.zip”,“S1A_IW_SLC__1SDV_20230215T111530_20230215T111558_047245_05AB64_F1B0.zip”)

The trouble is when I wanted to open in snap on my other computer I’m unable to read it and I have this trouble : Failed to open image view
java.lang.RuntimeException DimapProducReader : Unable to read file

Maybe snappy doesn’t allow us to see the result directly in SNAP and I just product the result instantly. So I need the data folder or maybe it’s just impossible.

Cheers,
Clément

This sounds as if you have not copied the data folder to your other computer.
BEAM-DIMAP consists of two main components, the *.dim file and the *.data folder.

Dear Marpet,

I didn’t see the file right but it seems i have the same issue :

I wanted to precise, with my windows computer the graph builder to make an interferogram took 20 min, with python seems to done in 2 min but nothing happens

The screenshot shows that the ‘q_ifg_***’ band ist not written yet. Also, the ‘i_ifg_***’ has zero bytes.
So, at the point in time, you are trying to open the data the processing is not yet finished.

Yes it seems not parameters are extracted from the script I will try to solve this problem, still have some difficulties using snap with Python

Greetings, I am doing my degree work that consists of obtaining the interferometry (Insar) and obtaining the digital model with the use of an API for python and the use of Snap, so I found Snappy, Mintpy, Snapista. I have started with Snappy, I installed it and I got to what the image indicates and I don’t know how to proceed to implement code in Python, by observing your work I see that it is possible to do it, so I ask if you can guide me a little on the subject or the guidelines he followed to do so.

Thank you so much.

Hi, I found this discussion useful for my work. I am trying to generate DEM using inSAR method. I got the .img files, I want to ingest the .img into my google earth engine assets so that i can work with it further. Could you suggest me how to make a tiff or vector data using the .img files generated with the above code.

Good morning ajha,

Snap allows you to export any product into generic data formats, for example NetCDF or (your choice) GeoTIFF.

So, you would open the product generated in SNAP by selecting the *.dim file of your created product.
Then you chose from the SNAP menu “File → Export → GeoTIFF/BigTIFF”
This opens a dialog that allows you to select a target directory and a product name.

When clicking on the button “Subset” in the upper right corner of the export dialog, another dialog box appears.
This one allows you to select a suitable subset of the complete product.

If exporting the full product, SNAP will write a TIFF file containing all bands of the original product. Using the subsetting functionality allows you to split data into separate TIFF file.

You can alternatively use the “pconvert” tool to automate/script these tasks.
https://step.esa.int/main/wp-content/help/?version=9.0.0&helpid=pconvertTool

Tom