예제 #1
0
 def _assert_array_indices(self, slice_tuple):
     if is_integer(slice_tuple) or isinstance(slice_tuple, string_types):
         return ([slice_tuple],)
     else:
         if isinstance(slice_tuple, slice):
             slice_tuple = (slice_tuple,)
         slice_list = []
         for slc in slice_tuple:
             if is_integer(slc) or isinstance(slc, string_types):
                 slice_list.append([slc])
             else:
                 slice_list.append(slc)
         return tuple(slice_list)
예제 #2
0
 def configure(self, tvb_model):
     self.tvb_model = tvb_model
     # Organize the different kinds of interfaces and set the TVB region model of the TVB Simulator
     self.spikeNet_to_tvb_params = OrderedDict()
     # self.spikeNet_to_tvb_params_interfaces_ids = []   # deprecated
     self.spikeNet_to_tvb_sv_interfaces_ids = []
     for interface_id, interface in enumerate(
             self.spikeNet_to_tvb_interfaces):
         if is_integer(interface.tvb_sv_id) and interface.tvb_sv_id >= 0:
             self.spikeNet_to_tvb_sv_interfaces_ids.append(interface_id)
         else:
             # self.spikeNet_to_tvb_params_interfaces_ids.append(interface_id)  # deprecated
             raise ValueError(
                 "tvb_sv_id=%s doesn't correspond "
                 "to the index of a TVB state variable for interface %s!\n"
                 % (str(interface.tvb_sv_id), str(interface)))
         # Even if the target in TVB is a state variable,
         # we are going to create a TVB parameter with the same name
         if interface.name not in list(self.spikeNet_to_tvb_params.keys()):
             self.spikeNet_to_tvb_params[
                 interface.name] = interface.nodes_ids
         else:
             self.spikeNet_to_tvb_params[
                 interface.name] += interface.nodes_ids
         self.spikeNet_to_tvb_params[interface.name] = \
             np.unique(self.spikeNet_to_tvb_params[interface.name]).tolist()
예제 #3
0
 def get_dimension_index(self, dim_name_or_index):
     if is_integer(dim_name_or_index):
         return self._assert_index(dim_name_or_index)
     elif isinstance(dim_name_or_index, string_types):
         return self._assert_index(
             self.labels_ordering.index(dim_name_or_index))
     else:
         raise ValueError(
             "dim_name_or_index is neither a string nor an integer!")
예제 #4
0
 def __getitem__(self, items):
     """If the argument is a sequence, a new SpikingRegionNode instance is returned.
        If the argument is an integer index or a string label index,
        the corresponding SpikingPopulation is returned.
     """
     if isinstance(items, string_types) or is_integer(items):
         return super(SpikingRegionNode, self).__getitem__(items)
     return SpikingRegionNode(label=self.label,
                              input_nodes=super(SpikingRegionNode,
                                                self).__getitem__(items))
예제 #5
0
 def _index_or_label_or_slice(self, inputs):
     inputs = ensure_list(inputs)
     if numpy.all([is_integer(inp) for inp in inputs]):
         return "index"
     elif numpy.all([isinstance(inp, string_types) for inp in inputs]):
         return "label"
     elif numpy.all([isinstance(inp, slice) for inp in inputs]):
         return "slice"
     else:
         raise ValueError(
             "input %s is not of type integer, string or slice!" %
             str(inputs))
예제 #6
0
def select_greater_values_array_inds(values, threshold=None, percentile=None, nvals=None, verbose=False):
    if threshold is None and percentile is not None:
        threshold = np.percentile(values, percentile)
    if threshold is not None:
        return np.where(values > threshold)[0]
    else:
        if is_integer(nvals):
            return get_greater_values_array_inds(values, nvals)
        if verbose:
            logger.warning("Switching to curve elbow point method since threshold=" + str(threshold))
        elbow_point = curve_elbow_point(values)
        return get_greater_values_array_inds(values, elbow_point)
예제 #7
0
 def _assert_neurons(self, neurons=None):
     """Method to assert an input set of neurons either as:
         - the present instance of ANNarchy.Population class
         - a ANNarchy.PopulationView instance of the present instance of ANNarchy.Population class
         - a collection (tuple, list, numpy.ndarray) of global indices (i.e., tuples of (population_inds, neuron_ind),
           of the present instance of ANNarchy.Population class, or of local indices thereof,
         Default input = None, which corresponds to the present instance of ANNarchy.Population class.
     """
     if neurons is None:
         neurons = self._population
     else:
         self._assert_annarchy()
         if isinstance(neurons, self.annarchy_instance.Population):
             # Assert that we refer to this object's Population
             assert self._population == neurons
         elif isinstance(neurons, self.annarchy_instance.PopulationView):
             # Assert that we refer to a view of this object's Population
             assert self._population == neurons.population
         else:
             # Let's check if these are global or local indices of neurons...
             local_inds = []
             for neuron in ensure_list(neurons):
                 if isinstance(neuron, (tuple, list)):
                     # If neurons are global_ids formed as tuples of (population_ind, neuron_ind)...
                     if neuron[0] == self.population_ind:
                         # ... confirm that the population_ind is correct and get the neuron_ind
                         local_inds.append(neuron[1])
                         # If neurons are just local inds, gather them...
                     elif is_integer(neuron):
                         local_inds.append(neuron)
                     else:
                         raise ValueError(
                             "neurons %s\nis neither an instance of ANNarchy.Population, "
                             "nor of  ANNarchy.PopulationView,\n"
                             "nor is it a collection (tuple, list, or numpy.ndarray) "
                             "of global (tuple of (population_inds, neuron_ind) or local indices of neurons!"
                         )
                     # Return a Population View:
                     neurons = self._population[neurons]
     return neurons
예제 #8
0
 def __getitem__(self, items):
     if isinstance(items, string_types) or is_integer(items):
         return super(SpikingBrain, self).__getitem__(items)
     return SpikingBrain(input_brain=super(SpikingBrain, self).__getitem__(items))