def _extra_metadata_to_folder(self, folder): # save probe if self.get_property('contact_vector') is not None: probegroup = self.get_probegroup() write_probeinterface(folder / 'probe.json', probegroup) # save time vector if any for segment_index, rs in enumerate(self._recording_segments): d = rs.get_times_kwargs() time_vector = d['time_vector'] if time_vector is not None: np.save(folder / f'times_cached_seg{segment_index}.npy', time_vector)
def test_probeinterface_format(): filename = 'test_pi_format.json' probegroup = generate_dummy_probe_group() write_probeinterface(filename, probegroup) probegroup2 = read_probeinterface(filename) assert len(probegroup.probes) == len(probegroup.probes) for i in range(len(probegroup.probes)): probe0 = probegroup.probes[i] probe1 = probegroup2.probes[i] assert probe0.get_electrode_count() == probe1.get_electrode_count() assert np.allclose(probe0.electrode_positions,probe1.electrode_positions) assert np.allclose(probe0.probe_planar_contour,probe1.probe_planar_contour)
def export_one_probe(probe_name, probe): """ Save one probe in "export_folder" + figure. """ probe_folder = export_folder / probe_name probe_folder.mkdir(exist_ok=True, parents=True) probe_file = probe_folder / (probe_name + '.json') figure_file = probe_folder / (probe_name + '.png') write_probeinterface(probe_file, probe) fig = create_CN_figure(probe_name, probe) fig.savefig(figure_file) # plt.show() # avoid memory error plt.close(fig)
def _save(self, format='binary', **save_kwargs): """ This function replaces the old CacheRecordingExtractor, but enables more engines for caching a results. At the moment only 'binary' with memmap is supported. We plan to add other engines, such as zarr and NWB. """ if format == 'binary': # TODO save propreties as npz!!!!! folder = save_kwargs['folder'] files_path = [folder / f'traces_cached_seg{i}.raw' for i in range(self.get_num_segments())] dtype = save_kwargs.get('dtype', 'float32') job_kwargs = {k: save_kwargs[k] for k in self._job_keys if k in save_kwargs} write_binary_recording(self, files_path=files_path, dtype=dtype, **job_kwargs) from .binaryrecordingextractor import BinaryRecordingExtractor cached = BinaryRecordingExtractor(files_path, self.get_sampling_frequency(), self.get_num_channels(), dtype, channel_ids=self.get_channel_ids(), time_axis=0) elif format == 'memory': job_kwargs = {k: save_kwargs[k] for k in self._job_keys if k in save_kwargs} traces_list = write_memory_recording(self, dtype=None, **job_kwargs) from .numpyextractors import NumpyRecording cached = NumpyRecording(traces_list, self.get_sampling_frequency(), channel_ids=self.channel_ids) elif format == 'zarr': # TODO implement a format based on zarr raise NotImplementedError elif format == 'nwb': # TODO implement a format based on zarr raise NotImplementedError else: raise ValueError(f'format {format} not supported') if self.get_property('contact_vector') is not None: probegroup = self.get_probegroup() write_probeinterface(folder / 'probe.json', probegroup) cached.set_probegroup(probegroup) return cached
probe0.create_auto_shape(probe_type='tip') probe1 = generate_tetrode(r=25) probe1.create_auto_shape(probe_type='tip') probe1.move([150, 0]) probe = combine_probes([probe0, probe1]) pos = probe.electrode_positions pos[np.abs(pos) < 0.0001] = 0 probe.electrode_positions = pos # do not include wiring in example : too complicated # probe.set_device_channel_indices([3,2,1,0, 7, 6, 5, 4]) probe.annotate(name='2 shank tetrodes', manufacturer='homemade') print(probe.shank_ids) d = probe.to_dict() print(d.keys()) fig, ax = plt.subplots(figsize=(8, 8)) plot_probe(probe, with_channel_index=True, ax=ax) ax.set_xlim(-50, 200) ax.set_ylim(-150, 120) write_probeinterface('probe_format_example.json', probe) fig.savefig('img/probe_format_example.png') plt.show()
# Let's first generate 2 dummy probes and combine them # into a ProbeGroup probe0 = generate_dummy_probe(elec_shapes='square') probe1 = generate_dummy_probe(elec_shapes='circle') probe1.move([250, -90]) probegroup = ProbeGroup() probegroup.add_probe(probe0) probegroup.add_probe(probe1) ############################################################################## # With the `write_probeinterface` and `read_probeinterface` functions we can # write to and read from the json-based probeinterface format: write_probeinterface('my_two_probe_setup.json', probegroup) probegroup2 = read_probeinterface('my_two_probe_setup.json') plot_probe_group(probegroup2) ############################################################################## # The format looks like this: with open('my_two_probe_setup.json', mode='r') as f: txt = f.read() print(txt[:600], '...') ############################################################################## # PRB is an historical format introduced by the Klusta team and it is also # used by SpikeInterface, Spyking-circus, and Tridesclous.
def _extra_metadata_to_folder(self, folder): # save probe if self.get_property('contact_vector') is not None: probegroup = self.get_probegroup() write_probeinterface(folder / 'probe.json', probegroup)