Skip to content

Commit def9324

Browse files
committed
feat/test: Update FPS widget to match netCDF file attributes and add corresponding tests
1 parent b429500 commit def9324

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

movement/napari/loader_widgets.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ def _on_load_clicked(self):
185185
if not success:
186186
return # Stop execution if formatting/validation failed
187187

188+
# Update self.fps in case the file loading changed the spinbox value
189+
self.fps = self.fps_spinbox.value()
190+
188191
logger.info("Converted dataset to a napari Tracks array.")
189192
logger.debug(f"Tracks array shape: {self.data.shape}")
190193
if self.data_bboxes is not None:
@@ -217,6 +220,8 @@ def _format_data_for_layers(self) -> bool:
217220
ds = self._load_netcdf_file()
218221
if ds is None:
219222
return False
223+
if "fps" in ds.attrs:
224+
self.fps_spinbox.setValue(ds.attrs["fps"])
220225

221226
# Convert to napari arrays
222227
self.data, self.data_bboxes, self.properties = ds_to_napari_layers(ds)

tests/test_unit/test_napari_plugin/test_data_loader_widget.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,55 +256,63 @@ def test_on_load_clicked_without_file_path(make_napari_viewer_proxy, capsys):
256256

257257

258258
@pytest.mark.parametrize(
259-
"filename, source_software, tracks_array_shape, is_bbox",
259+
"filename, source_software, tracks_array_shape, is_bbox, expected_fps",
260260
[
261261
(
262262
"VIA_single-crab_MOCA-crab-1.csv",
263263
"VIA-tracks",
264264
(35, 4),
265265
True,
266+
60.0,
266267
), # single individual, no keypoints (bboxes)
267268
(
268269
"VIA_multiple-crabs_5-frames_labels.csv",
269270
"VIA-tracks",
270271
(430, 4),
271272
True,
273+
60.0,
272274
), # multiple individuals, no keypoints (bboxes)
273275
(
274276
"SLEAP_single-mouse_EPM.predictions.slp",
275277
"SLEAP",
276278
(110910, 4),
277279
False,
280+
60.0,
278281
), # single individual, multiple keypoints
279282
(
280283
"DLC_single-wasp.predictions.h5",
281284
"DeepLabCut",
282285
(2170, 4),
283286
False,
287+
60.0,
284288
), # single individual, multiple keypoints
285289
(
286290
"DLC_two-mice.predictions.csv",
287291
"DeepLabCut",
288292
(1439976, 4),
289293
False,
294+
60.0,
290295
), # two individuals, multiple keypoints
291296
(
292297
"SLEAP_three-mice_Aeon_mixed-labels.analysis.h5",
293298
"SLEAP",
294299
(1803, 4),
295300
False,
301+
60.0,
296302
), # three individuals, one keypoint
297303
(
298304
"MOVE_two-mice_octagon.analysis.nc",
299305
"movement (netCDF)",
300306
(126000, 4),
301307
False,
308+
50.0,
302309
),
303310
(
304311
"MOVE_single-crab_MOCA-crab-1_linear-interp.nc",
305312
"movement (netCDF)",
306313
(168, 4),
307314
True,
315+
24.0,
308316
),
309317
],
310318
)
@@ -313,6 +321,7 @@ def test_on_load_clicked_with_valid_file_path(
313321
source_software,
314322
tracks_array_shape,
315323
is_bbox,
324+
expected_fps,
316325
make_napari_viewer_proxy,
317326
caplog,
318327
):
@@ -342,7 +351,7 @@ def test_on_load_clicked_with_valid_file_path(
342351
data_loader_widget._on_load_clicked()
343352

344353
# Check the class attributes from the input data
345-
assert data_loader_widget.fps == 60
354+
assert data_loader_widget.fps == expected_fps
346355
assert data_loader_widget.source_software == source_software
347356
assert Path(data_loader_widget.file_path) == file_path
348357
assert data_loader_widget.file_name == file_path.name

0 commit comments

Comments
 (0)