processing_components/skycomponent/operations.py
def insert_skycomponent(im: Image, sc: Union[Skycomponent, List[Skycomponent]], insert_method='Nearest',
                        bandwidth=1.0, support=8) -> Image:
    """ Insert a Skycomponent into an image
    
    :param im:
    :param sc: SkyComponent or list of SkyComponents
    :param insert_method: '' | 'Sinc' | 'Lanczos'
    :param bandwidth: Fractional of uv plane to optimise over (1.0)
    :param support: Support of kernel (7)
    :return: image
    """
    
    assert isinstance(im, Image)
    
    support = int(support / bandwidth)
    
    nchan, npol, ny, nx = im.data.shape
    
    if not isinstance(sc, collections.Iterable):
        sc = [sc]
    
    log.debug("insert_skycomponent: Using insert method %s" % insert_method)
    
    image_frequency = im.frequency
    
    ras = [comp.direction.ra.radian for comp in sc]
    decs = [comp.direction.dec.radian for comp in sc]
    skycoords = SkyCoord(ras * u.rad, decs * u.rad, frame='icrs')
    pixlocs = skycoord_to_pixel(skycoords, im.wcs, origin=0, mode='wcs')
    
    for icomp, comp in enumerate(sc):
        
        assert comp.shape == 'Point', "Cannot handle shape %s" % comp.shape
        
        assert_same_chan_pol(im, comp)
        pixloc = (pixlocs[0][icomp], pixlocs[1][icomp])
        flux = numpy.zeros([nchan, npol])
        
        if comp.flux.shape[0] > 1:
            for pol in range(npol):
                fint = interpolate.interp1d(comp.frequency, comp.flux[:, pol], kind="cubic")
                flux[:, pol] = fint(image_frequency)
        else:
            flux = comp.flux
        
        if insert_method == "Lanczos":
            insert_array(im.data, pixloc[0], pixloc[1], flux, bandwidth, support,
                         insert_function=insert_function_L)
        elif insert_method == "Sinc":
            insert_array(im.data, pixloc[0], pixloc[1], flux, bandwidth, support,
                         insert_function=insert_function_sinc)
        elif insert_method == "PSWF":
            insert_array(im.data, pixloc[0], pixloc[1], flux, bandwidth, support,
                         insert_function=insert_function_pswf)
        else:
            insert_method = 'Nearest'
            y, x = numpy.round(pixloc[1]).astype('int'), numpy.round(pixloc[0]).astype('int')
            if 0 <= x < nx and 0 <= y < ny:
                im.data[:, :, y, x] += flux[...]
    
    return im
 Insert a Skycomponent into an image
    
    :param im:
    :param sc: SkyComponent or list of SkyComponents
    :param insert_method: '' | 'Sinc' | 'Lanczos'
    :param bandwidth: Fractional of uv plane to optimise over (1.0)
    :param support: Support of kernel (7)
    :return: image
    
Insert a Skycomponent into an image
Insert a Skycomponent into an image
def insert_skycomponent(im: Image, sc: Union[Skycomponent, List[Skycomponent]], insert_method='Nearest',
                        bandwidth=1.0, support=8) -> Image:
    assert isinstance(im, Image)
    support = int(support / bandwidth)
    nchan, npol, ny, nx = im.data.shape
    if not isinstance(sc, collections.Iterable):
        sc = [sc]
    log.debug("insert_skycomponent: Using insert method %s" % insert_method)
    image_frequency = im.frequency
    ras = [comp.direction.ra.radian for comp in sc]
    decs = [comp.direction.dec.radian for comp in sc]
    skycoords = SkyCoord(ras * u.rad, decs * u.rad, frame='icrs')
    pixlocs = skycoord_to_pixel(skycoords, im.wcs, origin=0, mode='wcs')
    for icomp, comp in enumerate(sc):
        assert comp.shape == 'Point', "Cannot handle shape %s" % comp.shape
        assert_same_chan_pol(im, comp)
        pixloc = (pixlocs[0][icomp], pixlocs[1][icomp])
        flux = numpy.zeros([nchan, npol])
        if comp.flux.shape[0] > 1:
            for pol in range(npol):
                fint = interpolate.interp1d(comp.frequency, comp.flux[:, pol], kind="cubic")
                flux[:, pol] = fint(image_frequency)
        else:
            flux = comp.flux
        if insert_method == "Lanczos":
            insert_array(im.data, pixloc[0], pixloc[1], flux, bandwidth, support,
                         insert_function=insert_function_L)
        elif insert_method == "Sinc":
            insert_array(im.data, pixloc[0], pixloc[1], flux, bandwidth, support,
                         insert_function=insert_function_sinc)
        elif insert_method == "PSWF":
            insert_array(im.data, pixloc[0], pixloc[1], flux, bandwidth, support,
                         insert_function=insert_function_pswf)
        else:
            insert_method = 'Nearest'
            y, x = numpy.round(pixloc[1]).astype('int'), numpy.round(pixloc[0]).astype('int')
            if 0 <= x < nx and 0 <= y < ny:
                im.data[:, :, y, x] += flux[...]
    return im
def insert_skycomponent ( im : Image , sc : Union [ Skycomponent , List [ Skycomponent ] ] , insert_method = 'Nearest' , bandwidth = 1.0 , support = 8 ) -> Image : assert isinstance ( im , Image ) support = int ( support / bandwidth ) nchan , npol , ny , nx = im . data . shape if not isinstance ( sc , collections . Iterable ) : sc = [ sc ] log . debug ( "insert_skycomponent: Using insert method %s" % insert_method ) image_frequency = im . frequency ras = [ comp . direction . ra . radian for comp in sc ] decs = [ comp . direction . dec . radian for comp in sc ] skycoords = SkyCoord ( ras * u . rad , decs * u . rad , frame = 'icrs' ) pixlocs = skycoord_to_pixel ( skycoords , im . wcs , origin = 0 , mode = 'wcs' ) for icomp , comp in enumerate ( sc ) : assert comp . shape == 'Point' , "Cannot handle shape %s" % comp . shape assert_same_chan_pol ( im , comp ) pixloc = ( pixlocs [ 0 ] [ icomp ] , pixlocs [ 1 ] [ icomp ] ) flux = numpy . zeros ( [ nchan , npol ] ) if comp . flux . shape [ 0 ] > 1 : for pol in range ( npol ) : fint = interpolate . interp1d ( comp . frequency , comp . flux [ : , pol ] , kind = "cubic" ) flux [ : , pol ] = fint ( image_frequency ) else : flux = comp . flux if insert_method == "Lanczos" : insert_array ( im . data , pixloc [ 0 ] , pixloc [ 1 ] , flux , bandwidth , support , insert_function = insert_function_L ) elif insert_method == "Sinc" : insert_array ( im . data , pixloc [ 0 ] , pixloc [ 1 ] , flux , bandwidth , support , insert_function = insert_function_sinc ) elif insert_method == "PSWF" : insert_array ( im . data , pixloc [ 0 ] , pixloc [ 1 ] , flux , bandwidth , support , insert_function = insert_function_pswf ) else : insert_method = 'Nearest' y , x = numpy . round ( pixloc [ 1 ] ) . astype ( 'int' ) , numpy . round ( pixloc [ 0 ] ) . astype ( 'int' ) if 0 <= x < nx and 0 <= y < ny : im . data [ : , : , y , x ] += flux [ ... ] return im
Insert a Skycomponent into an image
Insert a Skycomponent into an image
""" Insert a Skycomponent into an image
    
    :param im:
    :param sc: SkyComponent or list of SkyComponents
    :param insert_method: '' | 'Sinc' | 'Lanczos'
    :param bandwidth: Fractional of uv plane to optimise over (1.0)
    :param support: Support of kernel (7)
    :return: image
    """
None
im
Image
None
sc
Union[Skycomponent, List[Skycomponent]]
SkyComponent or list of SkyComponents
SkyComponent or list of SkyComponents
insert_method
None
bandwidth
Fractional of uv plane to optimise over (1.0)
Fractional of uv plane to optimise over ( 1 . 0 )
support
Support of kernel (7)
Support of kernel ( 7 )