Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
allowed = ["neuron", "individual", "ind", "pair", "class", "type"]
if colorby not in allowed:
raise ValueError(
f"color by key should be one of {allowed} not {colorby}"
)
if colorby == "type":
color = cs.neurons_metadata.loc[
cs.neurons_metadata.neuron == neuron
]["type_color"].values[0]
color = ImageColor.getrgb(color)
elif (
colorby == "individual" or colorby == "ind" or colorby == "neuron"
):
color = get_random_colors()
else:
raise NotImplementedError
return color
else:
raise ValueError("You need to pass either a neuron, or a soma region or a soma")
else:
self.alleninfo = None
if soma_region is not None:
soma_region = self.scene.get_structure_parent(soma_region)['acronym']
else:
soma_region = "root"
if self.color_by_region:
try:
region_color = self.scene.structure_tree.get_structures_by_acronym([soma_region])[0]['rgb_triplet']
except:
print("could not find default color for region: {}. Using random color instead".format(soma_region))
region_color = get_random_colors(n_colors=1)
axon_color = soma_color = dendrites_color = region_color
return soma_color, axon_color, dendrites_color, soma_region
:param neurons: str, list, dict. File(s) with neurons data or list of rendered neurons.
:param color: default None. Can be:
- None: each neuron is given a random color
- color: rbg, hex etc. If a single color is passed all neurons will have that color
- cmap: str with name of a colormap: neurons are colored based on their sequential order and cmap
- dict: a dictionary specifying a color for soma, dendrites and axon actors, will be the same for all neurons
- list: a list of length = number of neurons with either a single color for each neuron
or a dictionary of colors for each neuron
"""
N = len(neurons)
colors = dict(soma=None, axon=None, dendrites=None,)
# If no color is passed, get random colors
if color is None:
cols = get_random_colors(N)
if not isinstance(cols, list):
cols = [cols]
colors = dict(soma=cols, axon=cols, dendrites=cols,)
else:
if isinstance(color, str):
# Deal with a a cmap being passed
if color in _mapscales_cmaps:
cols = [
colorMap(n, name=color, vmin=-2, vmax=N + 2)
for n in np.arange(N)
]
colors = dict(
soma=cols.copy(), axon=cols.copy(), dendrites=cols.copy(),
)
else:
def _render_neuron_get_params(self, neuron_number, neuron=None, soma_region=None, soma=None):
"""
Makes sure that all the parameters to specify how neurons should be rendered.
:param neuron_number: number of the neuron being rendered
:param neuron: neuron's metadata (Default value = None)
:param soma_region: str with the acronym of the region the soma is in (Default value = None)
:param soma: list with XYZ coordinates of the neuron's soma. (Default value = None)
"""
# Define colors of different components
if not self.color_by_region:
if self.random_color:
if not isinstance(self.random_color, str):
color = get_random_colors(n_colors=1)
else: # random_color is a colormap
color = colorMap(neuron_number, name=self.random_color, vmin=0, vmax=self.n_neurons)
axon_color = soma_color = dendrites_color = color
else:
if self.soma_color is None:
soma_color = get_random_colors(n_colors=1)
if not self.color_neurites:
axon_color = dendrites_color = soma_color = self.soma_color
else:
soma_color = self.soma_color
if self.axon_color is None:
axon_color = soma_color
else:
axon_color = self.axon_color
if self.dendrites_color is None:
:param neuron: neuron's metadata (Default value = None)
:param soma_region: str with the acronym of the region the soma is in (Default value = None)
:param soma: list with XYZ coordinates of the neuron's soma. (Default value = None)
"""
# Define colors of different components
if not self.color_by_region:
if self.random_color:
if not isinstance(self.random_color, str):
color = get_random_colors(n_colors=1)
else: # random_color is a colormap
color = colorMap(neuron_number, name=self.random_color, vmin=0, vmax=self.n_neurons)
axon_color = soma_color = dendrites_color = color
else:
if self.soma_color is None:
soma_color = get_random_colors(n_colors=1)
if not self.color_neurites:
axon_color = dendrites_color = soma_color = self.soma_color
else:
soma_color = self.soma_color
if self.axon_color is None:
axon_color = soma_color
else:
axon_color = self.axon_color
if self.dendrites_color is None:
dendrites_color = soma_color
else:
dendrites_color = self.dendrites_color
# check that the colors make sense
if not check_colors([soma_color, axon_color, dendrites_color]):