radio-astro-tools / spectral-cube

Library for reading and analyzing astrophysical spectral data cubes
http://spectral-cube.rtfd.org
BSD 3-Clause "New" or "Revised" License
98 stars 65 forks source link

apply_function_parallel_spectral with dask #772

Closed moellert0 closed 2 years ago

moellert0 commented 3 years ago

The function "apply_function_parallel_spectral" works fine for "normal" cubes, but the array describing the spectrum for the applied function always has length 1 when "dask" is used.

The function which is used with "apply_function_parallel_spectral" gets the spectrum for a certain position as input parameter. Without dask, the length of this input parameter is identical to the number of points along the spectral axis. Using dask, e.g.

with cube.use_dask_scheduler('threads', num_workers=4):
cube.apply_function_parallel_spectral(Func)

the array describing the intensity along the spectral axis, which is send to "Func" has always length 1 although the spectral axis of "cube" has e.g. 90 points. Without dask, the array, which is send to "Func" has a length of e.g. 90.

keflavich commented 3 years ago

Can you provide a specific example so we can reproduce and test this?

moellert0 commented 3 years ago

Here is an example. The kwargs argument is not read as well:

import astropy.units as u
import numpy as np
from astropy.utils import data
from spectral_cube import SpectralCube

def func(x, add = None):
    print ("\nSpectral axis within func: ", x)
    print ("\nAdd. keyword (should be 1) = ", add)
    y = x * np.nan
    return y

fn = data.get_pkg_data_filename('tests/data/example_cube.fits', 'spectral_cube')
cube = SpectralCube.read(fn, use_dask = True)
print(cube)

print ("\n\n\nSpectral axis of cube[0, :, :] = ", cube[:, 0, 0])

with cube.use_dask_scheduler('threads', num_workers = 4):
    cube.apply_function_parallel_spectral(func, add = 1)
e-koch commented 2 years ago

@moellert0 -- This should now be fixed with #773 merged.