Skip to content

Commit

Permalink
refactor visuals
Browse files Browse the repository at this point in the history
  • Loading branch information
talonchandler committed Sep 10, 2024
1 parent 242ceca commit bbe8935
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 538 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
from numpy.fft import fftshift

import waveorder as wo
from waveorder import optics, waveorder_reconstructor, util, visual
from waveorder import optics, waveorder_reconstructor, util

import zarr
from pathlib import Path
from iohub import open_ome_zarr
from waveorder.visuals import jupyter_visuals

# %%
# Initialization
Expand Down Expand Up @@ -110,7 +111,7 @@
Source_PolState[i, 1] = E_in[1]


visual.plot_multicolumn(
jupyter_visuals.plot_multicolumn(
fftshift(Source, axes=(1, 2)), origin="lower", num_col=5
)

Expand Down Expand Up @@ -162,7 +163,7 @@

# %%
# browse raw intensity stacks (stack_idx_1: z index, stack_idx2: pattern index)
visual.parallel_5D_viewer(
jupyter_visuals.parallel_5D_viewer(
np.transpose(I_meas[:, :, :, :, ::-1], (4, 1, 0, 2, 3)),
num_col=4,
size=10,
Expand All @@ -171,7 +172,7 @@

# %%
# browse uncorrected Stokes parameters (stack_idx_1: z index, stack_idx2: pattern index)
visual.parallel_5D_viewer(
jupyter_visuals.parallel_5D_viewer(
np.transpose(S_image_recon, (4, 1, 0, 2, 3)),
num_col=3,
size=8,
Expand All @@ -182,7 +183,7 @@

# %%
# browse corrected Stokes parameters (stack_idx_1: z index, stack_idx2: pattern index)
visual.parallel_5D_viewer(
jupyter_visuals.parallel_5D_viewer(
np.transpose(S_image_tm, (4, 1, 0, 2, 3)),
num_col=3,
size=8,
Expand Down Expand Up @@ -213,7 +214,7 @@

# %%
# browse the z-stack of components of scattering potential tensor
visual.parallel_4D_viewer(
jupyter_visuals.parallel_4D_viewer(
np.transpose(f_tensor, (3, 0, 1, 2)),
num_col=4,
origin="lower",
Expand Down Expand Up @@ -278,7 +279,7 @@

# %%
# browse the reconstructed physical properties
visual.parallel_4D_viewer(
jupyter_visuals.parallel_4D_viewer(
np.transpose(
np.stack(
[
Expand Down Expand Up @@ -546,7 +547,7 @@

# %%
# browse XY planes of the phase and differential permittivity
visual.parallel_4D_viewer(
jupyter_visuals.parallel_4D_viewer(
np.transpose(
[
np.clip(phase_PT, phase_min, phase_max),
Expand Down Expand Up @@ -585,7 +586,7 @@
),
(3, 1, 2, 0),
)
orientation_3D_image_RGB = visual.orientation_3D_to_rgb(
orientation_3D_image_RGB = jupyter_visuals.orientation_3D_to_rgb(
orientation_3D_image, interp_belt=20 / 180 * np.pi, sat_factor=1
)

Expand All @@ -600,7 +601,7 @@

# plot the top view of 3D orientation colorsphere
plt.figure(figsize=(3, 3))
visual.orientation_3D_colorwheel(
jupyter_visuals.orientation_3D_colorwheel(
wheelsize=256, circ_size=50, interp_belt=20 / 180 * np.pi, sat_factor=1
)

Expand Down Expand Up @@ -639,7 +640,7 @@
in_plane_orientation[:, y_layer], origin="lower", aspect=z_step / ps
)
plt.figure(figsize=(3, 3))
visual.orientation_2D_colorwheel()
jupyter_visuals.orientation_2D_colorwheel()

# %%
# out-of-plane tilt
Expand Down Expand Up @@ -686,7 +687,7 @@

fig, ax = plt.subplots(1, 1, figsize=(15, 15))

visual.plot3DVectorField(
jupyter_visuals.plot3DVectorField(
np.abs(differential_permittivity_PT[1, :, :, z_layer]),
azimuth[1, :, :, z_layer],
theta[1, :, :, z_layer],
Expand Down Expand Up @@ -722,7 +723,7 @@
# %%
# Angular histogram of 3D orientation

visual.orientation_3D_hist(
jupyter_visuals.orientation_3D_hist(
azimuth[1].flatten(),
theta[1].flatten(),
ret_mask.flatten(),
Expand Down
20 changes: 10 additions & 10 deletions examples/maintenance/PTI_simulation/PTI_Simulation_Forward_2D3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
from waveorder import (
optics,
waveorder_simulator,
visual,
util,
)
from waveorder.visuals import jupyter_visuals

#####################################################################
# Initialization - imaging system and sample #
Expand Down Expand Up @@ -145,7 +145,7 @@
### Visualize sample properties

#### XY sections
visual.plot_multicolumn(
jupyter_visuals.plot_multicolumn(
[
target[:, :, z_layer],
azimuth[:, :, z_layer] % (2 * np.pi),
Expand All @@ -158,7 +158,7 @@
set_title=True,
)
#### XZ sections
visual.plot_multicolumn(
jupyter_visuals.plot_multicolumn(
[
np.transpose(target[y_layer, :, :]),
np.transpose(azimuth[y_layer, :, :]) % (2 * np.pi),
Expand Down Expand Up @@ -197,7 +197,7 @@
),
(3, 1, 2, 0),
)
orientation_3D_image_RGB = visual.orientation_3D_to_rgb(
orientation_3D_image_RGB = jupyter_visuals.orientation_3D_to_rgb(
orientation_3D_image, interp_belt=20 / 180 * np.pi, sat_factor=1
)

Expand All @@ -206,7 +206,7 @@
plt.figure(figsize=(10, 10))
plt.imshow(orientation_3D_image_RGB[:, y_layer], origin="lower")
plt.figure(figsize=(3, 3))
visual.orientation_3D_colorwheel(
jupyter_visuals.orientation_3D_colorwheel(
wheelsize=128,
circ_size=50,
interp_belt=20 / 180 * np.pi,
Expand All @@ -216,7 +216,7 @@
plt.show()

#### Angular histogram of 3D orientation
visual.orientation_3D_hist(
jupyter_visuals.orientation_3D_hist(
azimuth.flatten(),
inclination.flatten(),
np.abs(target).flatten(),
Expand Down Expand Up @@ -258,7 +258,7 @@
epsilon_tensor[2, 2] = epsilon_mean + epsilon_del * np.cos(2 * inclination)


visual.plot_multicolumn(
jupyter_visuals.plot_multicolumn(
[
epsilon_tensor[0, 0, :, :, z_layer],
epsilon_tensor[0, 1, :, :, z_layer],
Expand Down Expand Up @@ -334,7 +334,7 @@
)


visual.plot_multicolumn(
jupyter_visuals.plot_multicolumn(
[
del_f_component[0, :, :, z_layer],
del_f_component[1, :, :, z_layer],
Expand Down Expand Up @@ -425,11 +425,11 @@

#### Circularly polarized illumination patterns

visual.plot_multicolumn(
jupyter_visuals.plot_multicolumn(
fftshift(Source_cont, axes=(1, 2)), origin="lower", num_col=5, size=5
)
# discretized illumination patterns used in simulation (faster forward model)
visual.plot_multicolumn(
jupyter_visuals.plot_multicolumn(
fftshift(Source, axes=(1, 2)), origin="lower", num_col=5, size=5
)
print(Source_PolState)
Expand Down
16 changes: 8 additions & 8 deletions examples/maintenance/PTI_simulation/PTI_Simulation_Recon2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from waveorder import (
optics,
waveorder_reconstructor,
visual,
)
from waveorder.visuals import jupyter_visuals

## Initialization
## Load simulated images and parameters
Expand Down Expand Up @@ -76,7 +76,7 @@
## Visualize 2 D transfer functions as a function of illumination pattern

# illumination patterns used
visual.plot_multicolumn(
jupyter_visuals.plot_multicolumn(
fftshift(Source_cont, axes=(1, 2)), origin="lower", num_col=5, size=5
)
plt.show()
Expand Down Expand Up @@ -118,7 +118,7 @@
S_image_tm, reg_inc=reg_inc, cupy_det=True
)

visual.plot_multicolumn(
jupyter_visuals.plot_multicolumn(
f_tensor,
num_col=4,
origin="lower",
Expand Down Expand Up @@ -255,14 +255,14 @@
),
(1, 2, 0),
)
orientation_3D_image_RGB = visual.orientation_3D_to_rgb(
orientation_3D_image_RGB = jupyter_visuals.orientation_3D_to_rgb(
orientation_3D_image, interp_belt=20 / 180 * np.pi, sat_factor=1
)

plt.figure(figsize=(5, 5))
plt.imshow(orientation_3D_image_RGB, origin="lower")
plt.figure(figsize=(3, 3))
visual.orientation_3D_colorwheel(
jupyter_visuals.orientation_3D_colorwheel(
wheelsize=256, circ_size=50, interp_belt=20 / 180 * np.pi, sat_factor=1
)
plt.show()
Expand Down Expand Up @@ -297,7 +297,7 @@
plt.figure(figsize=(5, 5))
plt.imshow(in_plane_orientation, origin="lower")
plt.figure(figsize=(3, 3))
visual.orientation_2D_colorwheel()
jupyter_visuals.orientation_2D_colorwheel()
plt.show()

# out-of-plane tilt
Expand Down Expand Up @@ -339,7 +339,7 @@
plt.figure(figsize=(10, 10))

fig, ax = plt.subplots(1, 1, figsize=(20, 10))
visual.plot3DVectorField(
jupyter_visuals.plot3DVectorField(
np.abs(retardance_pr_nm[0]),
azimuth[0],
theta[0],
Expand All @@ -362,7 +362,7 @@

plt.figure(figsize=(10, 10))
plt.imshow(ret_mask, cmap="gray", origin="lower")
visual.orientation_3D_hist(
jupyter_visuals.orientation_3D_hist(
azimuth[0].flatten(),
theta[0].flatten(),
ret_mask.flatten(),
Expand Down
22 changes: 11 additions & 11 deletions examples/maintenance/PTI_simulation/PTI_Simulation_Recon3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
from waveorder import (
optics,
waveorder_reconstructor,
visual,
)
from waveorder.visuals import jupyter_visuals

## Initialization
## Load simulated images and parameters
Expand Down Expand Up @@ -65,7 +65,7 @@


### Illumination patterns used
visual.plot_multicolumn(
jupyter_visuals.plot_multicolumn(
fftshift(Source_cont, axes=(1, 2)), origin="lower", num_col=5, size=5
)
plt.show()
Expand Down Expand Up @@ -113,7 +113,7 @@
S_image_tm, reg_inc=reg_inc, cupy_det=True
)

visual.plot_multicolumn(
jupyter_visuals.plot_multicolumn(
f_tensor[..., L // 2],
num_col=4,
origin="lower",
Expand Down Expand Up @@ -183,7 +183,7 @@
### Reconstructed phase, absorption, principal retardance, azimuth, and inclination assuming (+) and (-) optic sign

# browse the reconstructed physical properties
visual.plot_multicolumn(
jupyter_visuals.plot_multicolumn(
np.stack(
[
phase_PT[..., L // 2],
Expand Down Expand Up @@ -389,7 +389,7 @@
),
(3, 1, 2, 0),
)
orientation_3D_image_RGB = visual.orientation_3D_to_rgb(
orientation_3D_image_RGB = jupyter_visuals.orientation_3D_to_rgb(
orientation_3D_image, interp_belt=20 / 180 * np.pi, sat_factor=1
)

Expand All @@ -402,7 +402,7 @@
)
# plot the top view of 3D orientation colorsphere
plt.figure(figsize=(3, 3))
visual.orientation_3D_colorwheel(
jupyter_visuals.orientation_3D_colorwheel(
wheelsize=128,
circ_size=50,
interp_belt=20 / 180 * np.pi,
Expand Down Expand Up @@ -440,7 +440,7 @@
plt.figure(figsize=(10, 10))
plt.imshow(in_plane_orientation[:, y_layer], origin="lower", aspect=psz / ps)
plt.figure(figsize=(3, 3))
visual.orientation_2D_colorwheel()
jupyter_visuals.orientation_2D_colorwheel()
plt.show()


Expand Down Expand Up @@ -511,7 +511,7 @@


fig, ax = plt.subplots(2, 2, figsize=(10, 10))
visual.plot3DVectorField(
jupyter_visuals.plot3DVectorField(
np.abs(retardance_pr_PT[0, :, :, z_layer]),
azimuth[0, :, :, z_layer],
theta[0, :, :, z_layer],
Expand All @@ -529,7 +529,7 @@
)
ax[0, 0].set_title(f"XY section (z= {z_layer})")

visual.plot3DVectorField(
jupyter_visuals.plot3DVectorField(
np.transpose(np.abs(retardance_pr_PT[0, :, x_layer, :])),
np.transpose(azimuth_x[0, :, x_layer, :]),
np.transpose(theta_x[0, :, x_layer, :]),
Expand All @@ -547,7 +547,7 @@
)
ax[0, 1].set_title(f"YZ section (x = {x_layer})")

visual.plot3DVectorField(
jupyter_visuals.plot3DVectorField(
np.transpose(np.abs(retardance_pr_PT[0, y_layer, :, :])),
np.transpose(azimuth_y[0, y_layer, :, :]),
np.transpose(theta_y[0, y_layer, :, :]),
Expand Down Expand Up @@ -584,7 +584,7 @@

plt.figure(figsize=(10, 10))
plt.imshow(ret_mask[:, :, z_layer], cmap="gray", origin="lower")
visual.orientation_3D_hist(
jupyter_visuals.orientation_3D_hist(
azimuth[0].flatten(),
theta[0].flatten(),
ret_mask.flatten(),
Expand Down
Loading

0 comments on commit bbe8935

Please sign in to comment.