def convert_polimage_to_stokes(im: Image): """Convert a polarisation image to stokes IQUV (complex) For example: imIQUV = convert_polimage_to_stokes(impol) :param im: Complex Image in linear or circular :returns: Complex image See also :py:func:`rascil.processing_components.image.convert_stokes_to_polimage` :py:func:`rascil.data_models.polarisation.convert_stokes_to_circular` :py:func:`rascil.data_models.polarisation.convert_stokes_to_linear` """ assert isinstance(im, Image) assert im.data.dtype == 'complex' if im.polarisation_frame == PolarisationFrame('linear'): cimarr = convert_linear_to_stokes(im.data) return create_image_from_array(cimarr, im.wcs, PolarisationFrame('stokesIQUV')) elif im.polarisation_frame == PolarisationFrame('circular'): cimarr = convert_circular_to_stokes(im.data) return create_image_from_array(cimarr, im.wcs, PolarisationFrame('stokesIQUV')) else: raise ValueError("Cannot convert %s to stokes" % (im.polarisation_frame.type))
def convert_polimage_to_stokes(im: Image, complex_image=False, **kwargs): """Convert a polarisation image to stokes IQUV (complex) For example: imIQUV = convert_polimage_to_stokes(impol) :param im: Complex Image in linear or circular :param complex_image: Return complex image? :returns: Complex or Real image See also :py:func:`rascil.processing_components.image.operations.convert_stokes_to_polimage` :py:func:`rascil.data_models.polarisation.convert_stokes_to_circular` :py:func:`rascil.data_models.polarisation.convert_stokes_to_linear` """ assert isinstance(im, Image) assert im.data.dtype == 'complex' def to_required(cimarr): if complex_image: return cimarr else: return numpy.real(cimarr) if im.polarisation_frame == PolarisationFrame('linear'): cimarr = convert_linear_to_stokes(im.data) return create_image_from_array(to_required(cimarr), im.wcs, PolarisationFrame('stokesIQUV')) elif im.polarisation_frame == PolarisationFrame('linearnp'): cimarr = convert_linear_to_stokes(im.data) return create_image_from_array(to_required(cimarr), im.wcs, PolarisationFrame('stokesIQ')) elif im.polarisation_frame == PolarisationFrame('circular'): cimarr = convert_circular_to_stokes(im.data) return create_image_from_array(to_required(cimarr), im.wcs, PolarisationFrame('stokesIQUV')) elif im.polarisation_frame == PolarisationFrame('circularnp'): cimarr = convert_circular_to_stokes(im.data) return create_image_from_array(to_required(cimarr), im.wcs, PolarisationFrame('stokesIV')) elif im.polarisation_frame == PolarisationFrame('stokesI'): return create_image_from_array(to_required(im.data), im.wcs, PolarisationFrame('stokesI')) else: raise ValueError("Cannot convert %s to stokes" % (im.polarisation_frame.type))
def convert_visibility_to_stokes(vis): """Convert the polarisation frame data into Stokes parameters. :param vis: Visibility :return: Converted visibility data. """ poldef = vis.polarisation_frame if poldef == PolarisationFrame('linear'): vis.data['vis'] = convert_linear_to_stokes(vis.data['vis'], polaxis=1) vis.polarisation_frame = PolarisationFrame('stokesIQUV') elif poldef == PolarisationFrame('circular'): vis.data['vis'] = convert_circular_to_stokes(vis.data['vis'], polaxis=1) vis.polarisation_frame = PolarisationFrame('stokesIQUV') return vis
def convert_blockvisibility_to_stokes(vis): """Convert the polarisation frame data into Stokes parameters. Args: vis (obj): RASCIL visibility data. Returns: vis: Converted visibility data. """ poldef = vis.polarisation_frame if poldef == PolarisationFrame('linear'): vis.data['vis'] = convert_linear_to_stokes(vis.data['vis'], polaxis=4) vis.polarisation_frame = PolarisationFrame('stokesIQUV') elif poldef == PolarisationFrame('circular'): vis.data['vis'] = convert_circular_to_stokes(vis.data['vis'], polaxis=4) vis.polarisation_frame = PolarisationFrame('stokesIQUV') return vis
def convert_blockvisibility_to_stokes(vis): """Convert the polarisation frame data into Stokes parameters. :param vis: Visibility :return: Converted visibility data. """ poldef = vis.polarisation_frame if poldef == PolarisationFrame('linear'): vis.data['vis'] = convert_linear_to_stokes(vis.data['vis'], polaxis=4) vis.data['flags'] = \ numpy.logical_or(vis.flags[..., 0], vis.flags[..., 3])[ ..., numpy.newaxis] vis.polarisation_frame = PolarisationFrame('stokesIQUV') elif poldef == PolarisationFrame('circular'): vis.data['vis'] = convert_circular_to_stokes(vis.data['vis'], polaxis=4) vis.data['flags'] = \ numpy.logical_or(vis.flags[..., 0], vis.flags[..., 3])[ ..., numpy.newaxis] vis.polarisation_frame = PolarisationFrame('stokesIQUV') return vis
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)
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)
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)