processing_components/griddata/gridding.py
def convolution_mapping(vis, griddata, cf, channel_tolerance=1e-8):
    """Find the mappings between visibility, griddata, and convolution function
    
    :param vis:
    :param griddata:
    :param cf_griddata:
    :return:
    """
    
    assert isinstance(vis, Visibility), vis
    
    numpy.testing.assert_almost_equal(griddata.grid_wcs.wcs.cdelt[0], cf.grid_wcs.wcs.cdelt[0], 7)
    numpy.testing.assert_almost_equal(griddata.grid_wcs.wcs.cdelt[1], cf.grid_wcs.wcs.cdelt[1], 7)
    
    ####### UV mapping
    # We use the grid_wcs's to do the coordinate conversion
    # Find the nearest grid points
    pu_grid, pv_grid = \
        numpy.round(griddata.grid_wcs.sub([1, 2]).wcs_world2pix(vis.uvw[:, 0], vis.uvw[:, 1], 0)).astype('int')
    assert numpy.min(pu_grid) >= 0, "U axis underflows: %f" % numpy.min(pu_grid)
    assert numpy.max(pu_grid) < griddata.shape[3], "U axis overflows: %f" % numpy.max(pu_grid)
    assert numpy.min(pv_grid) >= 0, "V axis underflows: %f" % numpy.min(pv_grid)
    assert numpy.max(pv_grid) < griddata.shape[4], "V axis overflows: %f" % numpy.max(pv_grid)
    
    # We now have the location of grid points, convert back to uv space and find the remainder (in wavelengths). We
    # then use this to calculate the subsampling indices (DUU, DVV)
    wu_grid, wv_grid = griddata.grid_wcs.sub([1, 2]).wcs_pix2world(pu_grid, pv_grid, 0)
    wu_subsample, wv_subsample = vis.uvw[:, 0] - wu_grid, vis.uvw[:, 1] - wv_grid
    
    pu_offset, pv_offset = \
        numpy.floor(cf.grid_wcs.sub([3, 4]).wcs_world2pix(wu_subsample, wv_subsample, 0)).astype('int')
    
    ###### W mapping for Grid
    # nchan, npol, w, v, u
    pwg_pixel = griddata.grid_wcs.sub([3]).wcs_world2pix(vis.uvw[:, 2], 0)[0]
    # Find the nearest grid point
    pwg_grid = numpy.round(pwg_pixel).astype('int')
    if numpy.min(pwg_grid) < 0:
        print(vis.uvw[0:10, 2])
        print(cf.grid_wcs.sub([5]).__repr__())
    assert numpy.min(pwg_grid) >= 0, "W axis underflows: %f" % numpy.min(pwg_grid)
    assert numpy.max(pwg_grid) < cf.shape[2], "W axis overflows: %f" % numpy.max(pwg_grid)
    pwg_fraction = pwg_pixel - pwg_grid
    
    ###### W mapping for CF
    # nchan, npol, w, dv, du, v, u
    pwc_pixel = cf.grid_wcs.sub([5]).wcs_world2pix(vis.uvw[:, 2], 0)[0]
    pwc_grid = numpy.round(pwc_pixel).astype('int')
    if numpy.min(pwc_grid) < 0:
        print(vis.uvw[0:10, 2])
        print(cf.grid_wcs.sub([5]).__repr__())
    assert numpy.min(pwc_grid) >= 0, "W axis underflows: %f" % numpy.min(pwc_grid)
    assert numpy.max(pwc_grid) < cf.shape[2], "W axis overflows: %f" % numpy.max(pwc_grid)
    pwc_fraction = pwc_pixel - pwc_grid
    
    ###### Frequency mapping
    pfreq_pixel = griddata.grid_wcs.sub([5]).wcs_world2pix(vis.frequency, 0)[0]
    # Find the nearest grid point
    pfreq_grid = numpy.round(pfreq_pixel).astype('int')
    assert numpy.min(pfreq_grid) >= 0, "Frequency axis underflows: %f" % numpy.max(pfreq_grid)
    assert numpy.max(pfreq_grid) < cf.shape[0], "Frequency axis overflows: %f" % numpy.max(pfreq_grid)
    pfreq_fraction = pfreq_pixel - pfreq_grid
    # If we are doing spectral imaging, check the tolerances
    is_spectral = cf.shape[0] > 1
    if is_spectral and (numpy.max(numpy.abs(pfreq_fraction)) > channel_tolerance):
        print("convolution_mapping: alignment of visibility and image frequency grids exceeds tolerance %s" %
                    (numpy.max(pfreq_fraction)))
        log.warning("convolution_mapping: alignment of visibility and image frequency grids exceeds tolerance %s" %
                    (numpy.max(pfreq_fraction)))

    ######  TODO: Polarisation mapping
    
    return pu_grid, pu_offset, pv_grid, pv_offset, pwg_grid, pwg_fraction, pwc_grid, pwc_fraction, pfreq_grid
Find the mappings between visibility, griddata, and convolution function
    
    :param vis:
    :param griddata:
    :param cf_griddata:
    :return:
    
Find the mappings between visibility, griddata, and convolution function
Find the mappings between visibility griddata and convolution function
def convolution_mapping(vis, griddata, cf, channel_tolerance=1e-8):
    assert isinstance(vis, Visibility), vis
    numpy.testing.assert_almost_equal(griddata.grid_wcs.wcs.cdelt[0], cf.grid_wcs.wcs.cdelt[0], 7)
    numpy.testing.assert_almost_equal(griddata.grid_wcs.wcs.cdelt[1], cf.grid_wcs.wcs.cdelt[1], 7)
    pu_grid, pv_grid = \
        numpy.round(griddata.grid_wcs.sub([1, 2]).wcs_world2pix(vis.uvw[:, 0], vis.uvw[:, 1], 0)).astype('int')
    assert numpy.min(pu_grid) >= 0, "U axis underflows: %f" % numpy.min(pu_grid)
    assert numpy.max(pu_grid) < griddata.shape[3], "U axis overflows: %f" % numpy.max(pu_grid)
    assert numpy.min(pv_grid) >= 0, "V axis underflows: %f" % numpy.min(pv_grid)
    assert numpy.max(pv_grid) < griddata.shape[4], "V axis overflows: %f" % numpy.max(pv_grid)
    wu_grid, wv_grid = griddata.grid_wcs.sub([1, 2]).wcs_pix2world(pu_grid, pv_grid, 0)
    wu_subsample, wv_subsample = vis.uvw[:, 0] - wu_grid, vis.uvw[:, 1] - wv_grid
    pu_offset, pv_offset = \
        numpy.floor(cf.grid_wcs.sub([3, 4]).wcs_world2pix(wu_subsample, wv_subsample, 0)).astype('int')
    pwg_pixel = griddata.grid_wcs.sub([3]).wcs_world2pix(vis.uvw[:, 2], 0)[0]
    pwg_grid = numpy.round(pwg_pixel).astype('int')
    if numpy.min(pwg_grid) < 0:
        print(vis.uvw[0:10, 2])
        print(cf.grid_wcs.sub([5]).__repr__())
    assert numpy.min(pwg_grid) >= 0, "W axis underflows: %f" % numpy.min(pwg_grid)
    assert numpy.max(pwg_grid) < cf.shape[2], "W axis overflows: %f" % numpy.max(pwg_grid)
    pwg_fraction = pwg_pixel - pwg_grid
    pwc_pixel = cf.grid_wcs.sub([5]).wcs_world2pix(vis.uvw[:, 2], 0)[0]
    pwc_grid = numpy.round(pwc_pixel).astype('int')
    if numpy.min(pwc_grid) < 0:
        print(vis.uvw[0:10, 2])
        print(cf.grid_wcs.sub([5]).__repr__())
    assert numpy.min(pwc_grid) >= 0, "W axis underflows: %f" % numpy.min(pwc_grid)
    assert numpy.max(pwc_grid) < cf.shape[2], "W axis overflows: %f" % numpy.max(pwc_grid)
    pwc_fraction = pwc_pixel - pwc_grid
    pfreq_pixel = griddata.grid_wcs.sub([5]).wcs_world2pix(vis.frequency, 0)[0]
    pfreq_grid = numpy.round(pfreq_pixel).astype('int')
    assert numpy.min(pfreq_grid) >= 0, "Frequency axis underflows: %f" % numpy.max(pfreq_grid)
    assert numpy.max(pfreq_grid) < cf.shape[0], "Frequency axis overflows: %f" % numpy.max(pfreq_grid)
    pfreq_fraction = pfreq_pixel - pfreq_grid
    is_spectral = cf.shape[0] > 1
    if is_spectral and (numpy.max(numpy.abs(pfreq_fraction)) > channel_tolerance):
        print("convolution_mapping: alignment of visibility and image frequency grids exceeds tolerance %s" %
                    (numpy.max(pfreq_fraction)))
        log.warning("convolution_mapping: alignment of visibility and image frequency grids exceeds tolerance %s" %
                    (numpy.max(pfreq_fraction)))
    return pu_grid, pu_offset, pv_grid, pv_offset, pwg_grid, pwg_fraction, pwc_grid, pwc_fraction, pfreq_grid
def convolution_mapping ( vis , griddata , cf , channel_tolerance = 1e-8 ) : assert isinstance ( vis , Visibility ) , vis numpy . testing . assert_almost_equal ( griddata . grid_wcs . wcs . cdelt [ 0 ] , cf . grid_wcs . wcs . cdelt [ 0 ] , 7 ) numpy . testing . assert_almost_equal ( griddata . grid_wcs . wcs . cdelt [ 1 ] , cf . grid_wcs . wcs . cdelt [ 1 ] , 7 ) pu_grid , pv_grid = numpy . round ( griddata . grid_wcs . sub ( [ 1 , 2 ] ) . wcs_world2pix ( vis . uvw [ : , 0 ] , vis . uvw [ : , 1 ] , 0 ) ) . astype ( 'int' ) assert numpy . min ( pu_grid ) >= 0 , "U axis underflows: %f" % numpy . min ( pu_grid ) assert numpy . max ( pu_grid ) < griddata . shape [ 3 ] , "U axis overflows: %f" % numpy . max ( pu_grid ) assert numpy . min ( pv_grid ) >= 0 , "V axis underflows: %f" % numpy . min ( pv_grid ) assert numpy . max ( pv_grid ) < griddata . shape [ 4 ] , "V axis overflows: %f" % numpy . max ( pv_grid ) wu_grid , wv_grid = griddata . grid_wcs . sub ( [ 1 , 2 ] ) . wcs_pix2world ( pu_grid , pv_grid , 0 ) wu_subsample , wv_subsample = vis . uvw [ : , 0 ] - wu_grid , vis . uvw [ : , 1 ] - wv_grid pu_offset , pv_offset = numpy . floor ( cf . grid_wcs . sub ( [ 3 , 4 ] ) . wcs_world2pix ( wu_subsample , wv_subsample , 0 ) ) . astype ( 'int' ) pwg_pixel = griddata . grid_wcs . sub ( [ 3 ] ) . wcs_world2pix ( vis . uvw [ : , 2 ] , 0 ) [ 0 ] pwg_grid = numpy . round ( pwg_pixel ) . astype ( 'int' ) if numpy . min ( pwg_grid ) < 0 : print ( vis . uvw [ 0 : 10 , 2 ] ) print ( cf . grid_wcs . sub ( [ 5 ] ) . __repr__ ( ) ) assert numpy . min ( pwg_grid ) >= 0 , "W axis underflows: %f" % numpy . min ( pwg_grid ) assert numpy . max ( pwg_grid ) < cf . shape [ 2 ] , "W axis overflows: %f" % numpy . max ( pwg_grid ) pwg_fraction = pwg_pixel - pwg_grid pwc_pixel = cf . grid_wcs . sub ( [ 5 ] ) . wcs_world2pix ( vis . uvw [ : , 2 ] , 0 ) [ 0 ] pwc_grid = numpy . round ( pwc_pixel ) . astype ( 'int' ) if numpy . min ( pwc_grid ) < 0 : print ( vis . uvw [ 0 : 10 , 2 ] ) print ( cf . grid_wcs . sub ( [ 5 ] ) . __repr__ ( ) ) assert numpy . min ( pwc_grid ) >= 0 , "W axis underflows: %f" % numpy . min ( pwc_grid ) assert numpy . max ( pwc_grid ) < cf . shape [ 2 ] , "W axis overflows: %f" % numpy . max ( pwc_grid ) pwc_fraction = pwc_pixel - pwc_grid pfreq_pixel = griddata . grid_wcs . sub ( [ 5 ] ) . wcs_world2pix ( vis . frequency , 0 ) [ 0 ] pfreq_grid = numpy . round ( pfreq_pixel ) . astype ( 'int' ) assert numpy . min ( pfreq_grid ) >= 0 , "Frequency axis underflows: %f" % numpy . max ( pfreq_grid ) assert numpy . max ( pfreq_grid ) < cf . shape [ 0 ] , "Frequency axis overflows: %f" % numpy . max ( pfreq_grid ) pfreq_fraction = pfreq_pixel - pfreq_grid is_spectral = cf . shape [ 0 ] > 1 if is_spectral and ( numpy . max ( numpy . abs ( pfreq_fraction ) ) > channel_tolerance ) : print ( "convolution_mapping: alignment of visibility and image frequency grids exceeds tolerance %s" % ( numpy . max ( pfreq_fraction ) ) ) log . warning ( "convolution_mapping: alignment of visibility and image frequency grids exceeds tolerance %s" % ( numpy . max ( pfreq_fraction ) ) ) return pu_grid , pu_offset , pv_grid , pv_offset , pwg_grid , pwg_fraction , pwc_grid , pwc_fraction , pfreq_grid
Find the mappings between visibility, griddata, and convolution function
Find the mappings between visibility griddata and convolution function
"""Find the mappings between visibility, griddata, and convolution function
    
    :param vis:
    :param griddata:
    :param cf_griddata:
    :return:
    """ ####### UV mapping # We use the grid_wcs's to do the coordinate conversion # Find the nearest grid points # We now have the location of grid points, convert back to uv space and find the remainder (in wavelengths). We # then use this to calculate the subsampling indices (DUU, DVV) ###### W mapping for Grid # nchan, npol, w, v, u # Find the nearest grid point ###### W mapping for CF # nchan, npol, w, dv, du, v, u ###### Frequency mapping # Find the nearest grid point # If we are doing spectral imaging, check the tolerances ######  TODO: Polarisation mapping
None
vis
None
griddata
None
cf
channel_tolerance
cf_griddata
None