def test_whiten(): rec, sort = se.example_datasets.toy_example(duration=10, num_channels=4) rec_w = whiten(rec) cov_w = np.cov(rec_w.get_traces()) assert np.allclose(cov_w, np.eye(4), atol=0.3) # should size should not affect rec_w2 = whiten(rec, chunk_size=30000) assert np.array_equal(rec_w.get_traces(), rec_w2.get_traces())
def test_whiten(): rec, sort = se.example_datasets.toy_example(dump_folder='test', dumpable=True, duration=10, num_channels=4, seed=0) rec_w = whiten(rec) cov_w = np.cov(rec_w.get_traces()) assert np.allclose(cov_w, np.eye(4), atol=0.3) # should size should not affect rec_w2 = whiten(rec, chunk_size=30000) assert np.array_equal(rec_w.get_traces(), rec_w2.get_traces()) check_dumping(rec_w) shutil.rmtree('test')
def _run(self, recording, output_folder): recording = recover_recording(recording) # Sort # alias to params p = self.params if recording.is_filtered and p['filter']: print( "Warning! The recording is already filtered, but Mountainsort4 filter is enabled. You can disable " "filters by setting 'filter' parameter to False") samplerate = recording.get_sampling_frequency() # Bandpass filter if p['filter'] and p['freq_min'] is not None and p[ 'freq_max'] is not None: recording = bandpass_filter(recording=recording, freq_min=p['freq_min'], freq_max=p['freq_max']) # Whiten if p['whiten']: recording = whiten(recording=recording) # Check location no more needed done in basesorter sorting = ml_ms4alg.mountainsort4( recording=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=self.verbose) # Curate if p['noise_overlap_threshold'] is not None and p['curation'] is True: if self.verbose: print('Curating') sorting = ml_ms4alg.mountainsort4_curation( recording=recording, sorting=sorting, noise_overlap_threshold=p['noise_overlap_threshold']) se.MdaSortingExtractor.write_sorting( sorting, str(output_folder / 'firings.mda')) samplerate_fname = str(output_folder / 'samplerate.txt') with open(samplerate_fname, 'w') as f: f.write('{}'.format(samplerate))
def _run(self, recording, output_folder): # Sort # alias to params p = self.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: recording = bandpass_filter(recording=recording, freq_min=p['freq_min'], freq_max=p['freq_max']) # Whiten if p['whiten']: recording = whiten(recording=recording) # Check location if 'location' not in recording.get_shared_channel_property_names(): for i, chan in enumerate(recording.get_channel_ids()): recording.set_channel_property(chan, 'location', [0, i]) sorting = ml_ms4alg.mountainsort4( recording=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=self.verbose) # Curate if p['noise_overlap_threshold'] is not None and p['curation'] is True: if self.verbose: print('Curating') sorting = ml_ms4alg.mountainsort4_curation( recording=recording, sorting=sorting, noise_overlap_threshold=p['noise_overlap_threshold']) se.MdaSortingExtractor.write_sorting( sorting, str(output_folder / 'firings.mda')) samplerate_fname = str(output_folder / 'samplerate.txt') with open(samplerate_fname, 'w') as f: f.write('{}'.format(samplerate))
def _run(self, recording, output_folder): # Sort # alias to params p = self.params print(p) ind = self.recording_list.index(recording) # Bandpass filter if p['filter'] and p['freq_min'] is not None and p[ 'freq_max'] is not None: recording = bandpass_filter(recording=recording, freq_min=p['freq_min'], freq_max=p['freq_max']) # Whiten if p['whiten']: recording = whiten(recording=recording) # Check location if 'location' not in recording.get_channel_property_names(): for i, chan in enumerate(recording.get_channel_ids()): recording.set_channel_property(chan, 'location', [0, i]) sorting = ml_ms4alg.mountainsort4( recording=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']) # Curate if p['noise_overlap_threshold'] is not None and p['curation'] is True: print('Curating') sorting = ml_ms4alg.mountainsort4_curation( recording=recording, sorting=sorting, noise_overlap_threshold=p['noise_overlap_threshold']) se.MdaSortingExtractor.write_sorting( sorting, str(output_folder / 'firings.mda'))