Skip to content

Commit ef3dcda

Browse files
author
Aser Abdelhakeem
committed
changes to validation
1 parent 227dfb1 commit ef3dcda

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

src/sed/loader/cfel/buffer_handler.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from sed.loader.cfel.dataframe import DataFrameCreator
1010
from sed.loader.flash.buffer_handler import BufferFilePaths
1111
from sed.loader.flash.buffer_handler import BufferHandler as BaseBufferHandler
12+
from sed.loader.flash.utils import InvalidFileError
1213
from sed.loader.flash.utils import get_channels
1314
from sed.loader.flash.utils import get_dtypes
1415

@@ -32,6 +33,18 @@ def __init__(
3233
"""
3334
super().__init__(config)
3435

36+
def _validate_h5_files(self, config, h5_paths: list[Path]) -> list[Path]:
37+
valid_h5_paths = []
38+
for h5_path in h5_paths:
39+
try:
40+
dfc = DataFrameCreator(config_dataframe=config, h5_path=h5_path)
41+
dfc.validate_channel_keys()
42+
valid_h5_paths.append(h5_path)
43+
except InvalidFileError as e:
44+
logger.info(f"Skipping invalid file: {h5_path.stem}\n{e}")
45+
46+
return valid_h5_paths
47+
3548
def _save_buffer_file(self, paths: dict[str, Path]) -> None:
3649
"""Creates the electron and timed buffer files from the raw H5 file."""
3750
logger.debug(f"Processing file: {paths['raw'].stem}")

src/sed/loader/cfel/dataframe.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,10 @@ def df_timestamp(self) -> pd.DataFrame:
165165

166166
def validate_channel_keys(self) -> None:
167167
"""
168-
Validates if the index and dataset keys for all channels in the config exist in the h5 file.
168+
Validates if the dataset keys for all channels in the config exist in the h5 file.
169169
170170
Raises:
171-
InvalidFileError: If the index or dataset keys are missing in the h5 file.
171+
InvalidFileError: If the dataset keys are missing in the h5 file.
172172
"""
173173
invalid_channels = []
174174
for channel in self._config["channels"]:
@@ -182,7 +182,7 @@ def validate_channel_keys(self) -> None:
182182
@property
183183
def df(self) -> pd.DataFrame:
184184
"""
185-
Joins the 'per_electron', 'per_pulse', and 'per_train' using concat operation,
185+
Joins the 'per_electron', 'per_pulse' using concat operation,
186186
returning a single dataframe.
187187
188188
Returns:
@@ -201,7 +201,7 @@ def df(self) -> pd.DataFrame:
201201
@property
202202
def df_timed(self) -> pd.DataFrame:
203203
"""
204-
Joins the 'per_electron', 'per_pulse', and 'per_train' using concat operation,
204+
Joins the 'per_electron', 'per_pulse' using concat operation,
205205
returning a single dataframe.
206206
207207
Returns:

src/sed/loader/cfel/loader.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ def get_elapsed_time_from_fid(fid):
289289
try:
290290
fid = str(fid) # Ensure the key is a string
291291
time_stamps = file_statistics[fid]["columns"][time_stamp_alias]
292+
print(f"Time stamp max: {time_stamps['max']}")
293+
print(f"Time stamp min: {time_stamps['min']}")
292294
elapsed_time = time_stamps["max"] - time_stamps["min"]
293295
except KeyError as exc:
294296
raise KeyError(

0 commit comments

Comments
 (0)