desihub / redrock

Redshift fitting for spectroperfectionism
BSD 3-Clause "New" or "Revised" License
22 stars 13 forks source link

Numba required to access best-fit model #180

Closed dkirkby closed 5 months ago

dkirkby commented 4 years ago

I am following this tutorial to recreate the best-fit model from a redrock fit. However, the following import requires numba:

import redrock.templates

Is there a workaround to avoid this, or could this sub-module be refactored to not require numba?

sbailey commented 4 years ago

numba works as a decorator to functions to JIT compile, so it is needed at the package level rather than being isolated inside functions, even if you never call that particular function (in this case, the trapz rebinning of the templates to a given observed wavelength grid for a given redshift). So the "workaround" is to install numba if you want to use the redrock.templates code. There might be a more clever design pattern to follow, but this case is trickier than just moving an import into a function that needs to use it.

That being said, the templates are just 2D[numvec, numwave] arrays of eigenvectors, with the CRVAL1, CDELT1 keywords defining the wavelength grid, and LOGLAM defining whether they are logarithmically binned (1) or linearly binned (0) in wavelength. So you could read the template directly and not bother with the redrock.templates.Template class.

Broadly speaking, this is part of the bigger question for how much tutorials should use DESI code "for convenience" while thus inconveniently requiring a larger software stack, vs. replicating I/O etc. boilerplate code into the tutorials to avoid certain dependencies. This does seem like a fundamental enough use of the DESI data that we should document how to use the data products with a vanilla set of numpy+fitsio, even if we still require someone using redrock code to install numba too.

moustakas commented 5 months ago

@dkirkby please reopen if this is still an issue.