Skip to content
Merged
Show file tree
Hide file tree
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
13 changes: 3 additions & 10 deletions src/xrpd_toolbox/data_loader.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from functools import cached_property
from pathlib import Path

import numpy as np
Expand Down Expand Up @@ -26,12 +25,11 @@ class BaseDataLoader:
Handles Nexus/HDF5 access and metadata retrieval.
"""

def __init__(self, filepath: str | Path, data_path: str):
def __init__(self, filepath: str | Path, dataset_path: str):
self.filepath = Path(filepath)
self.data_path = data_path

self.entry = get_entry(self.filepath)
self.dataset_path = f"/{self.entry}/{self.data_path}/data"
self.dataset_path = dataset_path

def get_entries(self):
paths = []
Expand Down Expand Up @@ -68,7 +66,7 @@ def sum_frames(self):
summed_images = []

for frame in range(n_frames):
frame_image = data[:, frame, :, :]
frame_image = data[..., frame, :, :]
image_sum = np.sum(frame_image)

summed_images.append(image_sum)
Expand All @@ -82,11 +80,6 @@ def data(self) -> np.ndarray:
"""Load the entire dataset."""
return self.get_data()

@cached_property
def durations(self) -> np.ndarray:
path = f"/{self.entry}/instrument/{self.data_path}/count_time"
return h5_to_array(self.filepath, path)

def read_array(self, path: str) -> np.ndarray:
"""Helper for reading arbitrary datasets."""
return h5_to_array(self.filepath, path)
4 changes: 2 additions & 2 deletions src/xrpd_toolbox/i15_1/pe2ad.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@


class PE2AD(BaseDataLoader):
def __init__(self, filepath, data_path: str = "pe2AD"):
super().__init__(filepath, data_path)
def __init__(self, filepath, dataset_path: str = "/entry/pe2AD/data"):
super().__init__(filepath, dataset_path)

self.entries = self.get_entries()

Expand Down
8 changes: 3 additions & 5 deletions src/xrpd_toolbox/i15_1/sample_alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def run_sample_alignment(data: XYEData | str) -> SampleAligner:

def sample_alignment(
filepath: str | Path,
dataset_path: str,
dataset_path: str = "/entry/data",
beamline: str | None = None,
save: bool = False,
):
Expand All @@ -336,7 +336,7 @@ def sample_alignment(
if str(filepath).endswith(".csv"):
xyedata = XYEData.from_csv(filepath)
else:
data = BaseDataLoader(filepath=filepath, data_path=dataset_path)
data = BaseDataLoader(filepath=filepath, dataset_path=dataset_path)
summed_frames = data.sum_frames()
index = np.linspace(0, len(summed_frames), len(summed_frames))
xyedata = XYEData(x=index, y=summed_frames)
Expand Down Expand Up @@ -376,9 +376,7 @@ def sample_alignment(
if ".csv" not in filepath:
continue

sample_centre_result = sample_alignment(
filepath, dataset_path="", beamline=BEAMLINE
)
sample_centre_result = sample_alignment(filepath, beamline=BEAMLINE)

print(sample_centre_result.model_dump_json())

Expand Down
Loading