Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
ToolBox
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
SCS
ToolBox
Commits
e3189cfa
Commit
e3189cfa
authored
3 years ago
by
Cammille Carinan
Browse files
Options
Downloads
Patches
Plain Diff
Add docstrings
parent
42b9876c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/toolbox_scs/base/knife_edge.py
+64
-1
64 additions, 1 deletion
src/toolbox_scs/base/knife_edge.py
with
64 additions
and
1 deletion
src/toolbox_scs/base/knife_edge.py
+
64
−
1
View file @
e3189cfa
...
...
@@ -4,6 +4,34 @@ from scipy.optimize import curve_fit
def
knife_edge
(
positions
,
intensities
,
axisRange
=
None
,
p0
=
None
):
"""
The base implementation of the knife-edge scan analysis.
Calculates the beam radius at 1/e^2 from a knife-edge scan by
fitting with erfc function: f(a,b,u) = a*erfc(u) + b or
where u = sqrt(2)*(x-x0)/w0 with w0 the beam radius at 1/e^2
and x0 the beam center.
Parameters
----------
positions : np.ndarray
Motor position values, typically 1D
intensities : np.ndarray
Intensity values, could be either 1D or 2D, with the number or rows
equivalent with the position size
axisRange : sequence of two floats or None
Edges of the scanning axis between which to apply the fit.
p0 : list of floats, numpy 1D array
Initial parameters used for the fit: x0, w0, a, b. If None, a beam
radius of 100 um is assumed.
Returns
-------
width : float
The beam radius at 1/e^2
std : float
The standard deviation of the width
"""
popt
,
pcov
=
knife_edge_base
(
positions
,
intensities
,
axisRange
=
axisRange
,
p0
=
p0
)
width
,
std
=
0
,
0
...
...
@@ -14,7 +42,32 @@ def knife_edge(positions, intensities, axisRange=None, p0=None):
def
knife_edge_base
(
positions
,
intensities
,
axisRange
=
None
,
p0
=
None
):
"""
The base implementation of the knife-edge scan analysis.
Calculates the beam radius at 1/e^2 from a knife-edge scan by
fitting with erfc function: f(a,b,u) = a*erfc(u) + b or
where u = sqrt(2)*(x-x0)/w0 with w0 the beam radius at 1/e^2
and x0 the beam center.
Parameters
----------
positions : np.ndarray
Motor position values, typically 1D
intensities : np.ndarray
Intensity values, could be either 1D or 2D, with the number or rows
equivalent with the position size
axisRange : sequence of two floats or None
Edges of the scanning axis between which to apply the fit.
p0 : list of floats, numpy 1D array
Initial parameters used for the fit: x0, w0, a, b. If None, a beam
radius of 100 um is assumed.
Returns
-------
popt : sequence of floats or None
The parameters of the resulting fit.
pcov : sequence of floats
The covariance matrix of the resulting fit.
"""
# Prepare arrays
positions
,
intensities
=
prepare_arrays
(
positions
,
intensities
,
...
...
@@ -44,6 +97,14 @@ def function_fit(func, x, y, **kwargs):
def
prepare_arrays
(
arrX
:
np
.
ndarray
,
arrY
:
np
.
ndarray
,
xRange
=
None
,
yRange
=
None
):
"""
Preprocessing of the input x and y arrays.
This involves the following steps.
1. Converting the arrays to 1D of the same size
2. Select the ranges from the input x- and y-ranges
3. Retrieve finite values.
"""
# Convert both arrays to 1D of the same size
assert
arrX
.
shape
[
0
]
==
arrY
.
shape
[
0
]
arrX
=
arrX
.
flatten
()
...
...
@@ -72,6 +133,8 @@ def prepare_arrays(arrX: np.ndarray, arrY: np.ndarray,
def
range_mask
(
array
,
minimum
=
None
,
maximum
=
None
):
"""
Retrieve the resulting array from the given minimum and maximum
"""
default
=
np
.
ones
(
array
.
shape
,
dtype
=
np
.
bool
)
min_slice
,
max_slice
=
default
,
default
if
minimum
is
not
None
:
...
...
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