Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lpsinger opened this issue Aug 29, 2024 · 2 comments

Comments

@lpsinger
Copy link
Contributor

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
Copy link
Owner

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
Copy link
Contributor Author

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.

lpsinger added a commit to lpsinger/dust_extinction that referenced this issue Aug 29, 2024
Define the `input_units`, `return_units`, `input_units_equivalencies`,
and `bounding_box` properties for all models. Use Astropy models' built-in
unit conversion support.

All models now require inputs with valid units (wavelength, wavenumber, or
frequency). Dimensionless inputs are no longer automatically converted to
wavenumber.

Fixes karllark#237.
lpsinger added a commit to lpsinger/dust_extinction that referenced this issue Sep 5, 2024
Define the `input_units`, `return_units`, `input_units_equivalencies`,
and `bounding_box` properties for all models. Use Astropy models' built-in
unit conversion support.

All models now require inputs with valid units (wavelength, wavenumber, or
frequency). Dimensionless inputs are no longer automatically converted to
wavenumber.

Fixes karllark#237.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants