def test_create_gaintable_from_rows_makecopy(self): self.actualSetup('stokesIQUV', 'linear') gt = create_gaintable_from_blockvisibility(self.vis, timeslice='auto') rows = gt.time > 150.0 for makecopy in [True, False]: selected_gt = create_gaintable_from_rows(gt, rows, makecopy=makecopy) assert selected_gt.ntimes == numpy.sum(numpy.array(rows))
def plot_gaintable_on_screen(vis, gaintables, height=3e5, gaintable_slices=None, plotfile=None): """ Plot a gaintable on an ionospheric screen :param vis: :param sc: Sky components for which pierce points are needed :param height: Height (in m) of screen above telescope e.g. 3e5 :param scale: Multiply the screen by this factor :return: gridded screen image, weights image """ import matplotlib.pyplot as plt assert isinstance(vis, BlockVisibility) station_locations = vis.configuration.xyz t2r = numpy.pi / 43200.0 # The time in the Visibility is hour angle in seconds! plt.clf() for gaintable in gaintables: for iha, rows in enumerate( gaintable_timeslice_iter(gaintable, gaintable_slices=gaintable_slices)): gt = create_gaintable_from_rows(gaintable, rows) ha = numpy.average(gt.time) pp = find_pierce_points(station_locations, (gt.phasecentre.ra.rad + t2r * ha) * u.rad, gt.phasecentre.dec, height=height, phasecentre=vis.phasecentre) phases = numpy.angle(gt.gain[0, :, 0, 0, 0]) plt.scatter(pp[:, 0], pp[:, 1], c=phases, cmap='hsv', alpha=0.75, s=0.1) plt.title('Pierce point phases') plt.xlabel('X (m)') plt.ylabel('Y (m)') if plotfile is not None: plt.savefig(plotfile) plt.show()
def grid_gaintable_to_screen(vis, gaintables, screen, height=3e5, gaintable_slices=None, scale=1.0, **kwargs): """ Grid a gaintable to a screen image The phases are just average per grid cell, no phase unwrapping is performed. :param vis: :param sc: Sky components for which pierce points are needed :param screen: :param height: Height (in m) of screen above telescope e.g. 3e5 :param scale: Multiply the screen by this factor :return: gridded screen image, weights image """ assert isinstance(vis, BlockVisibility) station_locations = vis.configuration.xyz nant = station_locations.shape[0] t2r = numpy.pi / 43200.0 newscreen = create_empty_image_like(screen) weights = create_empty_image_like(screen) nchan, ntimes, ny, nx = screen.shape # The time in the Visibility is hour angle in seconds! number_no_weight = 0 for gaintable in gaintables: for iha, rows in enumerate( gaintable_timeslice_iter(gaintable, gaintable_slices=gaintable_slices)): gt = create_gaintable_from_rows(gaintable, rows) ha = numpy.average(gt.time) pp = find_pierce_points(station_locations, (gt.phasecentre.ra.rad + t2r * ha) * u.rad, gt.phasecentre.dec, height=height, phasecentre=vis.phasecentre) scr = numpy.angle(gt.gain[0, :, 0, 0, 0]) wt = gt.weight[0, :, 0, 0, 0] for ant in range(nant): pp0 = pp[ant][0:2] worldloc = [pp0[0], pp0[1], ha, 1e8] pixloc = newscreen.wcs.wcs_world2pix([worldloc], 0)[0].astype('int') assert pixloc[0] >= 0 assert pixloc[0] < nx assert pixloc[1] >= 0 assert pixloc[1] < ny newscreen.data[pixloc[3], pixloc[2], pixloc[1], pixloc[0]] += wt[ant] * scr[ant] weights.data[pixloc[3], pixloc[2], pixloc[1], pixloc[0]] += wt[ant] if wt[ant] == 0.0: number_no_weight += 1 if number_no_weight > 0: print("grid_gaintable_to_screen: %d pierce points are have no weight" % (number_no_weight)) log.warning( "grid_gaintable_to_screen: %d pierce points are have no weight" % (number_no_weight)) newscreen.data[weights.data > 0.0] = newscreen.data[ weights.data > 0.0] / weights.data[weights.data > 0.0] return newscreen, weights