radio-astro-tools/statcont

Speed up w/parallelization

Opened this issue · 2 comments

This is what you get running in spectral_cube:

In [5]: %timeit cube.sigma_clip(1.5, 0)
3.48 s ± 98.5 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

In [6]: %timeit cube.sigma_clip(1.5, 0, num_cores=4)
1.42 s ± 53.4 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

See radio-astro-tools/spectral-cube#494

More benchmark tests:

In [7]: %timeit stats.sigma_clip(data, sigma=1.5, axis=0)
305 ms ± 12.6 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

In [8]: %timeit stats.sigma_clip(data, sigma=1.5, axis=0, cenfunc=np.nanmean)
273 ms ± 6.09 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

In [9]: %timeit stats.sigma_clip(data, sigma=1.5, axis=0, cenfunc=np.nanmedian)
1.6 s ± 9.89 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

the spectral-cube approach is actually much slower because it has to iterate over pixels, but it will be faster (and not crash your machine) for much larger data sets.