Example #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))
Example #2
0
    def test_stokes_circular_conversion(self):
        stokes = numpy.array([1.0, 0.0, 0.0, 0.0])
        circular = convert_stokes_to_circular(stokes)
        assert_array_almost_equal(
            circular, 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])
        circular = convert_stokes_to_circular(stokes)
        assert_array_almost_equal(circular,
                                  numpy.array([0.0 + 0j, -1j, -1j, 0.0 + 0j]))

        stokes = numpy.array([0.0, 0.0, 1.0, 0.0])
        circular = convert_stokes_to_circular(stokes)
        assert_array_almost_equal(
            circular, 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])
        circular = convert_stokes_to_circular(stokes)
        assert_array_almost_equal(
            circular, numpy.array([1.0 + 0j, +0.0j, 0.0j, -1.0 + 0j]))
    def test_stokes_circular_conversion(self):
        stokes = numpy.array([1.0, 0.0, 0.0, 0.0])
        circular = convert_stokes_to_circular(stokes, 0)
        assert_array_almost_equal(
            circular, numpy.array([1.0 + 0j, 0.0 + 0j, 0.0 + 0j, 1.0 + 0j]))

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

        stokes = numpy.array([0.0, 1.0, 0.0, 0.0])
        circular = convert_stokes_to_circular(stokes, 0)
        assert_array_almost_equal(circular,
                                  numpy.array([0.0 + 0j, -1j, -1j, 0.0 + 0j]))

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

        stokes = numpy.array([1.0, -0.8, 0.2, 0.01])
        linear = convert_stokes_to_circular(stokes, 0)
        assert_array_almost_equal(
            linear,
            numpy.array([1.01 + 0.j, 0.2 + 0.8j, -0.2 + 0.8j, 0.99 + 0.j]))
Example #4
0
 def test_vis_conversion(self):
     stokes = numpy.array(random.uniform(-1.0, 1.0, [1000, 3, 4]))
     cir = convert_stokes_to_circular(stokes, polaxis=2)
     st = convert_circular_to_stokes(cir, polaxis=2)
     assert_array_almost_equal(st.real, stokes, 15)
Example #5
0
 def test_image_conversion(self):
     stokes = numpy.array(random.uniform(-1.0, 1.0, [3, 4, 128, 128]))
     cir = convert_stokes_to_circular(stokes)
     st = convert_circular_to_stokes(cir)
     assert_array_almost_equal(st.real, stokes, 15)
Example #6
0
 def test_stokes_circular_stokes_conversion(self):
     stokes = numpy.array([1, 0.5, 0.2, -0.1])
     circular = convert_stokes_to_circular(stokes)
     assert_array_almost_equal(
         convert_circular_to_stokes(circular).real, stokes, 15)
 def test_stokes_circularnp_stokesIV_conversion(self):
     stokes = numpy.array([1, 0.5])
     circularnp = convert_stokes_to_circular(stokes, 0)
     assert_array_almost_equal(
         convert_circular_to_stokes(circularnp, 0).real, stokes, 15)