spacetelescope / poppy

Physical Optics Propagation in Python
https://poppy-optics.readthedocs.io
BSD 3-Clause "New" or "Revised" License
219 stars 72 forks source link

Use astropy.Quantities for all wavelengths everywhere #165

Closed mperrin closed 6 years ago

mperrin commented 6 years ago

Issue by mperrin Monday Apr 25, 2016 at 22:35 GMT Originally opened as https://github.com/mperrin/poppy/pull/165


This addresses #145 by making lots of things into astropy Quantities, primarily wavelengths and pixel scales. As a result we can now explicitly specify wavelengths in meters or microns or whatever and things will Just Work.

As proposed in #145, a decorator is added to utils that allows back-compatible function arguments given as floating point values to be automatically converted to astropy Quantity lengths in meters. You can give other units explicitly as e.g. wavelength=2*u.micron. (This decorator is currently named "quantity_input", the same as the related but different function provided by astropy itself. I couldn't think of any better name apart from monstrosities like e.g. @back_compatible_quantity_input_with_slightly_different_behavior_than_the_astropy_one; please feel free to suggest improvements)

In any case, this decorator is then applied liberally throughout poppy_core, fresnel, and optics.py. Many string formatting and FITS header writing code lines had to be fixed. I added various casts to floating point values in meters where needed, which is awkward and a bit convoluted but is needed given that not absolutely everything uses Quantities yet.


mperrin included the following code: https://github.com/mperrin/poppy/pull/165/commits

mperrin commented 6 years ago

Comment by mperrin Wednesday Apr 27, 2016 at 22:10 GMT


Kinda pleased that all the webbpsf unit tests pass against this with no units-related changes. Guess I got the back-compatibility part right! ( #162 on the other hand did require some minor webbpsf changes for the custom optic classes there.)

And in the course of putting more units into the OpticalElement classes, I found and fixed two long-standing bugs we'd missed until now, with the NgonAperture class and the unit test for MFT forward & inverse transforms cancelling out. So that's a plus.

I will probably go ahead and merge this relatively soon, and then shift development attention more towards webbpsf.