Пример #1
0
def spectral_smooth(cube, smooth_factor, downsample=True, parallel=True,
                    numcores=None, **kwargs):
    """
    Smooth the cube along the spectral direction
    """

    yy,xx = numpy.indices(cube.shape[1:])

    if downsample:
        newshape = cube[::smooth_factor,:,:].shape
    else:
        newshape = cube.shape

    # need to make the cube "flat" along dims 1&2 for iteration in the "map"
    flatshape = (cube.shape[0],cube.shape[1]*cube.shape[2])

    Ssmooth = lambda x: smooth.smooth(x, smooth_factor, downsample=downsample, **kwargs)
    if parallel:
        newcube = numpy.array(parallel_map(Ssmooth, cube.reshape(flatshape).T, numcores=numcores)).T.reshape(newshape)
    else:
        newcube = numpy.array(map(Ssmooth, cube.reshape(flatshape).T)).T.reshape(newshape)

    #naive, non-optimal version
    # for (x,y) in zip(xx.flat,yy.flat):
    #     newcube[:,y,x] = smooth.smooth(cube[:,y,x], smooth_factor,
    #             downsample=downsample, **kwargs)

    return newcube
Пример #2
0
def plane_smooth(cube, cubedim=0, parallel=True, numcores=None, **kwargs):
    """
    parallel-map the smooth function

    Parameters
    ----------
    parallel: bool
        defaults True.  Set to false if you want serial (for debug purposes?)
    numcores: int
        pass to parallel_map (None = use all available)
    """
    if not smoothOK:
        return

    if cubedim != 0:
        cube = cube.swapaxes(0, cubedim)

    cubelist = [cube[ii, :, :] for ii in xrange(cube.shape[0])]

    Psmooth = lambda C: smooth.smooth(C, **kwargs)

    if parallel:
        smoothcube = array(parallel_map(Psmooth, cubelist, numcores=numcores))
    else:
        smoothcube = array(map(Psmooth, cubelist))

    if cubedim != 0:
        smoothcube = smoothcube.swapaxes(0, cubedim)

    return smoothcube
Пример #3
0
def plane_smooth(cube,cubedim=0,parallel=True,numcores=None,**kwargs):
    """
    parallel-map the smooth function

    Parameters
    ----------
    parallel: bool
        defaults True.  Set to false if you want serial (for debug purposes?)
    numcores: int
        pass to parallel_map (None = use all available)
    """
    if not smoothOK:
        return

    if cubedim != 0:
        cube = cube.swapaxes(0,cubedim)

    cubelist = [cube[ii,:,:] for ii in xrange(cube.shape[0])]

    Psmooth = lambda C: smooth.smooth(C,**kwargs)

    if parallel:
        smoothcube = array(parallel_map(Psmooth,cubelist,numcores=numcores))
    else:
        smoothcube = array(map(Psmooth,cubelist))

    if cubedim != 0:
        smoothcube = smoothcube.swapaxes(0,cubedim)

    return smoothcube
Пример #4
0
def spectral_smooth(cube,
                    smooth_factor,
                    downsample=True,
                    parallel=True,
                    numcores=None,
                    **kwargs):
    """
    Smooth the cube along the spectral direction
    """

    yy, xx = numpy.indices(cube.shape[1:])

    if downsample:
        newshape = cube[::smooth_factor, :, :].shape
    else:
        newshape = cube.shape

    # need to make the cube "flat" along dims 1&2 for iteration in the "map"
    flatshape = (cube.shape[0], cube.shape[1] * cube.shape[2])

    Ssmooth = lambda x: smooth.smooth(
        x, smooth_factor, downsample=downsample, **kwargs)
    if parallel:
        newcube = numpy.array(
            parallel_map(Ssmooth, cube.reshape(flatshape).T,
                         numcores=numcores)).T.reshape(newshape)
    else:
        newcube = numpy.array(map(
            Ssmooth,
            cube.reshape(flatshape).T)).T.reshape(newshape)

    #naive, non-optimal version
    # for (x,y) in zip(xx.flat,yy.flat):
    #     newcube[:,y,x] = smooth.smooth(cube[:,y,x], smooth_factor,
    #             downsample=downsample, **kwargs)

    return newcube