extinction icon indicating copy to clipboard operation
extinction copied to clipboard

dimensionality of input

Open zpace opened this issue 6 years ago • 2 comments

It appears that extinction only works with 1-d wavelength inputs.

Example:

import extinction
import numpy as np
a = extinction.fitzpatrick99(
    wave=np.random.uniform(3800., 10000., (1000, 10, 10)), r_v=3.1, a_v=1.)


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-12-d87da702ce4d> in <module>
----> 1 extinction.fitzpatrick99(wave=np.random.uniform(3800., 10000., (1000, 10, 10)), r_v=3.1, a_v=1.)

extinction.pyx in extinction.fitzpatrick99()

extinction.pyx in extinction.Fitzpatrick99.__call__()

ValueError: Buffer has wrong number of dimensions (expected 1, got 3)

zpace avatar Feb 18 '19 20:02 zpace

True! Quick fix: call wave.ravel() to get a 1-d array, then reshape the output array to match the input.

This limitation is because I used typed memory views. For example, see this function signature, which means the function only takes a 1-d array of doubles. While more complex, one could use the numpy C API to achieve the more flexible behavior you're looking for without much performance loss. Or there might be a better way.

Related issue about flexibility of inputs: #6 .

kbarbary avatar Feb 19 '19 03:02 kbarbary

Yes, that is a solution I considered. It was better for my workflow to just sample the dust law densely and interpolate it using scipy.interpolate.interp1d.

zpace avatar Feb 19 '19 15:02 zpace