How to use the brainrender.Utils.paths_manager.Paths 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 / brainrender / Utils / AllenMorphologyAPI / AllenMorphology.py View on Github external
from vtkplotter import shapes, load, merge

from allensdk.core.cell_types_cache import CellTypesCache
from allensdk.api.queries.cell_types_api import CellTypesApi
from allensdk.core.swc import Morphology


from brainrender.Utils.paths_manager import Paths
from brainrender.Utils.data_io import connected_to_internet
from brainrender.Utils.data_manipulation import get_coords
from brainrender.scene import Scene
from brainrender.Utils.data_io import listdir


class AllenMorphology(Paths):
	""" Handles the download and visualisation of neuronal morphology data from the Allen database. """

	def __init__(self, *args, scene_kwargs={},  **kwargs):
		"""
			Initialise API interaction and fetch metadata of neurons in the Allen Database. 
		"""
		if not connected_to_internet():
			raise ConnectionError("You will need to be connected to the internet to use the AllenMorphology class")

		Paths.__init__(self, *args, **kwargs)
		self.scene = Scene(add_root=False, display_inset=False, **scene_kwargs)

		# Create a Cache for the Cell Types Cache API
		self.ctc = CellTypesCache(manifest_file=os.path.join(self.morphology_allen, 'manifest.json'))

		# Get a list of cell metadata for neurons with reconstructions, download if necessary
github BrancoLab / BrainRender / brainrender / Utils / parsers / mouselight.py View on Github external
import pandas as pd
import numpy as np

import allensdk.core.swc as allen_swc

from brainrender.Utils.data_io import load_json, listdir, save_json
from brainrender.Utils.data_manipulation import get_coords
from brainrender.Utils.actors_funcs import mirror_actor_at_point
from brainrender.colors import get_random_colors, colorMap, check_colors
from brainrender import DEFAULT_NEURITE_RADIUS, USE_MORPHOLOGY_CACHE, SOMA_RADIUS, DECIMATE_NEURONS, SMOOTH_NEURONS
from brainrender import NEURON_RESOLUTION

from brainrender.Utils.paths_manager import Paths


class NeuronsParser(Paths):
	""" 
		Takes care of parsing neuron's morphology data from different formats (.json, .swc) and rendering them as vtk actors. 
		Supports various ways to specify how things should be rendered and classes to edit/modify rendered neurons. 
		Also saves and loads the results of parsing. 
	"""
	def __init__(self, scene=None, 
				render_neurites = True, mirror=False, 
				neurite_radius=None, color_by_region=False, force_to_hemisphere=None, base_dir=None,
				render_dendrites = True, render_axons = True,
				color_neurites=True, axon_color=None, soma_color=None, dendrites_color=None, random_color=False, **kwargs):
		"""
		Set up variables used for rendering

		:param scene: instance of class brainrender.Scene (Default value = None)
		:param render_neurites: Bool, If true, axons and dendrites are rendered (Default value = True)
		:param render_dendrites: Bool, if render neurites is true and this is false dendrites are not rendred
github BrancoLab / BrainRender / brainrender / Utils / MouseLightAPI / mouselight_api.py View on Github external
import sys
sys.path.append('./')

import json
import os 
from tqdm import tqdm

from brainrender.Utils.webqueries import post_mouselight, mouselight_base_url
from brainrender.Utils.paths_manager import Paths


"""
	These functions take care of downloading and parsing neurons reconstrucitions from: http://ml-neuronbrowser.janelia.org/
	by sending requests to: http://ml-neuronbrowser.janelia.org/tracings/tracings. 
"""
class MouseLightAPI(Paths):
	def __init__(self, base_dir=None, **kwargs):
		"""
			Handles the download of neurons morphology data from the Mouse Light project

			:param base_dir: path to directory to use for saving data (default value None)
			:param kwargs: can be used to pass path to individual data folders. See brainrender/Utils/paths_manager.py
		"""
		Paths.__init__(self, base_dir=base_dir, **kwargs)

	@staticmethod
	def make_json(neuron, file_path,  axon_tracing=None, dendrite_tracing=None):
		"""
		Creates a .json file with the neuron's data that can be read by the mouselight parser.

		:param neuron: dict with neuron's data
		:param file_path: str, path where to save the json file
github BrancoLab / BrainRender / brainrender / ABA / volumetric / VolumetricConnectomeAPI.py View on Github external
add_root=True,
        use_cache=True,
        scene_kwargs={},
        **kwargs,
    ):
        """
            Initialise the class instance to get a few useful paths and variables. 

            :param base_dir: str, path to base directory in which all of brainrender data are stored. 
                    Pass only if you want to use a different one from what's default.
            :param add_root: bool, if True the root mesh is added to the rendered scene
            :param use_cache: if true data are loaded from a cache to speed things up.
                    Useful to set it to false to help debugging.
            :param scene_kwargs: dict, params passed to the instance of Scene associated with this class
        """
        Paths.__init__(self, base_dir=base_dir, **kwargs)

        # Get MCM cache
        cache_path = (
            Path(self.mouse_connectivity_volumetric)
            / "voxel_model_manifest.json"
        )

        if not cache_path.exists():
            if not connected_to_internet():
                raise ValueError(
                    "The first time you use this class it will need to download some data, but it seems that you're not connected to the internet."
                )
            print(
                "Downloading volumetric data. This will take several minutes but it only needs to be done once."
            )
github BrancoLab / BrainRender / brainrender / atlases / custom_atlases / insects_brains_db.py View on Github external
The InsectBrainDB.org is primarily curated by Stanley Heinze

    The insectbraindb.org has a terms of use, which provides guidance on how best to credit data from these repositories. 

    The insectbraindb.org is primarily curated by Dr. Stanley Heinze, and 
    was buily by Kevin Tedore, and has several significant supporters, including the ERC.




    Check Examples/custom_atlases/insects_brains.py for more details.

"""


class IBDB(Paths):

    atlas_name = "InsectBrains"
    mesh_format = "obj"

    _base_url = "https://insectbraindb.org"
    _url_paths = dict(
        brain_info="archive/species/most_current_permitted/?species_id=",
        species_info="api/species/min/",
        data="https://s3.eu-central-1.amazonaws.com/ibdb-file-storage",
        structures_tree="https://insectbraindb.org/api/structures/list_hierarchy",
    )

    default_camera = dict(
        position=[1035.862, 420.237, -3058.244],
        focal=[1253.28, 759.97, 428.418],
        viewup=[0.03, -0.995, 0.095],
github BrancoLab / BrainRender / brainrender / atlases / celegans.py View on Github external
Check https://www.biorxiv.org/content/10.1101/2020.04.30.066209v1 
for more details.


Note: currently there is no support to let users download the
connectome data programmatically. If you need the data please
get in touch. We are working to improve this.


check example file at Examples/custom_atlases/celegans_connectome.py
for more details

"""


class Celegans(Paths):
    atlas_name = "Celegans"
    mesh_format = "obj"  #  or obj, stl etc..

    pre_synapses_color = "darkgray"
    post_synapses_color = "blackboard"
    synapses_radius = 0.2

    skeleton_radius = 0.05

    default_camera = dict(
        position=[-15.686, 65.978, 32.901],
        focal=[13.312, 20.159, -9.482],
        viewup=[-0.896, -0.412, -0.168],
        distance=68.823,
        clipping=[26.154, 122.7],
    )
github BrancoLab / BrainRender / brainrender / atlases / atlas.py View on Github external
import numpy as np
from bg_atlasapi.bg_atlas import BrainGlobeAtlas

import brainrender
from brainrender.Utils.paths_manager import Paths
from brainrender.atlases.aba import ABA
from brainrender.Utils.data_io import load_mesh_from_file
from brainrender.Utils import actors_funcs
from brainrender.Utils.data_manipulation import (
    return_list_smart,
    return_dict_smart,
)
from brainrender.colors import check_colors


class Atlas(BrainGlobeAtlas, Paths, ABA):
    default_camera = None

    def __init__(self, atlas_name, *args, base_dir=None, **kwargs):
        # Create brainglobe atlas
        BrainGlobeAtlas.__init__(self, *args, atlas_name=atlas_name, **kwargs)

        # Add brainrender paths
        Paths.__init__(self, base_dir=base_dir, **kwargs)
        self.meshes_folder = (
            None  # where the .obj mesh for each region is saved
        )

        # If it's a mouse atlas, add extra functionality
        if "Mus musculus" == self.metadata["species"]:
            ABA.__init__(self)