@@ -94,7 +94,7 @@ def parse_dtype(fieldstr: str) -> np.dtype:
9494 --------
9595 >>> fieldstr = '<time uint32><x float32><y float32><z float32>'
9696 >>> parse_dtype(fieldstr)
97- dtype([('time', '<u4') , ('x', '<f4') , ('y', '<f4') , ('z', '<f4')])
97+ dtype([('time', '<u4', (1,)) , ('x', '<f4', (1,)) , ('y', '<f4', (1,)) , ('z', '<f4', (1,) )])
9898
9999 """
100100 # Returns np.dtype from field string
@@ -172,6 +172,15 @@ def read_trodes_datafile(filename: Path) -> dict:
172172 return fields_text
173173
174174
175+ def convert_datafile_to_pandas (datafile ) -> pd .DataFrame :
176+ """Takes the output of read_trodes_datafile and converts it to a pandas dataframe.
177+ Added for changes identified in numpy 2.2.2
178+ """
179+ return pd .DataFrame (
180+ {key : np .squeeze (datafile ["data" ][key ]) for key in datafile ["data" ].dtype .names }
181+ )
182+
183+
175184def get_framerate (timestamps : np .ndarray ) -> float :
176185 """
177186 Calculates the framerate of a video based on the timestamps of each frame.
@@ -472,15 +481,12 @@ def get_video_timestamps(video_timestamps_filepath: Path) -> np.ndarray:
472481 An array of video timestamps.
473482 """
474483 # Get video timestamps
484+ video_timestamps = read_trodes_datafile (video_timestamps_filepath )["data" ]
475485 video_timestamps = (
476- pd .DataFrame (read_trodes_datafile (video_timestamps_filepath )["data" ])
477- .set_index ("PosTimestamp" )
478- .rename (columns = {"frameCount" : "HWframeCount" })
479- )
480- return (
481- np .asarray (video_timestamps .HWTimestamp , dtype = np .float64 )
486+ np .squeeze (video_timestamps ["HWTimestamp" ]).astype (np .float64 )
482487 / NANOSECONDS_PER_SECOND
483488 )
489+ return video_timestamps
484490
485491
486492def get_position_timestamps (
@@ -519,8 +525,9 @@ def get_position_timestamps(
519525 logger = logging .getLogger ("convert" )
520526
521527 # Get video timestamps
528+ datafile = read_trodes_datafile (position_timestamps_filepath )
522529 video_timestamps = (
523- pd . DataFrame ( read_trodes_datafile ( position_timestamps_filepath )[ "data" ] )
530+ convert_datafile_to_pandas ( datafile )
524531 .set_index ("PosTimestamp" )
525532 .rename (columns = {"frameCount" : "HWframeCount" })
526533 )
@@ -549,7 +556,7 @@ def get_position_timestamps(
549556 # Get position tracking information
550557 try :
551558 position_tracking = pd .DataFrame (
552- read_trodes_datafile (position_tracking_filepath )[ "data" ]
559+ convert_datafile_to_pandas ( read_trodes_datafile (position_tracking_filepath ))
553560 ).set_index ("time" )
554561 is_repeat_timestamp = detect_repeat_timestamps (position_tracking .index )
555562 position_tracking = position_tracking .iloc [~ is_repeat_timestamp ]
@@ -1005,7 +1012,7 @@ def add_associated_video_files(
10051012 ]
10061013 ].full_path .to_list ()[0 ]
10071014 # get the timestamps
1008- video_timestamps = get_video_timestamps (video_timestamps_filepath )
1015+ video_timestamps = np . squeeze ( get_video_timestamps (video_timestamps_filepath ) )
10091016
10101017 if convert_video :
10111018 video_file_name = convert_h264_to_mp4 (video_path , video_directory )
0 commit comments