def skymodel_cal_fit_skymodel(vis, calskymodel, gain=0.1, method='fit', **kwargs): """Fit a single skymodel to a visibility This is the update to the component part of the window. :param evis: Expected vis for this ssm :param calskymodel: scm element being fit i.e. (skymodel, gaintable) tuple :param gain: Gain in step :param method: 'fit' or 'sum' :param kwargs: :return: skycomponent """ cvis = convert_blockvisibility_to_visibility(vis) new_comps = list() for comp in calskymodel[0].components: new_comp = copy_skycomponent(comp) if method == 'sum': new_flux, _ = sum_visibility(cvis, new_comp.direction) new_comp.flux = gain * new_flux + (1.0 - gain) * comp[0].flux else: new_comp, _ = fit_visibility(cvis, new_comp) new_comp.flux = gain * new_comp.flux + (1.0 - gain) * comp.flux new_comps.append(new_comp) return SkyModel(components=new_comps)
def _checkcomponents(self, dirty, fluxthreshold=1.0, positionthreshold=1.0, check_dft=False): comps = find_skycomponents(dirty, fwhm=1.0, threshold=10 * fluxthreshold, npixels=5) assert len(comps) == len(self.components), "Different number of components found: original %d, recovered %d" % \ (len(self.components), len(comps)) cellsize = abs(dirty.wcs.wcs.cdelt[0]) for comp in comps: # Check for agreement in direction ocomp = find_nearest_component(comp.direction, self.components) radiff = abs(comp.direction.ra.deg - ocomp.direction.ra.deg) / cellsize assert radiff < positionthreshold, "Component differs in dec %.3f pixels" % radiff decdiff = abs(comp.direction.dec.deg - ocomp.direction.dec.deg) / cellsize assert decdiff < positionthreshold, "Component differs in dec %.3f pixels" % decdiff # Check for agreement between in flux image and DFT if check_dft: for comp in comps: sflux = sum_visibility(self.componentvis, comp.direction)[0] assert abs(comp.flux[0, 0] - sflux[0, 0]) < fluxthreshold, \ "Fitted and DFT flux differ %s %s" % (comp.flux[0, 0], sflux[0, 0])
def test_visibilitysum(self): self.vis = create_visibility(self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame("stokesIQUV")) self.vismodel = predict_skycomponent_visibility(self.vis, self.comp) # Sum the visibilities in the correct_visibility direction. This is limited by numerical precision summedflux, weight = sum_visibility(self.vismodel, self.compreldirection) assert_allclose(self.flux, summedflux, rtol=1e-7)
def test_sum_visibility(self): self.vis = create_visibility(self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, polarisation_frame=PolarisationFrame("linear"), weight=1.0) self.vis = predict_skycomponent_visibility(self.vis, self.comp) flux, weight = sum_visibility(self.vis, self.comp.direction) assert numpy.max(numpy.abs(flux - self.flux)) < 1e-7
def sagecal_fit_component(evis, theta, gain=0.1, method='fit', **kwargs): """Fit a single component to a visibility i.e. A13 This is the update to the component part of the window :param evis: :param theta: :param kwargs: :return: """ cvis = convert_blockvisibility_to_visibility(evis) new_comp = copy_skycomponent(theta[0]) if method == 'sum': new_flux, _ = sum_visibility(cvis, new_comp.direction) new_comp.flux = gain * new_flux + (1.0 - gain) * theta[0].flux else: new_comp, _ = fit_visibility(cvis, new_comp) new_comp.flux = gain * new_comp.flux + (1.0 - gain) * theta[0].flux return new_comp