Esempio n. 1
0
    def copy_sortings(self):

        sorter_folders = self.study_folder / 'sorter_folders'
        sorting_folders = self.study_folder / 'sortings'
        log_olders = self.study_folder / 'sortings' / 'run_log'

        log_olders.mkdir(parents=True, exist_ok=True)

        for rec_name, sorter_name, output_folder in iter_output_folders(
                sorter_folders):
            SorterClass = sorter_dict[sorter_name]
            fname = rec_name + '[#]' + sorter_name
            npz_filename = sorting_folders / (fname + '.npz')

            sorting = SorterClass.get_result_from_folder(output_folder)
            try:
                sorting = SorterClass.get_result_from_folder(output_folder)
                NpzSortingExtractor.write_sorting(sorting, npz_filename)
            except:
                if npz_filename.is_file():
                    npz_filename.unlink()
            if (output_folder / 'spikeinterface_log.json').is_file():
                shutil.copyfile(
                    output_folder / 'spikeinterface_log.json',
                    sorting_folders / 'run_log' / (fname + '.json'))

        self.scan_folder()
Esempio n. 2
0
    def _run_from_folder(cls, output_folder, params, verbose):
        import mountainsort4

        recording = load_extractor(output_folder /
                                   'spikeinterface_recording.json')

        # alias to params
        p = params

        samplerate = recording.get_sampling_frequency()

        # Bandpass filter
        if p['filter'] and p['freq_min'] is not None and p[
                'freq_max'] is not None:
            if verbose:
                print('filtering')
            recording = bandpass_filter(recording=recording,
                                        freq_min=p['freq_min'],
                                        freq_max=p['freq_max'])

        # Whiten
        if p['whiten']:
            if verbose:
                print('whitenning')
            recording = whiten(recording=recording)

        print(
            'Mountainsort4 use the OLD spikeextractors mapped with RecordingExtractorOldAPI'
        )
        old_api_recording = RecordingExtractorOldAPI(recording)

        # Check location no more needed done in basesorter
        old_api_sorting = mountainsort4.mountainsort4(
            recording=old_api_recording,
            detect_sign=p['detect_sign'],
            adjacency_radius=p['adjacency_radius'],
            clip_size=p['clip_size'],
            detect_threshold=p['detect_threshold'],
            detect_interval=p['detect_interval'],
            num_workers=p['num_workers'],
            verbose=verbose)

        # Curate
        if p['noise_overlap_threshold'] is not None and p['curation'] is True:
            if verbose:
                print('Curating')
            old_api_sorting = mountainsort4.mountainsort4_curation(
                recording=old_api_recording,
                sorting=old_api_sorting,
                noise_overlap_threshold=p['noise_overlap_threshold'])

        # convert sorting to new API and save it
        unit_ids = old_api_sorting.get_unit_ids()
        units_dict_list = [{
            u: old_api_sorting.get_unit_spike_train(u)
            for u in unit_ids
        }]
        new_api_sorting = NumpySorting.from_dict(units_dict_list, samplerate)
        NpzSortingExtractor.write_sorting(new_api_sorting,
                                          str(output_folder / 'firings.npz'))
Esempio n. 3
0
def iter_computed_sorting(study_folder):
    """
    Iter over sorting files.
    """
    sorting_folder = Path(study_folder) / 'sortings'
    for filename in os.listdir(sorting_folder):
        if filename.endswith('.npz') and '[#]' in filename:
            rec_name, sorter_name = filename.replace('.npz', '').split('[#]')
            sorting = NpzSortingExtractor(sorting_folder / filename)
            yield rec_name, sorter_name, sorting
Esempio n. 4
0
 def _get_result_from_folder(cls, output_folder):
     output_folder = Path(output_folder)
     result_fname = output_folder / 'firings.npz'
     sorting = NpzSortingExtractor(result_fname)
     return sorting