NCEMPY's 3D slicer

  • Interactively scroll through all images in a 3D dataset
  • Ideal for time series data and can be used for volume data

In [18]:
# Load needed modules
%matplotlib notebook

import numpy as np
import matplotlib.pyplot as plt

import ncempy.io as nio

import ipywidgets as widgets
from ipywidgets import interact, interactive

Load a 3D data set

  • Use the simple ser reader function
  • Change the file_name and the reader function as needed

In [21]:
# Set file path
file_name = r'c:\users\linol\Downloads\01_Si110_5images_1.ser'

# Read the data in the file
ser0 = nio.ser.serReader(file_name)

# Set the variable named data to the loaded dataset
data = ser0['data']

# Available information
# The 'data' key holds all of the data
print(ser0.keys())

# Print out the shape of the dataset
print('Dataset shape = {}'.format(data.shape))


dict_keys(['data', 'pixelSize', 'pixelUnit', 'pixelOrigin', 'filename'])
Dataset shape = (5, 1024, 1024)

Interactively show images in the time series

  • Use Jupyter's ipywidgets to create a basic user interface
  • Use the scroll bar at the bottom

In [22]:
fg1, ax1 = plt.subplots(1,1)
imax1 = ax1.imshow(data[0,:,:],
                   vmin=data.min(),vmax = data.max()) # Set the initial image and intenstiy scaling 

# Updates the plot
def axUpdate(i):
    imax1.set_data(data[i,:,:])

# Create the slider to update the plot
w = interactive(axUpdate, i=(0,data.shape[0]-1))
display(w)