brainglobe / brainrender

a python based software for visualization of neuroanatomical and morphological data.
https://brainglobe.info/documentation/brainrender/index.html
BSD 3-Clause "New" or "Revised" License
538 stars 75 forks source link

[Feature] Support multiple file types for screenshots #340

Closed IgorTatarnikov closed 4 months ago

IgorTatarnikov commented 4 months ago

Is your feature request related to a problem? Please describe. Currently screenshots are always saved as .png. It would be nice to allow users to save to different file formats.

Describe the solution you'd like Take into consideration the file name suffix passed to the screenshot function and save the appropriate file type. The file types currently supported by vedo are png, svg, jpg, pdf and eps.

Additional context image.sc post about this issue

imagesc-bot commented 4 months ago

This issue has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/screenshot-in-other-formats-than-png/95370/2

abisi commented 4 months ago

Thanks for doing this so quickly! I pulled the latest version but had package version errors I could not fully solve. I then proceeded to delete the environment and made a fresh one, pip install brainrender but I still encounter some errors:

Any idea what could be the reason?

Thanks! Axel

┌───────────────────── Traceback (most recent call last) ─────────────────────┐
│ C:\Users\bisi\Github\brainrender\examples\multi_mouse_probe_tracks.py:10 in │
│ <module>                                                                    │
│                                                                             │
│     7 import numpy as np                                                    │
│     8 import argparse                                                       │
│     9                                                                       │
│ >  10 import brainrender                                                    │
│    11 from brainrender import Scene                                         │
│    12 from brainrender.actors import Points                                 │
│    13                                                                       │
│                                                                             │
│ C:\Users\bisi\Github\brainrender\brainrender\__init__.py:15 in <module>     │
│                                                                             │
│   12 except ImportError:                                                    │
│   13 │   pass  # fails in notebooks                                         │
│   14                                                                        │
│ > 15 from brainrender.scene import Scene                                    │
│   16 import brainrender.actors                                              │
│   17 from brainrender.video import VideoMaker, Animation                    │
│   18 from brainrender.atlas import Atlas                                    │
│                                                                             │
│ C:\Users\bisi\Github\brainrender\brainrender\scene.py:23 in <module>        │
│                                                                             │
│    20 from brainrender._jupyter import JupyterMixIn, not_on_jupyter         │
│    21 from brainrender._utils import listify, return_list_smart             │
│    22 from brainrender.actor import Actor                                   │
│ >  23 from brainrender.actors import Volume                                 │
│    24 from brainrender.atlas import Atlas                                   │
│    25 from brainrender.render import Render                                 │
│    26                                                                       │
│                                                                             │
│ C:\Users\bisi\Github\brainrender\brainrender\actors\__init__.py:3 in        │
│ <module>                                                                    │
│                                                                             │
│   1 from brainrender.actors.points import Points, Point, PointsDensity      │
│   2 from brainrender.actors.ruler import ruler, ruler_from_surface          │
│ > 3 from brainrender.actors.neurons import Neuron, make_neurons             │
│   4 from brainrender.actors.cylinder import Cylinder                        │
│   5 from brainrender.actors.volume import Volume                            │
│   6 from brainrender.actors.streamlines import Streamlines                  │
│                                                                             │
│ C:\Users\bisi\Github\brainrender\brainrender\actors\neurons.py:4 in         │
│ <module>                                                                    │
│                                                                             │
│     1 from pathlib import Path                                              │
│     2                                                                       │
│     3 from loguru import logger                                             │
│ >   4 from morphapi.morphology.morphology import Neuron as MorphoNeuron     │
│     5 from pyinspect.utils import _class_name                               │
│     6 from vedo import Mesh                                                 │
│     7                                                                       │
│                                                                             │
│ C:\Users\bisi\AppData\Local\anaconda3\Lib\site-packages\morphapi\morphology │
│ \morphology.py:5 in <module>                                                │
│                                                                             │
│     2 from collections import namedtuple                                    │
│     3 from pathlib import Path                                              │
│     4                                                                       │
│ >   5 import neurom as nm                                                   │
│     6 from neurom.core.dataformat import COLS                               │
│     7 from vedo import merge                                                │
│     8 from vedo.colors import color_map                                     │
│                                                                             │
│ C:\Users\bisi\AppData\Local\anaconda3\Lib\site-packages\neurom\__init__.py: │
│ 58 in <module>                                                              │
│                                                                             │
│   55 │   >>> mapping = lambda n : len(n.points)                             │
│   56 │   >>> n_points = [n for n in nm.iter_neurites(pop, mapping, filter)] │
│   57 """                                                                    │
│ > 58 from neurom.core.dataformat import COLS                                │
│   59 from neurom.core.types import NeuriteType, NeuriteIter, NEURITES as NE │
│   60 from neurom.core.morphology import graft_morphology, iter_neurites, it │
│   61                                                                        │
│                                                                             │
│ C:\Users\bisi\AppData\Local\anaconda3\Lib\site-packages\neurom\core\__init_ │
│ _.py:32 in <module>                                                         │
│                                                                             │
│   29 """Core functionality and data types of NeuroM."""                     │
│   30                                                                        │
│   31 # those imports here for backward compatibility                        │
│ > 32 from neurom.core.soma import Soma                                      │
│   33 from neurom.core.morphology import Section, Neurite, Morphology, Neuro │
│   34 from neurom.core.population import Population                          │
│   35                                                                        │
│                                                                             │
│ C:\Users\bisi\AppData\Local\anaconda3\Lib\site-packages\neurom\core\soma.py │
│ :34 in <module>                                                             │
│                                                                             │
│    31 import warnings                                                       │
│    32                                                                       │
│    33 import numpy as np                                                    │
│ >  34 from morphio import SomaError, SomaType                               │
│    35 from neurom import morphmath                                          │
│    36 from neurom.core.dataformat import COLS                               │
│    37                                                                       │
│                                                                             │
│ C:\Users\bisi\AppData\Local\anaconda3\Lib\site-packages\morphio\__init__.py │
│ :10 in <module>                                                             │
│                                                                             │
│    7 │   # and MorphIO doesn't need to build hdf5                           │
│    8 │   import h5py as _h5py                                               │
│    9 │   if (1, 14) != _h5py.version.hdf5_version_tuple[:2]:                │
│ > 10 │   │   raise RuntimeError(f'HDF5 library version mismatch. 1.14.x !=  │
│   11 │   del _h5py                                                          │
│   12                                                                        │
│   13                                                                        │
└─────────────────────────────────────────────────────────────────────────────┘
RuntimeError: HDF5 library version mismatch. 1.14.x != 1.12.1
ERROR conda.cli.main_run:execute(49): `conda run python C:\Users\bisi\Github\brainrender\examples\multi_mouse_probe_tracks.py` failed. (See above for error)
adamltyson commented 4 months ago

Before installing brainrender in a fresh environment, could you try conda install hdf5 -c conda-forge?

@IgorTatarnikov @alessandrofelder any reason not to release a new version of brainrender with these changes today?

IgorTatarnikov commented 4 months ago

I don't see why not!

abisi commented 4 months ago

@adamltyson Thanks, this worked along with installing pyopenxl too. The code runs but eps and svg files are zipped (like in the test_screenshot function) but I am not sure whether this is the intended feature?

Thanks again, Axel

adamltyson commented 4 months ago

The code runs but eps and svg files are zipped (like in the test_screenshot function) but I am not sure whether this is the intended feature?

The zipped export is by vtk (which is called by vedo, which is called by brainrender). If it causes issues we could add some logic in brainrender to unzip after generation. I suspect there are good reasons why they are zipped in the first place though.

IgorTatarnikov commented 4 months ago

I dug into this a bit just now, adding a call to CompressOff somwhere in here solves the zipped issue.

Not sure if it's easier to add some logic to brainrender or open a PR to vedo.

adamltyson commented 4 months ago

Might be worth opening an issue on vedo and seeing what Marco thinks?