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
ce89f22a
Commit
ce89f22a
authored
4 years ago
by
Loïc Le Guyader
Browse files
Options
Downloads
Patches
Plain Diff
Clean up remaining scan_variable.nc file saving code
parent
7ef020b1
No related branches found
No related tags found
1 merge request
!76
Extra data and xfel kernel
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
DSSC.py
+8
-27
8 additions, 27 deletions
DSSC.py
with
8 additions
and
27 deletions
DSSC.py
+
8
−
27
View file @
ce89f22a
...
@@ -106,9 +106,9 @@ class DSSC:
...
@@ -106,9 +106,9 @@ class DSSC:
# create a dummy scan variable for dark run
# create a dummy scan variable for dark run
# for other type or run, use DSSC.define_run function to overwrite it
# for other type or run, use DSSC.define_run function to overwrite it
self
.
scan
=
xr
.
DataArray
(
np
.
ones_like
(
self
.
run
.
train_ids
),
dims
=
[
'
trainId
'
],
self
.
scan
=
xr
.
DataArray
(
np
.
ones_like
(
self
.
run
.
train_ids
),
dims
=
[
'
trainId
'
],
coords
=
{
'
trainId
'
:
self
.
run
.
train_ids
})
coords
=
{
'
trainId
'
:
self
.
run
.
train_ids
}).
to_dataset
(
name
=
'
scan_variable
'
)
self
.
scan_vname
=
'
dummy
'
self
.
scan_vname
=
'
dummy
'
self
.
vds_scan
=
None
def
define_scan
(
self
,
vname
,
bins
):
def
define_scan
(
self
,
vname
,
bins
):
"""
"""
...
@@ -121,30 +121,24 @@ class DSSC:
...
@@ -121,30 +121,24 @@ class DSSC:
"""
"""
if
type
(
vname
)
is
dict
:
if
type
(
vname
)
is
dict
:
self
.
scan
=
self
.
run
.
get_array
(
vname
[
'
source
'
],
vname
[
'
key
'
])
scan
=
self
.
run
.
get_array
(
vname
[
'
source
'
],
vname
[
'
key
'
])
elif
type
(
vname
)
is
str
:
elif
type
(
vname
)
is
str
:
if
vname
not
in
tb
.
mnemonics
:
if
vname
not
in
tb
.
mnemonics
:
raise
ValueError
(
f
'
{
vname
}
not found in the ToolBox mnemonics table
'
)
raise
ValueError
(
f
'
{
vname
}
not found in the ToolBox mnemonics table
'
)
self
.
scan
=
self
.
run
.
get_array
(
tb
.
mnemonics
[
vname
][
'
source
'
],
tb
.
mnemonics
[
vname
][
'
key
'
])
scan
=
self
.
run
.
get_array
(
tb
.
mnemonics
[
vname
][
'
source
'
],
tb
.
mnemonics
[
vname
][
'
key
'
])
else
:
else
:
raise
ValueError
(
f
'
vname should be a string or a dict. We got
{
type
(
vname
)
}
'
)
raise
ValueError
(
f
'
vname should be a string or a dict. We got
{
type
(
vname
)
}
'
)
if
(
type
(
bins
)
is
int
)
or
(
type
(
bins
)
is
float
):
if
(
type
(
bins
)
is
int
)
or
(
type
(
bins
)
is
float
):
self
.
scan
=
bins
*
np
.
round
(
self
.
scan
/
bins
)
scan
=
bins
*
np
.
round
(
scan
/
bins
)
else
:
else
:
# TODO: digitize the data
# TODO: digitize the data
raise
ValueError
(
f
'
To be implemented
'
)
raise
ValueError
(
f
'
To be implemented
'
)
self
.
scan_vname
=
vname
self
.
scan_vname
=
vname
self
.
vds_scan
=
os
.
path
.
join
(
self
.
tempdir
,
'
scan_variable.nc
'
)
self
.
scan
=
scan
.
to_dataset
(
name
=
'
scan_variable
'
)
if
os
.
path
.
isfile
(
self
.
vds_scan
):
os
.
remove
(
self
.
vds_scan
)
self
.
scan
=
self
.
scan
.
to_dataset
(
name
=
'
scan_variable
'
)
self
.
scan
[
'
xgm_pumped
'
]
=
self
.
xgm
[:,
:
self
.
nbunches
:
2
].
mean
(
'
dim_0
'
)
self
.
scan
[
'
xgm_pumped
'
]
=
self
.
xgm
[:,
:
self
.
nbunches
:
2
].
mean
(
'
dim_0
'
)
self
.
scan
[
'
xgm_unpumped
'
]
=
self
.
xgm
[:,
1
:
self
.
nbunches
:
2
].
mean
(
'
dim_0
'
)
self
.
scan
[
'
xgm_unpumped
'
]
=
self
.
xgm
[:,
1
:
self
.
nbunches
:
2
].
mean
(
'
dim_0
'
)
self
.
scan
.
to_netcdf
(
self
.
vds_scan
,
group
=
'
data
'
)
self
.
scan
.
close
()
self
.
scan_counts
=
xr
.
DataArray
(
np
.
ones
(
len
(
self
.
scan
[
'
scan_variable
'
])),
self
.
scan_counts
=
xr
.
DataArray
(
np
.
ones
(
len
(
self
.
scan
[
'
scan_variable
'
])),
dims
=
[
'
scan_variable
'
],
dims
=
[
'
scan_variable
'
],
...
@@ -297,15 +291,6 @@ class DSSC:
...
@@ -297,15 +291,6 @@ class DSSC:
"""
Bin the DSSC data by the predifined scan type (DSSC.define()) using multiprocessing
"""
Bin the DSSC data by the predifined scan type (DSSC.define()) using multiprocessing
"""
"""
if
self
.
vds_scan
is
None
:
# probably a dark run with a dummy scan variable
self
.
vds_scan
=
os
.
path
.
join
(
self
.
tempdir
,
'
scan_variable.nc
'
)
if
os
.
path
.
isfile
(
self
.
vds_scan
):
os
.
remove
(
self
.
vds_scan
)
self
.
scan
=
self
.
scan
.
to_dataset
(
name
=
'
scan_variable
'
)
self
.
scan
.
to_netcdf
(
self
.
vds_scan
,
group
=
'
data
'
)
self
.
scan
.
close
()
# get available memory in GB, we will try to use 80 % of it
# get available memory in GB, we will try to use 80 % of it
max_GB
=
psutil
.
virtual_memory
().
available
/
1024
**
3
max_GB
=
psutil
.
virtual_memory
().
available
/
1024
**
3
...
@@ -316,10 +301,6 @@ class DSSC:
...
@@ -316,10 +301,6 @@ class DSSC:
print
(
'
processing
'
,
self
.
chunksize
,
'
trains per chunk
'
)
print
(
'
processing
'
,
self
.
chunksize
,
'
trains per chunk
'
)
# load scan variable
scan
=
xr
.
load_dataset
(
self
.
vds_scan
,
group
=
'
data
'
)[
'
scan_variable
'
]
scan
.
name
=
'
scan
'
jobs
=
[]
jobs
=
[]
for
m
in
range
(
16
):
for
m
in
range
(
16
):
jobs
.
append
(
dict
(
jobs
.
append
(
dict
(
...
@@ -327,7 +308,7 @@ class DSSC:
...
@@ -327,7 +308,7 @@ class DSSC:
fpt
=
self
.
fpt
,
fpt
=
self
.
fpt
,
vdf_module
=
os
.
path
.
join
(
self
.
tempdir
,
f
'
dssc
{
m
}
_vds.h5
'
),
vdf_module
=
os
.
path
.
join
(
self
.
tempdir
,
f
'
dssc
{
m
}
_vds.h5
'
),
chunksize
=
self
.
chunksize
,
chunksize
=
self
.
chunksize
,
scan
=
s
can
,
scan
=
s
elf
.
scan
[
'
scan_variable
'
]
,
nbunches
=
self
.
nbunches
,
nbunches
=
self
.
nbunches
,
run_nr
=
self
.
run_nr
,
run_nr
=
self
.
run_nr
,
do_pulse_mean
=
do_pulse_mean
do_pulse_mean
=
do_pulse_mean
...
...
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