Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mpes incomplete files #523

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 62 additions & 39 deletions sed/loader/mpes/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,27 @@ def hdf5_to_dataframe(
)

# Delay-read all files
arrays = [
da.from_delayed(
dask.delayed(hdf5_to_array)(
h5file=h5py.File(f),
group_names=group_names,
time_stamps=time_stamps,
ms_markers_group=ms_markers_group,
first_event_time_stamp_key=first_event_time_stamp_key,
),
dtype=test_array.dtype,
shape=(test_array.shape[0], np.nan),
)
for f in files
]
arrays = []
for f in files:
try:
arrays.append(
da.from_delayed(
dask.delayed(hdf5_to_array)(
h5file=h5py.File(f),
group_names=group_names,
time_stamps=time_stamps,
ms_markers_group=ms_markers_group,
first_event_time_stamp_key=first_event_time_stamp_key,
),
dtype=test_array.dtype,
shape=(test_array.shape[0], np.nan),
),
)
except OSError as exc:
if "Unable to synchronously open file" in str(exc):
print(f"Unable to open file {f}: {str(exc)}")
pass

array_stack = da.concatenate(arrays, axis=1).T

return ddf.from_dask_array(array_stack, columns=column_names)
Expand Down Expand Up @@ -169,20 +176,26 @@ def hdf5_to_timed_dataframe(
)

# Delay-read all files
arrays = [
da.from_delayed(
dask.delayed(hdf5_to_timed_array)(
h5file=h5py.File(f),
group_names=group_names,
time_stamps=time_stamps,
ms_markers_group=ms_markers_group,
first_event_time_stamp_key=first_event_time_stamp_key,
),
dtype=test_array.dtype,
shape=(test_array.shape[0], np.nan),
)
for f in files
]
arrays = []
for f in files:
try:
arrays.append(
da.from_delayed(
dask.delayed(hdf5_to_timed_array)(
h5file=h5py.File(f),
group_names=group_names,
time_stamps=time_stamps,
ms_markers_group=ms_markers_group,
first_event_time_stamp_key=first_event_time_stamp_key,
),
dtype=test_array.dtype,
shape=(test_array.shape[0], np.nan),
),
)
except OSError as exc:
if "Unable to synchronously open file" in str(exc):
pass

array_stack = da.concatenate(arrays, axis=1).T

return ddf.from_dask_array(array_stack, columns=column_names)
Expand Down Expand Up @@ -914,13 +927,18 @@ def get_count_rate(
count_rate_list = []
accumulated_time = 0
for fid in fids:
count_rate_, secs_ = get_count_rate(
h5py.File(self.files[fid]),
ms_markers_group=ms_markers_group,
)
secs_list.append((accumulated_time + secs_).T)
count_rate_list.append(count_rate_.T)
accumulated_time += secs_[-1]
try:
count_rate_, secs_ = get_count_rate(
h5py.File(self.files[fid]),
ms_markers_group=ms_markers_group,
)
secs_list.append((accumulated_time + secs_).T)
count_rate_list.append(count_rate_.T)
accumulated_time += secs_[-1]
except OSError as exc:
if "Unable to synchronously open file" in str(exc):
print(f"Unable to open file {fid}: {str(exc)}")
pass

count_rate = np.concatenate(count_rate_list)
secs = np.concatenate(secs_list)
Expand Down Expand Up @@ -954,10 +972,15 @@ def get_elapsed_time(self, fids: Sequence[int] = None, **kwds) -> float:

secs = 0.0
for fid in fids:
secs += get_elapsed_time(
h5py.File(self.files[fid]),
ms_markers_group=ms_markers_group,
)
try:
secs += get_elapsed_time(
h5py.File(self.files[fid]),
ms_markers_group=ms_markers_group,
)
except OSError as exc:
if "Unable to synchronously open file" in str(exc):
print(f"Unable to open file {fid}: {str(exc)}")
pass

return secs

Expand Down