karllark / dust_extinction

Astronomical Dust Extinction
http://dust-extinction.readthedocs.io
BSD 3-Clause "New" or "Revised" License
39 stars 23 forks source link

Set input_units, return_units, input_units_equivalencies, and bounding_box to use astropy's built-in input preparation? #237

Open lpsinger opened 2 months ago

lpsinger commented 2 months ago

If you set the input_units, return_units, input_units_equivalencies, and bounding_box properties, then when you call a model, the astropy.modeling.Model base class will automatically convert the users' arguments to your desired units and do bounds checking. Note that the spectral() equivalency will do automatic conversion between wavelength and wavenumber. This builtin functionality could essentially replace _get_x_in_wavenumbers and _test_valid_x_range. Would you entertain a patch to do this? I'm working on a project where it would be nice to have the bounds and units of these models exposed in the conventional way.

karllark commented 2 months ago

I would definitely entertain such a PR.

One question, would this allow for no units to be passed and interpreted as wavenumbers (1/micron)? Not allowing this is not a show-shopper, I've thought about removing this option. It would potentially mean new versions are not compatible with existing code, but that can be ok/allowed.

lpsinger commented 2 months ago

One question, would this allow for no units to be passed and interpreted as wavenumbers (1/micron)?

There is the astropy.modeling.Model.input_units_allow_dimensionless attribute that you can set on model classes, but I tried it out and I personally don't like it. It seems like it turns off the automatic unit conversion so that either the units you declared or dimensionless quantities make it to your evaluate method.