Skip to content

Instantly share code, notes, and snippets.

@bmorris3
Last active November 21, 2016 06:26
Show Gist options
  • Save bmorris3/04f18354832f681a4a7a511f601a16dc to your computer and use it in GitHub Desktop.
Save bmorris3/04f18354832f681a4a7a511f601a16dc to your computer and use it in GitHub Desktop.
Save reconstructions to an HDF5 file, for opening with the Fiji HDF5 viewer.
from shampoo.reconstruction import Hologram
import numpy as np
import h5py
# Load the USAF test target hologram
h = Hologram.from_tif('data/USAF_test.tif')
# Make lists for holding the phase and intensity of each reconstruction
phases = []
intensities = []
# Reconstruct at three propagation distances
propagation_distances = [0.03585, 0.03685, 0.03785]
for d in propagation_distances:
wave = h.reconstruct(d)
phases.append(wave.phase)
intensities.append(wave.intensity)
# Save the output to an HDF5 file, for this hologram, taken at the zeroth time, "t0"
hdf5_file_path = 'example.hdf5'
f = h5py.File(hdf5_file_path, 'w')
t0 = f.create_group("t0")
# Save the raw hologram, the intensities, and the phases, using LZF compression
phase_dataset = t0.create_dataset('phase', data=np.array(phases), compression='lzf')
intensity_dataset = t0.create_dataset('intensity', data=np.array(intensities), compression='lzf')
hologram_dataset = t0.create_dataset('hologram', data=np.array([h.hologram]), compression='lzf')
# Close the file stream
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment