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
d59aabb0
Commit
d59aabb0
authored
5 years ago
by
Loïc Le Guyader
Browse files
Options
Downloads
Patches
Plain Diff
Keep virtual dataset h5 files closed outside 'with' context
parent
ce89f22a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!76
Extra data and xfel kernel
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
DSSC.py
+25
-21
25 additions, 21 deletions
DSSC.py
with
25 additions
and
21 deletions
DSSC.py
+
25
−
21
View file @
d59aabb0
...
@@ -101,7 +101,7 @@ class DSSC:
...
@@ -101,7 +101,7 @@ class DSSC:
print
(
f
'
Temporary directory:
{
self
.
tempdir
}
'
)
print
(
f
'
Temporary directory:
{
self
.
tempdir
}
'
)
print
(
'
Creating virtual dataset
'
)
print
(
'
Creating virtual dataset
'
)
self
.
vds
list
=
self
.
create_virtual_dssc_datasets
(
self
.
run
,
path
=
self
.
tempdir
)
self
.
vds
_filenames
=
self
.
create_virtual_dssc_datasets
(
self
.
run
,
path
=
self
.
tempdir
)
# 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
...
@@ -275,17 +275,25 @@ class DSSC:
...
@@ -275,17 +275,25 @@ class DSSC:
input:
input:
run: extra-data run
run: extra-data run
path: string where the virtual files are created
path: string where the virtual files are created
output:
dictionnary of key:module, value:virtual dataset filename
"""
"""
vds_list
=
[]
vds_filenames
=
{}
for
m
in
tqdm
(
range
(
16
)):
vds_filename
=
os
.
path
.
join
(
path
,
f
'
dssc
{
m
}
_vds.h5
'
)
for
module
in
tqdm
(
range
(
16
)):
if
os
.
path
.
isfile
(
vds_filename
):
fname
=
os
.
path
.
join
(
path
,
f
'
dssc
{
module
}
_vds.h5
'
)
os
.
remove
(
vds_filename
)
if
os
.
path
.
isfile
(
fname
):
module_vds
=
run
.
get_virtual_dataset
(
f
'
SCS_DET_DSSC1M-1/DET/
{
m
}
CH0:xtdf
'
,
os
.
remove
(
fname
)
'
image.data
'
,
filename
=
vds_filename
)
vds_list
.
append
([
vds_filename
,
module_vds
])
vds
=
run
.
get_virtual_dataset
(
f
'
SCS_DET_DSSC1M-1/DET/
{
module
}
CH0:xtdf
'
,
return
vds_list
'
image.data
'
,
filename
=
fname
)
vds
.
file
.
close
()
# keep h5 file closed outside 'with' context
vds_filenames
[
module
]
=
fname
return
vds_filenames
def
binning
(
self
,
do_pulse_mean
=
True
):
def
binning
(
self
,
do_pulse_mean
=
True
):
"""
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
...
@@ -306,7 +314,7 @@ class DSSC:
...
@@ -306,7 +314,7 @@ class DSSC:
jobs
.
append
(
dict
(
jobs
.
append
(
dict
(
module
=
m
,
module
=
m
,
fpt
=
self
.
fpt
,
fpt
=
self
.
fpt
,
vd
f_module
=
os
.
path
.
join
(
self
.
tempdir
,
f
'
dssc
{
m
}
_vds.h5
'
)
,
vd
s
=
self
.
vds_filenames
[
m
]
,
chunksize
=
self
.
chunksize
,
chunksize
=
self
.
chunksize
,
scan
=
self
.
scan
[
'
scan_variable
'
],
scan
=
self
.
scan
[
'
scan_variable
'
],
nbunches
=
self
.
nbunches
,
nbunches
=
self
.
nbunches
,
...
@@ -596,7 +604,7 @@ class DSSC:
...
@@ -596,7 +604,7 @@ class DSSC:
def
process_one_module
(
job
):
def
process_one_module
(
job
):
module
=
job
[
'
module
'
]
module
=
job
[
'
module
'
]
fpt
=
job
[
'
fpt
'
]
fpt
=
job
[
'
fpt
'
]
data_
vd
f
=
job
[
'
vd
f_module
'
]
vd
s
=
job
[
'
vd
s
'
]
scan
=
job
[
'
scan
'
]
scan
=
job
[
'
scan
'
]
chunksize
=
job
[
'
chunksize
'
]
chunksize
=
job
[
'
chunksize
'
]
nbunches
=
job
[
'
nbunches
'
]
nbunches
=
job
[
'
nbunches
'
]
...
@@ -604,8 +612,11 @@ def process_one_module(job):
...
@@ -604,8 +612,11 @@ def process_one_module(job):
image_path
=
f
'
INSTRUMENT/SCS_DET_DSSC1M-1/DET/
{
module
}
CH0:xtdf/image/data
'
image_path
=
f
'
INSTRUMENT/SCS_DET_DSSC1M-1/DET/
{
module
}
CH0:xtdf/image/data
'
npulse_path
=
f
'
INDEX/SCS_DET_DSSC1M-1/DET/
{
module
}
CH0:xtdf/image/count
'
npulse_path
=
f
'
INDEX/SCS_DET_DSSC1M-1/DET/
{
module
}
CH0:xtdf/image/count
'
with
h5py
.
File
(
data_
vd
f
,
'
r
'
)
as
m
:
with
h5py
.
File
(
vd
s
,
'
r
'
)
as
m
:
all_trainIds
=
m
[
'
INDEX/trainId
'
][()]
all_trainIds
=
m
[
'
INDEX/trainId
'
][()]
frames_per_train
=
m
[
npulse_path
][()]
trains_with_data
=
all_trainIds
[
frames_per_train
==
fpt
]
n_trains
=
len
(
all_trainIds
)
n_trains
=
len
(
all_trainIds
)
chunk_start
=
np
.
arange
(
n_trains
,
step
=
chunksize
,
dtype
=
int
)
chunk_start
=
np
.
arange
(
n_trains
,
step
=
chunksize
,
dtype
=
int
)
...
@@ -632,14 +643,7 @@ def process_one_module(job):
...
@@ -632,14 +643,7 @@ def process_one_module(job):
module_data
[
'
module
'
]
=
module
module_data
[
'
module
'
]
=
module
# crunching
# crunching
with
h5py
.
File
(
data_vdf
,
'
r
'
)
as
m
:
with
h5py
.
File
(
vds
,
'
r
'
)
as
m
:
#fpt_calc = int(len(m[image_path]) / n_trains)
#assert fpt_calc == fpt, f'data length does not match expected value (module {module})'
all_trainIds
=
m
[
'
INDEX/trainId
'
][()]
frames_per_train
=
m
[
npulse_path
][()]
trains_with_data
=
all_trainIds
[
frames_per_train
==
fpt
]
#print(np.unique(pulses_per_train), '/', fpt)
#print(len(trains_with_data))
chunk_start
=
np
.
arange
(
len
(
all_trainIds
),
step
=
chunksize
,
dtype
=
int
)
chunk_start
=
np
.
arange
(
len
(
all_trainIds
),
step
=
chunksize
,
dtype
=
int
)
trains_start
=
0
trains_start
=
0
...
...
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