mtazzari / galario

Gpu Accelerated Library for Analysing Radio Interferometer Observations
https://mtazzari.github.io/galario/
GNU Lesser General Public License v3.0
31 stars 15 forks source link

Add option for upper or lower origin of the input image #118

Closed mtazzari closed 6 years ago

mtazzari commented 6 years ago

At the moment, GALARIO sampleImage takes in input a matrix with x, y pixel axes having the origin in the top left corner and increasing towards the bottom and the right, respectively. The pixel indices start from 0. In the FT interpolation code, the v axis (and thus the Declination) is assumed coaxial with the y axis and everything is self-consistent. FITS files, however, assume the origin in the bottom left corner (and count the pixels starting from 1). This implies that to use a FITS image as an input to sampleImage one needs to do a manual flip up-down and also check that the center of the flipped image is in the cell (Nxy/2, Nxy/2) where Nxy is the number of pixels (starting from 0) (of the matrix, assumed square for simplicity).

There is an easy solution to avoid the flipping in the image taken from a FITS file, and can be implemented as an option (e.g. called origin) to the sampleImage function. Ideally, also to the other functions. E.g.:

sampleImage(reference_image, dxy, udat, vdat, dRA=0., dDec=0., PA=0., origin='lower'):

The solution consists in changing the direction of the interpolating v axis:

    if origin == 'lower':
        v_origin = 1.
    elif origin == 'upper':   
        v_origin = -1.      

    uroti = np.abs(urot)/du
    vroti = nxy/2. - v_origin*vrot/du
    uneg = urot < 0.
    vroti[uneg] = nxy/2 + v_origin*vrot[uneg]/du

This works perfectly and is easy to implement at C level.

mtazzari commented 6 years ago

Descoped for 1.1.