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
dc01485b
Commit
dc01485b
authored
4 months ago
by
Laurent Mercadier
Browse files
Options
Downloads
Patches
Plain Diff
Improve extract_GH2()
parent
974a9dba
No related branches found
No related tags found
1 merge request
!310
Gh2 mnemonics and pulse alignment
Pipeline
#156738
passed
4 months ago
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/toolbox_scs/detectors/gotthard2.py
+25
-12
25 additions, 12 deletions
src/toolbox_scs/detectors/gotthard2.py
with
25 additions
and
12 deletions
src/toolbox_scs/detectors/gotthard2.py
+
25
−
12
View file @
dc01485b
...
...
@@ -15,9 +15,13 @@ __all__ = [
log
=
logging
.
getLogger
(
__name__
)
def
extract_GH2
(
ds
,
run
,
firstFrame
=
0
,
bunchPattern
=
'
scs_ppl
'
):
def
extract_GH2
(
ds
,
run
,
firstFrame
=
0
,
bunchPattern
=
'
scs_ppl
'
,
gh2_dim
=
'
gh2_pId
'
):
'''
Extract the frames of the Gotthard-II that have been exposed to light.
Select and align the frames of the Gotthard-II that have been exposed
to light.
Parameters
------
ds: xarray.Dataset
...
...
@@ -30,33 +34,42 @@ def extract_GH2(ds, run, firstFrame=0, bunchPattern='scs_ppl'):
the bunch pattern used to align data. For
'
scs_ppl
'
, the gh2_pId
dimension in renamed
'
ol_pId
'
, and for
'
sase3
'
gh2_pId is renamed
'
sa3_pId
'
.
gh2_dim: str
The name of the dimension that corresponds to the Gotthard-II frames.
Returns
-------
nds: xarray Dataset
The aligned and reduced dataset with only-data-containing GH2 variables.
The aligned and reduced dataset with only-data-containing GH2
variables.
'''
if
gh2_dim
not
in
ds
.
dims
:
log
.
warning
(
f
'
gh2_dim
"
{
gh2_dim
}
"
not in dataset. Skipping.
'
)
return
ds
if
bunchPattern
==
'
scs_ppl
'
:
pattern
=
OpticalLaserPulses
(
run
)
dim
=
'
ol_pId
'
dim
=
'
ol_pId
'
else
:
pattern
=
XrayPulses
(
run
)
dim
=
'
sa3_pId
'
dim
=
'
sa3_pId
'
others
=
[
var
for
var
in
ds
if
dim
in
ds
[
var
].
coords
]
nds
=
ds
.
drop_dims
(
dim
)
if
pattern
.
is_constant_pattern
():
pulse_ids
=
pattern
.
peek_pulse_ids
(
labelled
=
False
)
nds
=
ds
.
isel
(
gh2_
pId
=
pulse_ids
+
firstFrame
)
nds
=
nds
.
assign_coords
(
gh2_
pId
=
pulse_ids
)
nds
=
nds
.
rename
(
gh2_
pId
=
dim
)
nds
=
n
ds
.
isel
(
{
gh2_
dim
:
pulse_ids
+
firstFrame
}
)
nds
=
nds
.
assign_coords
(
{
gh2_
dim
:
pulse_ids
}
)
nds
=
nds
.
rename
(
{
gh2_
dim
:
dim
}
)
else
:
log
.
warning
(
'
The number of pulses has changed during the run.
'
)
pulse_ids
=
np
.
unique
(
pattern
.
pulse_ids
(
labelled
=
False
,
copy
=
False
))
nds
=
ds
.
isel
(
gh2_
pId
=
pulse_ids
+
firstFrame
)
nds
=
nds
.
assign_coords
(
gh2_
pId
=
pulse_ids
)
nds
=
nds
.
rename
(
gh2_
pId
=
dim
)
nds
=
n
ds
.
isel
(
{
gh2_
dim
:
pulse_ids
+
firstFrame
}
)
nds
=
nds
.
assign_coords
(
{
gh2_
dim
:
pulse_ids
}
)
nds
=
nds
.
rename
(
{
gh2_
dim
:
dim
}
)
mask
=
pattern
.
pulse_mask
(
labelled
=
False
)
mask
=
xr
.
DataArray
(
mask
,
dims
=
[
'
trainId
'
,
dim
],
coords
=
{
'
trainId
'
:
run
.
train_ids
,
dim
:
np
.
arange
(
mask
.
shape
[
1
])})
mask
=
mask
.
sel
({
dim
:
pulse_ids
})
nds
=
nds
.
where
(
mask
,
drop
=
True
)
return
nds
ret
=
ds
[
others
].
merge
(
nds
,
join
=
'
inner
'
)
return
ret
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