processing_components/image/operations.py
def calculate_image_from_frequency_moments(im: Image, moment_image: Image, reference_frequency=None) -> Image:
    """Calculate image from frequency weighted moments

    Weights are ((freq-reference_frequency)/reference_frequency)**moment

    Note that a new image is created
    
    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 to be reconstructed
    :param moment_image: Moment cube (constructed using calculate_image_frequency_moments)
    :param reference_frequency: Reference frequency (default None uses average)
    :return: reconstructed image
    """
    assert isinstance(im, Image)
    nchan, npol, ny, nx = im.shape
    nmoment, mnpol, mny, mnx = moment_image.shape
    assert nmoment > 0

    assert npol == mnpol
    assert ny == mny
    assert nx == mnx
    
    assert moment_image.wcs.wcs.ctype[3] == 'MOMENT', "Second image should be a moment image"
    
    channels = numpy.arange(nchan)
    freq = im.wcs.sub(['spectral']).wcs_pix2world(channels, 0)[0]
    
    if reference_frequency is None:
        reference_frequency = numpy.average(freq)
    log.debug("calculate_image_from_frequency_moments: Reference frequency = %.3f (MHz)" % (reference_frequency))
    
    newim = copy_image(im)
    
    newim.data[...] = 0.0
    
    for moment in range(nmoment):
        for chan in range(nchan):
            weight = numpy.power((freq[chan] - reference_frequency) / reference_frequency, moment)
            newim.data[chan, ...] += moment_image.data[moment, ...] * weight
    
    return newim
Calculate image from frequency weighted moments

    Weights are ((freq-reference_frequency)/reference_frequency)**moment

    Note that a new image is created
    
    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 to be reconstructed
    :param moment_image: Moment cube (constructed using calculate_image_frequency_moments)
    :param reference_frequency: Reference frequency (default None uses average)
    :return: reconstructed image
    
Calculate image from frequency weighted moments
Weights are ((freq-reference_frequency)/reference_frequency)**moment

Note that a new image is created

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


Calculate image from frequency weighted moments Weights are (( freq - reference_frequency ) / reference_frequency ) ** moment Note that a new image is created For example to find the moments and then reconstruct from just the moments : .
def calculate_image_from_frequency_moments(im: Image, moment_image: Image, reference_frequency=None) -> Image:
    assert isinstance(im, Image)
    nchan, npol, ny, nx = im.shape
    nmoment, mnpol, mny, mnx = moment_image.shape
    assert nmoment > 0
    assert npol == mnpol
    assert ny == mny
    assert nx == mnx
    assert moment_image.wcs.wcs.ctype[3] == 'MOMENT', "Second image should be a moment image"
    channels = numpy.arange(nchan)
    freq = im.wcs.sub(['spectral']).wcs_pix2world(channels, 0)[0]
    if reference_frequency is None:
        reference_frequency = numpy.average(freq)
    log.debug("calculate_image_from_frequency_moments: Reference frequency = %.3f (MHz)" % (reference_frequency))
    newim = copy_image(im)
    newim.data[...] = 0.0
    for moment in range(nmoment):
        for chan in range(nchan):
            weight = numpy.power((freq[chan] - reference_frequency) / reference_frequency, moment)
            newim.data[chan, ...] += moment_image.data[moment, ...] * weight
    return newim
def calculate_image_from_frequency_moments ( im : Image , moment_image : Image , reference_frequency = None ) -> Image : assert isinstance ( im , Image ) nchan , npol , ny , nx = im . shape nmoment , mnpol , mny , mnx = moment_image . shape assert nmoment > 0 assert npol == mnpol assert ny == mny assert nx == mnx assert moment_image . wcs . wcs . ctype [ 3 ] == 'MOMENT' , "Second image should be a moment image" channels = numpy . arange ( nchan ) freq = im . wcs . sub ( [ 'spectral' ] ) . wcs_pix2world ( channels , 0 ) [ 0 ] if reference_frequency is None : reference_frequency = numpy . average ( freq ) log . debug ( "calculate_image_from_frequency_moments: Reference frequency = %.3f (MHz)" % ( reference_frequency ) ) newim = copy_image ( im ) newim . data [ ... ] = 0.0 for moment in range ( nmoment ) : for chan in range ( nchan ) : weight = numpy . power ( ( freq [ chan ] - reference_frequency ) / reference_frequency , moment ) newim . data [ chan , ... ] += moment_image . data [ moment , ... ] * weight return newim
Calculate image from frequency weighted moments
Weights are ((freq-reference_frequency)/reference_frequency)**moment
Calculate image from frequency weighted moments Weights are (( freq - reference_frequency ) / reference_frequency ) ** moment
"""Calculate image from frequency weighted moments

    Weights are ((freq-reference_frequency)/reference_frequency)**moment

    Note that a new image is created
    
    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 to be reconstructed
    :param moment_image: Moment cube (constructed using calculate_image_frequency_moments)
    :param reference_frequency: Reference frequency (default None uses average)
    :return: reconstructed image
    """
None
im
Image
Image cube to be reconstructed
Image cube to be reconstructed
moment_image
Image
Moment cube (constructed using calculate_image_frequency_moments)
Moment cube ( constructed using calculate_image_frequency_moments )
reference_frequency
Reference frequency (default None uses average)
Reference frequency ( default None uses average )