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

Runtime error in shiftnd #19

Open
rhysaph opened this issue Mar 15, 2018 · 6 comments
Open

Runtime error in shiftnd #19

rhysaph opened this issue Mar 15, 2018 · 6 comments

Comments

@rhysaph
Copy link

rhysaph commented Mar 15, 2018

Here is my code:

from image_registration import chi2_shift
from image_registration.fft_tools import shift

# -- Looping over subimages --

image_data1 = fits.getdata(sys.argv[1], ext=x)
image_data2 = fits.getdata(sys.argv[2], ext=x)
noise = np.zeros_like(image_data1,dtype=np.float)
                                                        
xoff, yoff, exoff, eyoff = chi2_shift(image_data1, image_data2, noise, return_error=True, upsample_factor='auto')
shifted_image_data2 = shift.shiftnd(image_data2, -yoff, -xoff)

and here is the runtime error:

  File "./subtractor_registration.py", line 128, in <module>
    shifted_image_data2 = shift.shiftnd(image_data2, -yoff, -xoff)
  File "/home/blah/site-packages/image_registration/fft_tools/shift.py", line 103, in shiftnd
    for dim,(off,nx) in enumerate(zip(offset,data.shape))],
TypeError: zip argument #1 must support iteration

It runs without error for shift.shift2d but produces a very shifted image for two almost aligned images.

@keflavich
Copy link
Owner

You've specified the arguments incorrectly. Look at the help for shiftnd:

Signature: shift.shiftnd(data, offset, phase=0, nthreads=1, use_numpy_fft=False, return_abs=False, return_real=True)
Docstring:
FFT-based sub-pixel image shift.
Will turn NaNs into zeros

Shift Theorem:

.. math::
    FT[f(t-t_0)](x) = e^{-2 \pi i x t_0} F(x)


Parameters
----------
data : np.ndarray
    Data to shift
offset : (int,)*ndim
    Offsets in each direction.  Must be iterable.
phase : float
    Phase, in radians

The offset must be an iterable. You should use shiftnd(image_data2, (-yoff, -xoff))

@cosmicoder
Copy link

Hi, I had the same TypeError of "zip argument #1 must support iteration". From the Quick Example section of the docs I pulled the general application - corrected_image2 = shift.shiftnd(offset_image, -yoff, -xoff)

As you pointed out, the argument has to be (-yoff,-xoff) i.e. a tuple. Can you correct the docs?

@keflavich
Copy link
Owner

@cosmicoder this issue was correct in 21f5a53. Where are you seeing the outdated documentation?

@cosmicoder
Copy link

@cosmicoder this issue was correct in 21f5a53. Where are you seeing the outdated documentation?

Found it here - https://image-registration.readthedocs.io/en/latest/# is this an outdated doc version?

@keflavich
Copy link
Owner

yes, it looks like readthedocs is not building any more

@keflavich
Copy link
Owner

the infrastructure is out of date. Thanks for pointing this out @cosmicoder ; it's going to take a bit of work to refactor this.

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

3 participants