Computational Article

Unveiling Interfaces and Structures: Cryogenic Laser Ablation and Plasma Focused Ion Beam Techniques for Complex and Beam-Sensitive Systems

SEM Slicer

import numpy as np
from tifffile import imread
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import matplotlib.cbook as cbook
from matplotlib_scalebar.scalebar import ScaleBar
from ipywidgets import interact, IntSlider
# Load the TIFF file into a NumPy array
tiff_array = imread('data/AlignedFilteredSEMData_SaveImage11-19.align.view3.to-byte01.resampled_2.tif')

# Check the dimensions of the array
print(tiff_array.shape)
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
/var/folders/yv/3_fvvfd97_9f0_xdt_0k38zh0000gn/T/ipykernel_2465/511800093.py in ?()
      1 # Load the TIFF file into a NumPy array
----> 2 tiff_array = imread('data/AlignedFilteredSEMData_SaveImage11-19.align.view3.filtered_3dtiff.tif')
      3 
      4 # Check the dimensions of the array
      5 print(tiff_array.shape)

~/Documents/myst-sites/large-fov-multiphase-materials/.venv/lib/python3.12/site-packages/tifffile/tifffile.py in ?(files, selection, aszarr, key, series, level, squeeze, maxworkers, buffersize, mode, name, offset, size, pattern, axesorder, categories, imread, imreadargs, sort, container, chunkshape, chunkdtype, axestiled, ioworkers, chunkmode, fillvalue, zattrs, multiscales, omexml, out, out_inplace, _multifile, _useframes, **kwargs)
   1203         ):
   1204             files = files[0]
   1205 
   1206         if isinstance(files, str) or not isinstance(files, Sequence):
-> 1207             with TiffFile(
   1208                 files,
   1209                 mode=mode,
   1210                 name=name,

~/Documents/myst-sites/large-fov-multiphase-materials/.venv/lib/python3.12/site-packages/tifffile/tifffile.py in ?(self, file, mode, name, offset, size, omexml, _multifile, _useframes, _parent, **is_flags)
   4278                 raise ValueError('invalid OME-XML')
   4279             self._omexml = omexml
   4280             self.is_ome = True
   4281 
-> 4282         fh = FileHandle(file, mode=mode, name=name, offset=offset, size=size)
   4283         self._fh = fh
   4284         self._multifile = True if _multifile is None else bool(_multifile)
   4285         self._files = {fh.name: self}

~/Documents/myst-sites/large-fov-multiphase-materials/.venv/lib/python3.12/site-packages/tifffile/tifffile.py in ?(self, file, mode, name, offset, size)
  13323         self._offset = -1 if offset is None else offset
  13324         self._size = -1 if size is None else size
  13325         self._close = True
  13326         self._lock = NullContext()
> 13327         self.open()
  13328         assert self._fh is not None

~/Documents/myst-sites/large-fov-multiphase-materials/.venv/lib/python3.12/site-packages/tifffile/tifffile.py in ?(self)
  13342             if self._mode not in {'rb', 'r+b', 'wb', 'xb'}:
  13343                 raise ValueError(f'invalid mode {self._mode}')
  13344             self._file = os.path.realpath(self._file)
  13345             self._dir, self._name = os.path.split(self._file)
> 13346             self._fh = open(self._file, self._mode, encoding=None)
  13347             self._close = True
  13348             self._offset = max(0, self._offset)
  13349         elif isinstance(self._file, FileHandle):

FileNotFoundError: [Errno 2] No such file or directory: '/Users/gvarnavides/Documents/myst-sites/large-fov-multiphase-materials/notebooks/data/AlignedFilteredSEMData_SaveImage11-19.align.view3.filtered_3dtiff.tif'
def show_slice(data, slice_num):
        fig, ax = plt.subplots()
        ax.imshow(data[slice_num, :, :], cmap='Greys_r')
        plt.title(f'slice number: {slice_num}')
        ax.axis('off')
        scalebar = ScaleBar(200, "nm", length_fraction=0.1, location="lower right")
        ax.set_aspect(1)
        ax.add_artist(scalebar)
        plt.show()
@interact(slice_num=IntSlider(min=0, max=tiff_array.shape[0]-1, step=1, description='Slice Number'))
def explore_slices(slice_num):
    show_slice(tiff_array, slice_num)