Code Monkey home page Code Monkey logo

poppy's Introduction

POPPY: Physical Optics Propagation in Python

image

Badge showing current released PyPI version

Badge showing continuous integration test status

Badge showing testing code coverage percentage

image

POPPY (Physical Optics Propagation in Python) is a Python package that simulates physical optical propagation including diffraction. It implements a flexible framework for modeling Fraunhofer and Fresnel diffraction and point spread function formation, particularly in the context of astronomical telescopes.

POPPY was developed as part of a simulation package for the James Webb Space Telescope, but is more broadly applicable to many kinds of imaging simulations. It is not, however, a substitute for high fidelity optical design software such as Zemax or Code V, but rather is intended as a lightweight alternative for cases for which diffractive rather than geometric optics is the topic of interest, and which require portability between platforms or ease of scripting.

For documentation, see http://poppy-optics.readthedocs.io/

Code by Marshall Perrin, Joseph Long, Ewan Douglas, Neil Zimmerman, Anand Sivaramakrishnan, Shannon Osborne, Kyle Douglass, Maciek Grochowicz, Phillip Springer, & Ted Corcovilos, with additional contributions from Remi Soummer, Kyle Van Gorkom, Jonathan Fraine, Christine Slocum, Roman Yurchak, and others on the Astropy team.

Projects using POPPY

POPPY provides the optical modeling framework used in:

poppy's People

Contributors

astrofrog avatar bsipocz avatar cdeil avatar corcoted avatar daphil avatar douglase avatar embray avatar eteq avatar hamogu avatar ivalaginja avatar joseph-long avatar josephoenix avatar kbarbary avatar kmdouglass avatar larrybradley avatar maciekgroch avatar mdboom avatar mmechtley avatar mperrin avatar mwcraig avatar neilzim avatar ojustino avatar robelgeda avatar rth avatar sdwill avatar shanosborne avatar wkerzendorf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

poppy's Issues

poppy.zernike functions return references to cached arrays instead of copies

It's possible to accidentally modify the cached copies of the Zernike polynomials as returned by zernike_list, which will then show up later if you think you're computing 'fresh' copies of the Zernike polynomials (because they're actually being returned out of zernike._ZCACHE, not re-computed).

To prevent unintentionally modifying the Zernike arrays, we can use the writeable (n.b. not writable) flag provided by NumPy. (Alternatively, we can copy the array on returning, at risk of additional memory use.) Example:

In [70]: temp = np.arange(10)
In [71]: temp
Out[71]: array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
In [73]: temp.flags.writeable = False
In [74]: temp[4] = 1
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-74-76362c99aa88> in <module>()
----> 1 temp[4] = 1

ValueError: assignment destination is read-only

I also propose replacing the _ZCACHE dict with an LRU cache that can enforce an upper bound on memory usage (so calling zernike_list repeatedly with different arguments doesn't result in excess memory usage). It might be helpful to implement the same kind of caching for hexikes, since they're computed in a similar way.

Rectangular detector (X,Y) vs (Y,X) consistency

It appears we're swapping axes order someplace:

    sys = poppy_core.OpticalSystem()
    sys.addDetector(pixelscale=pixscale, fov_pixels=(100,200), oversample=1)
    psf = sys.calcPSF()
    print psf[0].data.shape

yields:

(200, 100)

The Detector docstring says that the fov_pixels is given in Pythonic order but that appears not to be the case.

`test_instrument_source` tests are now failing

@josePhoenix After merging #57 and #58 I have the following tests failing:

poppy/tests/test_instrument.py:25: test_instrument_source_weight_dict FAILED poppy/tests/test_instrument.py:47: test_instrument_source_weight_array FAILED poppy/tests/test_instrument.py:69: test_instrument_source_pysynphot FAILED

(Nice reminder about why we definitely need #51 before too long. :-)

zernike.py is missing

Hi All,
I'd like to test (and use) the ZernikeWFE function in wfs.py, except zernike.py is not included in the repository.

Does it still need to be written, or was it left out?

Under certain (unclear) conditions, use_multiprocessing causes calculation to hang

For some reason, this sample code (using WebbPSF) causes a hang on my Mac Pro but not the science5 server or my personal machine (MacBook Air). Needs a better test case that uses only POPPY.

(To avoid the sometimes unusual behavior of multiprocessing + the interactive interpreter, I saved this as a separate script and ran it from the command line.)

import webbpsf
import poppy
nc = webbpsf.NIRCam()
nc.filter = 'F150W2'
poppy.conf.use_fftw = False
poppy.conf.use_multiprocessing = True
poppy.conf.n_processes = 8
nc.calcPSF()

Running this prints out logging output through "Propagating wavelength..." lines for the first 20 of 40 wavelengths, and then nothing happens.

If I interrupt the script with Ctrl-C, I get tracebacks from all the running workers interleaved (to be expected, but hard to interpret) and it looks like they're all waiting on "task = get()" which in turn is waiting
on "racquire()" which seems to acquire a lock on a pipe.

Error on running the 'Obscured Aperture' example

On poppy v0.3.2, when testing the FQPM on an Obscured Aperture (demonstrates compound optics)
the interpreter exits with error message:

aperture = poppy.CompoundAnalyticOptic( opticslist = [primary, secondary] )
  File "/python2.7/site-packages/poppy/optics.py", line 1330, in __init__
    or (isinstance(optic,InverseTransmission) and isinstance(optic.optic,AnalyticOpticalElement))):  #an inverted analytic element is also OK here
NameError: global name 'InverseTransmission' is not defined

Oversampling logic doesn't agree with docstring

From poppy.Instrument.calcPSF:

        Output sampling may be specified in one of two ways: 

        1) Set `oversample=<number>`. This will use that oversampling factor beyond detector pixels
           for output images, and beyond Nyquist sampling for any FFTs to prior optical planes. 
        2) set `detector_oversample=<number>` and `fft_oversample=<other_number>`. This syntax lets
           you specify distinct oversampling factors for intermediate and final planes. 

        By default, both oversampling factors are set equal to 2.
....
        oversample, detector_oversample, fft_oversample : int
            How much to oversample. Default=4. By default the same factor is used for final output 
            pixels and intermediate optical planes, but you may optionally use different factors 

The default oversampling is set to 4 when using Instrument.calcPSF, but if you're using an OpticalSystem class directly it's 2. I think oversampling should required explicitly when using calcPSF on an OpticalSystem, and all the business of choosing defaults limited to the Instrument.calcPSF level.

Python 3 incompatibility in poppy_core.py

Two lines in the poppy_core.py file are Python3 incompatible (lines 2145-2150):

        if len (self.opd.shape) != 2 or self.opd.shape[0] != self.opd.shape[1]:
            _log.debug('OPD shape: '+str(self.opd.shape))
            raise ValueError, "OPD image must be 2-D and square"

        if len (self.amplitude.shape) != 2 or self.amplitude.shape[0] != self.amplitude.shape[1]:
            raise ValueError, "Pupil amplitude image must be 2-D and square"

Apparently 2to3 does not fix it, and a manual conversion to brakets is necessary.

add tests for multiprocessing

Reminded by #55, we should have tests for multiprocessing.

  • Test basic functionality: can you make a PSF with multiprocessing enabled?
  • For a simple optical system, test that single process and multiprocess calculation give the same results
  • Test that using multiprocessing you can retrieve the intermediate planes, and they are consistent with the intermediate planes from a single process calculation
  • Test multiprocessing related utility functions such as estimate_optimal_nprocesses

Display of compound analytic optics problem

The following does not seem to display the phase of the defined compound lens correctly:

poppy.CompoundAnalyticOptic( [
        poppy.CircularAperture(), 
        poppy.ThinLens(nwaves=2, reference_wavelength=2e-6)]
                            ).display(what='both')

screen shot 2014-08-14 at 6 47 51 pm

Display of the optics individually works fine.

wavelen=2e-6
osys = poppy.OpticalSystem("test", oversample=2)
osys.addPupil( poppy.CircularAperture(radius=3))    # pupil radius in meters
osys.addPupil( poppy.ThinLens(nwaves=nwaves, reference_wavelength=wavelen))
osys.addDetector(pixelscale=0.01, fov_arcsec=4.0)
osys.display(what='both')

unknown

MIRI special case in Instrument._getWeights should be moved out

JWST-specific logic in poppy.Instrument._getWeights should be moved into JWInstrument in WebbPSF.

            minwave = band.wave[w_above10].min()
            maxwave = band.wave[w_above10].max()
            poppy_core._log.debug("Min, max wavelengths = %f, %f" % (minwave/1e4, maxwave/1e4))
            # special case: ignore red leak for MIRI F560W, which has a negligible effect in practice
            # this is lousy test data rather than a bad filter?
            if self.filter == 'F560W':
                poppy_core._log.debug("Special case: setting max wavelength to 6.38 um to ignore red leak")
                maxwave = 63800.0
            elif self.filter == 'F1280W':
                poppy_core._log.debug("Special case: setting max wavelength to 14.32 um to ignore red leak")
                maxwave = 143200.0

Also

 if self.filter == 'FND': # special case MIRI's ND filter since it is < 0.1% everywhere...
wtrans = np.where( ( filterdata.THROUGHPUT > 0.0005) & (filterdata.WAVELENGTH > 7e-6*1e10) & (filterdata.WAVELENGTH < 26e-6*1e10 ))

poppy.Instrument filter loading needs refactoring

There's some blurring of lines between WebbPSF and POPPY in the filter code in poppy.Instrument. In particular, there are references to a self._filter_files attribute (that's populated by JWInstrument) within poppy.Instrument. Also, there are special cases for Webb instruments in _getWeights (#20). Refactoring here would be a good opportunity to fix mperrin/webbpsf#28 as well.

Suggestions for improved MFT and SAM tests

Suggestions from Laurent:

  1. Test the MFT function by setting up a calculation that uses the MFT to produce a PSF on the exact same sampling as an FFT. These should be identical to near machine precision.
  • Done
  1. Test the overall SAM implementation by setting up a calculation of a band limited coronagraph on a square aperture, for which analytic solutions exist. Get these from Laurent since he already has this info organized somewhere. Compare numerical results to the analytic solution.
  • TBD

display_EE labeling only works for normalized images

(Trying to post the issue to garner feedback with my proposed solution before a pull request, let me know if this approach is easier or redundant.)

The labels all are all piled up at the bottom:
display_profiles

now I've fixed this for the moment (in my branch, commit: 1300926) by normalizing the levels to the max of the encircled energy (example below). This assumes all the energy is in image, which may not always be true, but should be a good enough assumption for most uses cases I can think of, does this seem reasonable?
display_profiles_fixed

pip install poppy fails

I'm using pip 1.3.1 with the command pip install poppy. See log below:

------------------------------------------------------------
/Users/mrdavis/.virtualenvs/pysynphot/bin/pip run on Tue Apr 30 12:14:28 2013
Downloading/unpacking poppy

  Getting page http://pypi.python.org/simple/poppy
  URLs to search for versions for poppy:
  * http://pypi.python.org/simple/poppy/
  Getting page http://www.stsci.edu/%7emperrin/software/webbpsf
  Skipping page http://www.stsci.edu/%7emperrin/software/webbpsf/poppy-0.2.8.tar.gz (from http://pypi.python.org/simple/poppy/) because of Content-Type: application/x-tar
  Analyzing links from page http://pypi.python.org/simple/poppy/
    Found link http://pypi.python.org/packages/source/p/poppy/poppy-0.2.8.tar.gz#md5=3546bff46b1a32f3b3fc1cfa56c7c95d (from http://pypi.python.org/simple/poppy/), version: 0.2.8
    Skipping link http://www.stsci.edu/%7emperrin/software/webbpsf (from http://pypi.python.org/simple/poppy/); not a file
    Found link http://www.stsci.edu/%7emperrin/software/webbpsf/poppy-0.2.8.tar.gz (from http://pypi.python.org/simple/poppy/), version: 0.2.8
    Skipping link http://www.stsci.edu/jwst/software/webbpsf/ (from http://pypi.python.org/simple/poppy/); not a file
  Analyzing links from page http://www-int.stsci.edu/~mperrin/software/webbpsf/
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/_static/default.css (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .css
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/_static/pygments.css (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .css
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/ (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); not a file
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/intro.html (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/genindex.html (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/py-modindex.html (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/np-modindex.html (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/#documentation-for-webbpsf (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); not a file
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/_images/fig_instrument_comparison.png (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .png
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/poppy.html#module-poppy (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/webbpsf.html#module-webbpsf (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/gui.html#module-webbpsfgui (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/Improved_PSFs_for_Webb.pdf (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .pdf
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/#contents (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); not a file
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/intro.html#why-a-new-jwst-psf-simulator (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/intro.html#algorithm-overview (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/intro.html#quick-start (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/installation.html (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/installation.html#software-requirements (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/installation.html#installing-webbpsf-via-pypi (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/installation.html#installing-webbpsf-manually (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/installation.html#installing-webbpsf-development-versions-and-or-contributing-to-its-development (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/installation.html#installing-the-required-data-files (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/installation.html#installing-or-updating-pysynphot (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/installation.html#note-for-stsci-internal-users (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/relnotes.html (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/relnotes.html#known-issues (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/relnotes.html#plans-for-future-releases (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/relnotes.html#version-0-2-8 (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/relnotes.html#version-0-2-7 (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/relnotes.html#version-0-2-6 (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/relnotes.html#version-0-2-5 (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/relnotes.html#versions-0-2-1-0-2-3 (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/relnotes.html#version-0-2 (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/relnotes.html#version-0-1 (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/webbpsf.html (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/webbpsf.html#usage-and-examples (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/webbpsf.html#the-jwinstrument-generic-class (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/webbpsf.html#notes-on-specific-instruments (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/webbpsf.html#utility-functions-for-display-and-plotting (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/gui.html (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/gui.html#gui-controls (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/poppy.html (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/poppy.html#list-of-classes (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/poppy.html#wavefront (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/poppy.html#optical-system (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/poppy.html#optical-elements (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/poppy.html#instrument (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/available_opds.html (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/references.html (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/references.html#ote (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/references.html#nircam (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/references.html#nirspec (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/references.html#niriss (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/references.html#miri (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/references.html#instrument-filter-throughputs (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/more_examples.html (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/more_examples.html#typical-usage-cases (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/more_examples.html#advanced-usage-tricks (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/sampling.html (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/sampling.html#key-concepts (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/sampling.html#some-useful-guidance (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/sampling.html#per-instrument-sampling-requirements (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/fft_optimization.html (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/fft_optimization.html#planning-in-fftw3 (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/fft_optimization.html#a-comparison-of-different-fft-methods (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/fft_optimization.html#a-test-comparing-all-four-planning-methods (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/fft_optimization.html#a-comparison-of-estimate-and-measure-for-different-sizes (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/fft_optimization.html#caching-of-plans-means-that-irunning-the-same-script-a-second-time-is-much-faster (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/fft_optimization.html#the-payoff-speed-improvements-in-poppy (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/#indices-and-tables (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); not a file
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/search.html (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .html
    Skipping link http://www-int.stsci.edu/%7emperrin/software/webbpsf/_sources/index.txt (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); unknown archive format: .txt
    Skipping link http://sphinx.pocoo.org/ (from http://www-int.stsci.edu/~mperrin/software/webbpsf/); not a file
  Using version 0.2.8 (newest of versions: 0.2.8, 0.2.8)
  Downloading from URL http://pypi.python.org/packages/source/p/poppy/poppy-0.2.8.tar.gz#md5=3546bff46b1a32f3b3fc1cfa56c7c95d (from http://pypi.python.org/simple/poppy/)
  Running setup.py egg_info for package poppy

    Traceback (most recent call last):

      File "<string>", line 16, in <module>

    IOError: [Errno 2] No such file or directory: '/Users/mrdavis/.virtualenvs/pysynphot/build/poppy/setup.py'

    Complete output from command python setup.py egg_info:

    Traceback (most recent call last):

  File "<string>", line 16, in <module>

IOError: [Errno 2] No such file or directory: '/Users/mrdavis/.virtualenvs/pysynphot/build/poppy/setup.py'

----------------------------------------

Command python setup.py egg_info failed with error code 1 in /Users/mrdavis/.virtualenvs/pysynphot/build/poppy

Exception information:
Traceback (most recent call last):
  File "/Users/mrdavis/.virtualenvs/pysynphot/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg/pip/basecommand.py", line 107, in main
    status = self.run(options, args)
  File "/Users/mrdavis/.virtualenvs/pysynphot/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg/pip/commands/install.py", line 256, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "/Users/mrdavis/.virtualenvs/pysynphot/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg/pip/req.py", line 1042, in prepare_files
    req_to_install.run_egg_info()
  File "/Users/mrdavis/.virtualenvs/pysynphot/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg/pip/req.py", line 236, in run_egg_info
    command_desc='python setup.py egg_info')
  File "/Users/mrdavis/.virtualenvs/pysynphot/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg/pip/util.py", line 612, in call_subprocess
    % (command_desc, proc.returncode, cwd))
InstallationError: Command python setup.py egg_info failed with error code 1 in /Users/mrdavis/.virtualenvs/pysynphot/build/poppy

matrixDFT.DFT_combined doesn't handle rectangular input arrays

DFT_combined seems to choke on rectangular input arrays, though it will gladly produce rectangular output arrays.

In the code below, rect_pupil is an array of shape (200, 400) with a pupil mask in ones and zeros.

First, I checked with the stand-along DFT_fftstyle_rect function:

rect_image = oldmatrixDFT.DFT_fftstyle_rect(rect_pupil, (100, 200), (200, 400))
plt.imshow(np.abs(rect_image))

and I got the expected output.

When I tried with DFT_combined...

rect_image = oldmatrixDFT.DFT_combined(rect_pupil, (100, 200), (200, 400), centering='FFTSTYLE')
plt.imshow(np.abs(rect_image))

... I got ...

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-69-7e4a707ac5e8> in <module>()
----> 1 rect_image = oldmatrixDFT.DFT_combined(rect_pupil, (100, 200), (200, 400), centering='FFTSTYLE')
      2 plt.imshow(np.abs(rect_image))

/Users/jdl/dev/poppy/poppy/oldmatrixDFT.py in DFT_combined(pupil, nlamD, npix, offset, inverse, centering, **kwargs)
    166     else:
    167         expXU = expXU.T.copy()
--> 168         t1 = np.dot(expXU, pupil)
    169         t2 = np.dot(t1, expYV)
    170 

ValueError: shapes (200,400) and (200,400) not aligned: 400 (dim 1) != 200 (dim 0)

Non-integer indices in imshow_with_mouseover causing abundance of DeprecationWarnings

@kvangorkom reports that recent versions of NumPy emit a deprecation warning when arrays are indexed with non-integer indices. The formatter in imshow_with_mouseover seems to do a lot of this, emitting a DeprecationWarning on every mouse movement.

In [1]: import warnings, exceptions

In [2]: warnings.filterwarnings("error",category=exceptions.DeprecationWarning)

In [3]: import webbpsf
WebbPSF log messages of level INFO and above will be shown.
WebbPSF log outputs will be directed to the screen.

In [4]: nircam = webbpsf.NIRCam()
#...
In [6]: import matplotlib.pyplot as plt
#...
In [8]: plt.ion() #I don't remember having to explicitly declare this to get display to show up? Whatevs.

In [9]: nircam.display()
webbpsf   : INFO     Creating optical system model:
poppy     : INFO     Initialized OpticalSystem: JWST+NIRCam
poppy     : INFO     JWST Pupil: Loaded amplitude transmission from /Users/kgorkom/webbpsf-data/pupil_RevV.fits
poppy     : INFO     JWST Pupil: Loaded OPD from /Users/kgorkom/webbpsf-data//NIRCam/OPD/OPD_RevV_nircam_155.fits
poppy     : INFO     The supplied pupil OPD is a datacube but no slice was specified. Defaulting to use slice 0.
poppy     : INFO     Added pupil plane: JWST Pupil
poppy     : INFO     Added detector: NIRCam detector, with pixelscale=0.031700 arcsec/pixel and oversampling=2
poppy     : INFO     Displaying plane JWST Pupil in row 1 of 1

#Mouse over the plots

In [10]: Exception in Tkinter callback
Traceback (most recent call last):
  File "/Users/kgorkom/STScI/ssbx/python/lib/python2.7/lib-tk/Tkinter.py", line 1470, in __call__
    return self.func(*args)
  File "/Users/kgorkom/STScI/ssbx/python/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-macosx-10.6-x86_64.egg/matplotlib/backends/backend_tkagg.py", line 380, in motion_notify_event
    FigureCanvasBase.motion_notify_event(self, x, y, guiEvent=event)
  File "/Users/kgorkom/STScI/ssbx/python/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-macosx-10.6-x86_64.egg/matplotlib/backend_bases.py", line 1834, in motion_notify_event
    self.callbacks.process(s, event)
  File "/Users/kgorkom/STScI/ssbx/python/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-macosx-10.6-x86_64.egg/matplotlib/cbook.py", line 527, in process
    proxy(*args, **kwargs)
  File "/Users/kgorkom/STScI/ssbx/python/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-macosx-10.6-x86_64.egg/matplotlib/cbook.py", line 405, in __call__
    return mtd(*args, **kwargs)
  File "/Users/kgorkom/STScI/ssbx/python/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-macosx-10.6-x86_64.egg/matplotlib/backend_bases.py", line 2788, in mouse_move
    s = event.inaxes.format_coord(event.xdata, event.ydata)
  File "/Users/kgorkom/STScI/ssbx/variants/common/src/poppy/poppy/utils.py", line 57, in <lambda>
    np.floor( (x - imext[0])/(imext[1]-imext[0])*imsize[1]  ).clip(0,imsize[1]-1)])
  File "/Users/kgorkom/STScI/ssbx/variants/common/lib/python2.7/site-packages/numpy/ma/core.py", line 2999, in __getitem__
    dout = ndarray.__getitem__(_data, indx)
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices

Further improve test coverage

This is just a catch all issue for places that need more coverage.

  • equivalence of inverse MFT with inverse FFT
  • Instrument class has pretty sparse coverage so far
  • None of the display code is tested at all; needs setup for headless testing without on screen drawing.
  • Bandlimited coron needs test coverage
  • MultiHexagonAperture needs test coverage
  • Zernike utility functions need test coverage

poppy.Instrument references CircularAperture incorrectly

Looks like CircularAperture got moved and nobody told Instrument. (I guess the WebbPSF JWInstrument class doesn't call the superclass __init__ or we would see this when starting up WebbPSF?)

>>> poppy.Instrument()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "poppy/instrument.py", line 54, in __init__
    self.pupil = poppy_core.CircularAperture( *args, **kwargs)
AttributeError: 'module' object has no attribute 'CircularAperture'

Numerical noise changes behavior of ThinLens optic

While working on adapting the ThinLens optic to use the poppy.zernike library of functions, I noticed that the present implementation of ThinLens has a problem: the radius normalization changes when inserting an intermediate image plane between the pupil and the thin lens.

Test case

import poppy

RADIUS = 3.0 # meters
WAVELENGTH = 4.6e-6 # meters
PIXSCALE = 0.01 # arcsec / pix
FOV = 3.0 # arcsec
NWAVES = 1.0

osys = poppy.OpticalSystem("Testing Zernikes")
circular_aperture = poppy.CircularAperture(radius=RADIUS)
osys.addPupil(circular_aperture)
# uncomment this to add an intermediate plane:
# osys.addImage()
thinlens = poppy.ThinLens(nwaves=NWAVES, reference_wavelength=WAVELENGTH)
osys.addPupil(thinlens)
osys.addDetector(pixelscale=PIXSCALE, fov_arcsec=FOV)

plt.figure(figsize=(8,8))
psf_without_intermediate = osys.calcPSF(wavelength=WAVELENGTH, display_intermediates=True)
plt.tight_layout()

With the addImage() call commented out as above, the resulting PSF looks like:

psf_without

With the addImage() call:

psf_with

Cause

The defocus analytic optic needs to know the extent of the aperture in order to normalize the radius such that rho = 1 at the edge of the illuminated portion. The way this works now, the radius is guessed from the pixels in the aperture.

From poppy/optics.py: ThinLens.getPhasor

y, x = wave.coordinates()
r = np.sqrt(x ** 2 + y ** 2)

max_r = r[np.where(wave.intensity > 0)].max()
r_norm = r / max_r

wave.intensity > 0 is true for all pixels after a single back-and-forth FFT/IFFT, because numerical noise shows up in the zero pixels (~1e-46).

Solution

The proposed solution is to require ThinLens instances to be instantiated with a size keyword argument specifying their radius in meters in the original pupil plane.

It may also be possible to make a better guess at which pixels are "close enough" to zero, and improve the guessing of the aperture radius. This would preserve backward compatibility, but may not be totally foolproof in the case of a grayscale pupil.

It's better to be explicit than implicit, so I'll update POPPY and the corresponding parts of WebbPSF to use a size= keyword argument.

Default nlambda specified in two places

There's both _getDefaultNLambda and a default keyword argument to _getWeights. There should only be one place that a default nlambda is specified to prevent surprises.

cleanup wfe.py; rationalize with ZernikeAberration class and related.

@josePhoenix - The existing wfe.py file is mostly a placeholder left over from early steps towards adding Zernike aberrations and other WFE forms. The partial Zernike WFE class in there is now almost certainly obsolete and redundant with your ZernikeAberration class, so we should take it out so there is one and only one obvious way to implement Zernike-based WFE.

The other classes are just notional hand wave placeholders; I'd probably comment them all out entirely although I wouldn't just delete them outright since I think in the long run we will want some other forms of aberrations besides just Zernikes.

Test user-specified weightings via source argument to calcPSF

This would probably be an Instrument instance and an OpticalSystem instance set up to do the same thing and a check to make sure the PSFs are approximately equal. (I'm not sure if there is or should be a test of the OpticalSystem code path that combines the weighted PSFs...)

performance optimization of matrixDFT by caching arrays

As suggested by email from Anand:

Hi Marshall

could you remind me if using mdft as:

  psf1 = mDFT.DFT_combined(vizclean, 200.0, 400, inverse = True, centering = "SYMMETRIC")

every time causes the underlying siney and cosiney (or imaginary-exponenty) vectors to be regenerated every time? I thought that for multiple use on the same sized problem I should do something more like…

# MFT setup style and execute
mft = matrixDFT.MatrixFourierTransform(centering=centering, verbose=True)
a = mft.perform(pupilA, u, npix)
b = mft.perform(pupilB, u, npix)
....
A = mft.inverse(imageA, u, npix)
B = mft.inverse(imageB, u, npix)

and so on, where u and npix are the same integers in all these calls, but looking through matrixDFT it looks like the vectors are generated afresh always.

I think I'm being confused by recaling Remi's Mathematica version from the first gen SFT where he stored the basis vectors when creating the object, and just used them in calls to perform() [or whatever he called that].

I'm getting ready to Gerchberg-Saxton, but there's no huge rush

Anand

to which I replied:

I would not at all be surprised if there are ways to improve the efficiency of this code. It definitely hasn't been optimized.

What you say makes good sense; we could cache those arrays and re-use them if they are the same size and other settings. Code improvements welcomed!

poppy docs need to be updated

These are issues with the poppy docs that should be fixed prior to our next release. @mperrin: please add any others as they occur to you.

  • Sphinx docs for classes.rst not making links for all classes. #17
  • add documentation for saving analytic pupils to a FITS file #9
  • add a label for the poppy homepage so we can intersphinx link to it
  • replace http://www.stsci.edu/~mperrin/software/poppy with a redirect to the pythonhosted.org docs
  • missing about or about_team label
/Users/jlong/dev/poppy/docs/index.rst:60: WARNING: undefined label: about_team (if the link has no caption the label must precede a section header)
/Users/jlong/dev/poppy/docs/relnotes.rst:8: WARNING: undefined label: about_team (if the link has no caption the label must precede a section header)
/Users/jlong/dev/poppy/docs/relnotes.rst:82: WARNING: undefined label: about (if the link has no caption the label must precede a section header)
  • undefined reference opticalelement (from docstring?)
/Users/jlong/dev/poppy/docs/api/poppy.OpticalSystem.rst:45: WARNING: undefined label: opticalelement (if the link has no caption the label must precede a section header)
  • Improve documentation for poppy.Instrument class and how to write your own instrument subclass. Document common Instrument functionality (in POPPY docs)
  • Add documentation for package level configuration settings to POPPY
  • Explain use_multiprocessing
  • Installation docs should be updated like WebbPSF's were (pysynphot install)

AnalyticOpticalElement.toFITS() output should be compatible with FITSOpticalElement()

Something I realized in the course of trying to write a test case that could have used this functionality, to discretize and store an AnalyticOpticalElement on a specific desired sampling.

This doesn't work right now due to header incompatibilities. It would also be nice to extend the FITSOpticalElement loading code to be a bit more flexible for handling both transmission and OPD in the same FITS file (which is possible now, but in a very clunky way passing in the same filename twice).

Ideally we could take any arbitrary AnalyticOptic and round-trip it through a FITS file to get back an equivalent FITSOpticalElement (at some specified sampling of course)

calcPSF should sanity check input wavefronts

I accidentally tried the following, in which I left out the source= keyword name

    source={'wavelengths': [1.0e-6, 1.1e-6, 1.2e-6, 1.3e-6], 'weights':[0.25, 0.25, 0.25, 0.25]}
    psf = osys.calcPSF(source)

Through a very confused chain of assignments and zip(), this results in a call to propagate_mono with wavelength set to the string "wavelengths" which obviously fails, and does so with a relatively unhelpful error message:

1184         wavefront = self.inputWavefront(wavelength)

ValueError: Unknown format code 'g' for object of type 'str'

Obviously one fix is for me to remember the API of my own code. But this is an obvious enough mistake that we should add some checking here.

`offset` argument to Detector class doesn't actually work

Looks like I left a few minor bits out of this implementation. Will fix.

Somewhat more complicatedly, _propagateMFTinverse doesn't support offset image planes.

I actually no longer remember the details of what motivated this feature - but I just came across a use case in making one of the MFT to FFT comparison tests. (Detector always uses ADJUSTABLE style MFTs, so there's no way to get exact equivalency with FFT outputs -- unless one uses this offset argument!)

default oversampling parameter defined in multiple places, inconsistently

How oversampling of wavefronts in image planes is handled is defined in multiple places, and the default are not all the same. This may need to be rationalized a bit.

  • The Detector class has a default oversample=1. This applies to the Detector object itself when created, and can be overridden when calling __init__.
  • The OpticalSystem class has a default oversample=2. This is applied to objects when added to the optical system, either a FITSOpticalElement added in addPupil, or an analytic optical element created from a function name inside addImage, or an empty image plane created via addImage, or a Detector added via a call to addDetector. It is also passed to the Wavefront class's __init__ in inputWavefront().
  • The Wavefront class has its own default oversample=2, consistent with OpticalSystem.

The practical result of the above is that while Detector(npix=npix,pixelscale=pixelscale) creates a detector with oversample=1, on the other hand some_opt_sys.addDetector(npix=npix,pixelscale=pixelscale) creates a detector with oversample=2.

This seems like an inconsistency we should fix, but I'm not sure which of the defaults makes the most sense to change.

N.B. WebbPSF makes an explicit distinction between "detector oversampling" (affects final image planes created via MFT) versus "FFT oversampling" (affects intermediate image planes created via FFT, implemented via zero-padding of arrays prior to FFTs). This distinction isn't formally maintained in POPPY - but maybe it should be?

Note also some of the above usage of oversample by OpticalSystem is vestigial. For instance passing oversample to FITSOpticalElement() does nothing. The sampling is set by the contents of the FITS file, and that parameter isn't even used. So that should be cleaned up, and there may be other similar instances.

Add Alex's analytic multi-hex PSFs

Alex Greenbaum has a Python implementation of Erin Elliot (Sabatke)'s analytic PSF for a multiple hexagonal aperture. This could be a nice ancillary utility to put into poppy/misc.py alongside the analytic Airy and sinc functions. I have all this code from Alex now, so this issue is to track that so I remember to merge it in sometime.

The version of poppy on pypi is out of date

The version of poppy on pypi does not work because it is missing a setup.py, so the install doesn't work.

Also, there appear to have been substantial modifications to poppy since then. I suggest it is time to make a new version of poppy and release it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.