def create_griddata_from_array( data: numpy.array, grid_wcs: WCS, projection_wcs: WCS, polarisation_frame: PolarisationFrame) -> GridData: """ Create a griddata from an array and wcs's The griddata has axes [chan, pol, z, y, x] where z, y, x are spatial axes in either sky or Fourier plane. The order in the WCS is reversed so the grid_WCS describes UU, VV, WW, STOKES, FREQ axes Griddata holds the original sky plane projection in the projection_wcs. :param data: Numpy.array :param grid_wcs: Grid world coordinate system :param projection_wcs: Projection world coordinate system :param polarisation_frame: Polarisation Frame :return: GridData """ fgriddata = GridData() fgriddata.polarisation_frame = polarisation_frame fgriddata.data = data fgriddata.grid_wcs = grid_wcs.deepcopy() fgriddata.projection_wcs = projection_wcs.deepcopy() if griddata_sizeof(fgriddata) >= 1.0: log.debug( "create_griddata_from_array: created %s image of shape %s, size %.3f (GB)" % (fgriddata.data.dtype, str( fgriddata.shape), griddata_sizeof(fgriddata))) assert isinstance(fgriddata, GridData), "Type is %s" % type(fgriddata) return fgriddata
def grid_visibility_weight_to_griddata(vis, griddata: GridData, cf): """Grid Visibility weight onto a GridData :param vis: Visibility to be gridded :param griddata: GridData :return: GridData """ assert isinstance(vis, Visibility), vis assert vis.polarisation_frame == griddata.polarisation_frame nchan, npol, nz, ny, nx = griddata.shape sumwt = numpy.zeros([nchan, npol]) pu_grid, pu_offset, pv_grid, pv_offset, pwg_grid, pwg_fraction, pwc_grid, pwc_fraction, pfreq_grid = \ convolution_mapping_visibility(vis, griddata, vis.frequency, cf) _, _, _, _, _, gv, gu = cf.shape coords = zip(vis.flagged_imaging_weight, pfreq_grid, pu_grid, pv_grid, pwg_grid) griddata.data[...] = 0.0 real_gd = numpy.real(griddata.data) for vwt, chan, xx, yy, zzg in coords: real_gd[chan, :, zzg, yy, xx] += vwt sumwt[chan, :] += vwt griddata.data = real_gd.astype("complex") return griddata, sumwt
def grid_blockvisibility_weight_to_griddata(vis, griddata: GridData, cf): """Grid BlockVisibility weight onto a GridData :param vis: BlockVisibility to be gridded :param griddata: GridData :param cf: Convolution function :return: GridData """ assert isinstance(vis, BlockVisibility), vis assert vis.polarisation_frame == griddata.polarisation_frame nchan, npol, nz, ny, nx = griddata.shape sumwt = numpy.zeros([nchan, npol]) _, _, _, _, _, gv, gu = cf.shape vis_to_im = numpy.round( griddata.grid_wcs.sub([5]).wcs_world2pix(vis.frequency, 0)[0]).astype('int') griddata.data[...] = 0.0 real_gd = numpy.real(griddata.data) nrows, nants, _, nvchan, nvpol = vis.vis.shape # Transpose to get row varying fastest fwtt = vis.flagged_imaging_weight.reshape([nrows * nants * nants, nvchan, nvpol]).T for vchan in range(nvchan): imchan = vis_to_im[vchan] pu_grid, pu_offset, pv_grid, pv_offset, pwg_grid, _, _, _ = \ convolution_mapping_blockvisibility(vis, griddata, vis.frequency[vchan], cf) for pol in range(nvpol): for row in range(nrows * nants * nants): real_gd[imchan, pol, pwg_grid[row], pv_grid[row], pu_grid[row]] += fwtt[ pol, vchan, row] sumwt[imchan, pol] += fwtt[pol, vchan, row] griddata.data = real_gd.astype("complex") return griddata, sumwt
def copy_griddata(gd): """ Copy griddata :param gd: :return: """ assert isinstance(gd, GridData), gd newgd = GridData() newgd.polarisation_frame = gd.polarisation_frame newgd.data = copy.deepcopy(gd.data) if gd.grid_wcs is None: newgd.grid_wcs = None else: newgd.grid_wcs = copy.deepcopy(gd.grid_wcs) if gd.projection_wcs is None: newgd.projection_wcs = None else: newgd.projection_wcs = copy.deepcopy(gd.projection_wcs) if griddata_sizeof(newgd) >= 1.0: log.debug("copy_image: copied %s image of shape %s, size %.3f (GB)" % (newgd.data.dtype, str(newgd.shape), griddata_sizeof(newgd))) assert type(newgd) == GridData return newgd