Skip to content

Commit af3afeb

Browse files
PTI example jupyter notebook to script and .html (#160)
* first-pass script and .html * html -> pdf * correct a docstring * remove obsolete waveOrderWriter calls * stub for iohub writer + correcting names of quantities * Save reconstruction to OME zarr for viewing in napari * fix mean/differential permittivity mistake * fix comments * don't track jupyter notebook * clean path * update pdf and readme --------- Co-authored-by: Shalin Mehta <2934183+mattersoflight@users.noreply.github.com>
1 parent 83bf24a commit af3afeb

8 files changed

+858
-1079
lines changed

examples/documentation/PTI_experiment/PTI_Experiment_Recon3D_anisotropic_target_small.ipynb

Lines changed: 0 additions & 1073 deletions
This file was deleted.

examples/documentation/PTI_experiment/PTI_Experiment_Recon3D_anisotropic_target_small.py

Lines changed: 737 additions & 0 deletions
Large diffs are not rendered by default.

examples/documentation/PTI_experiment/README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
The notebooks in this folder require data from this source:
1+
# PTI reconstructions
2+
3+
The demos in this folder illustrate reconstruction algorithm for permittivity tensor imaging (PTI). The main demo script is [PTI_Experiment_Recon3D_anisotropic_target_small.py](PTI_Experiment_Recon3D_anisotropic_target_small.py), which illustrates reconstruction of the permittivity tensor of an anisotropic glass target. The reconstructed results are rendered as PDF file [PTI_Experiment_Recon3D_anisotropic_target_small.pdf](PTI_Experiment_Recon3D_anisotropic_target_small.pdf).
4+
5+
The remaining notebooks illustrate the reconstruction of permittivity tensor of cells and tissues. However they are not maintained and require an old version of this repository from https://github.com/mehta-lab/waveorder/tree/1.0.0b0.
6+
7+
The scripts and notebooks in this folder require data from the image data repository:
28
https://www.ebi.ac.uk/biostudies/bioimages/studies/S-BIAD1063
39

4-
One notebook `PTI_Experiment_Recon3D_anisotropic_target_small.ipynb` will run as is with the latest version of the code and a ~500 MB download from https://www.ebi.ac.uk/biostudies/files/S-BIAD1063/PTI-BIA/Anisotropic_target_small.zip.
10+
The demo script [PTI_Experiment_Recon3D_anisotropic_target_small.py](PTI_Experiment_Recon3D_anisotropic_target_small.py) will run as is with the latest version of the code and a ~500 MB download from https://www.ebi.ac.uk/biostudies/files/S-BIAD1063/PTI-BIA/Anisotropic_target_small.zip.
511

6-
The remaining notebooks are not maintained, so they will require a download and an old version of this repository from https://github.com/mehta-lab/waveorder/tree/1.0.0b0.

examples/models/isotropic_thin_3d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"wavelength_illumination": 0.532,
1717
"index_of_refraction_media": 1.3,
1818
}
19-
phantom_arguments = {"index_of_refraction_sample": 1.50, "sphere_radius": 5}
19+
phantom_arguments = {"index_of_refraction_sample": 1.33, "sphere_radius": 5}
2020
z_shape = 100
2121
z_pixel_size = 0.25
2222
transfer_function_arguments = {
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# 3D partially coherent optical diffraction tomography (ODT) simulation
2+
# J. M. Soto, J. A. Rodrigo, and T. Alieva, "Label-free quantitative
3+
# 3D tomographic imaging for partially coherent light microscopy," Opt. Express
4+
# 25, 15699-15712 (2017)
5+
6+
import napari
7+
import numpy as np
8+
from waveorder import util
9+
from waveorder.models import isotropic_thin_3d
10+
11+
# Parameters
12+
# all lengths must use consistent units e.g. um
13+
simulation_arguments = {
14+
"yx_shape": (256, 256),
15+
"yx_pixel_size": 6.5 / 63,
16+
"wavelength_illumination": 0.532,
17+
"index_of_refraction_media": 1.3,
18+
}
19+
phantom_arguments = {"index_of_refraction_sample": 1.4, "sphere_radius": 0.05}
20+
z_shape = 100
21+
z_pixel_size = 0.25
22+
transfer_function_arguments = {
23+
"z_position_list": (np.arange(z_shape) - z_shape // 2) * z_pixel_size,
24+
"numerical_aperture_illumination": 0.9,
25+
"numerical_aperture_detection": 1.2,
26+
}
27+
28+
# Create a phantom
29+
yx_absorption, yx_phase = isotropic_thin_3d.generate_test_phantom(
30+
**simulation_arguments, **phantom_arguments
31+
)
32+
33+
# Calculate transfer function
34+
(
35+
absorption_2d_to_3d_transfer_function,
36+
phase_2d_to_3d_transfer_function,
37+
) = isotropic_thin_3d.calculate_transfer_function(
38+
**simulation_arguments, **transfer_function_arguments
39+
)
40+
41+
# Display transfer function
42+
viewer = napari.Viewer()
43+
zyx_scale = np.array(
44+
[
45+
z_pixel_size,
46+
simulation_arguments["yx_pixel_size"],
47+
simulation_arguments["yx_pixel_size"],
48+
]
49+
)
50+
isotropic_thin_3d.visualize_transfer_function(
51+
viewer,
52+
absorption_2d_to_3d_transfer_function,
53+
phase_2d_to_3d_transfer_function,
54+
)
55+
input("Showing OTFs. Press <enter> to continue...")
56+
viewer.layers.select_all()
57+
viewer.layers.remove_selected()
58+
59+
# Simulate
60+
zyx_data = isotropic_thin_3d.apply_transfer_function(
61+
yx_absorption,
62+
yx_phase,
63+
absorption_2d_to_3d_transfer_function,
64+
phase_2d_to_3d_transfer_function,
65+
)
66+
67+
# Reconstruct
68+
(
69+
yx_absorption_recon,
70+
yx_phase_recon,
71+
) = isotropic_thin_3d.apply_inverse_transfer_function(
72+
zyx_data,
73+
absorption_2d_to_3d_transfer_function,
74+
phase_2d_to_3d_transfer_function,
75+
)
76+
77+
# Display
78+
arrays = [
79+
(yx_absorption, "Phantom - absorption"),
80+
(yx_phase, "Phantom - phase"),
81+
(zyx_data, "Data"),
82+
(yx_absorption_recon, "Reconstruction - absorption"),
83+
(yx_phase_recon, "Reconstruction - phase"),
84+
]
85+
86+
for array in arrays:
87+
viewer.add_image(array[0].cpu().numpy(), name=array[1])
88+
input("Showing object, data, and recon. Press <enter> to quit...")

waveorder/models/isotropic_thin_3d.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def generate_test_phantom(
2828
/ wavelength_illumination
2929
) # phase in radians
3030

31-
yx_absorption = 0.99 * sphere[1]
31+
yx_absorption = 0.02 * sphere[1]
3232

3333
return yx_absorption, yx_phase
3434

@@ -113,6 +113,28 @@ def visualize_transfer_function(
113113
viewer.dims.order = (0, 1, 2)
114114

115115

116+
def visualize_point_spread_function(
117+
viewer,
118+
absorption_2d_to_3d_transfer_function,
119+
phase_2d_to_3d_transfer_function,
120+
):
121+
arrays = [
122+
(torch.fft.ifftn(absorption_2d_to_3d_transfer_function), "absorb PSF"),
123+
(torch.fft.ifftn(phase_2d_to_3d_transfer_function), "phase PSF"),
124+
]
125+
126+
for array in arrays:
127+
lim = 0.5 * torch.max(torch.abs(array[0]))
128+
viewer.add_image(
129+
torch.fft.ifftshift(array[0], dim=(1, 2)).cpu().numpy(),
130+
name=array[1],
131+
colormap="bwr",
132+
contrast_limits=(-lim, lim),
133+
scale=(1, 1, 1),
134+
)
135+
viewer.dims.order = (0, 1, 2)
136+
137+
116138
def apply_transfer_function(
117139
yx_absorption,
118140
yx_phase,

waveorder/optics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ def unit_conversion_from_scattering_potential_to_permittivity(
11471147
):
11481148
"""
11491149
1150-
compute the optic sign probability from the reconstructed material tendancy
1150+
Convert the scattering potential of the specimen to the relative permittivity.
11511151
11521152
Parameters
11531153
----------

0 commit comments

Comments
 (0)