processing_components/imaging/base.py
def create_image_from_visibility(vis: Union[BlockVisibility, Visibility], **kwargs) -> Image:
    """Make an empty image from params and Visibility
    
    This makes an empty, template image consistent with the visibility, allowing optional overriding of select
    parameters. This is a convenience function and does not transform the visibilities.

    :param vis:
    :param phasecentre: Phasecentre (Skycoord)
    :param channel_bandwidth: Channel width (Hz)
    :param cellsize: Cellsize (radians)
    :param npixel: Number of pixels on each axis (512)
    :param frame: Coordinate frame for WCS (ICRS)
    :param equinox: Equinox for WCS (2000.0)
    :param nchan: Number of image channels (Default is 1 -> MFS)
    :return: image
    """
    assert isinstance(vis, Visibility) or isinstance(vis, BlockVisibility), \
        "vis is not a Visibility or a BlockVisibility: %r" % (vis)
    
    log.debug("create_image_from_visibility: Parsing parameters to get definition of WCS")
    
    imagecentre = get_parameter(kwargs, "imagecentre", vis.phasecentre)
    phasecentre = get_parameter(kwargs, "phasecentre", vis.phasecentre)
    
    # Spectral processing options
    ufrequency = numpy.unique(vis.frequency)
    vnchan = len(ufrequency)
    
    frequency = get_parameter(kwargs, "frequency", vis.frequency)
    inchan = get_parameter(kwargs, "nchan", vnchan)
    reffrequency = frequency[0] * units.Hz
    channel_bandwidth = get_parameter(kwargs, "channel_bandwidth", 0.99999999999 * vis.channel_bandwidth[0]) * units.Hz
    
    if (inchan == vnchan) and vnchan > 1:
        log.debug(
            "create_image_from_visibility: Defining %d channel Image at %s, starting frequency %s, and bandwidth %s"
            % (inchan, imagecentre, reffrequency, channel_bandwidth))
    elif (inchan == 1) and vnchan > 1:
        assert numpy.abs(channel_bandwidth.value) > 0.0, "Channel width must be non-zero for mfs mode"
        log.debug("create_image_from_visibility: Defining single channel MFS Image at %s, starting frequency %s, "
                 "and bandwidth %s"
                 % (imagecentre, reffrequency, channel_bandwidth))
    elif inchan > 1 and vnchan > 1:
        assert numpy.abs(channel_bandwidth.value) > 0.0, "Channel width must be non-zero for mfs mode"
        log.debug("create_image_from_visibility: Defining multi-channel MFS Image at %s, starting frequency %s, "
                 "and bandwidth %s"
                 % (imagecentre, reffrequency, channel_bandwidth))
    elif (inchan == 1) and (vnchan == 1):
        assert numpy.abs(channel_bandwidth.value) > 0.0, "Channel width must be non-zero for mfs mode"
        log.debug("create_image_from_visibility: Defining single channel Image at %s, starting frequency %s, "
                 "and bandwidth %s"
                 % (imagecentre, reffrequency, channel_bandwidth))
    else:
        raise ValueError("create_image_from_visibility: unknown spectral mode ")
    
    # Image sampling options
    npixel = get_parameter(kwargs, "npixel", 512)
    uvmax = numpy.max((numpy.abs(vis.data['uvw'][..., 0:1])))
    if isinstance(vis, BlockVisibility):
        uvmax *= numpy.max(frequency) / constants.c.to('m s^-1').value
    log.debug("create_image_from_visibility: uvmax = %f wavelengths" % uvmax)
    criticalcellsize = 1.0 / (uvmax * 2.0)
    log.debug("create_image_from_visibility: Critical cellsize = %f radians, %f degrees" % (
        criticalcellsize, criticalcellsize * 180.0 / numpy.pi))
    cellsize = get_parameter(kwargs, "cellsize", 0.5 * criticalcellsize)
    log.debug("create_image_from_visibility: Cellsize          = %g radians, %g degrees" % (cellsize,
                                                                                           cellsize * 180.0 / numpy.pi))
    override_cellsize = get_parameter(kwargs, "override_cellsize", True)
    if override_cellsize and cellsize > criticalcellsize:
        log.debug("create_image_from_visibility: Resetting cellsize %g radians to criticalcellsize %g radians" % (
            cellsize, criticalcellsize))
        cellsize = criticalcellsize
    pol_frame = get_parameter(kwargs, "polarisation_frame", PolarisationFrame("stokesI"))
    inpol = pol_frame.npol
    
    # Now we can define the WCS, which is a convenient place to hold the info above
    # Beware of python indexing order! wcs and the array have opposite ordering
    shape = [inchan, inpol, npixel, npixel]
    log.debug("create_image_from_visibility: image shape is %s" % str(shape))
    w = wcs.WCS(naxis=4)
    # The negation in the longitude is needed by definition of RA, DEC
    w.wcs.cdelt = [-cellsize * 180.0 / numpy.pi, cellsize * 180.0 / numpy.pi, 1.0, channel_bandwidth.to(units.Hz).value]
    # The numpy definition of the phase centre of an FFT is n // 2 (0 - rel) so that's what we use for
    # the reference pixel. We have to use 0 rel everywhere.
    w.wcs.crpix = [npixel // 2 + 1, npixel // 2 + 1, 1.0, 1.0]
    w.wcs.ctype = ["RA---SIN", "DEC--SIN", 'STOKES', 'FREQ']
    w.wcs.crval = [phasecentre.ra.deg, phasecentre.dec.deg, 1.0, reffrequency.to(units.Hz).value]
    w.naxis = 4
    
    w.wcs.radesys = get_parameter(kwargs, 'frame', 'ICRS')
    w.wcs.equinox = get_parameter(kwargs, 'equinox', 2000.0)
    
    return create_image_from_array(numpy.zeros(shape), wcs=w, polarisation_frame=pol_frame)
Make an empty image from params and Visibility
    
    This makes an empty, template image consistent with the visibility, allowing optional overriding of select
    parameters. This is a convenience function and does not transform the visibilities.

    :param vis:
    :param phasecentre: Phasecentre (Skycoord)
    :param channel_bandwidth: Channel width (Hz)
    :param cellsize: Cellsize (radians)
    :param npixel: Number of pixels on each axis (512)
    :param frame: Coordinate frame for WCS (ICRS)
    :param equinox: Equinox for WCS (2000.0)
    :param nchan: Number of image channels (Default is 1 -> MFS)
    :return: image
    
Make an empty image from params and Visibility
This makes an empty, template image consistent with the visibility, allowing optional overriding of select
parameters. This is a convenience function and does not transform the visibilities.
Make an empty image from params and Visibility This makes an empty template image consistent with the visibility allowing optional overriding of select parameters . This is a convenience function and does not transform the visibilities .
def create_image_from_visibility(vis: Union[BlockVisibility, Visibility], **kwargs) -> Image:
    assert isinstance(vis, Visibility) or isinstance(vis, BlockVisibility), \
        "vis is not a Visibility or a BlockVisibility: %r" % (vis)
    log.debug("create_image_from_visibility: Parsing parameters to get definition of WCS")
    imagecentre = get_parameter(kwargs, "imagecentre", vis.phasecentre)
    phasecentre = get_parameter(kwargs, "phasecentre", vis.phasecentre)
    ufrequency = numpy.unique(vis.frequency)
    vnchan = len(ufrequency)
    frequency = get_parameter(kwargs, "frequency", vis.frequency)
    inchan = get_parameter(kwargs, "nchan", vnchan)
    reffrequency = frequency[0] * units.Hz
    channel_bandwidth = get_parameter(kwargs, "channel_bandwidth", 0.99999999999 * vis.channel_bandwidth[0]) * units.Hz
    if (inchan == vnchan) and vnchan > 1:
        log.debug(
            "create_image_from_visibility: Defining %d channel Image at %s, starting frequency %s, and bandwidth %s"
            % (inchan, imagecentre, reffrequency, channel_bandwidth))
    elif (inchan == 1) and vnchan > 1:
        assert numpy.abs(channel_bandwidth.value) > 0.0, "Channel width must be non-zero for mfs mode"
        log.debug("create_image_from_visibility: Defining single channel MFS Image at %s, starting frequency %s, "
                 "and bandwidth %s"
                 % (imagecentre, reffrequency, channel_bandwidth))
    elif inchan > 1 and vnchan > 1:
        assert numpy.abs(channel_bandwidth.value) > 0.0, "Channel width must be non-zero for mfs mode"
        log.debug("create_image_from_visibility: Defining multi-channel MFS Image at %s, starting frequency %s, "
                 "and bandwidth %s"
                 % (imagecentre, reffrequency, channel_bandwidth))
    elif (inchan == 1) and (vnchan == 1):
        assert numpy.abs(channel_bandwidth.value) > 0.0, "Channel width must be non-zero for mfs mode"
        log.debug("create_image_from_visibility: Defining single channel Image at %s, starting frequency %s, "
                 "and bandwidth %s"
                 % (imagecentre, reffrequency, channel_bandwidth))
    else:
        raise ValueError("create_image_from_visibility: unknown spectral mode ")
    npixel = get_parameter(kwargs, "npixel", 512)
    uvmax = numpy.max((numpy.abs(vis.data['uvw'][..., 0:1])))
    if isinstance(vis, BlockVisibility):
        uvmax *= numpy.max(frequency) / constants.c.to('m s^-1').value
    log.debug("create_image_from_visibility: uvmax = %f wavelengths" % uvmax)
    criticalcellsize = 1.0 / (uvmax * 2.0)
    log.debug("create_image_from_visibility: Critical cellsize = %f radians, %f degrees" % (
        criticalcellsize, criticalcellsize * 180.0 / numpy.pi))
    cellsize = get_parameter(kwargs, "cellsize", 0.5 * criticalcellsize)
    log.debug("create_image_from_visibility: Cellsize          = %g radians, %g degrees" % (cellsize,
                                                                                           cellsize * 180.0 / numpy.pi))
    override_cellsize = get_parameter(kwargs, "override_cellsize", True)
    if override_cellsize and cellsize > criticalcellsize:
        log.debug("create_image_from_visibility: Resetting cellsize %g radians to criticalcellsize %g radians" % (
            cellsize, criticalcellsize))
        cellsize = criticalcellsize
    pol_frame = get_parameter(kwargs, "polarisation_frame", PolarisationFrame("stokesI"))
    inpol = pol_frame.npol
    shape = [inchan, inpol, npixel, npixel]
    log.debug("create_image_from_visibility: image shape is %s" % str(shape))
    w = wcs.WCS(naxis=4)
    w.wcs.cdelt = [-cellsize * 180.0 / numpy.pi, cellsize * 180.0 / numpy.pi, 1.0, channel_bandwidth.to(units.Hz).value]
    w.wcs.crpix = [npixel // 2 + 1, npixel // 2 + 1, 1.0, 1.0]
    w.wcs.ctype = ["RA---SIN", "DEC--SIN", 'STOKES', 'FREQ']
    w.wcs.crval = [phasecentre.ra.deg, phasecentre.dec.deg, 1.0, reffrequency.to(units.Hz).value]
    w.naxis = 4
    w.wcs.radesys = get_parameter(kwargs, 'frame', 'ICRS')
    w.wcs.equinox = get_parameter(kwargs, 'equinox', 2000.0)
    return create_image_from_array(numpy.zeros(shape), wcs=w, polarisation_frame=pol_frame)
def create_image_from_visibility ( vis : Union [ BlockVisibility , Visibility ] , ** kwargs ) -> Image : assert isinstance ( vis , Visibility ) or isinstance ( vis , BlockVisibility ) , "vis is not a Visibility or a BlockVisibility: %r" % ( vis ) log . debug ( "create_image_from_visibility: Parsing parameters to get definition of WCS" ) imagecentre = get_parameter ( kwargs , "imagecentre" , vis . phasecentre ) phasecentre = get_parameter ( kwargs , "phasecentre" , vis . phasecentre ) ufrequency = numpy . unique ( vis . frequency ) vnchan = len ( ufrequency ) frequency = get_parameter ( kwargs , "frequency" , vis . frequency ) inchan = get_parameter ( kwargs , "nchan" , vnchan ) reffrequency = frequency [ 0 ] * units . Hz channel_bandwidth = get_parameter ( kwargs , "channel_bandwidth" , 0.99999999999 * vis . channel_bandwidth [ 0 ] ) * units . Hz if ( inchan == vnchan ) and vnchan > 1 : log . debug ( "create_image_from_visibility: Defining %d channel Image at %s, starting frequency %s, and bandwidth %s" % ( inchan , imagecentre , reffrequency , channel_bandwidth ) ) elif ( inchan == 1 ) and vnchan > 1 : assert numpy . abs ( channel_bandwidth . value ) > 0.0 , "Channel width must be non-zero for mfs mode" log . debug ( "create_image_from_visibility: Defining single channel MFS Image at %s, starting frequency %s, " "and bandwidth %s" % ( imagecentre , reffrequency , channel_bandwidth ) ) elif inchan > 1 and vnchan > 1 : assert numpy . abs ( channel_bandwidth . value ) > 0.0 , "Channel width must be non-zero for mfs mode" log . debug ( "create_image_from_visibility: Defining multi-channel MFS Image at %s, starting frequency %s, " "and bandwidth %s" % ( imagecentre , reffrequency , channel_bandwidth ) ) elif ( inchan == 1 ) and ( vnchan == 1 ) : assert numpy . abs ( channel_bandwidth . value ) > 0.0 , "Channel width must be non-zero for mfs mode" log . debug ( "create_image_from_visibility: Defining single channel Image at %s, starting frequency %s, " "and bandwidth %s" % ( imagecentre , reffrequency , channel_bandwidth ) ) else : raise ValueError ( "create_image_from_visibility: unknown spectral mode " ) npixel = get_parameter ( kwargs , "npixel" , 512 ) uvmax = numpy . max ( ( numpy . abs ( vis . data [ 'uvw' ] [ ... , 0 : 1 ] ) ) ) if isinstance ( vis , BlockVisibility ) : uvmax *= numpy . max ( frequency ) / constants . c . to ( 'm s^-1' ) . value log . debug ( "create_image_from_visibility: uvmax = %f wavelengths" % uvmax ) criticalcellsize = 1.0 / ( uvmax * 2.0 ) log . debug ( "create_image_from_visibility: Critical cellsize = %f radians, %f degrees" % ( criticalcellsize , criticalcellsize * 180.0 / numpy . pi ) ) cellsize = get_parameter ( kwargs , "cellsize" , 0.5 * criticalcellsize ) log . debug ( "create_image_from_visibility: Cellsize          = %g radians, %g degrees" % ( cellsize , cellsize * 180.0 / numpy . pi ) ) override_cellsize = get_parameter ( kwargs , "override_cellsize" , True ) if override_cellsize and cellsize > criticalcellsize : log . debug ( "create_image_from_visibility: Resetting cellsize %g radians to criticalcellsize %g radians" % ( cellsize , criticalcellsize ) ) cellsize = criticalcellsize pol_frame = get_parameter ( kwargs , "polarisation_frame" , PolarisationFrame ( "stokesI" ) ) inpol = pol_frame . npol shape = [ inchan , inpol , npixel , npixel ] log . debug ( "create_image_from_visibility: image shape is %s" % str ( shape ) ) w = wcs . WCS ( naxis = 4 ) w . wcs . cdelt = [ - cellsize * 180.0 / numpy . pi , cellsize * 180.0 / numpy . pi , 1.0 , channel_bandwidth . to ( units . Hz ) . value ] w . wcs . crpix = [ npixel // 2 + 1 , npixel // 2 + 1 , 1.0 , 1.0 ] w . wcs . ctype = [ "RA---SIN" , "DEC--SIN" , 'STOKES' , 'FREQ' ] w . wcs . crval = [ phasecentre . ra . deg , phasecentre . dec . deg , 1.0 , reffrequency . to ( units . Hz ) . value ] w . naxis = 4 w . wcs . radesys = get_parameter ( kwargs , 'frame' , 'ICRS' ) w . wcs . equinox = get_parameter ( kwargs , 'equinox' , 2000.0 ) return create_image_from_array ( numpy . zeros ( shape ) , wcs = w , polarisation_frame = pol_frame )
Make an empty image from params and Visibility
This makes an empty, template image consistent with the visibility, allowing optional overriding of select
parameters.
Make an empty image from params and Visibility This makes an empty template image consistent with the visibility allowing optional overriding of select parameters .
"""Make an empty image from params and Visibility
    
    This makes an empty, template image consistent with the visibility, allowing optional overriding of select
    parameters. This is a convenience function and does not transform the visibilities.

    :param vis:
    :param phasecentre: Phasecentre (Skycoord)
    :param channel_bandwidth: Channel width (Hz)
    :param cellsize: Cellsize (radians)
    :param npixel: Number of pixels on each axis (512)
    :param frame: Coordinate frame for WCS (ICRS)
    :param equinox: Equinox for WCS (2000.0)
    :param nchan: Number of image channels (Default is 1 -> MFS)
    :return: image
    """ # Spectral processing options # Image sampling options # Now we can define the WCS, which is a convenient place to hold the info above # Beware of python indexing order! wcs and the array have opposite ordering # The negation in the longitude is needed by definition of RA, DEC # The numpy definition of the phase centre of an FFT is n // 2 (0 - rel) so that's what we use for # the reference pixel. We have to use 0 rel everywhere.
None
vis
Union[BlockVisibility, Visibility]
None
phasecentre
None
channel_bandwidth
Channel width (Hz)
Channel width ( Hz )
cellsize
None
npixel
Number of pixels on each axis (512)
Number of pixels on each axis ( 512 )
frame
Coordinate frame for WCS (ICRS)
Coordinate frame for WCS ( ICRS )
equinox
None
nchan
Number of image channels (Default is 1 -> MFS)
Number of image channels ( Default is 1 - > MFS )