示例#1
0
def convert_stokes_to_polimage(im: Image, polarisation_frame: PolarisationFrame):
    """Convert a stokes image in IQUV to polarisation_frame

    For example::
        impol = convert_stokes_to_polimage(imIQUV, Polarisation_Frame('linear'))

    :param im: Image to be converted
    :param polarisation_frame: desired polarisation frame
    :returns: Complex image

    See also
        :py:func:`rascil.processing_components.image.convert_polimage_to_stokes`
        :py:func:`rascil.data_models.polarisation.convert_circular_to_stokes`
        :py:func:`rascil.data_models.polarisation.convert_linear_to_stokes`
    """

    assert isinstance(im, Image)
    assert image_is_canonical(im)
    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))
示例#2
0
    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 test_stokes_linear_conversion(self):
        stokes = numpy.array([1.0, 0.0, 0.0, 0.0])
        linear = convert_stokes_to_linear(stokes, 0)
        assert_array_almost_equal(
            linear, numpy.array([1.0 + 0j, 0.0 + 0j, 0.0 + 0j, 1.0 + 0j]))

        stokes = numpy.array([1.0, 0.0])
        linearnp = convert_stokes_to_linear(stokes, 0)
        assert_array_almost_equal(linearnp, numpy.array([1.0 + 0j, 1.0 + 0j]))

        stokes = numpy.array([0.0, 1.0, 0.0, 0.0])
        linear = convert_stokes_to_linear(stokes, 0)
        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, 0)
        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, 0)
        assert_array_almost_equal(
            linear, numpy.array([0.0 + 0j, +1.0j, -1.0j, 0.0 + 0j]))

        stokes = numpy.array([1.0, -0.8, 0.2, 0.01])
        linear = convert_stokes_to_linear(stokes, 0)
        assert_array_almost_equal(
            linear,
            numpy.array([0.2 + 0.j, 0.2 + 0.01j, 0.2 - 0.01j, 1.8 + 0.j]))
示例#4
0
 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)
 def test_stokes_linearnp_stokesIQ_conversion(self):
     stokes = numpy.array([1, 0.5])
     linearnp = convert_stokes_to_linear(stokes, 0)
     assert_array_almost_equal(
         convert_linear_to_stokes(linearnp, 0).real, stokes, 15)