processing_components/skycomponent/operations.py
def apply_beam_to_skycomponent(sc: Union[Skycomponent, List[Skycomponent]], beam: Image) \
        -> Union[Skycomponent, List[Skycomponent]]:
    """ Insert a Skycomponent into an image

    :param beam:
    :param sc: SkyComponent or list of SkyComponents
    :return: List of skycomponents
    """
    assert isinstance(beam, Image)
    single = not isinstance(sc, collections.Iterable)
    
    if single:
        sc = [sc]
    
    nchan, npol, ny, nx = beam.shape
    
    log.debug('apply_beam_to_skycomponent: Processing %d components' % (len(sc)))
    
    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, beam.wcs, origin=1, mode='wcs')
    
    newsc = []
    total_flux = numpy.zeros([nchan, npol])
    for icomp, comp in enumerate(sc):
        
        assert comp.shape == 'Point', "Cannot handle shape %s" % comp.shape
        
        assert_same_chan_pol(beam, comp)
        
        pixloc = (pixlocs[0][icomp], pixlocs[1][icomp])
        if not numpy.isnan(pixloc).any():
            x, y = int(round(float(pixloc[0]))), int(round(float(pixloc[1])))
            if 0 <= x < nx and 0 <= y < ny:
                comp.flux[:, :] *= beam.data[:, :, y, x]
                total_flux += comp.flux
                newsc.append(Skycomponent(comp.direction, comp.frequency, comp.name, comp.flux,
                                          shape=comp.shape,
                                          polarisation_frame=comp.polarisation_frame))
    
    log.debug('apply_beam_to_skycomponent: %d components with total flux %s' %
              (len(newsc), total_flux))
    if single:
        return newsc[0]
    else:
        return newsc
 Insert a Skycomponent into an image

    :param beam:
    :param sc: SkyComponent or list of SkyComponents
    :return: List of skycomponents
    
Insert a Skycomponent into an image
Insert a Skycomponent into an image
def apply_beam_to_skycomponent(sc: Union[Skycomponent, List[Skycomponent]], beam: Image) \
        -> Union[Skycomponent, List[Skycomponent]]:
    assert isinstance(beam, Image)
    single = not isinstance(sc, collections.Iterable)
    if single:
        sc = [sc]
    nchan, npol, ny, nx = beam.shape
    log.debug('apply_beam_to_skycomponent: Processing %d components' % (len(sc)))
    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, beam.wcs, origin=1, mode='wcs')
    newsc = []
    total_flux = numpy.zeros([nchan, npol])
    for icomp, comp in enumerate(sc):
        assert comp.shape == 'Point', "Cannot handle shape %s" % comp.shape
        assert_same_chan_pol(beam, comp)
        pixloc = (pixlocs[0][icomp], pixlocs[1][icomp])
        if not numpy.isnan(pixloc).any():
            x, y = int(round(float(pixloc[0]))), int(round(float(pixloc[1])))
            if 0 <= x < nx and 0 <= y < ny:
                comp.flux[:, :] *= beam.data[:, :, y, x]
                total_flux += comp.flux
                newsc.append(Skycomponent(comp.direction, comp.frequency, comp.name, comp.flux,
                                          shape=comp.shape,
                                          polarisation_frame=comp.polarisation_frame))
    log.debug('apply_beam_to_skycomponent: %d components with total flux %s' %
              (len(newsc), total_flux))
    if single:
        return newsc[0]
    else:
        return newsc
def apply_beam_to_skycomponent ( sc : Union [ Skycomponent , List [ Skycomponent ] ] , beam : Image ) -> Union [ Skycomponent , List [ Skycomponent ] ] : assert isinstance ( beam , Image ) single = not isinstance ( sc , collections . Iterable ) if single : sc = [ sc ] nchan , npol , ny , nx = beam . shape log . debug ( 'apply_beam_to_skycomponent: Processing %d components' % ( len ( sc ) ) ) 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 , beam . wcs , origin = 1 , mode = 'wcs' ) newsc = [ ] total_flux = numpy . zeros ( [ nchan , npol ] ) for icomp , comp in enumerate ( sc ) : assert comp . shape == 'Point' , "Cannot handle shape %s" % comp . shape assert_same_chan_pol ( beam , comp ) pixloc = ( pixlocs [ 0 ] [ icomp ] , pixlocs [ 1 ] [ icomp ] ) if not numpy . isnan ( pixloc ) . any ( ) : x , y = int ( round ( float ( pixloc [ 0 ] ) ) ) , int ( round ( float ( pixloc [ 1 ] ) ) ) if 0 <= x < nx and 0 <= y < ny : comp . flux [ : , : ] *= beam . data [ : , : , y , x ] total_flux += comp . flux newsc . append ( Skycomponent ( comp . direction , comp . frequency , comp . name , comp . flux , shape = comp . shape , polarisation_frame = comp . polarisation_frame ) ) log . debug ( 'apply_beam_to_skycomponent: %d components with total flux %s' % ( len ( newsc ) , total_flux ) ) if single : return newsc [ 0 ] else : return newsc
Insert a Skycomponent into an image
Insert a Skycomponent into an image
""" Insert a Skycomponent into an image

    :param beam:
    :param sc: SkyComponent or list of SkyComponents
    :return: List of skycomponents
    """
List of skycomponents
List of skycomponents
sc
Union[Skycomponent, List[Skycomponent]]
SkyComponent or list of SkyComponents
SkyComponent or list of SkyComponents
beam
Image
None