brainglobe / brainglobe-heatmap

Rendering anatomical heatmaps with brainrender and matplotlib
https://brainglobe.info
MIT License
34 stars 10 forks source link

Allow for read only brainglobe directories #65

Open leesuyee opened 1 week ago

leesuyee commented 1 week ago

when running brainglobe-heatmap through a jupyter notebook instantiation through code ocean, i am running into this error:

`f = bgh.Heatmap(
    values,
    position=1000,
    orientation="sagittal",  # 'frontal' or 'sagittal', or 'horizontal' or a tuple (x,y,z)
    thickness=1000,
    atlas_name="allen_cord_20um",
    format='2D'
).show()

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
File /opt/conda/lib/python3.10/site-packages/brainrender/atlas.py:26, in Atlas.__init__(self, atlas_name)
     25 try:
---> 26     super().__init__(atlas_name=atlas_name, print_authors=False)
     27 except TypeError:
     28     # The latest version of BGatlas has no print_authors argument

TypeError: BrainGlobeAtlas.__init__() got an unexpected keyword argument 'print_authors'

During handling of the above exception, another exception occurred:

OSError                                   Traceback (most recent call last)
Cell In[23], line 1
----> 1 f = bgh.Heatmap(
      2     values,
      3     position=1000,
      4     orientation="sagittal",  # 'frontal' or 'sagittal', or 'horizontal' or a tuple (x,y,z)
      5     thickness=1000,
      6     atlas_name="allen_cord_20um",
      7     format='2D'
      8 ).show()

File /opt/conda/lib/python3.10/site-packages/brainglobe_heatmap/heatmaps.py:82, in Heatmap.__init__(self, values, position, orientation, hemisphere, title, cmap, vmin, vmax, format, thickness, interactive, zoom, atlas_name, label_regions, **kwargs)
     79 self.label_regions = label_regions
     81 # create a scene
---> 82 self.scene = Scene(
     83     atlas_name=atlas_name,
     84     title=title,
     85     title_color=grey_darker,
     86     **kwargs,
     87 )
     89 # prep colors range
     90 self.prepare_colors(values, cmap, vmin, vmax)

File /opt/conda/lib/python3.10/site-packages/brainrender/scene.py:57, in Scene.__init__(self, root, atlas_name, inset, title, screenshots_folder, plotter, title_color)
     54 self.actors = []  # stores all actors in the scene
     55 self.labels = []  # stores all `labels` actors in scene
---> 57 self.atlas = Atlas(atlas_name=atlas_name)
     59 self.screenshots_folder = (
     60     Path(screenshots_folder)
     61     if screenshots_folder is not None
     62     else Path().cwd()
     63 )
     64 self.screenshots_folder.mkdir(exist_ok=True)

File /opt/conda/lib/python3.10/site-packages/brainrender/atlas.py:29, in Atlas.__init__(self, atlas_name)
     26     super().__init__(atlas_name=atlas_name, print_authors=False)
     27 except TypeError:
     28     # The latest version of BGatlas has no print_authors argument
---> 29     super().__init__(atlas_name=atlas_name)

File /opt/conda/lib/python3.10/site-packages/brainglobe_atlasapi/bg_atlas.py:86, in BrainGlobeAtlas.__init__(self, atlas_name, brainglobe_dir, interm_download_dir, check_latest, config_dir, fn_update)
     84 # Look for this atlas in local brainglobe folder:
     85 if self.local_full_name is None:
---> 86     if self.remote_version is None:
     87         check_internet_connection(raise_error=True)
     88         check_gin_status(raise_error=True)

File /opt/conda/lib/python3.10/site-packages/brainglobe_atlasapi/bg_atlas.py:122, in BrainGlobeAtlas.remote_version(self)
    118 remote_url = self._remote_url_base.format("last_versions.conf")
    120 try:
    121     # Grasp remote version
--> 122     versions_conf = utils.conf_from_url(remote_url)
    123 except requests.ConnectionError:
    124     return None

File /opt/conda/lib/python3.10/site-packages/brainglobe_atlasapi/utils.py:314, in conf_from_url(url)
    311     cache_path.parent.mkdir(parents=True, exist_ok=True)
    313 # Cache the available atlases
--> 314 with open(cache_path, "w") as f_out:
    315     config_obj.write(f_out)
    317 return config_obj

OSError: [Errno 30] Read-only file system: '/data/.brainglobe/last_versions.conf'

i ran into a similar issue when running brainglobe_atlasapi alone. this is due to this recent (commit) in latest_version.conf cache which now writes a file to a directory. in my setup, the directory is read-only so i simply add the check_latest = False parameter here: BrainGlobeAtlas('allen_mouse_10um', check_latest=False). could you add a check_latest variable to the bgh.Heatmap function to bypass writing a file to the directory?

adamltyson commented 1 week ago

Thanks @leesuyee this is a good idea. It will require the same to be done with brainrender first. The relevant issue is here: https://github.com/brainglobe/brainrender/issues/395