Skip to content

Commit

Permalink
black and isort
Browse files Browse the repository at this point in the history
  • Loading branch information
talonchandler committed Feb 18, 2025
1 parent 9193885 commit bf0cd25
Show file tree
Hide file tree
Showing 34 changed files with 276 additions and 243 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# %%
# This notebook-style script requires a ~500 MB download from https://www.ebi.ac.uk/biostudies/files/S-BIAD1063/PTI-BIA/Anisotropic_target_small.zip

import numpy as np
from pathlib import Path

import matplotlib.pyplot as plt
import numpy as np
import zarr
from iohub import open_ome_zarr
from numpy.fft import fftshift

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

import zarr
from pathlib import Path
from iohub import open_ome_zarr
from waveorder import optics, util, waveorder_reconstructor
from waveorder.visuals import jupyter_visuals

# %%
Expand Down Expand Up @@ -62,10 +62,12 @@
I_cali_mean = np.array(PTI_file.I_cali_mean)

# source polarization, instrument matrix calibration
E_in, A_matrix, I_cali_mean = (
wo.waveorder_reconstructor.instrument_matrix_and_source_calibration(
I_cali_mean, handedness="RCP"
)
(
E_in,
A_matrix,
I_cali_mean,
) = wo.waveorder_reconstructor.instrument_matrix_and_source_calibration(
I_cali_mean, handedness="RCP"
)

# %%
Expand Down Expand Up @@ -238,15 +240,18 @@
# "negative" -> only solution of negatively uniaxial material
# "unknown" -> both solutions of positively and negatively uniaxial material + optic sign estimation

differential_permittivity, azimuth, theta, mat_map = (
setup.scattering_potential_tensor_to_3D_orientation(
f_tensor,
S_image_tm,
material_type="unknown",
reg_ret_pr=reg_differential_permittivity,
itr=10,
fast_gpu_mode=True,
)
(
differential_permittivity,
azimuth,
theta,
mat_map,
) = setup.scattering_potential_tensor_to_3D_orientation(
f_tensor,
S_image_tm,
material_type="unknown",
reg_ret_pr=reg_differential_permittivity,
itr=10,
fast_gpu_mode=True,
)

# %%
Expand All @@ -264,7 +269,10 @@
[
((-1) ** i)
* util.wavelet_softThreshold(
((-1) ** i) * differential_permittivity_PT[i], "db8", 0.00303, level=1
((-1) ** i) * differential_permittivity_PT[i],
"db8",
0.00303,
level=1,
)
for i in range(2)
]
Expand Down Expand Up @@ -374,17 +382,27 @@

# compute the physical properties from the scattering potential tensor

differential_permittivity_p, azimuth_p, theta_p = (
optics.scattering_potential_tensor_to_3D_orientation_PN(
f_tensor, material_type="positive", reg_ret_pr=reg_differential_permittivity
)
)
differential_permittivity_n, azimuth_n, theta_n = (
optics.scattering_potential_tensor_to_3D_orientation_PN(
f_tensor, material_type="negative", reg_ret_pr=reg_differential_permittivity
)
(
differential_permittivity_p,
azimuth_p,
theta_p,
) = optics.scattering_potential_tensor_to_3D_orientation_PN(
f_tensor,
material_type="positive",
reg_ret_pr=reg_differential_permittivity,
)
(
differential_permittivity_n,
azimuth_n,
theta_n,
) = optics.scattering_potential_tensor_to_3D_orientation_PN(
f_tensor,
material_type="negative",
reg_ret_pr=reg_differential_permittivity,
)
differential_permittivity = np.array(
[differential_permittivity_p, differential_permittivity_n]
)
differential_permittivity = np.array([differential_permittivity_p, differential_permittivity_n])
azimuth = np.array([azimuth_p, azimuth_n])
theta = np.array([theta_p, theta_n])

Expand All @@ -402,7 +420,10 @@
[
((-1) ** i)
* util.wavelet_softThreshold(
((-1) ** i) * differential_permittivity_PT[i], "db8", 0.00303, level=1
((-1) ** i) * differential_permittivity_PT[i],
"db8",
0.00303,
level=1,
)
for i in range(2)
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@
# density and anisotropy," bioRxiv 2020.12.15.422951 (2020).``` #
####################################################################

import numpy as np
import matplotlib.pyplot as plt
import numpy as np
from numpy.fft import fftshift
from waveorder import (
optics,
waveorder_simulator,
util,
)

from waveorder import optics, util, waveorder_simulator
from waveorder.visuals import jupyter_visuals

#####################################################################
Expand Down
8 changes: 2 additions & 6 deletions examples/maintenance/PTI_simulation/PTI_Simulation_Recon2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@
# density and anisotropy," bioRxiv 2020.12.15.422951 (2020).``` #
####################################################################

import numpy as np
import matplotlib.pyplot as plt
import numpy as np
from numpy.fft import fftshift

from waveorder import (
optics,
waveorder_reconstructor,
)
from waveorder import optics, waveorder_reconstructor
from waveorder.visuals import jupyter_visuals

## Initialization
Expand Down Expand Up @@ -271,7 +268,6 @@
# in-plane orientation
from matplotlib.colors import hsv_to_rgb


ret_min_color = 0
ret_max_color = 1.5

Expand Down
8 changes: 3 additions & 5 deletions examples/maintenance/PTI_simulation/PTI_Simulation_Recon3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
# "uPTI: uniaxial permittivity tensor imaging of intrinsic #
# density and anisotropy," bioRxiv 2020.12.15.422951 (2020).``` #
####################################################################
import numpy as np
import matplotlib.pyplot as plt
import numpy as np
from numpy.fft import fftshift
from waveorder import (
optics,
waveorder_reconstructor,
)

from waveorder import optics, waveorder_reconstructor
from waveorder.visuals import jupyter_visuals

## Initialization
Expand Down
9 changes: 3 additions & 6 deletions examples/maintenance/QLIPP_simulation/2D_QLIPP_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@
#####################################################################################################


import numpy as np
import matplotlib.pyplot as plt
import numpy as np
from numpy.fft import fftshift
from waveorder import (
optics,
waveorder_simulator,
util,
)

from waveorder import optics, util, waveorder_simulator
from waveorder.visuals import jupyter_visuals

# Key parameters
Expand Down
8 changes: 3 additions & 5 deletions examples/maintenance/QLIPP_simulation/2D_QLIPP_recon.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
# eLife 9:e55502 (2020).``` #
#####################################################################################################

import numpy as np
import matplotlib.pyplot as plt
from waveorder import (
waveorder_reconstructor,
)
from waveorder.visuals import jupyter_visuals
import numpy as np

from waveorder import waveorder_reconstructor
from waveorder.visuals import jupyter_visuals

# ### Load simulated data
# Load simulations
Expand Down
36 changes: 18 additions & 18 deletions examples/models/inplane_oriented_thick_pol3d_vector.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import torch
import napari
import torch

from waveorder.models import (
inplane_oriented_thick_pol3d_vector,
)
from waveorder.models import inplane_oriented_thick_pol3d_vector

# Parameters
# all lengths must use consistent units e.g. um
Expand All @@ -25,20 +23,22 @@
)

# Calculate transfer function
sfZYX_transfer_function, intensity_to_stokes_matrix, singular_system = (
inplane_oriented_thick_pol3d_vector.calculate_transfer_function(
swing,
scheme,
zyx_shape,
yx_pixel_size,
z_pixel_size,
wavelength_illumination,
z_padding,
index_of_refraction_media,
numerical_aperture_illumination,
numerical_aperture_detection,
fourier_oversample_factor=fourier_oversample_factor,
)
(
sfZYX_transfer_function,
intensity_to_stokes_matrix,
singular_system,
) = inplane_oriented_thick_pol3d_vector.calculate_transfer_function(
swing,
scheme,
zyx_shape,
yx_pixel_size,
z_pixel_size,
wavelength_illumination,
z_padding,
index_of_refraction_media,
numerical_aperture_illumination,
numerical_aperture_detection,
fourier_oversample_factor=fourier_oversample_factor,
)

# Display transfer function
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 @@ -5,7 +5,7 @@

import napari
import numpy as np
from waveorder import util

from waveorder.models import isotropic_thin_3d

# Parameters
Expand Down
2 changes: 1 addition & 1 deletion examples/models/phase_thick_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import napari
import numpy as np
from waveorder import util

from waveorder.models import phase_thick_3d

# Parameters
Expand Down
12 changes: 7 additions & 5 deletions examples/visuals/plot_greens_tensor.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
from skimage import measure
import os

import napari
from napari.experimental import link_layers
import numpy as np
import torch
import os
from waveorder import util, optics
from napari.experimental import link_layers
from scipy.ndimage import gaussian_filter
from skimage import measure

from waveorder import optics, util

# Parameters
# all lengths must use consistent units e.g. um
output_dirpath = "./greens_plots"
os.makedirs(output_dirpath, exist_ok=True)
grid_size = 100 # 300 for publication
grid_size = 100 # 300 for publication
blur_width = grid_size // 35 # blurring to smooth sharp corners
zyx_shape = 3 * (grid_size,)
yx_pixel_size = 6.5 / 63
Expand Down
15 changes: 10 additions & 5 deletions examples/visuals/plot_vector_transfer_function_support.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

import napari
import numpy as np
import os
import matplotlib.pyplot as plt


def plot_otf_support(
Expand All @@ -28,8 +28,14 @@ def plot_otf_support(
points = np.array(
[
[0, 0],
[det_na - ill_na, (1 - ill_na**2) ** 0.5 - (1 - det_na**2) ** 0.5],
[det_na + ill_na, (1 - ill_na**2) ** 0.5 - (1 - det_na**2) ** 0.5],
[
det_na - ill_na,
(1 - ill_na**2) ** 0.5 - (1 - det_na**2) ** 0.5,
],
[
det_na + ill_na,
(1 - ill_na**2) ** 0.5 - (1 - det_na**2) ** 0.5,
],
[2 * ill_na, 0],
]
)
Expand Down Expand Up @@ -203,7 +209,6 @@ def plot_otf_support(
]

for my_color in my_colors:

plot_otf_support(
ill_na,
det_na,
Expand Down
1 change: 0 additions & 1 deletion tests/models/test_isotropic_fluorescent_thick_3d.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pytest
import torch

from waveorder.models import isotropic_fluorescent_thick_3d
Expand Down
6 changes: 3 additions & 3 deletions tests/models/test_phase_thick_3d.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
import numpy as np
import pytest

from waveorder.models import phase_thick_3d


Expand Down Expand Up @@ -27,7 +28,6 @@ def simulate_phase_recon(
z_pixel_size_um=0.1,
yx_pixel_size_um=6.5 / 63,
):

z_fov_um = 50
yx_fov_um = 50

Expand Down Expand Up @@ -98,4 +98,4 @@ def test_phase_invariance():

# test yx pixel size invariance
recon2 = simulate_phase_recon(yx_pixel_size_um=0.7 * 6.5 / 63)
assert np.abs((recon2 - recon) / recon) < 0.02
assert np.abs((recon2 - recon) / recon) < 0.02
5 changes: 3 additions & 2 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import subprocess
import os
import pytest
import subprocess
import sys

import pytest


def _run_scripts(scripts):
for script in scripts:
Expand Down
3 changes: 2 additions & 1 deletion tests/test_focus_estimator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
import numpy as np
import pytest

from waveorder import focus


Expand Down
Loading

0 comments on commit bf0cd25

Please sign in to comment.