processing_components/image/operations.py
def calculate_image_frequency_moments(im: Image, reference_frequency=None, nmoment=1) -> Image:
    """Calculate frequency weighted moments
    
    Weights are ((freq-reference_frequency)/reference_frequency)**moment
    
    Note that the spectral axis is replaced by a MOMENT axis.
    
    For example, to find the moments and then reconstruct from just the moments::
    
        moment_cube = calculate_image_frequency_moments(model_multichannel, nmoment=5)
        reconstructed_cube = calculate_image_from_frequency_moments(model_multichannel, moment_cube)

    :param im: Image cube
    :param reference_frequency: Reference frequency (default None uses average)
    :param nmoment: Number of moments to calculate
    :return: Moments image
    """
    assert isinstance(im, Image)
    assert nmoment > 0
    nchan, npol, ny, nx = im.shape
    channels = numpy.arange(nchan)
    freq = im.wcs.sub(['spectral']).wcs_pix2world(channels, 0)[0]
    
    assert nmoment <= nchan, "Number of moments %d cannot exceed the number of channels %d" % (nmoment, nchan)
    
    if reference_frequency is None:
        reference_frequency = numpy.average(freq)
    log.debug("calculate_image_frequency_moments: Reference frequency = %.3f (MHz)" % (reference_frequency/1e6))
    
    moment_data = numpy.zeros([nmoment, npol, ny, nx])
    
    for moment in range(nmoment):
        for chan in range(nchan):
            weight = numpy.power((freq[chan] - reference_frequency) / reference_frequency, moment)
            moment_data[moment, ...] += im.data[chan, ...] * weight
    
    moment_wcs = copy.deepcopy(im.wcs)
    moment_wcs.wcs.ctype[3] = 'MOMENT'
    moment_wcs.wcs.crval[3] = 0.0
    moment_wcs.wcs.crpix[3] = 1.0
    moment_wcs.wcs.cdelt[3] = 1.0
    moment_wcs.wcs.cunit[3] = ''
    
    return create_image_from_array(moment_data, moment_wcs, im.polarisation_frame)
Calculate frequency weighted moments
    
    Weights are ((freq-reference_frequency)/reference_frequency)**moment
    
    Note that the spectral axis is replaced by a MOMENT axis.
    
    For example, to find the moments and then reconstruct from just the moments::
    
        moment_cube = calculate_image_frequency_moments(model_multichannel, nmoment=5)
        reconstructed_cube = calculate_image_from_frequency_moments(model_multichannel, moment_cube)

    :param im: Image cube
    :param reference_frequency: Reference frequency (default None uses average)
    :param nmoment: Number of moments to calculate
    :return: Moments image
    
Calculate frequency weighted moments
Weights are ((freq-reference_frequency)/reference_frequency)**moment

Note that the spectral axis is replaced by a MOMENT axis.

For example, to find the moments and then reconstruct from just the moments:.


Calculate frequency weighted moments Weights are (( freq - reference_frequency ) / reference_frequency ) ** moment Note that the spectral axis is replaced by a MOMENT axis . For example to find the moments and then reconstruct from just the moments : .
def calculate_image_frequency_moments(im: Image, reference_frequency=None, nmoment=1) -> Image:
    assert isinstance(im, Image)
    assert nmoment > 0
    nchan, npol, ny, nx = im.shape
    channels = numpy.arange(nchan)
    freq = im.wcs.sub(['spectral']).wcs_pix2world(channels, 0)[0]
    assert nmoment <= nchan, "Number of moments %d cannot exceed the number of channels %d" % (nmoment, nchan)
    if reference_frequency is None:
        reference_frequency = numpy.average(freq)
    log.debug("calculate_image_frequency_moments: Reference frequency = %.3f (MHz)" % (reference_frequency/1e6))
    moment_data = numpy.zeros([nmoment, npol, ny, nx])
    for moment in range(nmoment):
        for chan in range(nchan):
            weight = numpy.power((freq[chan] - reference_frequency) / reference_frequency, moment)
            moment_data[moment, ...] += im.data[chan, ...] * weight
    moment_wcs = copy.deepcopy(im.wcs)
    moment_wcs.wcs.ctype[3] = 'MOMENT'
    moment_wcs.wcs.crval[3] = 0.0
    moment_wcs.wcs.crpix[3] = 1.0
    moment_wcs.wcs.cdelt[3] = 1.0
    moment_wcs.wcs.cunit[3] = ''
    return create_image_from_array(moment_data, moment_wcs, im.polarisation_frame)
def calculate_image_frequency_moments ( im : Image , reference_frequency = None , nmoment = 1 ) -> Image : assert isinstance ( im , Image ) assert nmoment > 0 nchan , npol , ny , nx = im . shape channels = numpy . arange ( nchan ) freq = im . wcs . sub ( [ 'spectral' ] ) . wcs_pix2world ( channels , 0 ) [ 0 ] assert nmoment <= nchan , "Number of moments %d cannot exceed the number of channels %d" % ( nmoment , nchan ) if reference_frequency is None : reference_frequency = numpy . average ( freq ) log . debug ( "calculate_image_frequency_moments: Reference frequency = %.3f (MHz)" % ( reference_frequency / 1e6 ) ) moment_data = numpy . zeros ( [ nmoment , npol , ny , nx ] ) for moment in range ( nmoment ) : for chan in range ( nchan ) : weight = numpy . power ( ( freq [ chan ] - reference_frequency ) / reference_frequency , moment ) moment_data [ moment , ... ] += im . data [ chan , ... ] * weight moment_wcs = copy . deepcopy ( im . wcs ) moment_wcs . wcs . ctype [ 3 ] = 'MOMENT' moment_wcs . wcs . crval [ 3 ] = 0.0 moment_wcs . wcs . crpix [ 3 ] = 1.0 moment_wcs . wcs . cdelt [ 3 ] = 1.0 moment_wcs . wcs . cunit [ 3 ] = '' return create_image_from_array ( moment_data , moment_wcs , im . polarisation_frame )
Calculate frequency weighted moments
Weights are ((freq-reference_frequency)/reference_frequency)**moment
Calculate frequency weighted moments Weights are (( freq - reference_frequency ) / reference_frequency ) ** moment
"""Calculate frequency weighted moments
    
    Weights are ((freq-reference_frequency)/reference_frequency)**moment
    
    Note that the spectral axis is replaced by a MOMENT axis.
    
    For example, to find the moments and then reconstruct from just the moments::
    
        moment_cube = calculate_image_frequency_moments(model_multichannel, nmoment=5)
        reconstructed_cube = calculate_image_from_frequency_moments(model_multichannel, moment_cube)

    :param im: Image cube
    :param reference_frequency: Reference frequency (default None uses average)
    :param nmoment: Number of moments to calculate
    :return: Moments image
    """
None
im
Image
None
reference_frequency
Reference frequency (default None uses average)
Reference frequency ( default None uses average )
nmoment
Number of moments to calculate
Number of moments to calculate