def import_image_from_fits(fitsfile: str) -> Image: """ Read an Image from fits :param fitsfile: :return: Image """ fim = Image() warnings.simplefilter('ignore', FITSFixedWarning) hdulist = fits.open(fitsfile) fim.data = hdulist[0].data fim.wcs = WCS(fitsfile) hdulist.close() if len(fim.data) == 2: fim.polarisation_frame = PolarisationFrame('stokesI') else: try: fim.polarisation_frame = polarisation_frame_from_wcs( fim.wcs, fim.data.shape) except ValueError: fim.polarisation_frame = PolarisationFrame('stokesI') log.debug( "import_image_from_fits: created %s image of shape %s, size %.3f (GB)" % (fim.data.dtype, str(fim.shape), image_sizeof(fim))) log.debug("import_image_from_fits: Max, min in %s = %.6f, %.6f" % (fitsfile, fim.data.max(), fim.data.min())) assert isinstance(fim, Image) return fim
def test_stokes_conversion(self): assert self.m31image.polarisation_frame == PolarisationFrame("stokesI") stokes = create_test_image( cellsize=0.0001, polarisation_frame=PolarisationFrame("stokesIQUV")) assert stokes.polarisation_frame == PolarisationFrame("stokesIQUV") for pol_name in ['circular', 'linear']: polarisation_frame = PolarisationFrame(pol_name) polimage = convert_stokes_to_polimage( stokes, polarisation_frame=polarisation_frame) assert polimage.polarisation_frame == polarisation_frame polarisation_frame_from_wcs(polimage.wcs, polimage.shape) rstokes = convert_polimage_to_stokes(polimage) assert polimage.data.dtype == 'complex' assert rstokes.data.dtype == 'complex' numpy.testing.assert_array_almost_equal(stokes.data, rstokes.data.real, 12)
def test_polarisation_frame_from_wcs(self): assert self.m31image.polarisation_frame == PolarisationFrame("stokesI") stokes = create_test_image( cellsize=0.0001, polarisation_frame=PolarisationFrame("stokesIQUV")) wcs = stokes.wcs.deepcopy() shape = stokes.shape assert polarisation_frame_from_wcs( wcs, shape) == PolarisationFrame("stokesIQUV") wcs = stokes.wcs.deepcopy().sub(['stokes']) wcs.wcs.crpix[0] = 1.0 wcs.wcs.crval[0] = -1.0 wcs.wcs.cdelt[0] = -1.0 assert polarisation_frame_from_wcs( wcs, shape) == PolarisationFrame('circular') wcs.wcs.crpix[0] = 1.0 wcs.wcs.crval[0] = -5.0 wcs.wcs.cdelt[0] = -1.0 assert polarisation_frame_from_wcs( wcs, shape) == PolarisationFrame('linear') wcs.wcs.crpix[0] = 1.0 wcs.wcs.crval[0] = -1.0 wcs.wcs.cdelt[0] = -1.0 assert polarisation_frame_from_wcs( wcs, shape) == PolarisationFrame('circular') with self.assertRaises(ValueError): wcs.wcs.crpix[0] = 1.0 wcs.wcs.crval[0] = -100.0 wcs.wcs.cdelt[0] = -1.0 polarisation_frame_from_wcs(wcs, shape)