Skip to content

Commit

Permalink
Merge pull request #542 from OpenCOMPES/more-broken-file-fixes
Browse files Browse the repository at this point in the history
add further exceptions for completely empty files, and exceptions
  • Loading branch information
rettigl authored Jan 12, 2025
2 parents 2dca036 + 39c2e52 commit a99b945
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/sed/loader/mirrorutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,10 @@ def mycopy(source: str, dest: str, gid: int, mode: int, replace: bool = False):
if replace:
if os.path.exists(dest):
os.remove(dest)
shutil.copy2(source, dest)
try:
shutil.copy2(source, dest)
except OSError:
shutil.copy(source, dest)
# fix permissions and group ownership:
os.chown(dest, -1, gid)
os.chmod(dest, mode)
36 changes: 29 additions & 7 deletions src/sed/loader/mpes/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,12 @@ def hdf5_to_dataframe(
for name, channel in channels.items():
if channel["format"] == "per_file":
if channel["dataset_key"] in test_proc.attrs:
values = [float(get_attribute(h5py.File(f), channel["dataset_key"])) for f in files]
values = []
for f in files:
try:
values.append(float(get_attribute(h5py.File(f), channel["dataset_key"])))
except OSError:
pass
delayeds = [
add_value(partition, name, value)
for partition, value in zip(dataframe.partitions, values)
Expand Down Expand Up @@ -274,7 +279,12 @@ def hdf5_to_timed_dataframe(
for name, channel in channels.items():
if channel["format"] == "per_file":
if channel["dataset_key"] in test_proc.attrs:
values = [float(get_attribute(h5py.File(f), channel["dataset_key"])) for f in files]
values = []
for f in files:
try:
values.append(float(get_attribute(h5py.File(f), channel["dataset_key"])))
except OSError:
pass
delayeds = [
add_value(partition, name, value)
for partition, value in zip(dataframe.partitions, values)
Expand Down Expand Up @@ -843,11 +853,23 @@ def get_start_and_end_time(self) -> tuple[float, float]:
)
ts_from = timestamps[-1][1]
h5filename = self.files[-1]
timestamps = hdf5_to_array(
h5filename=h5filename,
channels=channels,
time_stamps=True,
)
try:
timestamps = hdf5_to_array(
h5filename=h5filename,
channels=channels,
time_stamps=True,
)
except OSError:
try:
h5filename = self.files[-2]
timestamps = hdf5_to_array(
h5filename=h5filename,
channels=channels,
time_stamps=True,
)
except OSError:
ts_to = ts_from
logger.warning("Could not read end time, using start time as end time!")
ts_to = timestamps[-1][-1]
return (ts_from, ts_to)

Expand Down

0 comments on commit a99b945

Please sign in to comment.