How to use the brainrender.colors.check_colors function in brainrender

To help you get started, we’ve selected a few brainrender examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github BrancoLab / BrainRender / tests / test_utils.py View on Github external
getColor("#ffffff")
    getColor(7)
    getColor(-7)

    getColorName("#ffffff")

    cols = colorMap([0, 1, 2])
    if not isinstance(cols, (list, np.ndarray)):
        raise ValueError
    if len(cols) != 3:
        raise ValueError

    c = colorMap(3, vmin=-3, vmax=4)

    check_colors(cols)
    check_colors(c)
github BrancoLab / BrainRender / tests / test_utils.py View on Github external
getColor("k")
    getColor("#ffffff")
    getColor(7)
    getColor(-7)

    getColorName("#ffffff")

    cols = colorMap([0, 1, 2])
    if not isinstance(cols, (list, np.ndarray)):
        raise ValueError
    if len(cols) != 3:
        raise ValueError

    c = colorMap(3, vmin=-3, vmax=4)

    check_colors(cols)
    check_colors(c)
github BrancoLab / BrainRender / brainrender / atlases / brainglobe.py View on Github external
brain_regions = [brain_regions]

        # check the colors input is correct
        if colors is not None:
            if isinstance(colors, (list, tuple)):
                if not len(colors) == len(brain_regions):
                    raise ValueError(
                        "when passing colors as a list, the number of colors must match the number of brain regions"
                    )
                for col in colors:
                    if not check_colors(col):
                        raise ValueError(
                            "Invalide colors in input: {}".format(col)
                        )
            else:
                if not check_colors(colors):
                    raise ValueError(
                        "Invalide colors in input: {}".format(colors)
                    )
                colors = [colors for i in range(len(brain_regions))]

        # loop over all brain regions
        actors = {}
        for i, region in enumerate(brain_regions):
            if region in self.ignore_regions:
                continue
            if verbose:
                print("Rendering: ({})".format(region))

            # get the structure and check if we need to download the object file
            if region not in self.lookup.acronym.values:
                print(
github BrancoLab / BrainRender / brainrender / ABA / aba_utils.py View on Github external
:param others_color: str, color for not VIP data (Default value = "white")
    """
    # check coloring mode used and prepare a list COLORS to use for coloring stuff
    if color_by == "manual":
        # check color argument
        if color is None:
            color = brainrender.TRACT_DEFAULT_COLOR
            COLORS = [color for i in range(len(tractography))]
        elif isinstance(color, list):
            if not len(color) == len(tractography):
                raise ValueError(
                    "If a list of colors is passed, it must have the same number of items as the number of tractography traces"
                )
            else:
                for col in color:
                    if not check_colors(col):
                        raise ValueError(
                            "Color variable passed to tractography is invalid: {}".format(
                                col
                            )
                        )

                COLORS = color
        else:
            if not check_colors(color):
                raise ValueError(
                    "Color variable passed to tractography is invalid: {}".format(
                        color
                    )
                )
            else:
                COLORS = [color for i in range(len(tractography))]
github BrancoLab / BrainRender / brainrender / Utils / parsers / mouselight.py View on Github external
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]):
				raise ValueError("The colors chosen are not valid: soma - {}, dendrites {}, axon {}".format(soma_color, dendrites_color, axon_color))

			# check if we have lists of colors or single colors
			if isinstance(soma_color, list):
				if isinstance(soma_color[0], str) or isinstance(soma_color[0], list):
					soma_color = soma_color[neuron_number]
			if isinstance(dendrites_color, list):
				if isinstance(dendrites_color[0], str) or isinstance(dendrites_color[0], list):
					dendrites_color = dendrites_color[neuron_number]
			if isinstance(axon_color, list):
				if isinstance(axon_color[0], str) or isinstance(axon_color[0], list):
					axon_color = axon_color[neuron_number]                

		# get allen info: it containes the allenID of each brain region
		# each sample has the corresponding allen ID so we can recontruct in which brain region it is
		if neuron is not None:
github BrancoLab / BrainRender / brainrender / atlases / base.py View on Github external
brain_regions = [brain_regions]

        # check the colors input is correct
        if colors is not None:
            if isinstance(colors, (list, tuple)):
                if not len(colors) == len(brain_regions):
                    raise ValueError(
                        "when passing colors as a list, the number of colors must match the number of brain regions"
                    )
                for col in colors:
                    if not check_colors(col):
                        raise ValueError(
                            "Invalide colors in input: {}".format(col)
                        )
            else:
                if not check_colors(colors):
                    raise ValueError(
                        "Invalide colors in input: {}".format(colors)
                    )
                colors = [colors for i in range(len(brain_regions))]

        # loop over all brain regions
        actors = {}
        for i, region in enumerate(brain_regions):
            if verbose:
                print("Rendering: ({})".format(region))

            # get the structure and check if we need to download the object file
            if region not in self.lookup_df.acronym.values:
                print(
                    f"The region {region} doesn't seem to belong to the atlas being used: {self.atlas_name}. Skipping"
                )
github BrancoLab / BrainRender / brainrender / atlases / brainglobe.py View on Github external
if alpha is None:
            alpha = brainrender.DEFAULT_STRUCTURE_ALPHA

        # check that we have a list
        if not isinstance(brain_regions, list):
            brain_regions = [brain_regions]

        # check the colors input is correct
        if colors is not None:
            if isinstance(colors, (list, tuple)):
                if not len(colors) == len(brain_regions):
                    raise ValueError(
                        "when passing colors as a list, the number of colors must match the number of brain regions"
                    )
                for col in colors:
                    if not check_colors(col):
                        raise ValueError(
                            "Invalide colors in input: {}".format(col)
                        )
            else:
                if not check_colors(colors):
                    raise ValueError(
                        "Invalide colors in input: {}".format(colors)
                    )
                colors = [colors for i in range(len(brain_regions))]

        # loop over all brain regions
        actors = {}
        for i, region in enumerate(brain_regions):
            if region in self.ignore_regions:
                continue
            if verbose:
github BrancoLab / BrainRender / brainrender / atlases / atlas.py View on Github external
if alpha is None:
            alpha = brainrender.DEFAULT_STRUCTURE_ALPHA

        # check that we have a list
        if not isinstance(brain_regions, list):
            brain_regions = [brain_regions]

        # check the colors input is correct
        if colors is not None:
            if isinstance(colors, (list, tuple)):
                if not len(colors) == len(brain_regions):
                    raise ValueError(
                        "when passing colors as a list, the number of colors must match the number of brain regions"
                    )
                for col in colors:
                    if not check_colors(col):
                        raise ValueError(
                            "Invalide colors in input: {}".format(col)
                        )
            else:
                if not check_colors(colors):
                    raise ValueError(
                        "Invalide colors in input: {}".format(colors)
                    )
                colors = [colors for i in range(len(brain_regions))]

        # loop over all brain regions
        actors = {}
        for i, region in enumerate(brain_regions):
            if verbose:
                print("Rendering: ({})".format(region))
github BrancoLab / BrainRender / brainrender / atlases / atlas.py View on Github external
brain_regions = [brain_regions]

        # check the colors input is correct
        if colors is not None:
            if isinstance(colors, (list, tuple)):
                if not len(colors) == len(brain_regions):
                    raise ValueError(
                        "when passing colors as a list, the number of colors must match the number of brain regions"
                    )
                for col in colors:
                    if not check_colors(col):
                        raise ValueError(
                            "Invalide colors in input: {}".format(col)
                        )
            else:
                if not check_colors(colors):
                    raise ValueError(
                        "Invalide colors in input: {}".format(colors)
                    )
                colors = [colors for i in range(len(brain_regions))]

        # loop over all brain regions
        actors = {}
        for i, region in enumerate(brain_regions):
            if verbose:
                print("Rendering: ({})".format(region))

            # get the structure and check if we need to download the object file
            if region not in self.lookup_df.acronym.values:
                print(
                    f"The region {region} doesn't seem to belong to the atlas being used: {self.atlas_name}. Skipping"
                )
github BrancoLab / BrainRender / brainrender / ABA / aba_utils.py View on Github external
)

                COLORS = color
        else:
            if not check_colors(color):
                raise ValueError(
                    "Color variable passed to tractography is invalid: {}".format(
                        color
                    )
                )
            else:
                COLORS = [color for i in range(len(tractography))]

    elif color_by == "target_region":
        if VIP_color is not None:
            if not check_colors(VIP_color) or not check_colors(others_color):
                raise ValueError("Invalid VIP or other color passed")
            try:
                if include_all_inj_regions:
                    COLORS = [
                        VIP_color
                        if is_any_item_in_list(
                            [
                                x["abbreviation"]
                                for x in t["injection-structures"]
                            ],
                            VIP_regions,
                        )
                        else others_color
                        for t in tractography
                    ]
                else: