-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgauss_beam.py
More file actions
43 lines (32 loc) · 788 Bytes
/
gauss_beam.py
File metadata and controls
43 lines (32 loc) · 788 Bytes
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
43
import numpy as np
def gauss_beam(sigma, ny, nx, FWHM=False):
'''
Return a Gaussian beam at the center of an image
Parameters
----------
sigma: float
Standard deviation (sigma) of the Gaussian function
nx, ny: integers
Size of the output image
FWHM: bool
If True, the sigma parameter becomes the Full Width Half Max
Return
----------
Gaussian beam at the center of the image
'''
X=np.arange(nx)
Y=np.arange(ny)
ymap,xmap=np.meshgrid(X,Y)
if (nx % 2) == 0:
xmap = xmap - (nx)/2.
else:
xmap = xmap - (nx-1.)/2.
if (ny % 2) == 0:
ymap = ymap - (ny)/2.
else:
ymap = ymap - (ny-1.)/2.
map = np.sqrt(xmap**2.+ymap**2.)
if FWHM == True:
sigma = sigma / (2.*np.sqrt(2.*np.log(2.)))
gauss = np.exp(-0.5*(map)**2./sigma**2.)
return gauss