{"id":25483361,"url":"https://github.com/xgrg/nisnap","last_synced_at":"2025-04-09T18:52:24.457Z","repository":{"id":45406697,"uuid":"302386149","full_name":"xgrg/nisnap","owner":"xgrg","description":"Display segmentation results over MRI scans in Jupyter notebooks.","archived":false,"fork":false,"pushed_at":"2024-01-22T11:32:06.000Z","size":32249,"stargazers_count":8,"open_issues_count":2,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-23T20:51:13.794Z","etag":null,"topics":["jupyter-notebook","neuroimaging","quality-control"],"latest_commit_sha":null,"homepage":"http://xgrg.github.io/nisnap","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xgrg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-10-08T15:34:46.000Z","updated_at":"2023-06-21T13:53:13.000Z","dependencies_parsed_at":"2022-09-04T01:12:05.913Z","dependency_job_id":"303d92d8-a7a6-4f5c-9e21-0841f91e2222","html_url":"https://github.com/xgrg/nisnap","commit_stats":{"total_commits":114,"total_committers":5,"mean_commits":22.8,"dds":0.5964912280701755,"last_synced_commit":"ffe5ef17864f04f7de8dfbf0328d6e18b6e9195a"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgrg%2Fnisnap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgrg%2Fnisnap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgrg%2Fnisnap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgrg%2Fnisnap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xgrg","download_url":"https://codeload.github.com/xgrg/nisnap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247986970,"owners_count":21028890,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jupyter-notebook","neuroimaging","quality-control"],"created_at":"2025-02-18T17:31:17.011Z","updated_at":"2025-04-09T18:52:24.424Z","avatar_url":"https://github.com/xgrg.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nisnap\n\n![main](https://github.com/xgrg/nisnap/actions/workflows/main.yml/badge.svg)\n[![coverage report](https://coveralls.io/repos/github/xgrg/nisnap/badge.svg?branch=master)](https://coveralls.io/github/xgrg/nisnap?branch=master)\n[![downloads](https://img.shields.io/pypi/dm/nisnap.svg)](https://pypi.org/project/nisnap/)\n[![python versions](https://img.shields.io/pypi/pyversions/nisnap.svg)](https://pypi.org/project/nisnap/)\n[![pypi version](https://img.shields.io/pypi/v/nisnap.svg)](https://pypi.org/project/nisnap/)\n[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4075418.svg)](https://doi.org/10.5281/zenodo.4075418)\n\n\nCreate snapshots of segmentation maps produced by neuroimaging software.\nInspired by tools like [nilearn](https://nilearn.github.io/),\n[visualqc](https://github.com/raamana/visualqc), [fmriprep](https://fmriprep.readthedocs.io/en/stable/) and others.\n\n\u003cimg src=\"https://github.com/xgrg/nisnap/raw/master/doc/nisnap.gif\" width=\"1000px\"\u003e\n\n\u003cimg src=\"https://github.com/xgrg/nisnap/raw/master/doc/nisnap2.gif\" width=\"1000px\"\u003e\n\n\n## Usage\n\n#### From a Terminal:\n\n```sh\nnisnap c1.nii.gz c2.nii.gz c3.nii.gz --bg /tmp/raw.nii.gz --opacity 50 -o /tmp/snapshot.gif\n\nnisnap labels.nii.gz --bg raw.nii.gz --opacity 50 --axes x --contours -o /tmp/snapshot.gif\n```\n\n```sh\nArguments:\n\n  files                 segmentation map(s) to create snapshots from\n\noptional arguments:\n  --bg BG               background image on which segmentations will be plotted.\n  --axes AXES           choose the direction of the cuts (among 'x', 'y', or 'z')\n  --opacity OPACITY     opacity (in %) of the segmentation maps when plotted over a background image. Only used if a background image is provided.\n  --contours            if True, segmentations will be rendered as contoured regions. If False, will be rendered as superimposed masks.\n  -o OUTPUT, --output OUTPUT\n                        snapshot will be stored in this file. If extension is .gif, snapshot will be rendered as an animation.\n  --config CONFIG       [XNAT mode] XNAT configuration file\n  --nobg                [XNAT mode] no background image. Plots segmentation maps only.\n  -e EXPERIMENT, --experiment EXPERIMENT\n                        [XNAT mode] ID of the experiment to create snapshots from.\n  --resource RESOURCE   [XNAT mode] name of the resource to download\n  --cache               [XNAT mode] skip downloads (e.g. if running for a second time\n  --disable_warnings\n  --verbose\n```\n\n\n#### From IPython/Jupyter Notebook:\n\nExample:\n\n```python\nimport nisnap\nfilepaths = ['c1.nii.gz', 'c2.nii.gz', 'c3.nii.gz']\nbg = 'source.nii.gz'\nnisnap.plot_segment(filepaths, bg=bg, opacity=30, axes='x', animated=True)\n```\n\n#### Reference:\n\n```python\ndef plot_segment(filepaths, axes='xyz', bg=None, opacity=30, slices=None,\n        animated=False, savefig=None, contours=False, rowsize=None,\n        figsize=None, width=2000):\n    \"\"\"Plots a set of segmentation maps/masks.\n\n    Parameters\n    ----------\n    filepaths: a list of str\n        Paths to segmentation maps (between 1 and 3). Must be of same dimensions\n        and in same reference space.\n\n    axes: string, or a tuple of strings\n        Choose the direction of the cuts (among 'x', 'y', or 'z')\n\n    bg: None or str\n        Path to the background image that the masks will be plotted on top of.\n        If nothing is specified, the segmentation maps/masks will be plotted only.\n        The opacity (in %) of the segmentation maps when plotted over a background\n        image. Only used if a background image is provided. Default: 10\n\n    slices: None, or a tuple of floats\n        The indexes of the slices that will be rendered. If None is given, the\n        slices are selected automatically.\n\n    animated: boolean, optional\n        If True, the snapshot will be rendered as an animated GIF.\n        If False, the snapshot will be rendered as a static PNG image. Default:\n        False\n\n    savefig: string, optional\n        Filepath where the resulting snapshot will be created. If None is given,\n        a temporary file will be created and/or the result will be displayed\n        inline in a Jupyter Notebook.\n\n    contours: boolean, optional\n        If True, segmentations will be rendered as contoured regions. If False,\n        will be rendered as superimposed masks. Default: False\n\n    rowsize: None, or int, or dict\n        Set the number of slices per row in the final compiled figure.\n        Default: {'x': 9, 'y': 9, 'z': 6}\n\n    figsize: None, or a 2-uple of floats, or dict\n        Sets the dimensions of one row of slices.\n        Default: {'x': (37, 3), 'y': (40, 3), 'z': (18, 3)}\n\n    width: int, optional\n        Width (in px) of the final compiled figure. Default: 2000.\n\n\n    See Also\n    --------\n    xnat.plot_segment : To plot segmentation maps directly providing their\n        experiment_id on an XNAT instance\n    \"\"\"\n```\n\n### Using XNAT\n\n#### From a Terminal:\n\n```sh\nnisnap --config .xnat.cfg -e EXPERIMENT_ID --resource ASHS --axes A --opacity 50 -o /tmp/test.gif\n```\n\n#### From IPython/Jupyter Notebook:\n\nExample:\n\n```python\nfrom nisnap import xnat\nxnat.plot_segment(config='/home/grg/.xnat.cfg', experiment_id='BBRC_E000',\n  raw=True, opacity=30, axes='x', slices=range(100,120,2), figsize=(15,5),\n  animated=True)\n```\n\n#### Reference:\n\n```python\ndef plot_segment(config, experiment_id, savefig=None, slices=None,\n    resource_name='SPM12_SEGMENT_T2T1_COREG',\n    axes='xyz', raw=True, opacity=10, animated=False, rowsize=None,\n    figsize=None, width=2000, contours=False, cache=False):\n    \"\"\"Download a given experiment/resource from an XNAT instance and create\n    snapshots of this resource along a selected set of slices.\n\n    Parameters\n    ----------\n    config: string\n        Configuration file to the XNAT instance.\n\n    experiment_id : string\n        ID of the experiment from which to download the segmentation maps and\n        raw anatomical image.\n\n    savefig: string, optional\n        Filepath where the resulting snapshot will be created. If None is given,\n        a temporary file will be created and/or the result will be displayed\n        inline in a Jupyter Notebook.\n\n    slices: None, or a tuple of floats\n        The indexes of the slices that will be rendered. If None is given, the\n        slices are selected automatically.\n\n    resource_name: string, optional\n        Name of the resource where the segmentation maps are stored in the XNAT\n        instance. Default: SPM12_SEGMENT_T2T1_COREG\n\n    axes: string, or a tuple of strings\n        Choose the direction of the cuts (among 'x', 'y', 'z')\n\n    raw: boolean, optional\n        If True, the segmentation maps will be plotted over a background image\n        (e.g. anatomical T1 or T2, as in xnat.download_resources). If False,\n        the segmentation maps will be rendered only. Default: True\n\n    opacity: integer, optional\n        The opacity (in %) of the segmentation maps when plotted over a background\n        image. Only used if a background image is provided. Default: 10\n\n    animated: boolean, optional\n        If True, the snapshot will be rendered as an animated GIF.\n        If False, the snapshot will be rendered as a static PNG image. Default:\n        False\n\n    rowsize: None, or int, or dict\n        Set the number of slices per row in the final compiled figure.\n        Default: {'x': 9, 'y': 9, 'z': 6}\n\n    figsize: None, or a 2-uple of floats, or dict\n        Sets the dimensions of one row of slices.\n        Default: {'x': (37, 3), 'y': (40, 3), 'z': (18, 3)}\n\n    width: int, optional\n        Width (in px) of the final compiled figure. Default: 2000.\n\n    contours: boolean, optional\n        If True, segmentations will be rendered as contoured regions. If False,\n        will be rendered as superimposed masks. Default: False\n\n    cache: boolean, optional\n        If False, resources will be normally downloaded from XNAT. If True,\n        download will be skipped and data will be looked up locally.\n        Default: False\n\n    Notes\n    -----\n    Requires an XNAT instance where SPM segmentation maps will be found\n    following a certain data organization in experiment resources named\n    `resource_name`.\n\n    See Also\n    --------\n    xnat.download_resources : To download resources (e.g. segmentation maps +\n        raw images) from an XNAT instance (e.g. prior to snapshot creation)\n    nisnap.plot_segment : To plot segmentation maps directly providing their\n        filepaths\n    \"\"\"\n```\n\n\n```python\ndef download_resources(config, experiment_id, resource_name,  destination,\n    raw=True, cache=False):\n    \"\"\"Download a given experiment/resource from an XNAT instance in a local\n    destination folder.\n\n    Parameters\n    ----------\n    config: string\n        Configuration file to the XNAT instance.\n        See http://xgrg.github.io/first-steps-with-pyxnat/ for more details.\n\n    experiment_id : string\n        ID of the experiment from which to download the segmentation maps and\n        raw anatomical image.\n\n    resource_name: string\n        Name of the resource where the segmentation maps are stored in the XNAT\n        instance.\n\n    destination: string\n        Destination folder where to store the downloaded resources.\n\n    raw: boolean, optional\n        If True, a raw anatomical image will be downloaded along with the\n        target resources. If False, only the resources referred to by\n        `resource_name` will be downloaded. Default: True\n\n    cache: boolean, optional\n        If False, resources will be normally downloaded from XNAT. If True,\n        download will be skipped and data will be looked up locally.\n        Default: False\n\n    Notes\n    -----\n    Requires an XNAT instance where SPM segmentation maps will be found\n    following a certain data organization in experiment resources named\n    `resource_name`.\n\n    See Also\n    --------\n    xnat.plot_segment : To plot segmentation maps directly providing their\n        experiment_id on an XNAT instance\n    nisnap.plot_segment : To plot segmentation maps directly providing their\n        filepaths\n    \"\"\"\n\n```\n\n## How to install\n\n```\npip install nisnap\n```\n\n## Credits\n\nGreg Operto and Jordi Huguet ([BarcelonaBeta Brain Research Center](http://barcelonabeta.org))\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxgrg%2Fnisnap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxgrg%2Fnisnap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxgrg%2Fnisnap/lists"}