avoid copy to binary when not needed in kilosort
@@ -62,14 +62,8 @@ class KilosortBase:
channel_map['fs'] = float(sample_rate)
scipy.io.savemat(str(output_folder / 'chanMap.mat'), channel_map)
- @staticmethod
- def _write_recording(recording, output_folder, params, verbose):
- # save binary file
- BinaryRecordingExtractor.write_recording(recording, file_paths=output_folder / 'recording.dat',
- dtype='int16', verbose=False, **get_job_kwargs(params, verbose))
-
@classmethod
- def _generate_ops_file(cls, recording, params, output_folder):
+ def _generate_ops_file(cls, recording, params, output_folder, binary_file_path):
"""
This function generates ops (configs) data for kilosort and saves as `ops.mat`
@@ -92,7 +86,7 @@ class KilosortBase:
ops['Nchan'] = nchan # number of active channels (omit if already in chanMap file)
ops['datatype'] = 'dat' # binary ('dat', 'bin') or 'openEphys'
- ops['fbinary'] = str((output_folder / 'recording.dat').absolute()) # will be created for 'openEphys'
+ ops['fbinary'] = str(binary_file_path.absolute()) # will be created for 'openEphys'
ops['fproc'] = str((output_folder / 'temp_wh.dat').absolute()) # residual from RAM of preprocessed data
ops['root'] = str(output_folder.absolute()) # 'openEphys' only: where raw files are
ops['trange'] = [0, np.Inf] # time range to sort
@@ -122,9 +116,16 @@ class KilosortBase:
cls._generate_channel_map_file(recording, output_folder)
- cls._write_recording(recording, output_folder, params, verbose)
+ if isinstance(recording, BinaryRecordingExtractor) and recording._kwargs['time_axis'] == 0 and \
+ recording._kwargs['dtype'] == np.dtype('int16') and len(recording._kwargs['file_paths']) == 1:
+ # in this specific case no copy is needed !!
+ binary_file_path = recording._kwargs['file_paths'][0]
+ else:
+ binary_file_path = output_folder / 'recording.dat'
+ BinaryRecordingExtractor.write_recording(recording, file_paths=binary_file_path,
+ dtype='int16', verbose=False, **get_job_kwargs(params, verbose))
- cls._generate_ops_file(recording, params, output_folder)
+ cls._generate_ops_file(recording, params, output_folder, binary_file_path)
@classmethod
def _run_from_folder(cls, output_folder, params, verbose):
