@@ -250,8 +250,8 @@ def _parse_header(self):
250250 # The digital word is stored as the last channel, after all the individual analog channels
251251 # For example: if there are 8 analog channels (indices 0-7), the digital word is at index 8
252252 num_samples = info ["sample_length" ]
253- num_chan = info ["num_chan" ]
254- data = np .memmap (info ["bin_file" ], dtype = "int16" , mode = "r" , shape = (num_samples , num_chan ), order = "C" )
253+ num_channels = info ["num_chan" ]
254+ data = np .memmap (info ["bin_file" ], dtype = "int16" , mode = "r" , shape = (num_samples , num_channels ), order = "C" )
255255 digital_word_channel_index = len (info ["analog_channels" ])
256256 self ._events_memmap_digital_word = data [:, digital_word_channel_index ]
257257 event_channels = np .array (event_channels , dtype = _event_channel_dtype )
@@ -686,7 +686,12 @@ def extract_stream_info(meta_file, meta):
686686 info ["sampling_rate" ] = float (meta [k ])
687687 info ["num_chan" ] = num_chan
688688
689- info ["sample_length" ] = int (meta ["fileSizeBytes" ]) // 2 // num_chan
689+ # Calculate sample_length from actual file size instead of metadata to handle stub/modified files
690+ # The metadata fileSizeBytes may not match the actual .bin file (e.g., in test stub files)
691+ # Original calculation (only correct for unmodified files):
692+ # info["sample_length"] = int(meta["fileSizeBytes"]) // 2 // num_chan
693+ actual_file_size = Path (meta_file ).with_suffix (".bin" ).stat ().st_size
694+ info ["sample_length" ] = actual_file_size // 2 // num_chan # 2 bytes per int16 sample
690695 info ["gate_num" ] = gate_num
691696 info ["trigger_num" ] = trigger_num
692697 info ["device" ] = device
0 commit comments