Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
famewoks
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
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
F-CRG
FAMEs
famewoks
Commits
58362d46
Commit
58362d46
authored
4 months ago
by
Mauro Rovezzi
Browse files
Options
Downloads
Patches
Plain Diff
wip: safe pre_edge
parent
db20acaa
No related branches found
No related tags found
2 merge requests
!4
Minor updates and bug fixes
,
!3
Fix10 rebin second dataset
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
notebooks/devel_sandbox.ipynb
+22
-2
22 additions, 2 deletions
notebooks/devel_sandbox.ipynb
src/famewoks/bliss2larch.py
+25
-0
25 additions, 0 deletions
src/famewoks/bliss2larch.py
with
47 additions
and
2 deletions
notebooks/devel_sandbox.ipynb
+
22
−
2
View file @
58362d46
...
...
@@ -57,7 +57,7 @@
"# \"INFO\" -> useful messages\n",
"# \"WARNING\" -> warnings only\n",
"# \"ERROR\" -> only errors\n",
"_logger.setLevel(\"
INFO
\")\n",
"_logger.setLevel(\"
DEBUG
\")\n",
"\n",
"# show workflow version (and famewoks branch information)\n",
"branch = os.popen(\"cd ~/devel/famewoks; git branch --show-current\").read()[:-1]\n",
...
...
@@ -153,11 +153,31 @@
" ynorm=\"area\",\n",
" show_slide=True,\n",
" show_i0=False,\n",
" show_deriv=False,\n",
" show_e0=True,\n",
" show_merge=
\"rebin\"
,\n",
" show_merge=
True
,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig.add_vline(x=dataset.fluo.e0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from famewoks.bliss2larch import safe_pre_edge\n",
"sg = safe_pre_edge(session, group=dataset.fluo)"
]
},
{
"cell_type": "code",
"execution_count": null,
...
...
%% Cell type:markdown id: tags:
# Development sandbox notebook
This notebook is for development and testing of new features and bug fixes only.
%% Cell type:code id: tags:
```
python
%
load_ext
autoreload
%
autoreload
2
# Uncomment the following two lines if the plots do not show in the notebook
# import plotly.io as pio
# pio.renderers.default = "iframe"
import
os
from
dataclasses
import
asdict
from
IPython.display
import
display
from
famewoks
import
__version__
as
wkflver
from
famewoks.datamodel
import
(
ExpSession
,
ExpCounters
,
CNTS_FLUO_XMAP
,
CNTS_FLUO
,
CNTS_CAS
,
)
from
famewoks.tests.datainfos
import
DATAINFOS
,
get_exp_session
from
famewoks.plots
import
plot_data
,
plot_eshift
from
famewoks.bliss2larch
import
(
search_samples
,
show_samples_info
,
search_datasets
,
load_data
,
get_scans
,
get_group
,
set_enealign
,
apply_eshift
,
set_bad_fluo_channels
,
set_bad_scans
,
set_bad_samples
,
merge_data
,
save_data
,
)
from
famewoks.bliss2larch
import
_logger
# adjust the logger level:
# "DEBUG" -> show all messages
# "INFO" -> useful messages
# "WARNING" -> warnings only
# "ERROR" -> only errors
_logger
.
setLevel
(
"
INFO
"
)
_logger
.
setLevel
(
"
DEBUG
"
)
# show workflow version (and famewoks branch information)
branch
=
os
.
popen
(
"
cd ~/devel/famewoks; git branch --show-current
"
).
read
()[:
-
1
]
_logger
.
info
(
f
"
--> Using famewoks version:
{
wkflver
}
(branch:
{
branch
}
)
"
)
# define the counters names or use those already defined for BM16: CNTS_FLUO_XMAP, CNTS_FLUO, CNTS_CAS
CNTS_CAS_XPAD
=
ExpCounters
(
ene
=
"
energy_enc
"
,
ix
=
[
"
p201_1_bkg_sub
"
,
"
p201_3_bkg_sub
"
,
"
p201_5_bkg_sub
"
],
#: I0, I1, I2
fluo_roi
=
[
"
xpad_roi1
"
],
# all detector names for ROI1
fluo_corr
=
[
"
xpad_roi1
"
],
# all detector names (DT corrected)
fluo_time
=
[
"
sec
"
],
# elapsed time, which is different for the spikes
time
=
"
sec
"
,
# "musst_timer"
)
# define the experimental session metadata manually
session
=
ExpSession
(
flag
=
1
,
datadir
=
"
/data/visitor/a161838/bm16/20241113
"
,
proposal
=
"
a161838
"
,
session
=
"
20241113
"
,
proposer
=
"
Quantin
"
,
lc
=
"
AA, IK
"
,
elem
=
"
V
"
,
edge
=
"
K
"
,
comment
=
""
,
counters
=
CNTS_CAS
,
# *NOTE* give here the correct counters names!
samples
=
[],
bad_samples
=
[],
bad_fluo_channels
=
None
,
enealign
=
None
,
)
# (testing) otherwise it is possible to get the session from a collection of previous experiments
# session = get_exp_session(DATAINFOS, proposer="Isaure",session="20241003")
# session = get_exp_session(DATAINFOS, proposer="Rimondi",session="20241001")
# session = get_exp_session(DATAINFOS, proposer="Biswas",session="20240924")
# session = get_exp_session(DATAINFOS, proposer="Sanchez",session="20240716")
# session = get_exp_session(DATAINFOS, proposer="Stellato",session="20240625")
# session = get_exp_session(DATAINFOS, proposer="Bertrand",session="20240910")
# display the session metadata
#display(asdict(session))
```
%% Cell type:code id: tags:
```
python
samples
=
search_samples
(
session
,
ignore_names
=
[
"
rack
"
,
"
mount
"
,
"
align
"
,
"
bl_
"
,
"
sample
"
])
```
%% Cell type:code id: tags:
```
python
sel_sample
=
10
datasets
=
search_datasets
(
session
,
sample
=
sel_sample
)
```
%% Cell type:code id: tags:
```
python
sel_dataset
=
0
dataset
=
datasets
[
sel_dataset
]
load_data
(
session
,
dataset
,
use_fluo_corr
=
False
,
iskip
=
1
,
#: ignore the first point
istrip
=
1
,
#: ignore the last point
calc_eshift
=
True
,
merge
=
True
,
skip_scans
=
[],
)
```
%% Cell type:code id: tags:
```
python
fig
=
plot_data
(
dataset
,
data
=
"
fluo
"
,
ynorm
=
"
area
"
,
show_slide
=
True
,
show_i0
=
False
,
show_deriv
=
False
,
show_e0
=
True
,
show_merge
=
"
rebin
"
,
show_merge
=
True
,
)
```
%% Cell type:code id: tags:
```
python
fig
.
add_vline
(
x
=
dataset
.
fluo
.
e0
)
```
%% Cell type:code id: tags:
```
python
from
famewoks.bliss2larch
import
safe_pre_edge
sg
=
safe_pre_edge
(
session
,
group
=
dataset
.
fluo
)
```
%% Cell type:code id: tags:
```
python
```
...
...
This diff is collapsed.
Click to expand it.
src/famewoks/bliss2larch.py
+
25
−
0
View file @
58362d46
...
...
@@ -32,6 +32,8 @@ from larch.io import AthenaProject
from
larch.xafs
import
pre_edge
from
larch.xafs.rebin_xafs
import
rebin_xafs
from
xraydb
import
xray_edge
# from larch.xafs.pre_edge import energy_align
from
famewoks.energy
import
energy_align
...
...
@@ -45,6 +47,29 @@ _logger.setLevel("INFO") # adjust logger level .DEBUG, .INFO, .WARNING, .ERROR
_logger
.
debug
(
f
"
DataSourceSpecH5 version:
{
ds_version
}
"
)
_logger
.
debug
(
f
"
workflow version:
{
wkfl_version
}
"
)
def
safe_pre_edge
(
session
:
ExpSession
,
group
:
Group
,
verbose
:
bool
=
True
)
->
Group
:
"""
Apply `pre_edge` to a group, safely catching errors and checking for correct E0
"""
infolab
=
group
.
filename
glabel
=
group
.
label
if
not
None
else
""
try
:
e0ref
=
xray_edge
(
session
.
elem
,
session
.
edge
).
energy
_logger
.
debug
(
f
"
{
infolab
}
_
{
glabel
}
-> safe_pre_ede() -> E0 for
{
session
.
elem
}
{
session
.
edge
}
edge:
{
e0ref
:
.
2
f
}
eV
"
)
except
Exception
as
err
:
_logger
.
error
(
f
"
{
infolab
}
_
{
glabel
}
-> cannot get edge energy from session -> check element and edge
"
)
_logger
.
debug
(
f
"
ERR--->
{
err
}
"
)
e0ref
=
0
try
:
pre_edge
(
group
)
except
Exception
as
err
:
_logger
.
warning
(
f
"
{
infolab
}
_
{
glabel
}
-> `pre_edge()` failed
"
)
_logger
.
debug
(
f
"
ERR--->
{
err
}
"
)
e0thr
=
e0ref
*
0.01
if
abs
(
group
.
e0
-
e0ref
)
>
e0thr
:
_logger
.
debug
(
f
"
{
infolab
}
_
{
glabel
}
-> found E0 is out of 1% threshold from theory (
{
e0ref
:
.
2
f
}
eV) -> forced from
{
group
.
e0
:
.
2
f
}
to
{
e0ref
:
.
2
f
}
eV
"
)
group
.
e0
=
e0ref
return
group
def
search_samples
(
session
:
ExpSession
,
...
...
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