Skip to content

Commit

Permalink
2d phase wrap safety
Browse files Browse the repository at this point in the history
  • Loading branch information
talonchandler committed Sep 10, 2024
1 parent 55f8e5a commit 22a059b
Showing 1 changed file with 60 additions and 1 deletion.
61 changes: 60 additions & 1 deletion waveorder/models/isotropic_thin_3d.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from typing import Literal, Tuple

import numpy as np
import torch
from torch import Tensor

from waveorder import optics, util
from waveorder import optics, sampling, util


def generate_test_phantom(
Expand Down Expand Up @@ -42,6 +43,64 @@ def calculate_transfer_function(
numerical_aperture_illumination,
numerical_aperture_detection,
invert_phase_contrast=False,
):
transverse_nyquist = sampling.transverse_nyquist(
wavelength_illumination,
numerical_aperture_illumination,
numerical_aperture_detection,
)
yx_factor = int(np.ceil(yx_pixel_size / transverse_nyquist))

absorption_2d_to_3d_transfer_function, phase_2d_to_3d_transfer_function = (
_calculate_wrap_unsafe_transfer_function(
(
yx_shape[0] * yx_factor,
yx_shape[1] * yx_factor,
),
yx_pixel_size / yx_factor,
z_position_list,
wavelength_illumination,
index_of_refraction_media,
numerical_aperture_illumination,
numerical_aperture_detection,
invert_phase_contrast=invert_phase_contrast,
)
)

absorption_2d_to_3d_transfer_function_out = torch.zeros(
(len(z_position_list),) + tuple(yx_shape), dtype=torch.complex64
)
phase_2d_to_3d_transfer_function_out = torch.zeros(
(len(z_position_list),) + tuple(yx_shape), dtype=torch.complex64
)

for z in range(len(z_position_list)):
absorption_2d_to_3d_transfer_function_out[z] = (
sampling.nd_fourier_central_cuboid(
absorption_2d_to_3d_transfer_function[z], yx_shape
)
)
phase_2d_to_3d_transfer_function_out[z] = (
sampling.nd_fourier_central_cuboid(
phase_2d_to_3d_transfer_function[z], yx_shape
)
)

return (
absorption_2d_to_3d_transfer_function_out,
phase_2d_to_3d_transfer_function_out,
)


def _calculate_wrap_unsafe_transfer_function(
yx_shape,
yx_pixel_size,
z_position_list,
wavelength_illumination,
index_of_refraction_media,
numerical_aperture_illumination,
numerical_aperture_detection,
invert_phase_contrast=False,
):
if invert_phase_contrast:
z_position_list = torch.flip(torch.tensor(z_position_list), dims=(0,))
Expand Down

0 comments on commit 22a059b

Please sign in to comment.