-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdetilt-DonIDL.py
More file actions
38 lines (32 loc) · 1.12 KB
/
detilt-DonIDL.py
File metadata and controls
38 lines (32 loc) · 1.12 KB
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
import numpy as np
def detilt(phase, aperture=np.zeros(1)):
"""
; detilt - remove tilt over an aperture
;
; USAGE:
; phdt = detilt(ph,ap)
;
; INPUTS:
; ph - phase - 2D numpy array
; ap - aperture - optional 2D numpy array
;
; OUTPUTS:
; phdt - phase with tilt removed
; tx, ty - (optional) tip and tilt coefficients (units: phase/pixel)
;
"""
n = np.float(phase.shape[0]) # number of rows
m = np.float(phase.shape[1]) # number of columns
if len(aperture) == 1:
aperture = np.ones(phase.shape)
# x = ((findgen(n) # (fltarr(m)+1)) - n/2) in IDL,
# where n = n_columns and m = n_rows
x = np.multiply.outer(np.arange(m),np.ones(n)).T - np.int(m)/2
x = x - np.sum(x*aperture)/aperture.sum()
# y = (((fltarr(n)+1) # findgen(m)) - m/2)
y = np.multiply.outer(np.ones(m),np.arange(n)).T - np.int(n)/2
y = y - np.sum(y*aperture)/aperture.sum()
tx = np.sum(phase*x*aperture)/np.sum(x*x*aperture)
ty = np.sum(phase*y*aperture)/np.sum(y*y*aperture)
phdt = (phase - tx*x - ty*y)
return phdt