nisnap

Display segmentation results over MRI scans in Jupyter notebooks.

https://github.com/xgrg/nisnap

Science Score: 36.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
    Found 3 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.4%) to scientific vocabulary

Keywords

jupyter-notebook neuroimaging quality-control

Keywords from Contributors

transformation
Last synced: 5 months ago · JSON representation

Repository

Display segmentation results over MRI scans in Jupyter notebooks.

Basic Info
Statistics
  • Stars: 9
  • Watchers: 2
  • Forks: 6
  • Open Issues: 2
  • Releases: 2
Topics
jupyter-notebook neuroimaging quality-control
Created over 5 years ago · Last pushed about 2 years ago
Metadata Files
Readme License

README.md

nisnap

main coverage report downloads python versions pypi version DOI

Create snapshots of segmentation maps produced by neuroimaging software. Inspired by tools like nilearn, visualqc, fmriprep and others.

Usage

From a Terminal:

```sh nisnap c1.nii.gz c2.nii.gz c3.nii.gz --bg /tmp/raw.nii.gz --opacity 50 -o /tmp/snapshot.gif

nisnap labels.nii.gz --bg raw.nii.gz --opacity 50 --axes x --contours -o /tmp/snapshot.gif ```

```sh Arguments:

files segmentation map(s) to create snapshots from

optional arguments: --bg BG background image on which segmentations will be plotted. --axes AXES choose the direction of the cuts (among 'x', 'y', or 'z') --opacity OPACITY opacity (in %) of the segmentation maps when plotted over a background image. Only used if a background image is provided. --contours if True, segmentations will be rendered as contoured regions. If False, will be rendered as superimposed masks. -o OUTPUT, --output OUTPUT snapshot will be stored in this file. If extension is .gif, snapshot will be rendered as an animation. --config CONFIG [XNAT mode] XNAT configuration file --nobg [XNAT mode] no background image. Plots segmentation maps only. -e EXPERIMENT, --experiment EXPERIMENT [XNAT mode] ID of the experiment to create snapshots from. --resource RESOURCE [XNAT mode] name of the resource to download --cache [XNAT mode] skip downloads (e.g. if running for a second time --disable_warnings --verbose ```

From IPython/Jupyter Notebook:

Example:

python import nisnap filepaths = ['c1.nii.gz', 'c2.nii.gz', 'c3.nii.gz'] bg = 'source.nii.gz' nisnap.plot_segment(filepaths, bg=bg, opacity=30, axes='x', animated=True)

Reference:

```python def plot_segment(filepaths, axes='xyz', bg=None, opacity=30, slices=None, animated=False, savefig=None, contours=False, rowsize=None, figsize=None, width=2000): """Plots a set of segmentation maps/masks.

Parameters
----------
filepaths: a list of str
    Paths to segmentation maps (between 1 and 3). Must be of same dimensions
    and in same reference space.

axes: string, or a tuple of strings
    Choose the direction of the cuts (among 'x', 'y', or 'z')

bg: None or str
    Path to the background image that the masks will be plotted on top of.
    If nothing is specified, the segmentation maps/masks will be plotted only.
    The opacity (in %) of the segmentation maps when plotted over a background
    image. Only used if a background image is provided. Default: 10

slices: None, or a tuple of floats
    The indexes of the slices that will be rendered. If None is given, the
    slices are selected automatically.

animated: boolean, optional
    If True, the snapshot will be rendered as an animated GIF.
    If False, the snapshot will be rendered as a static PNG image. Default:
    False

savefig: string, optional
    Filepath where the resulting snapshot will be created. If None is given,
    a temporary file will be created and/or the result will be displayed
    inline in a Jupyter Notebook.

contours: boolean, optional
    If True, segmentations will be rendered as contoured regions. If False,
    will be rendered as superimposed masks. Default: False

rowsize: None, or int, or dict
    Set the number of slices per row in the final compiled figure.
    Default: {'x': 9, 'y': 9, 'z': 6}

figsize: None, or a 2-uple of floats, or dict
    Sets the dimensions of one row of slices.
    Default: {'x': (37, 3), 'y': (40, 3), 'z': (18, 3)}

width: int, optional
    Width (in px) of the final compiled figure. Default: 2000.


See Also
--------
xnat.plot_segment : To plot segmentation maps directly providing their
    experiment_id on an XNAT instance
"""

```

Using XNAT

From a Terminal:

sh nisnap --config .xnat.cfg -e EXPERIMENT_ID --resource ASHS --axes A --opacity 50 -o /tmp/test.gif

From IPython/Jupyter Notebook:

Example:

python from nisnap import xnat xnat.plot_segment(config='/home/grg/.xnat.cfg', experiment_id='BBRC_E000', raw=True, opacity=30, axes='x', slices=range(100,120,2), figsize=(15,5), animated=True)

Reference:

```python def plotsegment(config, experimentid, savefig=None, slices=None, resourcename='SPM12SEGMENTT2T1COREG', axes='xyz', raw=True, opacity=10, animated=False, rowsize=None, figsize=None, width=2000, contours=False, cache=False): """Download a given experiment/resource from an XNAT instance and create snapshots of this resource along a selected set of slices.

Parameters
----------
config: string
    Configuration file to the XNAT instance.

experiment_id : string
    ID of the experiment from which to download the segmentation maps and
    raw anatomical image.

savefig: string, optional
    Filepath where the resulting snapshot will be created. If None is given,
    a temporary file will be created and/or the result will be displayed
    inline in a Jupyter Notebook.

slices: None, or a tuple of floats
    The indexes of the slices that will be rendered. If None is given, the
    slices are selected automatically.

resource_name: string, optional
    Name of the resource where the segmentation maps are stored in the XNAT
    instance. Default: SPM12_SEGMENT_T2T1_COREG

axes: string, or a tuple of strings
    Choose the direction of the cuts (among 'x', 'y', 'z')

raw: boolean, optional
    If True, the segmentation maps will be plotted over a background image
    (e.g. anatomical T1 or T2, as in xnat.download_resources). If False,
    the segmentation maps will be rendered only. Default: True

opacity: integer, optional
    The opacity (in %) of the segmentation maps when plotted over a background
    image. Only used if a background image is provided. Default: 10

animated: boolean, optional
    If True, the snapshot will be rendered as an animated GIF.
    If False, the snapshot will be rendered as a static PNG image. Default:
    False

rowsize: None, or int, or dict
    Set the number of slices per row in the final compiled figure.
    Default: {'x': 9, 'y': 9, 'z': 6}

figsize: None, or a 2-uple of floats, or dict
    Sets the dimensions of one row of slices.
    Default: {'x': (37, 3), 'y': (40, 3), 'z': (18, 3)}

width: int, optional
    Width (in px) of the final compiled figure. Default: 2000.

contours: boolean, optional
    If True, segmentations will be rendered as contoured regions. If False,
    will be rendered as superimposed masks. Default: False

cache: boolean, optional
    If False, resources will be normally downloaded from XNAT. If True,
    download will be skipped and data will be looked up locally.
    Default: False

Notes
-----
Requires an XNAT instance where SPM segmentation maps will be found
following a certain data organization in experiment resources named
`resource_name`.

See Also
--------
xnat.download_resources : To download resources (e.g. segmentation maps +
    raw images) from an XNAT instance (e.g. prior to snapshot creation)
nisnap.plot_segment : To plot segmentation maps directly providing their
    filepaths
"""

```

```python def downloadresources(config, experimentid, resource_name, destination, raw=True, cache=False): """Download a given experiment/resource from an XNAT instance in a local destination folder.

Parameters
----------
config: string
    Configuration file to the XNAT instance.
    See http://xgrg.github.io/first-steps-with-pyxnat/ for more details.

experiment_id : string
    ID of the experiment from which to download the segmentation maps and
    raw anatomical image.

resource_name: string
    Name of the resource where the segmentation maps are stored in the XNAT
    instance.

destination: string
    Destination folder where to store the downloaded resources.

raw: boolean, optional
    If True, a raw anatomical image will be downloaded along with the
    target resources. If False, only the resources referred to by
    `resource_name` will be downloaded. Default: True

cache: boolean, optional
    If False, resources will be normally downloaded from XNAT. If True,
    download will be skipped and data will be looked up locally.
    Default: False

Notes
-----
Requires an XNAT instance where SPM segmentation maps will be found
following a certain data organization in experiment resources named
`resource_name`.

See Also
--------
xnat.plot_segment : To plot segmentation maps directly providing their
    experiment_id on an XNAT instance
nisnap.plot_segment : To plot segmentation maps directly providing their
    filepaths
"""

```

How to install

pip install nisnap

Credits

Greg Operto and Jordi Huguet (BarcelonaBeta Brain Research Center)

Owner

  • Name: Greg Operto
  • Login: xgrg
  • Kind: user
  • Location: France
  • Company: @therapixel

A bunch of dirty code that happens to be handy sometimes.

GitHub Events

Total
Last Year

Committers

Last synced: over 2 years ago

All Time
  • Total Commits: 114
  • Total Committers: 5
  • Avg Commits per committer: 22.8
  • Development Distribution Score (DDS): 0.596
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
xgrg g****o@b****g 46
xgrg g****o@g****m 34
xgrg 21
jhuguetn j****n@g****m 12
Jordi Huguet j****t@a****l 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 4
  • Total pull requests: 7
  • Average time to close issues: about 1 month
  • Average time to close pull requests: about 1 month
  • Total issue authors: 3
  • Total pull request authors: 1
  • Average comments per issue: 0.5
  • Average comments per pull request: 0.14
  • Merged pull requests: 4
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 1
  • Pull requests: 0
  • Average time to close issues: 4 days
  • Average time to close pull requests: N/A
  • Issue authors: 1
  • Pull request authors: 0
  • Average comments per issue: 1.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • jhuguetn (2)
  • stoujia (1)
Pull Request Authors
  • jhuguetn (8)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 100 last-month
  • Total docker downloads: 34
  • Total dependent packages: 1
  • Total dependent repositories: 1
  • Total versions: 17
  • Total maintainers: 2
pypi.org: nisnap

nisnap

  • Versions: 17
  • Dependent Packages: 1
  • Dependent Repositories: 1
  • Downloads: 100 Last month
  • Docker Downloads: 34
Rankings
Docker downloads count: 3.7%
Dependent packages count: 4.7%
Average: 14.8%
Forks count: 15.3%
Stargazers count: 18.5%
Dependent repos count: 21.7%
Downloads: 25.0%
Maintainers (2)
Last synced: 6 months ago

Dependencies

requirements.txt pypi
  • Pillow >=7.0
  • coverage >=4.5
  • coveralls *
  • ipython >=7.3
  • matplotlib >=2.2
  • nibabel >=2.0
  • nilearn >=0.8
  • nose >=1.3
  • numpy >=1.16
  • pyxnat >=1.3
  • tqdm >=4.31
  • urllib3 >=1.24
setup.py pypi
  • Pillow >=7.0
  • coverage >=4.5
  • ipython >=7.3
  • matplotlib >=3.1
  • nibabel >=2.0
  • nilearn >=0.8
  • nose >=1.3
  • numpy >=1.16
  • pyxnat >=1.3
  • tqdm >=4.31
  • urllib3 >=1.24