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
62e98945
Commit
62e98945
authored
4 years ago
by
Loïc Le Guyader
Browse files
Options
Downloads
Plain Diff
Merge branch 'xas_error' into 'master'
XAS standard deviation See merge request
!80
parents
1e1aec1d
3e51828a
No related branches found
No related tags found
1 merge request
!80
XAS standard deviation
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
XAS.py
+20
-17
20 additions, 17 deletions
XAS.py
with
20 additions
and
17 deletions
XAS.py
+
20
−
17
View file @
62e98945
...
@@ -47,7 +47,6 @@ def absorption(T, Io, fluorescence=False):
...
@@ -47,7 +47,6 @@ def absorption(T, Io, fluorescence=False):
good
=
np
.
logical_and
(
np
.
isfinite
(
T
),
np
.
isfinite
(
Io
))
good
=
np
.
logical_and
(
np
.
isfinite
(
T
),
np
.
isfinite
(
Io
))
T
=
T
[
good
]
T
=
T
[
good
]
Io
=
Io
[
good
]
Io
=
Io
[
good
]
# return type of the structured array
# return type of the structured array
fdtype
=
[(
'
muA
'
,
'
f8
'
),
(
'
sigmaA
'
,
'
f8
'
),
(
'
weights
'
,
'
f8
'
),
fdtype
=
[(
'
muA
'
,
'
f8
'
),
(
'
sigmaA
'
,
'
f8
'
),
(
'
weights
'
,
'
f8
'
),
(
'
muT
'
,
'
f8
'
),
(
'
sigmaT
'
,
'
f8
'
),
(
'
muIo
'
,
'
f8
'
),
(
'
sigmaIo
'
,
'
f8
'
),
(
'
muT
'
,
'
f8
'
),
(
'
sigmaT
'
,
'
f8
'
),
(
'
muIo
'
,
'
f8
'
),
(
'
sigmaIo
'
,
'
f8
'
),
...
@@ -64,21 +63,26 @@ def absorption(T, Io, fluorescence=False):
...
@@ -64,21 +63,26 @@ def absorption(T, Io, fluorescence=False):
weights
=
np
.
sum
(
Io
)
weights
=
np
.
sum
(
Io
)
p
=
np
.
corrcoef
(
T
,
Io
)[
0
,
1
]
p
=
np
.
corrcoef
(
T
,
Io
)[
0
,
1
]
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
# weighted average of T/Io with Io as weights
#mask = (Io != 0)
muA
=
muT
/
muIo
#sigmaA = np.nanstd(-np.log(T[mask]/Io[mask]))
#Derivation of standard deviation
#1. using biased weighted sample variance:
#sigmaA = np.sqrt(np.average((T/Io - muA)**2, weights=Io))
#2. using unbiased weighted sample variance (reliablility weights):
V2
=
np
.
sum
(
Io
**
2
)
sigmaA
=
np
.
sqrt
(
np
.
sum
(
Io
*
(
T
/
Io
-
muA
)
**
2
)
/
(
weights
-
V2
/
weights
))
#3. using error propagation for correlated data:
#sigmaA = np.abs(muA)*(np.sqrt((sigmaT/muT)**2 +
# (sigmaIo/muIo)**2 - 2*p*sigmaIo*sigmaT/(muIo*muT)))
if
not
fluorescence
:
sigmaA
=
sigmaA
/
np
.
abs
(
muA
)
muA
=
-
np
.
log
(
muA
)
return
np
.
array
([(
muA
,
sigmaA
,
weights
,
muT
,
sigmaT
,
muIo
,
sigmaIo
,
return
np
.
array
([(
muA
,
sigmaA
,
weights
,
muT
,
sigmaT
,
muIo
,
sigmaIo
,
p
,
counts
)],
dtype
=
fdtype
)
p
,
counts
)],
dtype
=
fdtype
)
...
@@ -97,7 +101,6 @@ def binning(x, data, func, bins=100, bin_length=None):
...
@@ -97,7 +101,6 @@ def binning(x, data, func, bins=100, bin_length=None):
bins: the bins edges
bins: the bins edges
res: a structured array of binned data
res: a structured array of binned data
"""
"""
if
bin_length
is
not
None
:
if
bin_length
is
not
None
:
bin_start
=
np
.
amin
(
x
)
bin_start
=
np
.
amin
(
x
)
bin_end
=
np
.
amax
(
x
)
bin_end
=
np
.
amax
(
x
)
...
@@ -108,7 +111,7 @@ def binning(x, data, func, bins=100, bin_length=None):
...
@@ -108,7 +111,7 @@ def binning(x, data, func, bins=100, bin_length=None):
bins
=
np
.
linspace
(
bin_start
,
bin_end
,
bins
)
bins
=
np
.
linspace
(
bin_start
,
bin_end
,
bins
)
bin_centers
=
(
bins
[
1
:]
+
bins
[:
-
1
])
/
2
bin_centers
=
(
bins
[
1
:]
+
bins
[:
-
1
])
/
2
nb_bins
=
len
(
bin_centers
)
nb_bins
=
len
(
bin_centers
)
bin_idx
=
np
.
digitize
(
x
,
bins
)
bin_idx
=
np
.
digitize
(
x
,
bins
)
dummy
=
func
([])
dummy
=
func
([])
res
=
np
.
empty
((
nb_bins
),
dtype
=
dummy
.
dtype
)
res
=
np
.
empty
((
nb_bins
),
dtype
=
dummy
.
dtype
)
...
@@ -187,7 +190,7 @@ def xas(nrun, bins=None, Iokey='SCS_SA3', Itkey='MCP3apd', nrjkey='nrj',
...
@@ -187,7 +190,7 @@ def xas(nrun, bins=None, Iokey='SCS_SA3', Itkey='MCP3apd', nrjkey='nrj',
dummy
,
nosample
=
binning
(
rundata
[
'
nrj
'
],
rundata
,
whichIo
,
bins
)
dummy
,
nosample
=
binning
(
rundata
[
'
nrj
'
],
rundata
,
whichIo
,
bins
)
muA
=
nosample
[
'
muA
'
]
muA
=
nosample
[
'
muA
'
]
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
)
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
)])
nrj
=
np
.
array
([
np
.
mean
(
rundata
[
'
nrj
'
][
idx
+
1
==
bin_idx
])
for
idx
in
range
(
len
(
bins
)
-
1
)])
...
...
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