def test_image_auto_conversion_I(self): stokes = numpy.array(random.uniform(-1.0, 1.0, [3, 4, 128, 128])) ipf = PolarisationFrame('stokesI') opf = PolarisationFrame('stokesI') cir = convert_pol_frame(stokes, ipf, opf) st = convert_pol_frame(cir, opf, ipf) assert_array_almost_equal(st.real, stokes, 15)
def test_vis_auto_conversion_I(self): stokes = numpy.array(random.uniform(-1.0, 1.0, [1000, 3, 1])) ipf = PolarisationFrame('stokesI') opf = PolarisationFrame('stokesI') cir = convert_pol_frame(stokes, ipf, opf, polaxis=2) st = convert_pol_frame(cir, opf, ipf, polaxis=2) assert_array_almost_equal(st.real, stokes, 15)
def test_circular_to_linear(self): stokes = numpy.array(random.uniform(-1.0, 1.0, [3, 4, 128, 128])) ipf = PolarisationFrame('stokesIQUV') opf = PolarisationFrame('circular') cir = convert_pol_frame(stokes, ipf, opf) wrong_pf = PolarisationFrame('linear') with self.assertRaises(ValueError): lin = convert_pol_frame(cir, opf, wrong_pf)
def predict_skycomponent_visibility( vis: Union[Visibility, BlockVisibility], sc: Union[Skycomponent, List[Skycomponent]]) -> Visibility: """Predict the visibility from a Skycomponent, add to existing visibility, for Visibility or BlockVisibility :param vis: Visibility or BlockVisibility :param sc: Skycomponent or list of SkyComponents :return: Visibility or BlockVisibility """ if not isinstance(sc, collections.Iterable): sc = [sc] if isinstance(vis, Visibility): _, im_nchan = list(get_frequency_map(vis, None)) npol = vis.polarisation_frame.npol for comp in sc: assert_same_chan_pol(vis, comp) l, m, n = skycoord_to_lmn(comp.direction, vis.phasecentre) phasor = simulate_point(vis.uvw, l, m) for ivis in range(vis.nvis): for pol in range(npol): vis.data['vis'][ivis, pol] += comp.flux[im_nchan[ivis], pol] * phasor[ivis] elif isinstance(vis, BlockVisibility): nchan = vis.nchan npol = vis.npol k = numpy.array(vis.frequency) / constants.c.to('m/s').value for comp in sc: assert_same_chan_pol(vis, comp) flux = comp.flux if comp.polarisation_frame != vis.polarisation_frame: flux = convert_pol_frame(flux, comp.polarisation_frame, vis.polarisation_frame) l, m, n = skycoord_to_lmn(comp.direction, vis.phasecentre) for chan in range(nchan): phasor = simulate_point(vis.uvw * k[chan], l, m) for pol in range(npol): vis.data['vis'][..., chan, pol] += flux[chan, pol] * phasor[...] return vis
def predict_skycomponent_blockvisibility(vis: BlockVisibility, sc: Union[Skycomponent, List[Skycomponent]], **kwargs) -> BlockVisibility: """Predict the visibility from a Skycomponent, add to existing visibility, for BlockVisibility :param vis: BlockVisibility :param sc: Skycomponent or list of SkyComponents :param spectral_mode: {mfs|channel} (channel) :return: BlockVisibility """ assert type( vis) is BlockVisibility, "vis is not a BlockVisibility: %r" % vis if not isinstance(sc, collections.Iterable): sc = [sc] nchan = vis.nchan npol = vis.npol if not isinstance(sc, collections.Iterable): sc = [sc] k = vis.frequency / constants.c.to('m/s').value for comp in sc: assert_same_chan_pol(vis, comp) flux = comp.flux if comp.polarisation_frame != vis.polarisation_frame: flux = convert_pol_frame(flux, comp.polarisation_frame, vis.polarisation_frame) l, m, n = skycoord_to_lmn(comp.direction, vis.phasecentre) for chan in range(nchan): phasor = simulate_point(vis.uvw * k[chan], l, m) for pol in range(npol): vis.data['vis'][..., chan, pol] += flux[chan, pol] * phasor[...] return vis