insarlab / MintPy

Miami InSAR time-series software in Python
https://mintpy.readthedocs.io
Other
616 stars 260 forks source link

save_kmz.py for wrapped ISCE2 interferogram #1266

Closed tshreve closed 2 months ago

tshreve commented 2 months ago

Hi, I've found save_kmz.py very useful to quickly visualize in Google Earth a geocoded, wrapped interferogram processed with ISCE2. However, I've been running:

save_kmz.py filt_topophase.flat.geo --wrap --zero-mask --unit rad

and receiving the following error message:

data   coverage in y/x: (0, 0, 5887, 6068)
subset coverage in y/x: (0, 0, 5887, 6068)
update LENGTH, WIDTH, Y/XMAX
update/add SUBSET_XMIN/YMIN/XMAX/YMAX: 0/0/5887/6068
update Y/X_FIRST
masking out pixels with zero value
Traceback (most recent call last):
  File "/home/tshreve/anaconda3/envs/isce2env/bin/save_kmz.py", line 10, in <module>
    sys.exit(main())
  File "/home/tshreve/anaconda3/envs/isce2env/lib/python3.8/site-packages/mintpy/cli/save_kmz.py", line 150, in main
    save_kmz(inps)
  File "/home/tshreve/anaconda3/envs/isce2env/lib/python3.8/site-packages/mintpy/save_kmz.py", line 462, in save_kmz
    data, inps.disp_unit, inps.disp_scale, inps.wrap = pp.scale_data4disp_unit_and_rewrap(
  File "/home/tshreve/anaconda3/envs/isce2env/lib/python3.8/site-packages/mintpy/utils/plot.py", line 1770, in scale_data4disp_unit_and_rewrap
    data, disp_unit, disp_scale = scale_data2disp_unit(
  File "/home/tshreve/anaconda3/envs/isce2env/lib/python3.8/site-packages/mintpy/utils/plot.py", line 1686, in scale_data2disp_unit
    phase2range = -float(metadata['WAVELENGTH']) / (4*np.pi)
KeyError: 'WAVELENGTH'

I fixed this issue by modifying plot.py to not calculate phase2rangeif data_unit and disp_unit are both 'radian'. Happy to share this mod, but was first wondering if there is already a built-in fix. Thanks in advance!

System information

welcome[bot] commented 2 months ago

👋 Thanks for opening your first issue here! Please filled out the template with as much details as possible. We appreciate that you took the time to contribute! Make sure you read our contributing guidelines.

yunjunz commented 2 months ago

I am glad to hear you find it useful @tshreve. If data_unit and disp_unit are the same, the code is supposed to skip and return directly, it would be nice to figure out why it did not: https://github.com/insarlab/MintPy/blob/08ae3f3081d3c3790cbdc3d68b93db84c287dd74/src/mintpy/utils/plot.py#L1657-L1659

Please feel free to open a PR to submit your change. Could you also share an example data and metadata files for testing?

tshreve commented 2 months ago

Hi @yunjunz, you can download the data and metadata files here. Since there is no UNIT defined in the .xml or .vrt files, maybe the issue is related to the data_unit being attributed incorrectly as 'm'?

yunjunz commented 2 months ago

I was able to reproduce the error above, thank you for the data files. The data_unit is recognized as radian, slightly different from the user-specified rad. If you run --unit radian, it will work. However, the code should also work if one type --unit rad. I think modifying utils.plot.scale_data2disp_unit() in the part below, as you suggested (to not grab WAVELENGTH if not necessary), is the right way to go. Could you issue a PR for it?

https://github.com/insarlab/MintPy/blob/08ae3f3081d3c3790cbdc3d68b93db84c287dd74/src/mintpy/utils/plot.py#L1686-L1700