-
Notifications
You must be signed in to change notification settings - Fork 1
/
doe_add.py
42 lines (41 loc) · 1.11 KB
/
doe_add.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#Written by Nikitas Kanellakopoulos, 11/11/2014
#doe_add2.py
#Purpose: Combine two phase gratings into one.
import numpy as np
import scipy as sp
import random
def construct(phi1, phi2, nomod = 0, amp1 =[], amp2=[], eta = 0, ampout= 0): #does ampout need to be there?
if len(amp1) > 0 or len(amp2) > 0:
tempshape = phi1.shape
w = tempshape[1]
h = tempshape[0]
if len(amp1) == 0:
temp1 = np.ones(w)
temp2 = np.ones(h)
for r in temp2:
amp1 += [temp1]
if len(amp2) == 0:
temp1 = np.ones(w)
temp2 = np.ones(h)
for r in temp2:
amp2 += [temp1]
psi1 = amp1 * np.exp(1j*phi1)
psi2 = amp2 * np.exp(1j*phi2)
psi = psi1 * psi2
psi = np.array(psi)
apsi = abs(psi)
psi = psi/(np.amax(abs(psi)))
phi = np.arctan2(sp.real(psi),sp.imag(psi))
phi -= np.amin(phi)
phi = phi % (2.*np.pi)
eta = 2*np.median(abs(psi))
randarray = np.array([[random.random() for i in range(w)] for j in range(h)])
shape = (abs(psi) >= (eta*randarray))
index = np.where(shape == False)
phi[index] = 0
ampout = abs(psi)
else:
phi = phi1 + phi2
phi = phi - np.amin(phi)
phi = phi % (2.*np.pi)
return phi