def configure(self, time_series): """ Do any configuration needed before launching and create an instance of the algorithm. """ shape = time_series.read_data_shape() LOG.debug("time_series shape is %s" % (str(shape))) ##-------------------- Fill Algorithm for Analysis -------------------## self.algorithm = NodeComplexCoherence() self.algorithm.time_series = time_series self.memory_factor = 1
def configure(self, time_series): """ Do any configuration needed before launching and create an instance of the algorithm. """ self.input_time_series_index = time_series self.input_shape = (self.input_time_series_index.data_length_1d, self.input_time_series_index.data_length_2d, self.input_time_series_index.data_length_3d, self.input_time_series_index.data_length_4d) LOG.debug("Time series shape is %s" % (str(self.input_shape))) # -------------------- Fill Algorithm for Analysis -------------------## self.algorithm = NodeComplexCoherence() self.memory_factor = 1
def configure(self, view_model): # type: (NodeComplexCoherenceModel) -> None """ Do any configuration needed before launching and create an instance of the algorithm. """ self.input_time_series_index = self.load_entity_by_gid(view_model.time_series.hex) self.input_shape = (self.input_time_series_index.data_length_1d, self.input_time_series_index.data_length_2d, self.input_time_series_index.data_length_3d, self.input_time_series_index.data_length_4d) self.log.debug("Time series shape is %s" % (str(self.input_shape))) # -------------------- Fill Algorithm for Analysis -------------------## self.algorithm = NodeComplexCoherence() self.memory_factor = 1
def configure(self, time_series): """ Do any configuration needed before launching and create an instance of the algorithm. """ shape = time_series.read_data_shape() LOG.debug("time_series shape is %s" % (str(shape))) ##-------------------- Fill Algorithm for Analysis -------------------## self.algorithm = NodeComplexCoherence() self.algorithm.time_series = time_series self.memory_factor = 1
def get_input_tree(self): """ Return a list of lists describing the interface to the analyzer. This is used by the GUI to generate the menus and fields necessary for defining a simulation. """ algorithm = NodeComplexCoherence() algorithm.trait.bound = self.INTERFACE_ATTRIBUTES_ONLY tree = algorithm.interface[self.INTERFACE_ATTRIBUTES] for node in tree: if node['name'] == 'time_series': node['conditions'] = FilterChain( fields=[FilterChain.datatype + '._nr_dimensions'], operations=["=="], values=[4]) return tree
class NodeComplexCoherenceAdapter(ABCAdapter): """ TVB adapter for calling the NodeComplexCoherence algorithm. """ _ui_name = "Complex Coherence of Nodes" _ui_description = "Compute the node complex (imaginary) coherence for a TimeSeries input DataType." _ui_subsection = "complexcoherence" def get_form_class(self): return NodeComplexCoherenceForm def get_output(self): return [ComplexCoherenceSpectrumIndex] def get_required_memory_size(self, view_model): # type: (NodeComplexCoherenceModel) -> int """ Return the required memory to run this algorithm. """ input_size = numpy.prod(self.input_shape) * 8.0 output_size = self.algorithm.result_size( self.input_shape, self.algorithm.max_freq, self.algorithm.epoch_length, self.algorithm.segment_length, self.algorithm.segment_shift, self.input_time_series_index.sample_period, self.algorithm.zeropad, self.algorithm.average_segments) return input_size + output_size def get_required_disk_size(self, view_model): # type: (NodeComplexCoherenceModel) -> int """ Returns the required disk size to be able to run the adapter (in kB). """ result = self.algorithm.result_size( self.input_shape, self.algorithm.max_freq, self.algorithm.epoch_length, self.algorithm.segment_length, self.algorithm.segment_shift, self.input_time_series_index.sample_period, self.algorithm.zeropad, self.algorithm.average_segments) return self.array_size2kb(result) def configure(self, view_model): # type: (NodeComplexCoherenceModel) -> None """ Do any configuration needed before launching and create an instance of the algorithm. """ self.input_time_series_index = self.load_entity_by_gid( view_model.time_series.hex) self.input_shape = (self.input_time_series_index.data_length_1d, self.input_time_series_index.data_length_2d, self.input_time_series_index.data_length_3d, self.input_time_series_index.data_length_4d) self.log.debug("Time series shape is %s" % (str(self.input_shape))) # -------------------- Fill Algorithm for Analysis -------------------## self.algorithm = NodeComplexCoherence() self.memory_factor = 1 def launch(self, view_model): # type: (NodeComplexCoherenceModel) -> [ComplexCoherenceSpectrumIndex] """ Launch algorithm and build results. """ # TODO ---------- Iterate over slices and compose final result ------------## self.algorithm.time_series = h5.load_from_index( self.input_time_series_index) ht_result = self.algorithm.evaluate() self.log.debug("got ComplexCoherenceSpectrum result") self.log.debug("ComplexCoherenceSpectrum segment_length is %s" % (str(ht_result.segment_length))) self.log.debug("ComplexCoherenceSpectrum epoch_length is %s" % (str(ht_result.epoch_length))) self.log.debug("ComplexCoherenceSpectrum windowing_function is %s" % (str(ht_result.windowing_function))) # LOG.debug("ComplexCoherenceSpectrum frequency vector is %s" % (str(ht_result.frequency))) return h5.store_complete(ht_result, self.storage_path)
def get_traited_datatype(self): return NodeComplexCoherence()
class NodeComplexCoherenceAdapter(ABCAsynchronous): """ TVB adapter for calling the NodeComplexCoherence algorithm. """ _ui_name = "Complex Coherence of Nodes" _ui_description = "Compute the node complex (imaginary) coherence for a TimeSeries input DataType." _ui_subsection = "complexcoherence" def get_form_class(self): return NodeComplexCoherenceForm def get_output(self): return [ComplexCoherenceSpectrumIndex] def get_required_memory_size(self, **kwargs): """ Return the required memory to run this algorithm. """ input_size = numpy.prod(self.input_shape) * 8.0 output_size = self.algorithm.result_size( self.input_shape, self.algorithm.max_freq, self.algorithm.epoch_length, self.algorithm.segment_length, self.algorithm.segment_shift, self.input_time_series_index.sample_period, self.algorithm.zeropad, self.algorithm.average_segments) return input_size + output_size def get_required_disk_size(self, **kwargs): """ Returns the required disk size to be able to run the adapter (in kB). """ result = self.algorithm.result_size( self.input_shape, self.algorithm.max_freq, self.algorithm.epoch_length, self.algorithm.segment_length, self.algorithm.segment_shift, self.input_time_series_index.sample_period, self.algorithm.zeropad, self.algorithm.average_segments) return self.array_size2kb(result) def configure(self, time_series): """ Do any configuration needed before launching and create an instance of the algorithm. """ self.input_time_series_index = time_series self.input_shape = (self.input_time_series_index.data_length_1d, self.input_time_series_index.data_length_2d, self.input_time_series_index.data_length_3d, self.input_time_series_index.data_length_4d) LOG.debug("Time series shape is %s" % (str(self.input_shape))) # -------------------- Fill Algorithm for Analysis -------------------## self.algorithm = NodeComplexCoherence() self.memory_factor = 1 def launch(self, time_series): """ Launch algorithm and build results. :returns: the `ComplexCoherenceSpectrum` built with the given time-series """ # ------- Prepare a ComplexCoherenceSpectrum object for result -------## complex_coherence_spectrum_index = ComplexCoherenceSpectrumIndex() time_series_h5 = h5.h5_file_for_index(time_series) dest_path = h5.path_for(self.storage_path, ComplexCoherenceSpectrumH5, complex_coherence_spectrum_index.gid) spectra_h5 = ComplexCoherenceSpectrumH5(dest_path) spectra_h5.gid.store(uuid.UUID(complex_coherence_spectrum_index.gid)) spectra_h5.source.store(time_series_h5.gid.load()) # ------------------- NOTE: Assumes 4D TimeSeries. -------------------## input_shape = time_series_h5.data.shape node_slice = [ slice(input_shape[0]), slice(input_shape[1]), slice(input_shape[2]), slice(input_shape[3]) ] # ---------- Iterate over slices and compose final result ------------## small_ts = TimeSeries() small_ts.sample_period = time_series_h5.sample_period.load() small_ts.data = time_series_h5.read_data_slice(tuple(node_slice)) self.algorithm.time_series = small_ts partial_result = self.algorithm.evaluate() LOG.debug("got partial_result") LOG.debug("partial segment_length is %s" % (str(partial_result.segment_length))) LOG.debug("partial epoch_length is %s" % (str(partial_result.epoch_length))) LOG.debug("partial windowing_function is %s" % (str(partial_result.windowing_function))) # LOG.debug("partial frequency vector is %s" % (str(partial_result.frequency))) spectra_h5.write_data_slice(partial_result) spectra_h5.segment_length.store(partial_result.segment_length) spectra_h5.epoch_length.store(partial_result.epoch_length) spectra_h5.windowing_function.store(partial_result.windowing_function) # spectra.frequency = partial_result.frequency spectra_h5.close() time_series_h5.close() complex_coherence_spectrum_index.source_gid = self.input_time_series_index.gid complex_coherence_spectrum_index.epoch_length = partial_result.epoch_length complex_coherence_spectrum_index.segment_length = partial_result.segment_length complex_coherence_spectrum_index.windowing_function = partial_result.windowing_function complex_coherence_spectrum_index.frequency_step = partial_result.freq_step complex_coherence_spectrum_index.max_frequency = partial_result.max_freq return complex_coherence_spectrum_index
class NodeComplexCoherenceAdapter(ABCAsynchronous): """ TVB adapter for calling the NodeComplexCoherence algorithm. """ _ui_name = "Complex Coherence of Nodes" _ui_description = "Compute the node complex (imaginary) coherence for a TimeSeries input DataType." _ui_subsection = "complexcoherence" def get_input_tree(self): """ Return a list of lists describing the interface to the analyzer. This is used by the GUI to generate the menus and fields necessary for defining a simulation. """ algorithm = NodeComplexCoherence() algorithm.trait.bound = self.INTERFACE_ATTRIBUTES_ONLY tree = algorithm.interface[self.INTERFACE_ATTRIBUTES] for node in tree: if node['name'] == 'time_series': node['conditions'] = FilterChain( fields=[FilterChain.datatype + '._nr_dimensions'], operations=["=="], values=[4]) return tree def get_output(self): return [ComplexCoherenceSpectrum] def get_required_memory_size(self, **kwargs): """ Return the required memory to run this algorithm. """ used_shape = self.algorithm.time_series.read_data_shape() input_size = numpy.prod(used_shape) * 8.0 output_size = self.algorithm.result_size( used_shape, self.algorithm.max_freq, self.algorithm.epoch_length, self.algorithm.segment_length, self.algorithm.segment_shift, self.algorithm.time_series.sample_period, self.algorithm.zeropad, self.algorithm.average_segments) return input_size + output_size def get_required_disk_size(self, **kwargs): """ Returns the required disk size to be able to run the adapter (in kB). """ used_shape = self.algorithm.time_series.read_data_shape() result = self.algorithm.result_size( used_shape, self.algorithm.max_freq, self.algorithm.epoch_length, self.algorithm.segment_length, self.algorithm.segment_shift, self.algorithm.time_series.sample_period, self.algorithm.zeropad, self.algorithm.average_segments) return self.array_size2kb(result) def configure(self, time_series): """ Do any configuration needed before launching and create an instance of the algorithm. """ shape = time_series.read_data_shape() LOG.debug("time_series shape is %s" % (str(shape))) ##-------------------- Fill Algorithm for Analysis -------------------## self.algorithm = NodeComplexCoherence() self.algorithm.time_series = time_series self.memory_factor = 1 def launch(self, time_series): """ Launch algorithm and build results. :returns: the `ComplexCoherenceSpectrum` built with the given time-series """ shape = time_series.read_data_shape() ##------- Prepare a ComplexCoherenceSpectrum object for result -------## spectra = ComplexCoherenceSpectrum(source=time_series, storage_path=self.storage_path) ##------------------- NOTE: Assumes 4D TimeSeries. -------------------## node_slice = [ slice(shape[0]), slice(shape[1]), slice(shape[2]), slice(shape[3]) ] ##---------- Iterate over slices and compose final result ------------## small_ts = TimeSeries(use_storage=False) small_ts.sample_rate = time_series.sample_rate small_ts.data = time_series.read_data_slice(tuple(node_slice)) self.algorithm.time_series = small_ts partial_result = self.algorithm.evaluate() LOG.debug("got partial_result") LOG.debug("partial segment_length is %s" % (str(partial_result.segment_length))) LOG.debug("partial epoch_length is %s" % (str(partial_result.epoch_length))) LOG.debug("partial windowing_function is %s" % (str(partial_result.windowing_function))) #LOG.debug("partial frequency vector is %s" % (str(partial_result.frequency))) spectra.write_data_slice(partial_result) spectra.segment_length = partial_result.segment_length spectra.epoch_length = partial_result.epoch_length spectra.windowing_function = partial_result.windowing_function #spectra.frequency = partial_result.frequency spectra.close_file() return spectra
class NodeComplexCoherenceAdapter(ABCAsynchronous): """ TVB adapter for calling the NodeComplexCoherence algorithm. """ _ui_name = "Complex Coherence of Nodes" _ui_description = "Compute the node complex (imaginary) coherence for a TimeSeries input DataType." _ui_subsection = "complexcoherence" def get_input_tree(self): """ Return a list of lists describing the interface to the analyzer. This is used by the GUI to generate the menus and fields necessary for defining a simulation. """ algorithm = NodeComplexCoherence() algorithm.trait.bound = self.INTERFACE_ATTRIBUTES_ONLY tree = algorithm.interface[self.INTERFACE_ATTRIBUTES] for node in tree: if node['name'] == 'time_series': node['conditions'] = FilterChain(fields=[FilterChain.datatype + '._nr_dimensions'], operations=["=="], values=[4]) return tree def get_output(self): return [ComplexCoherenceSpectrum] def get_required_memory_size(self, **kwargs): """ Return the required memory to run this algorithm. """ used_shape = self.algorithm.time_series.read_data_shape() input_size = numpy.prod(used_shape) * 8.0 output_size = self.algorithm.result_size(used_shape, self.algorithm.max_freq, self.algorithm.epoch_length, self.algorithm.segment_length, self.algorithm.segment_shift, self.algorithm.time_series.sample_period, self.algorithm.zeropad, self.algorithm.average_segments) return input_size + output_size def get_required_disk_size(self, **kwargs): """ Returns the required disk size to be able to run the adapter (in kB). """ used_shape = self.algorithm.time_series.read_data_shape() return self.algorithm.result_size(used_shape, self.algorithm.max_freq, self.algorithm.epoch_length, self.algorithm.segment_length, self.algorithm.segment_shift, self.algorithm.time_series.sample_period, self.algorithm.zeropad, self.algorithm.average_segments) * TVBSettings.MAGIC_NUMBER / 8 / 2 ** 10 def configure(self, time_series): """ Do any configuration needed before launching and create an instance of the algorithm. """ shape = time_series.read_data_shape() LOG.debug("time_series shape is %s" % (str(shape))) ##-------------------- Fill Algorithm for Analysis -------------------## self.algorithm = NodeComplexCoherence() self.algorithm.time_series = time_series self.memory_factor = 1 def launch(self, time_series): """ Launch algorithm and build results. :returns: the `ComplexCoherenceSpectrum` built with the given time-series """ shape = time_series.read_data_shape() ##------- Prepare a ComplexCoherenceSpectrum object for result -------## spectra = ComplexCoherenceSpectrum(source=time_series, storage_path=self.storage_path) ##------------------- NOTE: Assumes 4D TimeSeries. -------------------## node_slice = [slice(shape[0]), slice(shape[1]), slice(shape[2]), slice(shape[3])] ##---------- Iterate over slices and compose final result ------------## small_ts = TimeSeries(use_storage=False) small_ts.sample_rate = time_series.sample_rate small_ts.data = time_series.read_data_slice(tuple(node_slice)) self.algorithm.time_series = small_ts partial_result = self.algorithm.evaluate() LOG.debug("got partial_result") LOG.debug("partial segment_length is %s" % (str(partial_result.segment_length))) LOG.debug("partial epoch_length is %s" % (str(partial_result.epoch_length))) LOG.debug("partial windowing_function is %s" % (str(partial_result.windowing_function))) #LOG.debug("partial frequency vector is %s" % (str(partial_result.frequency))) spectra.write_data_slice(partial_result) spectra.segment_length = partial_result.segment_length spectra.epoch_length = partial_result.epoch_length spectra.windowing_function = partial_result.windowing_function #spectra.frequency = partial_result.frequency spectra.close_file() return spectra