Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
finesse
pykat
Commits
2f242555
Commit
2f242555
authored
May 11, 2016
by
Andreas Freise
Browse files
removing not-needed function from gaussian beam, chaning HG beam plot to not use pylab
parent
d4bfa426
Pipeline
#1107
failed with stage
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
pykat/optics/gaussian_beams.py
View file @
2f242555
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
from
__future__
import
unicode_literals
import
pykat.exceptions
as
pkex
import
numpy
as
np
import
math
...
...
@@ -7,59 +12,6 @@ import cmath
from
scipy.special
import
hermite
from
pykat.SIfloat
import
SIfloat
def
fit_beam_size
(
z_data
,
w_data
,
w0guess
,
z0guess
,
lam
=
1064e-9
,
show_plot
=
True
,
plotpts
=
100
,
title
=
'Beam scan fit'
,
w2zero
=
True
,
filename
=
None
):
"""
Function to fit a beam size (w0 and z) to a 2D intensity array. Plotting can
be switched on or off.
Returns best fit of (w0, z)
Contributed by Paul Fulda on 15/01/16
"""
import
scipy.optimize
def
zw0z02w
(
z
,
w0
,
z0
,
lam
):
z_R
=
pl
.
pi
*
w0
**
2
/
lam
w
=
w0
*
pl
.
sqrt
(
1
+
((
z
-
z0
)
/
z_R
)
**
2
)
return
w
popt
,
pcov
=
scipy
.
optimize
.
curve_fit
(
lambda
z_data
,
w0
,
z0
:
zw0z02w
(
z_data
,
w0
,
z0
,
lam
),
z_data
,
w_data
,
p0
=
[
w0guess
,
z0guess
])
w0out
=
popt
[
0
]
z0out
=
popt
[
1
]
z_fit
=
pl
.
linspace
(
min
(
z_data
),
max
(
z_data
),
plotpts
)
w_fit
=
zw0z02w
(
z_fit
,
w0out
,
z0out
,
lam
)
if
show_plot
or
filename
is
not
None
:
import
pylab
as
pl
um
=
1e6
pl
.
figure
()
pl
.
plot
(
z_data
,
w_data
*
um
,
'bo'
,
label
=
'Data'
)
pl
.
plot
(
z_fit
,
w_fit
*
um
,
'b'
,
label
=
'Fit'
)
pl
.
tight_layout
pl
.
grid
()
pl
.
xlabel
(
'Position [m]'
)
pl
.
ylabel
(
'Beam size [$\mu$m]'
)
pl
.
xlim
((
min
(
z_data
),
max
(
z_data
)))
if
w2zero
:
pl
.
ylim
((
0
,
max
(
w_data
)
*
um
))
pl
.
legend
(
loc
=
0
)
pl
.
title
(
title
)
if
filename
is
not
None
:
pl
.
savefig
(
filename
)
return
w0out
,
z0out
class
gauss_param
(
object
):
"""
Use beam_param instead, will be the future name of this object.
...
...
@@ -316,9 +268,15 @@ class gauss_param(object):
class
beam_param
(
gauss_param
):
pass
# Should be renamed to HG_mode?
class
HG_beam
(
object
):
""" Hermite-Gauss beam profile. Example usage:
import pykat.optics.gaussian_beams as gb
qx=gb.beam_param(w0=1e-3,z=0)
beam=gb.HG_beam(qx,n=2,m=0)
beam.plot()
"""
def
__init__
(
self
,
qx
,
qy
=
None
,
n
=
0
,
m
=
0
):
self
.
_qx
=
copy
.
deepcopy
(
qx
)
self
.
_2pi_qrt
=
math
.
pow
(
2.0
/
math
.
pi
,
0.25
)
...
...
@@ -427,7 +385,9 @@ class HG_beam(object):
return
np
.
outer
(
_un
,
_um
)
def
plot
(
self
,
ndx
=
100
,
ndy
=
100
,
xscale
=
4
,
yscale
=
4
):
import
pylab
""" Make a simple plot the HG_beam """
import
pykat.plotting
import
matplotlib.pyplot
as
plt
xrange
=
xscale
*
np
.
linspace
(
-
self
.
_qx
.
w
,
self
.
_qx
.
w
,
ndx
)
yrange
=
yscale
*
np
.
linspace
(
-
self
.
_qy
.
w
,
self
.
_qy
.
w
,
ndy
)
...
...
@@ -437,11 +397,11 @@ class HG_beam(object):
data
=
self
.
Unm
(
xrange
,
yrange
)
fig
=
py
lab
.
figure
()
axes
=
p
ylab
.
imshow
(
np
.
abs
(
data
),
aspect
=
dx
/
dy
,
extent
=
[
min
(
xrange
),
max
(
xrange
),
min
(
yrange
),
max
(
yrange
)])
p
ylab
.
xlabel
(
'x [m]'
)
p
ylab
.
ylabel
(
'y [m]'
)
fig
=
py
kat
.
plotting
.
figure
()
axes
=
p
lt
.
imshow
(
np
.
abs
(
data
.
T
),
aspect
=
dx
/
dy
,
extent
=
[
min
(
xrange
),
max
(
xrange
),
min
(
yrange
),
max
(
yrange
)])
p
lt
.
xlabel
(
'x [m]'
)
p
lt
.
ylabel
(
'y [m]'
)
cbar
=
fig
.
colorbar
(
axes
)
p
ylab
.
show
()
p
lt
.
show
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment