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
76960bcb
Commit
76960bcb
authored
4 years ago
by
Loïc Le Guyader
Browse files
Options
Downloads
Plain Diff
Merge branch 'xas_binning' into 'master'
Xas binning See merge request
!81
parents
8e806941
a6385763
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!81
Xas binning
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
XAS.py
+11
-10
11 additions, 10 deletions
XAS.py
with
11 additions
and
10 deletions
XAS.py
+
11
−
10
View file @
76960bcb
...
@@ -113,12 +113,12 @@ def binning(x, data, func, bins=100, bin_length=None):
...
@@ -113,12 +113,12 @@ def binning(x, data, func, bins=100, bin_length=None):
dummy
=
func
([])
dummy
=
func
([])
res
=
np
.
empty
((
nb_bins
),
dtype
=
dummy
.
dtype
)
res
=
np
.
empty
((
nb_bins
),
dtype
=
dummy
.
dtype
)
for
k
in
range
(
nb_bins
):
for
k
in
range
(
nb_bins
):
res
[
k
]
=
func
(
data
[
bin_idx
==
k
])
res
[
k
]
=
func
(
data
[
k
+
1
==
bin_idx
])
return
bins
,
res
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
'
,
fluorescence
=
False
):
Iooffset
=
0
,
plot
=
False
,
fluorescence
=
False
):
"""
Compute the XAS spectra from a xarray nrun.
"""
Compute the XAS spectra from a xarray nrun.
Inputs:
Inputs:
...
@@ -130,12 +130,12 @@ def xas(nrun, bins=None, Iokey='SCS_SA3', Itkey='MCP3apd', nrjkey='nrj', Iooffse
...
@@ -130,12 +130,12 @@ def xas(nrun, bins=None, Iokey='SCS_SA3', Itkey='MCP3apd', nrjkey='nrj', Iooffse
NRJkey: string for the nrj fields, typically
'
nrj
'
NRJkey: string for the nrj fields, typically
'
nrj
'
Iooffset: offset to apply on Io
Iooffset: offset to apply on Io
plot: boolean, displays a XAS spectrum if True
plot: boolean, displays a XAS spectrum if True
fluorescnce: boolean, if True, absorption is the ratio,
fluoresc
e
nce: boolean, if True, absorption is the ratio,
if False, absorption is negative log
if False, absorption is negative log
Outputs:
Outputs:
a dictionnary containing:
a dictionnary containing:
nrj: the
bins c
en
t
er
nrj: the
mean of photon
ener
gy in each bin
muA: the absorption
muA: the absorption
sigmaA: standard deviation on the absorption
sigmaA: standard deviation on the absorption
sterrA: standard error on the absorption
sterrA: standard error on the absorption
...
@@ -189,12 +189,13 @@ def xas(nrun, bins=None, Iokey='SCS_SA3', Itkey='MCP3apd', nrjkey='nrj', Iooffse
...
@@ -189,12 +189,13 @@ def xas(nrun, bins=None, Iokey='SCS_SA3', Itkey='MCP3apd', nrjkey='nrj', Iooffse
sterrA
=
nosample
[
'
sigmaA
'
]
/
np
.
sqrt
(
nosample
[
'
counts
'
])
sterrA
=
nosample
[
'
sigmaA
'
]
/
np
.
sqrt
(
nosample
[
'
counts
'
])
bins_c
=
0.5
*
(
bins
[
1
:]
+
bins
[:
-
1
])
bins_c
=
0.5
*
(
bins
[
1
:]
+
bins
[:
-
1
])
bin_idx
=
np
.
digitize
(
rundata
[
'
nrj
'
],
bins
)
nrj
=
np
.
array
([
np
.
mean
(
rundata
[
'
nrj
'
][
idx
+
1
==
bin_idx
])
for
idx
in
range
(
len
(
bins
)
-
1
)])
if
plot
:
if
plot
:
f
=
plt
.
figure
(
figsize
=
(
6.5
,
6
))
f
=
plt
.
figure
(
figsize
=
(
6.5
,
6
))
gs
=
gridspec
.
GridSpec
(
2
,
1
,
height_ratios
=
[
4
,
1
])
gs
=
gridspec
.
GridSpec
(
2
,
1
,
height_ratios
=
[
4
,
1
])
ax1
=
plt
.
subplot
(
gs
[
0
])
ax1
=
plt
.
subplot
(
gs
[
0
])
ax1
.
plot
(
bins_c
,
muA
,
color
=
'
C1
'
,
label
=
r
'
$\sigma$
'
)
ax1
.
plot
(
nrj
,
muA
,
color
=
'
C1
'
,
label
=
r
'
$\sigma$
'
)
if
fluorescence
:
if
fluorescence
:
ax1
.
set_ylabel
(
'
XAS (fluorescence)
'
)
ax1
.
set_ylabel
(
'
XAS (fluorescence)
'
)
else
:
else
:
...
@@ -202,7 +203,7 @@ def xas(nrun, bins=None, Iokey='SCS_SA3', Itkey='MCP3apd', nrjkey='nrj', Iooffse
...
@@ -202,7 +203,7 @@ def xas(nrun, bins=None, Iokey='SCS_SA3', Itkey='MCP3apd', nrjkey='nrj', Iooffse
ax1
.
set_xlabel
(
'
Energy (eV)
'
)
ax1
.
set_xlabel
(
'
Energy (eV)
'
)
ax1
.
legend
()
ax1
.
legend
()
ax1_twin
=
ax1
.
twinx
()
ax1_twin
=
ax1
.
twinx
()
ax1_twin
.
bar
(
bins_c
,
nosample
[
'
muIo
'
],
width
=
0.80
*
(
bins_c
[
1
]
-
bins_c
[
0
]),
ax1_twin
.
bar
(
nrj
,
nosample
[
'
muIo
'
],
width
=
0.80
*
(
bins_c
[
1
]
-
bins_c
[
0
]),
color
=
'
C1
'
,
alpha
=
0.2
)
color
=
'
C1
'
,
alpha
=
0.2
)
ax1_twin
.
set_ylabel
(
'
Io
'
)
ax1_twin
.
set_ylabel
(
'
Io
'
)
try
:
try
:
...
@@ -213,13 +214,13 @@ def xas(nrun, bins=None, Iokey='SCS_SA3', Itkey='MCP3apd', nrjkey='nrj', Iooffse
...
@@ -213,13 +214,13 @@ def xas(nrun, bins=None, Iokey='SCS_SA3', Itkey='MCP3apd', nrjkey='nrj', Iooffse
f
.
suptitle
(
nrun
.
attrs
[
'
plot_title
'
])
f
.
suptitle
(
nrun
.
attrs
[
'
plot_title
'
])
ax2
=
plt
.
subplot
(
gs
[
1
])
ax2
=
plt
.
subplot
(
gs
[
1
])
ax2
.
bar
(
bins_c
,
nosample
[
'
counts
'
],
width
=
0.80
*
(
bins_c
[
1
]
-
bins_c
[
0
]),
ax2
.
bar
(
nrj
,
nosample
[
'
counts
'
],
width
=
0.80
*
(
bins_c
[
1
]
-
bins_c
[
0
]),
color
=
'
C0
'
,
alpha
=
0.2
)
color
=
'
C0
'
,
alpha
=
0.2
)
ax2
.
set_xlabel
(
'
Energy (eV)
'
)
ax2
.
set_xlabel
(
'
Energy (eV)
'
)
ax2
.
set_ylabel
(
'
counts
'
)
ax2
.
set_ylabel
(
'
counts
'
)
plt
.
tight_layout
()
plt
.
tight_layout
()
return
{
'
nrj
'
:
bins_c
,
'
muA
'
:
muA
,
'
sterrA
'
:
sterrA
,
'
sigmaA
'
:
nosample
[
'
sigmaA
'
],
return
{
'
nrj
'
:
nrj
,
'
muA
'
:
muA
,
'
sterrA
'
:
sterrA
,
'
sigmaA
'
:
nosample
[
'
sigmaA
'
],
'
muIo
'
:
nosample
[
'
muIo
'
],
'
counts
'
:
nosample
[
'
counts
'
]}
'
muIo
'
:
nosample
[
'
muIo
'
],
'
counts
'
:
nosample
[
'
counts
'
]}
def
xasxmcd
(
dataP
,
dataN
):
def
xasxmcd
(
dataP
,
dataN
):
...
...
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