Skip to content

Commit

Permalink
remove obsolete waveOrderWriter calls
Browse files Browse the repository at this point in the history
  • Loading branch information
mattersoflight committed Mar 10, 2024
1 parent 2fbd3bf commit 4ab5fc1
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
# %%
# Load data and bg
# Download data from
PTI_file_name = "/Users/talon.chandler/Downloads/Anisotropic_target_small/Anisotropic_target_small_raw.zarr"
PTI_file_name = "/Users/shalin.mehta/docs/data/waveOrder/Anisotropic_target_small/Anisotropic_target_small_raw.zarr"
reader = zarr.open(PTI_file_name, mode="r")
I_meas = np.transpose(
np.array(reader["Row_0/Col_0/I_meas/array"]), (0, 1, 3, 4, 2)
Expand Down Expand Up @@ -305,24 +305,6 @@
],
)

# %%
# (Obsolete, not maintained) save results to zarr array

# writer = WaveorderWriter('.', hcs=False, hcs_meta=None, verbose=True)
# writer.create_zarr_root('Anisotropic_target_small_processed.zarr')
# chan_names = ['f_tensor0r', 'f_tensor0i', 'f_tensor1c','f_tensor1s','f_tensor2c','f_tensor2s', 'f_tensor3', 'mat_map0', 'mat_map1']
# PTI_array = np.transpose(np.concatenate((f_tensor, mat_map),axis=0)[np.newaxis,...],(0,1,4,2,3)) # dimension (T, C, Z, Y, X)
# data_shape = PTI_array.shape
# chunk_size = (1,1,1)+PTI_array.shape[3:]
# writer.init_array(0, data_shape, chunk_size, chan_names, position_name='f_tensor', overwrite=True)
# writer.write(PTI_array, p=0)

# chan_names_phys = ['Phase3D', 'Retardance3D', 'Orientation', 'Inclination', 'Optic_sign']
# phys_data_array = np.transpose(np.array([phase_PT, np.abs(retardance_pr_PT[1]), azimuth[1], theta[1], p_mat_map]),(0,3,1,2))[np.newaxis,...]
# data_shape_phys = phys_data_array.shape
# dtype = 'float32'
# writer.init_array(1, data_shape_phys, chunk_size, chan_names_phys, dtype, position_name='Stitched_physical', overwrite=True)
# writer.write(phys_data_array, p=1)

# %%
# Load the processed results
Expand Down
2 changes: 1 addition & 1 deletion examples/models/isotropic_thin_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"wavelength_illumination": 0.532,
"index_of_refraction_media": 1.3,
}
phantom_arguments = {"index_of_refraction_sample": 1.50, "sphere_radius": 5}
phantom_arguments = {"index_of_refraction_sample": 1.33, "sphere_radius": 5}
z_shape = 100
z_pixel_size = 0.25
transfer_function_arguments = {
Expand Down
88 changes: 88 additions & 0 deletions examples/models/isotropic_thin_3d_resolution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# 3D partially coherent optical diffraction tomography (ODT) simulation
# J. M. Soto, J. A. Rodrigo, and T. Alieva, "Label-free quantitative
# 3D tomographic imaging for partially coherent light microscopy," Opt. Express
# 25, 15699-15712 (2017)

import napari
import numpy as np
from waveorder import util
from waveorder.models import isotropic_thin_3d

# Parameters
# all lengths must use consistent units e.g. um
simulation_arguments = {
"yx_shape": (256, 256),
"yx_pixel_size": 6.5 / 63,
"wavelength_illumination": 0.532,
"index_of_refraction_media": 1.3,
}
phantom_arguments = {"index_of_refraction_sample": 1.4, "sphere_radius": 0.05}
z_shape = 100
z_pixel_size = 0.25
transfer_function_arguments = {
"z_position_list": (np.arange(z_shape) - z_shape // 2) * z_pixel_size,
"numerical_aperture_illumination": 0.9,
"numerical_aperture_detection": 1.2,
}

# Create a phantom
yx_absorption, yx_phase = isotropic_thin_3d.generate_test_phantom(
**simulation_arguments, **phantom_arguments
)

# Calculate transfer function
(
absorption_2d_to_3d_transfer_function,
phase_2d_to_3d_transfer_function,
) = isotropic_thin_3d.calculate_transfer_function(
**simulation_arguments, **transfer_function_arguments
)

# Display transfer function
viewer = napari.Viewer()
zyx_scale = np.array(
[
z_pixel_size,
simulation_arguments["yx_pixel_size"],
simulation_arguments["yx_pixel_size"],
]
)
isotropic_thin_3d.visualize_transfer_function(
viewer,
absorption_2d_to_3d_transfer_function,
phase_2d_to_3d_transfer_function,
)
input("Showing OTFs. Press <enter> to continue...")
viewer.layers.select_all()
viewer.layers.remove_selected()

# Simulate
zyx_data = isotropic_thin_3d.apply_transfer_function(
yx_absorption,
yx_phase,
absorption_2d_to_3d_transfer_function,
phase_2d_to_3d_transfer_function,
)

# Reconstruct
(
yx_absorption_recon,
yx_phase_recon,
) = isotropic_thin_3d.apply_inverse_transfer_function(
zyx_data,
absorption_2d_to_3d_transfer_function,
phase_2d_to_3d_transfer_function,
)

# Display
arrays = [
(yx_absorption, "Phantom - absorption"),
(yx_phase, "Phantom - phase"),
(zyx_data, "Data"),
(yx_absorption_recon, "Reconstruction - absorption"),
(yx_phase_recon, "Reconstruction - phase"),
]

for array in arrays:
viewer.add_image(array[0].cpu().numpy(), name=array[1])
input("Showing object, data, and recon. Press <enter> to quit...")
24 changes: 23 additions & 1 deletion waveorder/models/isotropic_thin_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def generate_test_phantom(
/ wavelength_illumination
) # phase in radians

yx_absorption = 0.99 * sphere[1]
yx_absorption = 0.02 * sphere[1]

return yx_absorption, yx_phase

Expand Down Expand Up @@ -113,6 +113,28 @@ def visualize_transfer_function(
viewer.dims.order = (0, 1, 2)


def visualize_point_spread_function(
viewer,
absorption_2d_to_3d_transfer_function,
phase_2d_to_3d_transfer_function,
):
arrays = [
(torch.fft.ifftn(absorption_2d_to_3d_transfer_function), "absorb PSF"),
(torch.fft.ifftn(phase_2d_to_3d_transfer_function), "phase PSF"),
]

for array in arrays:
lim = 0.5 * torch.max(torch.abs(array[0]))
viewer.add_image(
torch.fft.ifftshift(array[0], dim=(1, 2)).cpu().numpy(),
name=array[1],
colormap="bwr",
contrast_limits=(-lim, lim),
scale=(1, 1, 1),
)
viewer.dims.order = (0, 1, 2)


def apply_transfer_function(
yx_absorption,
yx_phase,
Expand Down

0 comments on commit 4ab5fc1

Please sign in to comment.