Skip to content

Commit 807d5d6

Browse files
committed
Respond to review from Neil
1 parent ae121e2 commit 807d5d6

3 files changed

Lines changed: 85 additions & 9 deletions

File tree

AFMReader/general_loader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def load(self) -> tuple[npt.NDArray | str, float | None]: # noqa: C901
4545
Returns
4646
-------
4747
tuple
48-
The image data (stack if ''.asd'') and the pixel to nanometre scaling ratio.
48+
The image data (stack if ''.asd'' or ''.h5-jpk'') and the pixel to nanometre scaling ratio.
4949
5050
Raises
5151
------

AFMReader/h5_jpk.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def _parse_channel_name(channel: str) -> tuple[str, str]:
4646
return channel_type, trace_type
4747

4848

49-
def _get_channel_info(f: h5py.File, channel: str):
49+
def _get_channel_info(h5py_file: h5py.File, channel: str):
5050
"""
5151
Retrieve channel-related HDF5 groups and dataset name.
5252
@@ -69,13 +69,13 @@ def _get_channel_info(f: h5py.File, channel: str):
6969
"""
7070
_parse_channel_name(channel) # just for validation
7171

72-
channel_map = _discover_available_channels(f)
72+
channel_map = _available_channels(h5py_file)
7373
if channel not in channel_map:
7474
raise ValueError(f"'{channel}' not found. Available channels: {list(channel_map)}")
7575

7676
channel_path = channel_map[channel]
77-
channel_group = f[channel_path]
78-
measurement_group = f[channel_path.split("/")[0]]
77+
channel_group = h5py_file[channel_path]
78+
measurement_group = h5py_file[channel_path.split("/")[0]]
7979
dataset_name = channel.split("_")[0].capitalize()
8080

8181
return channel_group, measurement_group, dataset_name
@@ -179,7 +179,7 @@ def _attr_to_bool(attr: bytes | str | bool | int | float) -> bool:
179179
return bool(attr)
180180

181181

182-
def _discover_available_channels(f: h5py.File) -> dict[str, str]:
182+
def _available_channels(f: h5py.File) -> dict[str, str]:
183183
"""
184184
Discover all available scan channels in the HDF5 file.
185185
@@ -263,8 +263,7 @@ def generate_timestamps(num_frames: int, line_rate: float, image_size: int) -> d
263263
dict
264264
A dictionary mapping frame labels (e.g., "frame 0") to timestamps in seconds.
265265
"""
266-
frame_interval = image_size / line_rate # seconds per frame (height lines / lines per second)
267-
timestamps = np.arange(num_frames) * frame_interval
266+
timestamps = np.arange(num_frames) * (image_size / line_rate)
268267
# Compose a dictionary of timestamsps
269268
return {f"frame {i}": timestamp for i, timestamp in enumerate(timestamps)}
270269

tests/test_h5jpk.py

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,84 @@
3333
dict,
3434
48525583.047271535,
3535
id="test image 0",
36-
)
36+
),
37+
pytest.param(
38+
"sample_0.h5-jpk",
39+
"height_retrace",
40+
True,
41+
1.171875,
42+
(4, 128, 128),
43+
float,
44+
dict,
45+
48517762.77380567,
46+
id="test image 0",
47+
),
48+
pytest.param(
49+
"sample_0.h5-jpk",
50+
"error_trace",
51+
True,
52+
1.171875,
53+
(4, 128, 128),
54+
float,
55+
dict,
56+
-360.7100517131785,
57+
id="test image 0",
58+
),
59+
pytest.param(
60+
"sample_0.h5-jpk",
61+
"error_retrace",
62+
True,
63+
1.171875,
64+
(4, 128, 128),
65+
float,
66+
dict,
67+
367.81162274907103,
68+
id="test image 0",
69+
),
70+
pytest.param(
71+
"sample_0.h5-jpk",
72+
"phase_retrace",
73+
True,
74+
1.171875,
75+
(4, 128, 128),
76+
float,
77+
dict,
78+
1741828.7412469066,
79+
id="test image 0",
80+
),
81+
pytest.param(
82+
"sample_0.h5-jpk",
83+
"phase_trace",
84+
True,
85+
1.171875,
86+
(4, 128, 128),
87+
float,
88+
dict,
89+
1734511.5577225098,
90+
id="test image 0",
91+
),
92+
pytest.param(
93+
"sample_0.h5-jpk",
94+
"amplitude_retrace",
95+
True,
96+
1.171875,
97+
(4, 128, 128),
98+
float,
99+
dict,
100+
275567.73614739266,
101+
id="test image 0",
102+
),
103+
pytest.param(
104+
"sample_0.h5-jpk",
105+
"amplitude_trace",
106+
True,
107+
1.171875,
108+
(4, 128, 128),
109+
float,
110+
dict,
111+
276296.25732934737,
112+
id="test image 0",
113+
),
37114
],
38115
)
39116
def test_load_h5jpk(

0 commit comments

Comments
 (0)