Package: nisnap
nisnapCreate snapshots of segmentation maps produced by neuroimaging software.
Inspired by tools likenilearn,visualqc,fmriprepand others.UsageFrom a Terminal:nisnapc1.nii.gzc2.nii.gzc3.nii.gz--bg/tmp/raw.nii.gz--opacity50-o/tmp/snapshot.gif

nisnaplabels.nii.gz--bgraw.nii.gz--opacity50--axesx--contours-o/tmp/snapshot.gifArguments:filessegmentationmap(s)tocreatesnapshotsfrom

optionalarguments:--bgBGbackgroundimageonwhichsegmentationswillbeplotted.--axesAXESchoosethedirectionofthecuts(among'x','y',or'z')--opacityOPACITYopacity(in%)ofthesegmentationmapswhenplottedoverabackgroundimage.Onlyusedifabackgroundimageisprovided.--contoursifTrue,segmentationswillberenderedascontouredregions.IfFalse,willberenderedassuperimposedmasks.-oOUTPUT,--outputOUTPUTsnapshotwillbestoredinthisfile.Ifextensionis.gif,snapshotwillberenderedasananimation.--configCONFIG[XNATmode]XNATconfigurationfile--nobg[XNATmode]nobackgroundimage.Plotssegmentationmapsonly.-eEXPERIMENT,--experimentEXPERIMENT[XNATmode]IDoftheexperimenttocreatesnapshotsfrom.--resourceRESOURCE[XNATmode]nameoftheresourcetodownload--cache[XNATmode]skipdownloads(e.g.ifrunningforasecondtime--disable_warnings--verboseFrom IPython/Jupyter Notebook:Example:importnisnapfilepaths=['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:defplot_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 strPaths to segmentation maps (between 1 and 3). Must be of same dimensionsand in same reference space.axes: string, or a tuple of stringsChoose the direction of the cuts (among 'x', 'y', or 'z')bg: None or strPath 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 backgroundimage. Only used if a background image is provided. Default: 10slices: None, or a tuple of floatsThe indexes of the slices that will be rendered. If None is given, theslices are selected automatically.animated: boolean, optionalIf True, the snapshot will be rendered as an animated GIF.If False, the snapshot will be rendered as a static PNG image. Default:Falsesavefig: string, optionalFilepath where the resulting snapshot will be created. If None is given,a temporary file will be created and/or the result will be displayedinline in a Jupyter Notebook.contours: boolean, optionalIf True, segmentations will be rendered as contoured regions. If False,will be rendered as superimposed masks. Default: Falserowsize: None, or int, or dictSet 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 dictSets the dimensions of one row of slices.Default: {'x': (37, 3), 'y': (40, 3), 'z': (18, 3)}width: int, optionalWidth (in px) of the final compiled figure. Default: 2000.See Also--------xnat.plot_segment : To plot segmentation maps directly providing theirexperiment_id on an XNAT instance"""Using XNATFrom a Terminal:nisnap--config.xnat.cfg-eEXPERIMENT_ID--resourceASHS--axesA--opacity50-o/tmp/test.gifFrom IPython/Jupyter Notebook:Example:fromnisnapimportxnatxnat.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:defplot_segment(config,experiment_id,savefig=None,slices=None,resource_name='SPM12_SEGMENT_T2T1_COREG',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 createsnapshots of this resource along a selected set of slices.Parameters----------config: stringConfiguration file to the XNAT instance.experiment_id : stringID of the experiment from which to download the segmentation maps andraw anatomical image.savefig: string, optionalFilepath where the resulting snapshot will be created. If None is given,a temporary file will be created and/or the result will be displayedinline in a Jupyter Notebook.slices: None, or a tuple of floatsThe indexes of the slices that will be rendered. If None is given, theslices are selected automatically.resource_name: string, optionalName of the resource where the segmentation maps are stored in the XNATinstance. Default: SPM12_SEGMENT_T2T1_COREGaxes: string, or a tuple of stringsChoose the direction of the cuts (among 'x', 'y', 'z')raw: boolean, optionalIf 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: Trueopacity: integer, optionalThe opacity (in %) of the segmentation maps when plotted over a backgroundimage. Only used if a background image is provided. Default: 10animated: boolean, optionalIf True, the snapshot will be rendered as an animated GIF.If False, the snapshot will be rendered as a static PNG image. Default:Falserowsize: None, or int, or dictSet 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 dictSets the dimensions of one row of slices.Default: {'x': (37, 3), 'y': (40, 3), 'z': (18, 3)}width: int, optionalWidth (in px) of the final compiled figure. Default: 2000.contours: boolean, optionalIf True, segmentations will be rendered as contoured regions. If False,will be rendered as superimposed masks. Default: Falsecache: boolean, optionalIf False, resources will be normally downloaded from XNAT. If True,download will be skipped and data will be looked up locally.Default: FalseNotes-----Requires an XNAT instance where SPM segmentation maps will be foundfollowing 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 theirfilepaths"""defdownload_resources(config,experiment_id,resource_name,destination,raw=True,cache=False):"""Download a given experiment/resource from an XNAT instance in a localdestination folder.Parameters----------config: stringConfiguration file to the XNAT instance.See http://xgrg.github.io/first-steps-with-pyxnat/ for more details.experiment_id : stringID of the experiment from which to download the segmentation maps andraw anatomical image.resource_name: stringName of the resource where the segmentation maps are stored in the XNATinstance.destination: stringDestination folder where to store the downloaded resources.raw: boolean, optionalIf True, a raw anatomical image will be downloaded along with thetarget resources. If False, only the resources referred to by`resource_name` will be downloaded. Default: Truecache: boolean, optionalIf False, resources will be normally downloaded from XNAT. If True,download will be skipped and data will be looked up locally.Default: FalseNotes-----Requires an XNAT instance where SPM segmentation maps will be foundfollowing a certain data organization in experiment resources named`resource_name`.See Also--------xnat.plot_segment : To plot segmentation maps directly providing theirexperiment_id on an XNAT instancenisnap.plot_segment : To plot segmentation maps directly providing theirfilepaths"""How to installpip install nisnapCreditsGreg Operto and Jordi Huguet (BarcelonaBeta Brain Research Center)