Comments (3)
Never mind, you can do this with the ArrayOpticalElement class, which I did not have with version 0.6. Here is an implementation below showing that it is doing the right thing
import poppy
import numpy as np
import astropy.units as u
if __name__ == "__main__":
wl = 500e-9
#create a wavefront
wf = poppy.FresnelWavefront(0.01*u.m,
wavelength=wl,
npix=1024,
oversample = 2)
#add 1 nm surface error through a "screen"
surf_error = np.random.normal(loc = 0, scale = 1e-9, size = wf.shape)
#convert to phase
error = np.exp(2*np.pi*1j/wl*surf_error)
#Use the poppy version
error_p= poppy.ArrayOpticalElement(opd = surf_error)
#make sure the phasor is in accordance with expectation
print np.allclose(error, error_p.get_phasor(wl*u.m))
wf *= error_p
from poppy.
Great, glad you figured this out, Michael.
The problem with the first version is that the *=
invokes the Wavefront.__imul__
function, which knows how to "multiply" a wavefront by a scalar, an OpticalElement instance, or a coordinate transform, but not a plain ndarray. Wrapping the error into an ArrayOpticalElement fixes that, as you figured out.
The other way you could have done this in your first example is by directly accessing the wavefront data as an ndarray rather than via the Wavefront class:
wf.wavefront *= error
It would be simple enough to extend the Wavefront.__imul__
function to do the right thing if it's handed a complex ndarray with the right dimensions. Do you think that would be a useful enough thing to add in here?
Cleaning up and improving the documentation is on our to-do list for the next release this fall. I'll make sure we include an example along these lines!
from poppy.
Thanks Marshall. In my opinion it would be useful to allow for multiplication by complex matrices of the correct shape natively, without passing to an optical element class...but it seems straightforward enough to do it either way.
from poppy.
Related Issues (20)
- need to update minimum version of astropy in setup.py HOT 1
- python3 Integer division in poppy/utils.py HOT 2
- calcPSF halts in certain specific circumstances. HOT 5
- zernike.arbitrary_basis still sometimes clips the edges of apertures HOT 1
- Fresnel propagation detector and setting pixel pitch HOT 1
- poppy travis builds failing silently HOT 1
- OpticalSystem.input_wavefront default sampling should look to OpticalSystem attributes first
- API inconsistency in specifying shifts between FITS and Analytic optics
- test function `test_fresnel_FITS_Optical_element` misses the point
- Bug in QuadraticPhase? HOT 14
- Implement ThermalBloomingWFE HOT 1
- loading FFTW wisdom from disk is unreliable?
- re-importing modules breaks fresnel propagation HOT 3
- Clone / copy repo to https://github.com/spacetelescope/poppy HOT 6
- Remove all Python 2.x items HOT 2
- Phase and ampliude modulation HOT 2
- Missing dependence on pysynphot HOT 2
- Support for intermediate planes? HOT 1
- poppy.display_profiles() Output Plot Inquiry
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from poppy.