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
Thomas Kluyver
ToolBox
Commits
bda46e1b
"README.md" did not exist on "a720be575f9f5dd16a79f0b8e00a7b84ed31cf55"
Commit
bda46e1b
authored
5 years ago
by
Loïc Le Guyader
Committed by
Alexander Yaroslavtsev
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Adds absorption calculation from fluorescence
parent
293916da
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
XAS.py
+28
-13
28 additions, 13 deletions
XAS.py
with
28 additions
and
13 deletions
XAS.py
+
28
−
13
View file @
bda46e1b
...
...
@@ -14,11 +14,15 @@ import matplotlib.gridspec as gridspec
import
matplotlib.pyplot
as
plt
import
re
def
absorption
(
T
,
Io
):
"""
Compute the absorption A = -ln(T/Io)
def
absorption
(
T
,
Io
,
fluorescence
=
False
):
"""
Compute the absorption A = -ln(T/Io) (or A = T/Io
for fluorescence)
Inputs:
T: 1-D transmission value array of length N
Io: 1-D Io monitor value array of length N
fluorescence: boolean, if False, compute A as
negative log, if True, compute A as ratio
Output:
a structured array with:
...
...
@@ -61,14 +65,19 @@ def absorption(T, Io):
p
=
np
.
corrcoef
(
T
,
Io
)[
0
,
1
]
muA
=
-
np
.
log
(
muT
/
muIo
)
# from error propagation for correlated data
sigmaA
=
(
np
.
sqrt
((
sigmaT
/
muT
)
**
2
+
(
sigmaIo
/
muIo
)
**
2
-
2
*
p
*
sigmaIo
*
sigmaT
/
(
muIo
*
muT
)))
if
fluorescence
:
muA
=
muT
/
muIo
sigmaA
=
np
.
abs
(
muA
)
*
(
np
.
sqrt
((
sigmaT
/
muT
)
**
2
+
(
sigmaIo
/
muIo
)
**
2
-
2
*
p
*
sigmaIo
*
sigmaT
/
(
muIo
*
muT
)))
else
:
muA
=
-
np
.
log
(
muT
/
muIo
)
# from error propagation for correlated data
sigmaA
=
(
np
.
sqrt
((
sigmaT
/
muT
)
**
2
+
(
sigmaIo
/
muIo
)
**
2
-
2
*
p
*
sigmaIo
*
sigmaT
/
(
muIo
*
muT
)))
# direct calculation
#mask = (Io != 0)
#sigmaA = np.nanstd(-np.log(T[mask]/Io[mask]))
# direct calculation
#mask = (Io != 0)
#sigmaA = np.nanstd(-np.log(T[mask]/Io[mask]))
return
np
.
array
([(
muA
,
sigmaA
,
weights
,
muT
,
sigmaT
,
muIo
,
sigmaIo
,
p
,
counts
)],
dtype
=
fdtype
)
...
...
@@ -108,7 +117,8 @@ def binning(x, data, func, bins=100, bin_length=None):
return
bins
,
res
def
xas
(
nrun
,
bins
=
None
,
Iokey
=
'
SCS_SA3
'
,
Itkey
=
'
MCP3apd
'
,
nrjkey
=
'
nrj
'
,
Iooffset
=
0
,
plot
=
False
):
def
xas
(
nrun
,
bins
=
None
,
Iokey
=
'
SCS_SA3
'
,
Itkey
=
'
MCP3apd
'
,
nrjkey
=
'
nrj
'
,
Iooffset
=
0
,
plot
=
False
,
fluorescence
=
False
):
"""
Compute the XAS spectra from a xarray nrun.
Inputs:
...
...
@@ -120,6 +130,8 @@ def xas(nrun, bins=None, Iokey='SCS_SA3', Itkey='MCP3apd', nrjkey='nrj', Iooffse
NRJkey: string for the nrj fields, typically
'
nrj
'
Iooffset: offset to apply on Io
plot: boolean, displays a XAS spectrum if True
fluorescnce: boolean, if True, absorption is the ratio,
if False, absorption is negative log
Outputs:
a dictionnary containing:
...
...
@@ -157,9 +169,9 @@ def xas(nrun, bins=None, Iokey='SCS_SA3', Itkey='MCP3apd', nrjkey='nrj', Iooffse
if
len
(
data
)
==
0
:
return
absorption
([],
[])
return
absorption
([],
[]
,
fluorescence
)
else
:
return
absorption
(
It_sign
*
data
[
'
It
'
],
Io_sign
*
data
[
'
Io
'
])
return
absorption
(
It_sign
*
data
[
'
It
'
],
Io_sign
*
data
[
'
Io
'
]
,
fluorescence
)
if
bins
is
None
:
num_bins
=
80
...
...
@@ -183,7 +195,10 @@ def xas(nrun, bins=None, Iokey='SCS_SA3', Itkey='MCP3apd', nrjkey='nrj', Iooffse
gs
=
gridspec
.
GridSpec
(
2
,
1
,
height_ratios
=
[
4
,
1
])
ax1
=
plt
.
subplot
(
gs
[
0
])
ax1
.
plot
(
bins_c
,
muA
,
color
=
'
C1
'
,
label
=
r
'
$\sigma$
'
)
ax1
.
set_ylabel
(
'
XAS
'
)
if
fluorescence
:
ax1
.
set_ylabel
(
'
XAS (fluorescence)
'
)
else
:
ax1
.
set_ylabel
(
'
XAS (-log)
'
)
ax1
.
set_xlabel
(
'
Energy (eV)
'
)
ax1
.
legend
()
ax1_twin
=
ax1
.
twinx
()
...
...
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