Skip to content
Davide Punzo edited this page May 3, 2017 · 239 revisions

Welcome to the SlicerAstro wiki


Intro: SlicerAstro, an Astronomy (HI) extension for 3DSlicer

Upcoming HI (neutral Hydrogen) surveys will deliver large datasets, and automated processing using the full 3-D information (two positional dimensions and one spectral dimension) to find and characterize HI objects is imperative. In this context, visualization is an essential tool for enabling qualitative and quantitative human control on an automated source finding and analysis pipeline. Visual Analytics, the combination of automated data processing and human reasoning, creativity and intuition, supported by interactive visualization, enables flexible and fast interaction with the 3-D data, helping the astronomer to deal with the analysis of complex sources. 3-D visualization, coupled to modeling, provides additional capabilities helping the discovery and analysis of subtle structures in the 3-D domain.

Check also:

https://arxiv.org/abs/1505.06976 https://arxiv.org/abs/1609.03782 https://arxiv.org/pdf/1703.06651 http://ascl.net/1611.021

Objective: general description

  • Proper visualization of astronomical data cubes: using data astronomical data formats, such as FITS, and astronomical world coordinates system (WCS);
  • Quantification: visualization of the beam, generation of Histogram, flux density profiles, moment maps and position-velocity diagrams, statistics linked with the 3-D view, masking volumes with segmentations;
  • Enabling interactive smoothing in all three dimensions;
  • Interactive HI data modeling coupled to visualization;
  • Introduction of the SAMP protocol to enable interoperability with Topcat, and other VO tools and catalogs.

SlicerAstro is a work in progress project. Below you can find a detailed list of the current status. Please, report any bug and error that you may encounter (https://github.com/Punzo/SlicerAstro/issues).

Progress (1):

  • FITS reader and AstroVolume done;
  • WCS included in AstroVolume;
  • Added AstroLabelMapVolume (WCS compatible);
  • Generalization of qSlicerUnits;
  • Slicer dataProbe moduile overrided with AstroDataProbe one;
  • First desing of the AstroVolume interface done;
  • Added WCS axis in the 2-D views;
  • Customization of 2-D and 3-D Views;
  • Welcoming to SlicerAstro and AstroSampleData modules implemented;
  • Done!

Progress (2):

  • Beam;
  • Histogram;
  • flux density profiles;
  • easy creation of contour plots;
  • moment maps;
  • position-velocity diagrams and linking with the projected model rotation curve;
  • statistics;
  • module for cropping / masking volumes with segmentations (taking care of WCS);

Progress (3):

  • module created;
  • interface designed;
  • Logic methods implemented on CPU (OpenMP);
  • Logic methods implemented on GPU (OpenGL);
  • Done!

Progress (4):

  • implementing CloudLasso (3-D Lasso) effect in the segmentation editor;
  • implementing interface for easy conversion of AstroLabelMapVolume to/from SegmentationNode;
  • adding tilted-ring model routine (3DBarolo);
  • Done!

Progress (5):

  • implementing SAMP protocol in SlicerAstro;
  • skill to overlay observations at different wavelength (i.e. different WCS and gridding);

General NOTE

  • at the moment datacubes NAXIS>3 not supported (NAXIS=4 and NAXIS4=1 -> NAXIS=3).
  • In Slicer is possible to overley two datacube in the 2-D Views. However, at the moment, SlicerAstro does not perform any regridding and/or reprojection operations. This means that, at the moment, the user should take care to load datacubes with same gridding and and same WCS if she/he desires to overlay them on the 2-D Views.
  • at the moment the SlicerAstro is not aware of the CELLSCAL keyword.
  • 3-DSlicer, at the moment, uses Qt4.8.5. For example, using last versions of Ubuntu, it may happen to spot odd behaviour for the popup menus. This will be solved by the upgrade of 3-DSlicer to Qt5 (see https://www.slicer.org/slicerWiki/index.php/Documentation/Labs/Qt5).
  • OpenGL filters in the current binaries are disabled. They require Slicer_VTK_RENDERING_BACKEND set to OpenGL2 (current 3-DSlicer binaries use OpenGL; https://www.slicer.org/wiki/Documentation/Labs/VTK7). If such features is required the user may try to compile 3-DSlicer following https://www.slicer.org/wiki/Documentation/Nightly/Developers/Build_Instructions and setting in cmake Slicer_VTK_RENDERING_BACKEND=OpenGL2.

Get SlicerAstro

SlicerAstro is an official 3-DSlicer extension. Please, download 3-DSlicer nightly build: http://download.slicer.org/

donwload SlicerAstro (available for Linux and MAC) using the 3-DSlicer extension manager tool:

For more information, please visit: http://wiki.slicer.org/slicerWiki/index.php/Documentation/Nightly/SlicerApplication/ExtensionsManager

After the installation, please configure the settings (not necessary, but suggested) with the following instructions (to open the setting interface, you may press ctrl+2 / Command ⌘+2):

  • Volume Rendering: setup if the default rendering pipeline runs on CPU or GPU (and the amount of your DRAM).
  • Modules: A) toggle Skip loading of any for the command-line plugins; B) restart; C) Remove all the remaining medical modules by untoggling all the modules which are not included in the following list: Annotations, AstroDataProbe, AstroDataSample, AstroVolume, Cameras, Colors, Data, DataProbe, DataStore, Markups, Reformat, Scene Views, Screen Capture, Segment Editor, Segmentations, Smooth Volume, Subject Hierarchy, Tables, Transforms, Units, Volume Rendering, Volumes, Welcome to Slicer, Welcome to SlicerAstro, Smooth Volume.
  • Set the default startup module: Welcome to AstroVolume.
  • Set as favourite modules the Astro ones.
  • Restart

Before the use, visit the Module: Welcome to SlicerAstro.

Additional Users documentation (first-time users are advised to check it): https://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Extensions/SlicerAstro

The interface

For information about the GUI and the navigation, we refer to the Slicer documentation:

The SlicerAstro's Modules Interface

Check https://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Extensions/SlicerAstro

Developers documentation: coming soon...

Python interactor

It is a very useful util to access run-time the Slicer classes (e.g. the data of the fits file are stored in the AstroVolume class). Python script can also be runned typing on termianl Slicer --python ...

See:

3DSlicer Python scripts repository

SlicerAstro Python scripts repository

  • SmoothRenderSaveVideos.py:
slicer.util.loadVolume("/full_path/galaxy.fits",{"center":True})
mw = slicer.util.mainWindow()
ms = mw.moduleSelector()
# Smooth the datacube
ms.selectModule('AstroSmoothing')
smowidget = slicer.modules.astrosmoothing.widgetRepresentation()
smomrmlpara = smowidget.mrmlAstroSmoothingParametersNode()
smomrmlpara.SetMode("Manual")
# only if a GPU is present:
#smomrmlpara.SetHardware(1)
smowidget.onApply()
ms.selectModule('AstroVolume')
# Setting maximum quality for the rendering
astrovolumewidget = slicer.modules.astrovolume.widgetRepresentation()
astrovolumewidget.onCurrentQualityControlChanged(1)
volumes = slicer.mrmlScene.GetNodesByClass("vtkMRMLAstroVolumeNode")
volumefiltered = volumes.GetItemAsObject(1)
smomrmlpara.SetInputVolumeNodeID(volumefiltered.GetID())
astrovolumewidget.onCurrentQualityControlChanged(1)
# Create videos 
ms.selectModule('ScreenCapture')
screencapturewidget = slicer.modules.screencapture.widgetRepresentation()
instance = screencapturewidget.self()
viewNode = slicer.util.getNode('vtkMRMLViewNode1')
instance.viewNodeSelector.setCurrentNode(viewNode)
instance.numberOfStepsSliderWidget.setValue(360)
instance.videoExportCheckBox.setChecked(1)
instance.videoFormatWidget.setCurrentIndex(1)
instance.videoFileNameWidget.setText("WEIN069.mp4")
instance.videoLengthSliderWidget.setValue(6)
instance.onCaptureButton()
viewNode = slicer.util.getNode('vtkMRMLViewNode2')
instance.viewNodeSelector.setCurrentNode(viewNode)
instance.viewNodeSelector.setCurrentNode(viewNode)
instance.numberOfStepsSliderWidget.setValue(360)
instance.videoExportCheckBox.setChecked(1)
instance.videoFormatWidget.setCurrentIndex(1)
instance.videoFileNameWidget.setText("WEIN069_smoothed.mp4")
instance.videoLengthSliderWidget.setValue(6)
instance.onCaptureButton()
  • Create(alike)MomentMap.py:
# Get the data-cube volume
volumeNode = getNode('name of the object')
datacube = volumeNode.GetImageData()

# Get dimensions
N1 = int(volumeNode.GetAttribute("SlicerAstro.NAXIS1"))
N2 = int(volumeNode.GetAttribute("SlicerAstro.NAXIS2"))
RMS = float(volumeNode.GetAttribute("SlicerAstro.RMS"))

# Create an empty 2-D image
imageSize = [N1, N2, 1]
imageSpacing = [1.0, 1.0, 1.0]
voxelType = vtk.VTK_FLOAT
imageDataTemp = vtk.vtkImageData()
imageDataTemp.SetDimensions(imageSize)
imageDataTemp.AllocateScalars(voxelType, 1)

extentTemp = imageDataTemp.GetExtent()
for i in xrange(extentTemp[0], extentTemp[1]+1):
    for j in xrange(extentTemp[2], extentTemp[3]+1):
       for k in xrange(extentTemp[4], extentTemp[5]+1):
          imageDataTemp.SetScalarComponentFromFloat(i,j,k,0,0.)

# calculate moment map
imageData = volumeNode.GetImageData()
extent = imageData.GetExtent()
for i in xrange(extent[0], extent[1]+1):
    for j in xrange(extent[2], extent[3]+1):
       sum = 0.
       for k in xrange(extent[4], extent[5]+1):
          value = imageData.GetScalarComponentAsFloat(i,j,k,0)
          if value > 3 * RMS:
             sum += imageData.GetScalarComponentAsFloat(i,j,k,0)
       imageDataTemp.SetScalarComponentFromFloat(i,j,0,0,sum)

imageDataTemp.Modified()
point = imageDataTemp.GetPointData()
array = piont.GetArray("ImageScalars")
point.Modified()
array.Modified()
array.GetValueRange()

# create Astro Volume for the moment map
astroVolumeLogic = slicer.modules.astrovolume.logic()
volumeNodeMomentMap = astroVolumeLogic.CloneVolume(slicer.mrmlScene, volumeNode, 'MomentMap')

# modify fits attributes
volumeNodeMomentMap.SetAttribute("SlicerAstro.NAXIS", "2")
volumeNodeMomentMap.RemoveAttribute("SlicerAstro.NAXIS3")
volumeNodeMomentMap.RemoveAttribute("SlicerAstro.CROTA3")
volumeNodeMomentMap.RemoveAttribute("SlicerAstro.CRPIX3")
volumeNodeMomentMap.RemoveAttribute("SlicerAstro.CRVAL3")
volumeNodeMomentMap.RemoveAttribute("SlicerAstro.CTYPE3")
volumeNodeMomentMap.RemoveAttribute("SlicerAstro.CUNIT3")
volumeNodeMomentMap.RemoveAttribute("SlicerAstro.DTYPE3")
volumeNodeMomentMap.RemoveAttribute("SlicerAstro.DRVAL3")
volumeNodeMomentMap.RemoveAttribute("SlicerAstro.DUNIT3")

# copy 2-D image into the Astro Volume object
volumeNodeMomentMap.SetAndObserveImageData(imageDataTemp)
volumeNodeMomentMap.UpdateNoiseAttributes()
volumeNodeMomentMap.UpdateRangeAttributes()

# change colorMap of the 2-D image
displayNode = volumeNodeMomentMap.GetDisplayNode()
displayNode.SetAndObserveColorNodeID('vtkMRMLColorTableNodeRainbow')

# changing the colorMap parameters
#displayNode.AutoWindowLevelOff()
#displayNode.SetWindow(??)
#displayNode.SetLevel(??)


  • AccessDataAsNumpy.py:
def array(pattern = "", index = 0):
  """Return the array you are "most likely to want" from the indexth
  MRML node that matches the pattern.  Meant to be used in the python
  console for quick debugging/testing.
  """

  import vtk.util.numpy_support
  n = getNode(pattern=pattern, index=index)
  i = n.GetImageData()
  shape = list(n.GetImageData().GetDimensions())
  shape.reverse()
  a = vtk.util.numpy_support.vtk_to_numpy(i.GetPointData().GetScalars()).reshape(shape)
  return a

run as: ./Slicer --python-script SmoothRenderSaveVideos.py or copy and paste in the python console

more to come...

Clone this wiki locally