def test_stokes_linear_conversion(self): stokes = numpy.array([1.0, 0.0, 0.0, 0.0]) linear = convert_stokes_to_linear(stokes) assert_array_almost_equal( linear, numpy.array([1.0 + 0j, 0.0 + 0j, 0.0 + 0j, 1.0 + 0j])) stokes = numpy.array([0.0, 1.0, 0.0, 0.0]) linear = convert_stokes_to_linear(stokes) assert_array_almost_equal(linear, numpy.array([1.0 + 0j, 0j, 0j, -1.0 + 0j])) stokes = numpy.array([0.0, 0.0, 1.0, 0.0]) linear = convert_stokes_to_linear(stokes) assert_array_almost_equal( linear, numpy.array([0.0 + 0j, 1.0 + 0j, 1.0 + 0j, 0.0 + 0j])) stokes = numpy.array([0.0, 0.0, 0.0, 1.0]) linear = convert_stokes_to_linear(stokes) assert_array_almost_equal( linear, numpy.array([0.0 + 0j, +1.0j, -1.0j, 0.0 + 0j]))
def convert_stokes_to_polimage(im: Image, polarisation_frame: PolarisationFrame): """Convert a stokes image to polarisation_frame """ assert isinstance(im, Image) assert isinstance(polarisation_frame, PolarisationFrame) if polarisation_frame == PolarisationFrame('linear'): cimarr = convert_stokes_to_linear(im.data) return create_image_from_array(cimarr, im.wcs, polarisation_frame) elif polarisation_frame == PolarisationFrame('circular'): cimarr = convert_stokes_to_circular(im.data) return create_image_from_array(cimarr, im.wcs, polarisation_frame) else: raise ValueError("Cannot convert stokes to %s" % (polarisation_frame.type))
def test_stokes_linear_stokes_conversion(self): stokes = numpy.array([1, 0.5, 0.2, -0.1]) linear = convert_stokes_to_linear(stokes) assert_array_almost_equal( convert_linear_to_stokes(linear).real, stokes, 15)