@@ -567,6 +567,65 @@ def test_dimension_slider_with_nans(
567567 )
568568
569569
570+ @pytest .mark .parametrize (
571+ "nan_time_location" ,
572+ ["start" , "middle" , "end" ],
573+ )
574+ def test_dimension_slider_with_nans_bboxes (
575+ valid_bboxes_path_and_ds_with_localised_nans ,
576+ nan_time_location ,
577+ make_napari_viewer_proxy ,
578+ ):
579+ """Test that the dimension slider is set to the total number of frames
580+ when bboxes data layers with NaNs are loaded.
581+
582+ Only one individual is set to NaN at a given time, because the
583+ VIA-tracks CSV format drops frames where all individuals have NaN
584+ positions, making the round-trip lossy for all-NaN frames.
585+ """
586+ nan_location = {
587+ "time" : nan_time_location ,
588+ "individuals" : ["id_0" ],
589+ }
590+ file_path , ds = valid_bboxes_path_and_ds_with_localised_nans (
591+ nan_location
592+ )
593+
594+ # Define the expected frame index with the NaN value
595+ if nan_location ["time" ] == "start" :
596+ expected_frame = ds .coords ["time" ][0 ]
597+ elif nan_location ["time" ] == "middle" :
598+ expected_frame = ds .coords ["time" ][ds .coords ["time" ].shape [0 ] // 2 ]
599+ elif nan_location ["time" ] == "end" :
600+ expected_frame = ds .coords ["time" ][- 1 ]
601+
602+ # Load the data loader widget
603+ viewer = make_napari_viewer_proxy ()
604+ data_loader_widget = DataLoader (viewer )
605+
606+ # Read sample data with a NaN at the specified location
607+ data_loader_widget .file_path_edit .setText (file_path .as_posix ())
608+ data_loader_widget .source_software_combo .setCurrentText ("VIA-tracks" )
609+
610+ # Check the data contains nans where expected
611+ assert (
612+ ds .position .sel (
613+ individuals = nan_location ["individuals" ],
614+ time = expected_frame ,
615+ )
616+ .isnull ()
617+ .all ()
618+ )
619+
620+ # Call the _on_load_clicked method
621+ data_loader_widget ._on_load_clicked ()
622+
623+ # Check the frame slider is set to the full range of frames
624+ assert viewer .dims .range [0 ] == RangeTuple (
625+ start = 0.0 , stop = ds .position .shape [0 ] - 1 , step = 1.0
626+ )
627+
628+
570629@pytest .mark .parametrize (
571630 "list_input_data_files" ,
572631 [
@@ -614,6 +673,53 @@ def test_dimension_slider_multiple_files(
614673 assert max_frames == ds_long .sizes ["time" ]
615674
616675
676+ @pytest .mark .parametrize (
677+ "list_input_data_files" ,
678+ [
679+ ["valid_bboxes_path_and_ds" , "valid_bboxes_path_and_ds_short" ],
680+ ["valid_bboxes_path_and_ds_short" , "valid_bboxes_path_and_ds" ],
681+ ],
682+ ids = ["long_first" , "short_first" ],
683+ )
684+ def test_dimension_slider_multiple_files_bboxes (
685+ list_input_data_files , make_napari_viewer_proxy , request
686+ ):
687+ """Test that the dimension slider is set to the maximum number of frames
688+ when multiple bboxes data layers are loaded.
689+ """
690+ # Get the datasets to load (paths and ds)
691+ list_paths , list_datasets = [
692+ [
693+ request .getfixturevalue (file_name )[j ]
694+ for file_name in list_input_data_files
695+ ]
696+ for j in range (len (list_input_data_files ))
697+ ]
698+
699+ # Get the maximum number of frames from all datasets
700+ max_frames = max (ds .sizes ["time" ] for ds in list_datasets )
701+
702+ # Load the data loader widget
703+ viewer = make_napari_viewer_proxy ()
704+ data_loader_widget = DataLoader (viewer )
705+
706+ # Load each dataset in order
707+ for file_path in list_paths :
708+ data_loader_widget .file_path_edit .setText (file_path .as_posix ())
709+ data_loader_widget .source_software_combo .setCurrentText ("VIA-tracks" )
710+ data_loader_widget ._on_load_clicked ()
711+
712+ # Check the frame slider is as expected
713+ assert viewer .dims .range [0 ] == RangeTuple (
714+ start = 0.0 , stop = max_frames - 1 , step = 1.0
715+ )
716+
717+ # Check the maximum number of frames is the number of frames
718+ # in the longest dataset
719+ _ , ds_long = request .getfixturevalue ("valid_bboxes_path_and_ds" )
720+ assert max_frames == ds_long .sizes ["time" ]
721+
722+
617723@pytest .mark .parametrize (
618724 "list_input_data_files" ,
619725 [
0 commit comments