Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problems in geocoding wrapped interferograms in complex type #955

Closed
comma-never-coma opened this issue Feb 9, 2023 · 4 comments · Fixed by #957
Closed

problems in geocoding wrapped interferograms in complex type #955

comma-never-coma opened this issue Feb 9, 2023 · 4 comments · Fixed by #957

Comments

@comma-never-coma
Copy link
Contributor

Description of the problem
I am trying to geocode ISCE-2 interferograms using geocode.py, and I just run the example commend obtained from geocode.py as follows.
Full script that generated the error

geocode.py filt_fine.int --lat-file ../../geom_reference/lat.rdr --lon-file ../../geom_reference/lon.rdr

The program runs successfully, however the wrapped phase in a geocoded interferogram is incorrect. Phase values after geocoding change into 3.14, which is the same as pi. Give the interferograms below.

Figure_1

Figure_2

And there appears some unexpected messages ComplexWarning in the terminal, this is the output:
Full error message

No lookup table info range/lat found in files.
number of processor to be used: 1
resampling software: pyresample
read latitude / longitude from lookup table file: ../../geom_reference/lat.rdr
output pixel size in (lat, lon) in degree: (-0.00031570278911694004, 0.00032012760497859225)
output area extent in (S, N, W, E) in degree: (33.464494425028974, 33.96488334577933, 112.49700943082642, 113.56847652468977)
output file row / column number: (1585, 3347)
--------------------------------------------------
resampling file: filt_fine.int
--------------------------------------------------1/1
reading complex in block (0, 0, 2550, 1423) from filt_fine.int ...
nearest resampling with pyresample.kd_tree using 1 CPU cores in 6 segments ...
/home/comma/miniconda3/envs/isce2/lib/python3.9/site-packages/pyresample/kd_tree.py:824: ComplexWarning: Casting complex values to real discards the imaginary part
  full_result[valid_output_index] = result
/home/comma/miniconda3/envs/isce2/lib/python3.9/site-packages/mintpy/geocode.py:140: ComplexWarning: Casting complex values to real discards the imaginary part
  dsDict[dsName][block[0]:block[1],
write file: geo_filt_fine.int
write file: geo_filt_fine.int.rsc
write file: geo_filt_fine.int.xml
write file: geo_filt_fine.int.vrt
time used: 00 mins 1.5 secs.

According to the error message, I modified the line 823 in kd_tree.py and line 103 in geocode.py, to add dtype = 'complex_' while creating the matrix, just like:
full_result = np.ones(output_raw_shape, dtype = 'complex_') * fill_value # line 823 in kd_tree.py
dsDict[dsName] = np.zeros((res_obj.length, res_obj.width), dtype = 'complex_') # line 103 in geocode.py
Under the condition dtype = 'complex_', I got a correct geocoded interferogram with geocode.py as below:
Figure_3
At the same time, it would generate the same ComplexWarning under the condition dtype = 'complex_' if we try to geocode unwrapped interferograms or coherence maps whose data type is actually not complex. But the output data seems to be true although there is a ComplexWarning.

System information

  • Operating system: Linux-Ubuntu
  • Python environment: conda
  • MintPy version: 1.5.0
@welcome
Copy link

welcome bot commented Feb 9, 2023

👋 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 yunjunz changed the title problems in geocoding wrapped interferograms problems in geocoding wrapped interferograms in complex type Feb 9, 2023
@yunjunz
Copy link
Member

yunjunz commented Feb 9, 2023

Thank you @comma-never-coma for the reporting and fixing! I am able to reproduce your error and solution. This is because mintpy (and pyresample I guess) was NOT designed to resample complex data arrays.

The following generalization of your solution should work. Could you please issue an pull request in both mintpy and pyresample for this?

                dsDict[dsName] = np.zeros((res_obj.length, res_obj.width))

to:

                dsDict[dsName] = np.zeros((res_obj.length, res_obj.width), dtype=atr['DATA_TYPE'])
    full_result = np.ones(output_raw_shape) * fill_value

to:

    full_result = np.ones(output_raw_shape, dtype=data.dtype) * fill_value

@comma-never-coma
Copy link
Contributor Author

comma-never-coma commented Feb 9, 2023

Thank you @comma-never-coma for the reporting and fixing! I am able to reproduce your error and solution. This is because mintpy (and pysample I guess) was designed to resample complex data arrays.

The following generalization of your solution should work. Could you please issue an pull request in both mintpy and pysample for this?

* In mintpy, change [`mintpy.geocode.py#103`](https://github.com/insarlab/MintPy/blob/1a3e85df8c855b97f9a745b7838023d369579e92/src/mintpy/geocode.py#L103) from:
                dsDict[dsName] = np.zeros((res_obj.length, res_obj.width))

to:

                dsDict[dsName] = np.zeros((res_obj.length, res_obj.width), dtype=atr['DATA_TYPE'])
* In pyresample, change [`pyresample.kd_tree.py#823`](https://github.com/pytroll/pyresample/blob/b8ecc7104cf132f10dee5438eb3049f526199013/pyresample/kd_tree.py#L823) from:
    full_result = np.ones(output_raw_shape) * fill_value

to:

    full_result = np.ones(output_raw_shape, dtype=data.dtype) * fill_value

Thanks for your suggestion! I have issued a pull request in both mintpy and pysample. I'm sorry because this is my first time to make a PR and I'm not sure if there would be something wrong.

@yunjunz
Copy link
Member

yunjunz commented Feb 9, 2023

Thank you @comma-never-coma, your PRs look good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants