Esempio n. 1
0
    def _cache_neuron(self, neuron_actors, neuron_name, params):
        """
		Save a loaded neuron

		:param neuron_actors: list of neuron's actors
		:param neuron_name: name of the neuron

		"""
        if not neuron_name or neuron_name is None: return

        # Create/update entry in metadata
        self.cache_metadata[neuron_name] = params
        save_json(self.morphology_cache_metadata,
                  self.cache_metadata,
                  append=True)
        self.cache_metadata = load_json(self.morphology_cache_metadata)

        for neurite, actor in neuron_actors.items():
            if actor is None: continue
            fl = os.path.join(self.morphology_cache,
                              neuron_name + "_" + neurite + ".vtk")
            if isinstance(actor, list):
                if not actor: continue
                else:
                    raise ValueError(
                        "Something went wrong while saving the actor")
            actor.write(fl)
Esempio n. 2
0
    def __init__(self, base_dir=None, **kwargs):
        """
        Parses a YAML file to get data folders paths. Stores paths to a number of folders used throughtout brainrender. 
        Other classes (e.g. brainrender.Scene) subclass Paths.
        
        :param base_dir: str with path to directory to use to save data. If none the user's base directiry is used. 
        :param kwargs: use the name of a folder as key and a path as argument to specify the path of individual subfolders
        """
        # Get and make base directory
        if base_dir is None:
            user_dir = os.path.expanduser("~")
            if not os.path.isdir(user_dir):
                raise FileExistsError(
                    "Could not find user base folder (to save brainrender data). Platform: {}"
                    .format(sys.platform))
            self.base_dir = os.path.join(user_dir, ".brainrender")
        else:
            self.base_dir = base_dir

        if not os.path.isdir(self.base_dir):
            os.mkdir(self.base_dir)

        for fld_name in self._folders:
            # Check if user provided a path for this folder, otherwise use default
            fld_path = kwargs.pop(fld_name, default_paths[fld_name])

            # Make complete path and save it as an attribute of this class
            path = os.path.join(self.base_dir, fld_path)

            # Create folder if it doesn't exist
            if not os.path.isdir(path):
                print("Creating folder at: {}".format(path))
                os.makedirs(path)
            self.__setattr__(fld_name, path)

        # Make a file for morphology cache metadata
        self.morphology_cache_metadata = os.path.join(self.morphology_cache,
                                                      'metadata.json')
        if not os.path.isfile(self.morphology_cache_metadata):
            save_json(self.morphology_cache_metadata, {})