Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pykat
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sean Leavey
pykat
Commits
91678a90
Commit
91678a90
authored
9 years ago
by
Daniel Brown
Browse files
Options
Downloads
Patches
Plain Diff
adding Paul's fitting function
parent
e43923a0
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
pykat/optics/gaussian_beams.py
+52
-0
52 additions, 0 deletions
pykat/optics/gaussian_beams.py
with
52 additions
and
0 deletions
pykat/optics/gaussian_beams.py
+
52
−
0
View file @
91678a90
...
...
@@ -7,6 +7,58 @@ 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
):
"""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment