mask_from_array for scalar_masks_XY

Issue #298 resolved
Jonas Herbst created an issue

Hello,

I have a 2 dim. array which contains pixelated phase data. I would like to create a mask for it, so I defined a function “mask_from_array” inside scalar_masks_XY.py.

def mask_from_array(self,
index,
a1,
a2,
radius,
mask = True,
x0=0, y0=0):
if isinstance(radius, (float, int, complex)):
radius = (radius, radius)
k = 2 * pi / self.wavelength

    if mask is True:
        amplitude = Scalar_mask_XY(self.x, self.y, self.wavelength)
        #amplitude.slit(x0, radius)
        t = amplitude.u
    else:
        t = np.ones_like(self.x)

    F1 = a1
    F2 = a2

    self.u = t * np.exp(1.j * k * (index - 1) * (F2 - F1))

However, I am not sure how to define it in such a way that it works.

My array has a shape of (4002,4002). It is basically a Fresnel diffractive lens. But in order to simulate manufacturing tolerances I have to simulate it as 2d array.

Could you please help me with defining the function?

I think also it would be a nice addition to your package.

Best regards,

Jonas

Comments (3)

  1. LUIS MIGUEL SANCHEZ BREA repo owner

    Dear Jonas Herbst.

    Thank you very much for you commentary.

    Let us consider that you have a lens, defined by a 2D array.

    from diffractio import degrees, mm, plt, sp, um, np
    from diffractio.scalar_masks_XY import Scalar_mask_XY
    x = np.linspace(-2 * mm, 2 * mm, 4002)
    y = np.linspace(-2 * mm, 2 * mm, 4002)
    
    wavelength = 0.6328*umç
    t=Scalar_mask_XY(x,y,wavelength)
    t.lens(r0=(0,0), focal=500*mm)
    t.pupil()
    t.draw('phase')
    
    mask = t.u
    del t
    

    Then, to load the mask in Scalar_mask_XY, you just need to define the x,y arrays:

    x = np.linspace(-2 * mm, 2 * mm, 4002)
    y = np.linspace(-2 * mm, 2 * mm, 4002)
    
    wavelength = 0.6328*um
    

    and then, load the mask, in the .u parameter.

    t2 = Scalar_mask_XY(x, y, wavelength)
    t2.u = mask
    

    Consider that the matrices size and x,y arrays should be the same.

    Perhaps I have not understood properly. If not, please contact me again.

    regards

    Luis Miguel

  2. Jonas Herbst reporter

    <!doctype html> <html> <head> <meta name="viewport" content="width=device-width"> <meta http-equiv="Content-Type" content="text/vnd.ui.insecure+html;charset=utf-8"> </head>

  3. Log in to comment