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

problem with isce3.cal.point_target_info.oversample #14

Open
kanglcn opened this issue Jun 10, 2023 · 1 comment
Open

problem with isce3.cal.point_target_info.oversample #14

kanglcn opened this issue Jun 10, 2023 · 1 comment

Comments

@kanglcn
Copy link

kanglcn commented Jun 10, 2023

isce3 version 0.13.0, installed from conda-forge

I find when apply oversample to an array, the original array will be changed.

A minimum test case:

from isce3.cal.point_target_info import oversample
import numpy as np

a = np.random.rand(10,10)+1j*np.random.rand(10,10)
a_copy = a.copy()

np.testing.assert_array_equal(a,a_copy) # it passed with no error

a_oversampled = oversample(a,nov=5)

np.testing.assert_array_equal(a,a_copy) # it failed
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Cell In[38], line 1
----> 1 np.testing.assert_array_equal(a,a_copy)

    [... skipping hidden 1 frame]

File /lustre/work/client/users/kangl/.conda/envs/gslc_13/lib/python3.11/contextlib.py:81, in ContextDecorator.__call__.<locals>.inner(*args, **kwds)
     78 @wraps(func)
     79 def inner(*args, **kwds):
     80     with self._recreate_cm():
---> 81         return func(*args, **kwds)

File /lustre/work/client/users/kangl/.conda/envs/gslc_13/lib/python3.11/site-packages/numpy/testing/_private/utils.py:862, in assert_array_compare(comparison, x, y, err_msg, verbose, header, precision, equal_nan, equal_inf, strict)
    858         err_msg += '\n' + '\n'.join(remarks)
    859         msg = build_err_msg([ox, oy], err_msg,
    860                             verbose=verbose, header=header,
    861                             names=('x', 'y'), precision=precision)
--> 862         raise AssertionError(msg)
    863 except ValueError:
    864     import traceback

AssertionError: 
Arrays are not equal

Mismatched elements: 99 / 100 (99%)
Max absolute difference: 0.60713429
Max relative difference: 0.64424912
 x: array([[0.662784+0.404032j, 0.666327+0.449343j, 0.673974+0.373827j,
        0.501126+0.900433j, 0.676094+0.160175j, 0.771293+0.304292j,
        0.875867+0.731421j, 0.461425-0.130037j, 0.856009-0.075911j,...
 y: array([[0.662784+0.404032j, 0.642459+0.482853j, 0.632233+0.440759j,
        0.357471+0.9665j  , 0.629393+0.294318j, 0.669114+0.489666j,
        0.613705+0.962022j, 0.47772 +0.040072j, 0.815438+0.271247j,...

I suspect the problem is in

def shift_frequency(z, fx, fy):
x = np.arange(z.shape[1])
y = np.arange(z.shape[0])
z *= np.exp(1j * fx * x)[None,:]
z *= np.exp(1j * fy * y)[:,None]
return z

The *= is in-place operator. It shouldn't be used here. But I haven't do any test on it.

@bhawkins
Copy link

Thanks for the report! I don't really mind shift_frequency operating in-place, but it should probably return None in order to prevent this sort of confusion. I agree it's surprising that oversample would modify the input array and will try to include a patch in the next release.

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

No branches or pull requests

2 participants