def idft_visibility_skycomponent(vis: Union[Visibility, BlockVisibility], sc: Union[Skycomponent, List[Skycomponent]]) -> \ ([Skycomponent, List[Skycomponent]], List[numpy.ndarray]): """Inverse DFT a Skycomponent from Visibility or BlockVisibility :param vis: Visibility or BlockVisibility :param sc: Skycomponent or list of SkyComponents :return: Skycomponent or list of SkyComponents, array of weights """ if sc is None: return sc if not isinstance(sc, collections.abc.Iterable): sc = [sc] newsc = list() weights_list = list() for comp in sc: assert isinstance(comp, Skycomponent), comp assert_same_chan_pol(vis, comp) newcomp = copy_skycomponent(comp) if isinstance(vis, Visibility): flux = numpy.zeros_like(comp.flux, dtype='complex') weight = numpy.zeros_like(comp.flux, dtype='float') _, im_nchan = list(get_frequency_map(vis, None)) phasor = numpy.conjugate( calculate_visibility_phasor(comp.direction, vis)) fvwp = vis.flagged_weight * vis.flagged_vis * phasor fw = vis.flagged_weight for row in range(vis.nvis): ic = im_nchan[row] flux[ic, :] += fvwp[row, :] weight[ic, :] += fw[row, :] elif isinstance(vis, BlockVisibility): phasor = numpy.conjugate( calculate_blockvisibility_phasor(comp.direction, vis)) flux = numpy.sum(vis.flagged_weight * vis.flagged_vis * phasor, axis=(0, 1, 2)) weight = numpy.sum(vis.flagged_weight, axis=(0, 1, 2)) flux[weight > 0.0] = flux[weight > 0.0] / weight[weight > 0.0] flux[weight <= 0.0] = 0.0 if comp.polarisation_frame != vis.polarisation_frame: flux = convert_pol_frame(flux, vis.polarisation_frame, comp.polarisation_frame) newcomp.flux = flux newsc.append(newcomp) weights_list.append(weight) return newsc, weights_list
def ft_ift_sm(ov, sm, g): assert isinstance(ov, Visibility) or isinstance(ov, BlockVisibility), ov assert isinstance(sm, SkyModel), sm if g is not None: assert len(g) == 2, g assert isinstance(g[0], Image), g[0] assert isinstance(g[1], ConvolutionFunction), g[1] v = copy_visibility(ov) v.data['vis'][...] = 0.0 + 0.0j if len(sm.components) > 0: if isinstance(sm.mask, Image): comps = copy_skycomponent(sm.components) comps = apply_beam_to_skycomponent(comps, sm.mask) v = predict_skycomponent_visibility(v, comps) else: v = predict_skycomponent_visibility(v, sm.components) if isinstance(sm.image, Image): if numpy.max(numpy.abs(sm.image.data)) > 0.0: if isinstance(sm.mask, Image): model = copy_image(sm.image) model.data *= sm.mask.data else: model = sm.image v = predict_list_serial_workflow([v], [model], context=context, vis_slices=vis_slices, facets=facets, gcfcf=[g], **kwargs)[0] assert isinstance(sm.image, Image), sm.image result = invert_list_serial_workflow([v], [sm.image], context=context, vis_slices=vis_slices, facets=facets, gcfcf=[g], **kwargs)[0] if isinstance(sm.mask, Image): result[0].data *= sm.mask.data return result
def ft_cal_sm(obv, sm): assert isinstance(obv, BlockVisibility), obv bv = copy_visibility(obv) bv.data['vis'][...] = 0.0 + 0.0j assert len(sm.components) > 0 if isinstance(sm.mask, Image): comps = copy_skycomponent(sm.components) comps = apply_beam_to_skycomponent(comps, sm.mask) bv = predict_skycomponent_visibility(bv, comps) else: bv = predict_skycomponent_visibility(bv, sm.components) if docal and isinstance(sm.gaintable, GainTable): bv = apply_gaintable(bv, sm.gaintable, inverse=True) return bv
def test_apply_primary_beam_imageplane(self): self.createVis() telescope = 'MID' lflux = numpy.array([[100.0, 1.0, -10.0, +60.0]]) cflux = numpy.array([[100.0, 60.0, -10.0, +1.0]]) apply_pb = True for flux, vpol in ((lflux, PolarisationFrame("linear")), (cflux, PolarisationFrame("circular"))): # print("Testing {0}".format(vpol.type)) # print("Original flux = {}".format(flux)) bvis = create_blockvisibility( self.config, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=vpol, zerow=True) component_centre = SkyCoord(ra=+15.5 * u.deg, dec=-35.0 * u.deg, frame='icrs', equinox='J2000') component = create_skycomponent( direction=component_centre, flux=flux, frequency=self.frequency, polarisation_frame=PolarisationFrame("stokesIQUV")) model = create_image_from_visibility( bvis, cellsize=self.cellsize, npixel=self.npixel, override_cellsize=False, polarisation_frame=PolarisationFrame("stokesIQUV")) pb = create_pb(model, telescope=telescope, use_local=False) if apply_pb: pbcomp = apply_beam_to_skycomponent(component, pb) # print("After application of primary beam {}".format(str(pbcomp.flux))) else: pbcomp = copy_skycomponent(component) bvis = dft_skycomponent_visibility(bvis, pbcomp) iquv_image = idft_visibility_skycomponent(bvis, component)[0]
def ft_cal_sm(ov, sm, g): assert isinstance(ov, Visibility), ov assert isinstance(sm, SkyModel), sm if g is not None: assert len(g) == 2, g assert isinstance(g[0], Image), g[0] assert isinstance(g[1], ConvolutionFunction), g[1] v = copy_visibility(ov) v.data['vis'][...] = 0.0 + 0.0j if len(sm.components) > 0: if isinstance(sm.mask, Image): comps = copy_skycomponent(sm.components) comps = apply_beam_to_skycomponent(comps, sm.mask) v = predict_skycomponent_visibility(v, comps) else: v = predict_skycomponent_visibility(v, sm.components) if isinstance(sm.image, Image): if numpy.max(numpy.abs(sm.image.data)) > 0.0: if isinstance(sm.mask, Image): model = copy_image(sm.image) model.data *= sm.mask.data else: model = sm.image v = predict_list_serial_workflow([v], [model], context=context, vis_slices=vis_slices, facets=facets, gcfcf=[g], **kwargs)[0] if docal and isinstance(sm.gaintable, GainTable): bv = convert_visibility_to_blockvisibility(v) bv = apply_gaintable(bv, sm.gaintable, inverse=True) v = convert_blockvisibility_to_visibility(bv) return v