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

issue with unit_check_wrapper #171

Closed
mperrin opened this issue Aug 23, 2018 · 5 comments
Closed

issue with unit_check_wrapper #171

mperrin opened this issue Aug 23, 2018 · 5 comments

Comments

@mperrin
Copy link
Collaborator

mperrin commented Aug 23, 2018

Issue by tiggersternchen
Friday Jul 08, 2016 at 09:20 GMT
Originally opened as mperrin/poppy#171


First of all: thanks for this great toolbox !

Unfortunately I have encountered an error with the unit_check_wrapper in poppy 0.5.0. If I try to run the unit tests or the example scripts the following error (or similar) occurs:

"Only dimensionless scalar quantities can be converted to Python scalars" or
" 'm' (length) and '' (dimensionless) are not convertible"

I've tried this on a fresh installed system with Python 2.7 x64, Python 3.5 x64 and Python 3.5 x32 (Anaconda distributions). The same for the included ipython notebook files.

With poppy 0.4.1 the error doesn't occur.

What am I doing wrong ? Thanks in advance.

Sven

@mperrin
Copy link
Collaborator Author

mperrin commented Aug 23, 2018

Comment by josePhoenix
Friday Jul 08, 2016 at 12:34 GMT


Thanks for the report! I'll look into this for you. Can you come up with a minimal test case? Does it happen any time a quantity is passed through that wrapper, or only with certain virtual optics or functions?

@mperrin
Copy link
Collaborator Author

mperrin commented Aug 23, 2018

Comment by josePhoenix
Friday Jul 08, 2016 at 13:11 GMT


As a data point, I created a fresh Python 3.5 conda env and installed POPPY 0.5.0 from source. (There was an issue with a distutils import on install, which was unrelated.)

Running this example from the notebooks/POPPY Examples.ipynb file with and without the * u.m included seems to work.

from astropy import units as u

osys = poppy.OpticalSystem()
osys.add_pupil( poppy.CircularAperture(radius=3 * u.m))    # pupil radius in meters
osys.add_detector(pixelscale=0.010, fov_arcsec=5.0)  # image plane coordinates in arcseconds

psf = osys.calc_psf(2e-6)                            # wavelength in microns
poppy.display_psf(psf, title='The Airy Function') 

@mperrin
Copy link
Collaborator Author

mperrin commented Aug 23, 2018

Comment by tiggersternchen
Friday Jul 08, 2016 at 13:55 GMT


Thanks for the fast response. This example file works for me too. The problem occurs with the MatrixFTCoronagraph.ipynb example, more precisely during the execution of the following call:

"annFPM_mft_psf, annFPM_mft_interm = matrixFTcoron_annFPM_osys.calcPSF(wavelen, display_intermediates=True, return_intermediates=True)"

The error also occurs if I run the tests:

import poppy
poppy.test()

@mperrin
Copy link
Collaborator Author

mperrin commented Aug 23, 2018

Comment by josePhoenix
Friday Jul 08, 2016 at 14:16 GMT


Okay, there might be more than one bug here. (Haven't had the chance to run the test suite yet.)

Looks like in https://github.com/mperrin/poppy/blob/master/poppy/poppy_core.py#L2083 there's an attempt to format a unit-having quantity as a simple float, which is incorrect. It's done correctly elsewhere, so I'm going to read through and see how we missed that one.

If you want a quick fix, replace that line with just title = None in your copy. The only thing you'll miss is the note in the plot title about which wavelength was last propagated.

@mperrin
Copy link
Collaborator Author

mperrin commented Aug 23, 2018

Comment by tiggersternchen
Friday Jul 08, 2016 at 14:53 GMT


Great,

your workaround does the trick.

Thanks a lot

@mperrin mperrin closed this as completed Aug 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant