Skip to content

Commit 7e3dcbb

Browse files
committed
Made glob_str a parameter than can be passed from block data. Default behaviour is now to load all files in the folder.
1 parent fc005f2 commit 7e3dcbb

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/datalab_app_plugin_insitu/apps/xrd/blocks.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def process_and_store_data(self, file_path: str | Path):
9595

9696
start_exp = int(self.data.get("start_exp", self.defaults["start_exp"]))
9797
exclude_exp = self.data.get("exclude_exp", self.defaults["exclude_exp"])
98+
glob_str = self.data.get("glob_str") # Optional: if None, all files are used
9899
try:
99100
data = process_local_xrd_data(
100101
file_path=file_path,
@@ -104,6 +105,7 @@ def process_and_store_data(self, file_path: str | Path):
104105
exclude_exp=exclude_exp,
105106
time_series_source=self.data["time_series_source"],
106107
echem_folder_name=self.data.get("echem_folder_name"),
108+
glob_str=glob_str,
107109
)
108110

109111
num_samples, data_length = data["2D_data"].shape

src/datalab_app_plugin_insitu/apps/xrd/utils.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
from scipy.interpolate import interp1d
1111

1212
from datalab_app_plugin_insitu.echem_utils import process_echem_data
13-
from datalab_app_plugin_insitu.utils import _find_folder_path, flexible_data_reader
13+
from datalab_app_plugin_insitu.utils import (
14+
_find_folder_path,
15+
flexible_data_reader,
16+
should_skip_path,
17+
)
1418

1519

1620
def process_local_xrd_data(
@@ -21,6 +25,7 @@ def process_local_xrd_data(
2125
exclude_exp: Union[list, None] = None,
2226
time_series_source: str = "log",
2327
echem_folder_name: Optional[Path] = None,
28+
glob_str: Optional[str] = None,
2429
):
2530
"""
2631
Process local XRD data from a zip file.
@@ -33,6 +38,7 @@ def process_local_xrd_data(
3338
exclude_exp: List of experiments to exclude.
3439
time_series_source: Source of time series data, either 'log' or 'echem' to select whether temperature or echem is the time series data shown.
3540
echem_folder_name: Optional path to the folder containing echem data. Only used if time_series_source is 'echem'.
41+
glob_str: Optional glob pattern to match XRD files (e.g., "*summed*"). If None, all files in the folder are used.
3642
3743
Returns:
3844
dict: Processed XRD data and metadata.
@@ -94,7 +100,7 @@ def process_local_xrd_data(
94100
xrd_folder=xrd_path,
95101
start_at=start_exp,
96102
exclude_exp=exclude_exp,
97-
glob_str="*summed*",
103+
glob_str=glob_str,
98104
)
99105

100106
# Load the 1D data
@@ -241,16 +247,17 @@ def process_xrd_data(
241247
xrd_folder: Path,
242248
start_at: int = 1,
243249
exclude_exp: Optional[List[int]] = None,
244-
glob_str: str = "*summed*",
250+
glob_str: Optional[str] = None,
245251
) -> Dict:
246252
"""
247253
Process XRD data from a specified folder.
248254
249255
Args:
250256
xrd_folder: Path to the folder containing XRD data.
251-
log_file: Path to the log file for storing processing results.
252257
start_at: Starting experiment number.
253258
exclude_exp: List of experiments to exclude.
259+
glob_str: Optional glob pattern to match files (e.g., "*summed*", "*.xy").
260+
If None, all files in the folder are processed.
254261
255262
Returns:
256263
Dict: Processed XRD data and metadata.
@@ -260,10 +267,17 @@ def process_xrd_data(
260267
if not xrd_folder.exists():
261268
raise FileNotFoundError(f"XRD folder does not exist: {xrd_folder}")
262269

263-
file_list = list(xrd_folder.glob(glob_str))
270+
# Get list of files based on glob_str
271+
if glob_str is None:
272+
# Select all files in the folder (excluding directories and system files)
273+
file_list = [f for f in xrd_folder.iterdir() if f.is_file() and not should_skip_path(f)]
274+
else:
275+
file_list = [f for f in xrd_folder.glob(glob_str) if not should_skip_path(f)]
276+
264277
# Process the first XRD pattern file
265278
if not file_list:
266-
raise FileNotFoundError(f"No XRD files found in {xrd_folder} with pattern {glob_str}")
279+
pattern_msg = f"with pattern '{glob_str}'" if glob_str else ""
280+
raise FileNotFoundError(f"No XRD files found in {xrd_folder} {pattern_msg}".strip())
267281

268282
first_file = XRDBlock.load_pattern(file_list[0])
269283
two_theta = first_file[0]["2θ (°)"].values

0 commit comments

Comments
 (0)