Code Monkey home page Code Monkey logo

Comments (3)

mb2448 avatar mb2448 commented on June 24, 2024

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.

mperrin avatar mperrin commented on June 24, 2024

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.

mb2448 avatar mb2448 commented on June 24, 2024

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)

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.