def __init__(self, cells_args=None, cells_params=None, **kwargs): # Preinitialize object with the base class. block.Block.__init__(self, **kwargs) self.sampling_rate = self.sampling_rate # Useful to disable some PyCharm warnings. self.nb_samples = self.nb_samples # Useful to disable some PyCharm warnings. self.seed = self.seed # Useful to disable some PyCharm warnings. self.is_realistic = self.is_realistic # Useful to disable some PyCharm warnings. self.working_directory = self.working_directory # Useful to disable some PyCharm warnings. if self.working_directory is None: self.mode = 'default' else: self.mode = 'preconfigured' if self.mode == 'default': # Save class parameters. self.cells_args = cells_args if cells_params is None: self.cells_params = {} else: self.cells_params = cells_params # Compute the number of cells. if self.cells_args is not None: self.nb_cells = len(self.cells_args) # Open the probe file. if self.probe is None: self.log.error('{n}: the probe file must be specified!'.format( n=self.name)) else: self.probe = io.load_probe(self.probe, logger=self.log) self.log.info('{n} reads the probe layout'.format(n=self.name)) # TODO log/save input keyword argument to file. self.log_path = self.log_path # Useful to disable some PyCharm warnings. if self.log_path is not None: log_kwargs = {k: self.params[k] for k in ['nb_samples']} with open(self.log_path, 'w') as log_file: json.dump(log_kwargs, log_file, sort_keys=True, indent=4) elif self.mode == 'preconfigured': parameters_path = os.path.join(self.working_directory, "parameters.txt") parameters = io.get_data_parameters(parameters_path) # TODO get rid of the following try ... except ... try: self.duration = parameters['general']['duration'] except KeyError: self.duration = 60.0 # s probe_path = os.path.join(self.working_directory, "probe.prb") self.probe = io.load_probe(probe_path, logger=self.log) self._number = -1 # Add data output. self.add_output('data', structure='dict')
def __init__(self, spk_writer_params, probe, template_store, synthetic_store=None, filtered_data=None, threshold_data=None, start_time=0, stop_time=None): self.probe = io.load_probe(probe) self.spikes = numpy.fromfile(spk_writer_params['spike_times'], dtype=numpy.int32) self.temp_ids = numpy.fromfile(spk_writer_params['templates'], dtype=numpy.int32) self.amps = numpy.fromfile(spk_writer_params['amplitudes'], dtype=numpy.float32) if filtered_data is not None: self.filtered_data = numpy.fromfile(filtered_data, dtype=numpy.float32) self.filtered_data = self.filtered_data.reshape( self.filtered_data.size / self.nb_channels, self.nb_channels) else: self.filtered_data = None self.template_store = TemplateStore( os.path.join(os.path.abspath(template_store), 'template_store.h5'), 'r') self.set_cmap_circus('jet') if synthetic_store is not None: self.synthetic_store = SyntheticStore( os.path.abspath(synthetic_store), 'r') self.set_cmap_synthetic('jet') else: self.synthetic_store = None if threshold_data is not None: self.threshold_data = numpy.fromfile(threshold_data, dtype=numpy.float32) self.threshold_data = self.threshold_data.reshape( self.threshold_data.size / self.nb_channels, self.nb_channels) else: self.threshold_data = None self.start_time = start_time if stop_time is None: if self.filtered_data is not None: self.stop_time = self.filtered_data.shape[0] else: self.stop_time = None else: self.stop_time = stop_time
def find_or_generate_probe(path=None, directory=None): """Find or generate probe to use during the pregeneration. Parameters: path: none | string (optional) Path to the probe file. The default value is None. directory: none | string (optional) Path to the probe directory. The default value is None. Return: probe: circusort.io.Probe Found or generated probe. """ if path is None: if directory is None: directory = os.path.join("~", ".spyking-circus-ort", "probes") directory = os.path.expanduser(directory) # Check if there is a probe file in the directory. path = os.path.join(directory, "probe.prb") # TODO check if there is any .prb file not only a probe.prb file. if os.path.isfile(path): # Load the probe. probe = io.load_probe(path) else: # Generate the probe. probe = io.generate_probe() else: # Check if the probe file exists. if os.path.isfile(path): # Load the probe. probe = io.load_probe(path) else: # Raise an error. message = "No such probe file: {}".format(path) raise OSError(message) return probe
def __init__(self, generator_kwargs, signal_writer_kwargs, mad_writer_kwargs, peak_writer_kwargs, updater_kwargs, spike_writer_kwargs): # Save raw input arguments. self.generator_kwargs = generator_kwargs self.signal_writer_kwargs = signal_writer_kwargs self.mad_writer_kwargs = mad_writer_kwargs self.peak_writer_kwargs = peak_writer_kwargs self.updater_kwargs = updater_kwargs self.spike_writer_kwargs = spike_writer_kwargs # Retrieve generation parameters. hdf5_path = os.path.abspath(self.generator_kwargs['hdf5_path']) self.gen = SyntheticStore(hdf5_path) log_path = os.path.abspath(self.generator_kwargs['log_path']) with open(log_path, mode='r') as log_file: self.generator = json.load(log_file) self.probe_path = self.generator_kwargs['probe'] # Retrieve detected peak. peaks_path = self.peak_writer_kwargs['neg_peaks'] self.detected_peaks = io.load_peaks(peaks_path) # Retrieve probe. self.probe = io.load_probe(self.probe_path) # Sampling rate. self.sampling_rate = 20e+3 # [Hz] self.chunk_size = self.generator['nb_samples'] # Retrieve detected spikes. spike_times_path = self.spike_writer_kwargs['spike_times'] spike_templates_path = self.spike_writer_kwargs['templates'] spike_amplitudes_path = self.spike_writer_kwargs['amplitudes'] self.detected_spikes = io.load_spikes(spike_times_path, spike_templates_path, spike_amplitudes_path)
def __init__(self, generator, signal_writer, mad_writer, peak_writer, probe_path): # Save raw input arguments. self.generator = generator self.signal_writer = signal_writer self.mad_writer = mad_writer self.peak_writer = peak_writer self.probe_path = probe_path # Retrieve generated peaks. gen_path = os.path.abspath(self.generator.hdf5_path) self.gen = SyntheticStore(gen_path) # Retrieve detected peak. peaks_path = self.peak_writer.recorded_peaks['negative'] self.detected_peaks = io.load_peaks(peaks_path) # Retrieve probe. self.probe = io.load_probe(self.probe_path) # Sampling rate. self.sampling_rate = 20.0e+3 # [Hz] self.chunk_size = self.generator.nb_samples