Hi James

On Thu, Mar 15, 2007 at 06:01:55PM -0400, James Turner wrote:
> >Code snippets to illustrate the problem would be welcome.
> 
> OK. I have had a go at producing a code snippet. I apologize that
> this is based on numarray rather than numpy, since I'm using STScI
> Python, but I think it should be very easy to convert if you have
> numpy instead.
> 
> What I am doing is to transform overlapping input images onto a
> common, larger grid and co-adding them. Although I'm using affine_
> transform on 3D data from FITS images, the issue can be illustrated
> using a simple 1D translation of a single 2D test array. The input
> values are just [4., 3., 2., 1.] in each row. With a translation of
> -0.1, the values should therefore be something like
> [X, 3.1, 2.1, 1.1, X, X], where the Xs represent points outside the
> original data range. What I actually get, however, is roughly
> [X, 3.1, 2.1, 1.0, 1.9, X]. The 5th value of 1.9 contaminates the
> co-added data in the final output array. Now I'm looking at this
> element-by-element, I suppose the bad value of 1.9 is just a result
> of extrapolating in order to preserve the original number of data
> points, isn't it? Sorry I wasn't clear on that in my original post
> -- but surely a blank value (as specified by cval) would be better?

I'd like to confirm that you see the same results when running your
script:

[[ 4.  3.  2.  1.]
 [ 4.  3.  2.  1.]]
[[-1.          3.12520003  2.11439991  1.01719999  1.87479997 -1.        ]
 [-1.          3.12520003  2.11439991  1.01719999  1.87479997 -1.        ]]
[[-1.          3.0996666   2.0999999   1.34300005  1.90033329 -1.        ]
 [-1.          3.0996666   2.0999999   1.34300005  1.90033329 -1.        ]]

Cheers
Stéfan
import numpy as N
from scipy import ndimage as ndi

# Create a 2D test pattern:
I = N.zeros((2,4),N.float32)
I[:,:] = N.arange(4.0, 0.0, -1.0)

# Transformation parameters for a simple translation in 1D:
trmatrix = N.array([[1,0],[0,1]])
troffset = (0.0, -0.1)

# Apply the offset to the test pattern:
I_off1 = ndi.affine_transform(I, trmatrix, troffset, order=3, mode='constant',
                              cval=-1.0, output_shape=(2,6))

I_off2 = ndi.affine_transform(I, trmatrix, troffset, order=3, mode='constant',
                              cval=-1.0, output_shape=(2,6), prefilter=False)

# Compare the data before and after interpolation:
print I
print I_off1
print I_off2
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to