def __init__(self, header=None, wcs=None): super(WCSCoordinates, self).__init__() from astropy.wcs import WCS if header is None and wcs is None: raise ValueError('Must provide either FITS header or WCS or both') if header is None: header = wcs.to_header() self._header = header try: naxis = header['NAXIS'] except (KeyError, TypeError): naxis = None wcs = wcs or WCS(header, naxis=naxis) # update WCS interface if using old API mapping = { 'wcs_pix2world': 'wcs_pix2sky', 'wcs_world2pix': 'wcs_sky2pix', 'all_pix2world': 'all_pix2sky' } for k, v in mapping.items(): if not hasattr(wcs, k): setattr(wcs, k, getattr(wcs, v)) self._wcs = wcs # Pre-compute dependent axes. The matrix returned by # axis_correlation_matrix is (n_world, n_pixel) but we want to know # which pixel coordinates are linked to which other pixel coordinates. # So to do this we take a column from the matrix and find if there are # any entries in common with all other columns in the matrix. matrix = axis_correlation_matrix(wcs)[::-1, ::-1] self._dependent_axes = [] for axis in range(wcs.naxis): world_dep = matrix[:, axis:axis + 1] dependent = tuple(np.nonzero((world_dep & matrix).any(axis=0))[0]) self._dependent_axes.append(dependent)
def __init__(self, header=None, wcs=None): super(WCSCoordinates, self).__init__() from astropy.wcs import WCS if header is None and wcs is None: raise ValueError('Must provide either FITS header or WCS or both') if header is None: header = wcs.to_header() self._header = header try: naxis = header['NAXIS'] except (KeyError, TypeError): naxis = None wcs = wcs or WCS(header, naxis=naxis) # update WCS interface if using old API mapping = {'wcs_pix2world': 'wcs_pix2sky', 'wcs_world2pix': 'wcs_sky2pix', 'all_pix2world': 'all_pix2sky'} for k, v in mapping.items(): if not hasattr(wcs, k): setattr(wcs, k, getattr(wcs, v)) self._wcs = wcs # Pre-compute dependent axes. The matrix returned by # axis_correlation_matrix is (n_world, n_pixel) but we want to know # which pixel coordinates are linked to which other pixel coordinates. # So to do this we take a column from the matrix and find if there are # any entries in common with all other columns in the matrix. matrix = axis_correlation_matrix(wcs)[::-1, ::-1] self._dependent_axes = [] for axis in range(wcs.naxis): world_dep = matrix[:, axis:axis + 1] dependent = tuple(np.nonzero((world_dep & matrix).any(axis=0))[0]) self._dependent_axes.append(dependent)