alignment of mpdaf image when no overlap
When using align_with_image using an input image with no overlap with the reference image, an error occurs (below). This case could be treated by the function and return an image with 0 values everywhere, of the same size as the reference image, as well as masked values. I attach the test case which breaks and the detailed error message below.
im_new=Image('TEST_im_new.fits')
im_cube=Image('TEST_im_cube.fits')
im_rebin=im_new.align_with_image(im_cube)
MaskError Traceback (most recent call last) Cell In[17], line 1 ----> 1 im_rebin = im_new.align_with_image(im_cube)
File /opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/mpdaf/obj/image.py:3117, in Image.align_with_image(self, other, flux, inplace, cutoff, antialias, window) 3112 centersky = other.wcs.pix2sky(centerpix)[0] 3114 # Re-sample the rotated image to have the same axis 3115 # increments, offset and number of pixels as the image that we 3116 # are aligning it with. -> 3117 out.regrid(other.shape, centersky, centerpix, 3118 other.wcs.get_axis_increments(unit=u.deg), 3119 flux, unit_inc=u.deg, inplace=True, cutoff=cutoff, 3120 antialias=antialias, window=window) 3121 return out
File /opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/mpdaf/obj/image.py:2806, in Image.regrid(self, newdim, refpos, refpix, newinc, flux, order, interp, unit_pos, unit_inc, antialias, inplace, cutoff, window) 2803 newinc = UnitArray(newinc, unit_inc, self.wcs.unit) 2805 # Get a copy of the data array with masked values filled. -> 2806 data = self._prepare_data(interp) 2808 # If the angular pixel increments along either axis are being 2809 # increased, then low-pass filter the data along that axis to 2810 # prevent aliasing in the resampled data. 2811 if antialias:
File /opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/mpdaf/obj/image.py:1618, in Image._prepare_data(self, interp) 1616 data = self._interp_data(spline=True) 1617 else: -> 1618 data = np.ma.filled(self.data, np.ma.median(self.data)) 1619 return data
File /opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/mpdaf/obj/data.py:548, in DataArray.data(self)
528 @property
529 def data(self):
530 """Return data as a numpy.ma.MaskedArray
.
531
532 The DataArray constructor postpones reading data from FITS files until
(...)
546
547 """
--> 548 res = ma.MaskedArray(self._data, mask=self._mask, copy=False)
549 res._sharedmask = False
550 return res
File /opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/numpy/ma/core.py:2900, in MaskedArray.new(cls, data, mask, dtype, copy, subok, ndmin, fill_value, keep_mask, hard_mask, shrink, order)
2897 else:
2898 msg = "Mask and data not compatible: data size is %i, " +
2899 "mask size is %i."
-> 2900 raise MaskError(msg % (nd, nm))
2901 copy = True
2902 # Set the mask to the new value
MaskError: Mask and data not compatible: data size is 1, mask size is 36.