Skip to content

Commit 796d932

Browse files
committed
more refactoring of pyTFM to disentangle files
1 parent d10f5aa commit 796d932

10 files changed

+1013
-1107
lines changed

saenopy/pyTFM/TFM_tractions.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@
77

88

99
def ffttc_traction(
10-
u, v, pixel_size1, pixel_size2, young, sigma=0.49, spatial_filter="gaussian", fs=None
10+
u,
11+
v,
12+
pixel_size1,
13+
pixel_size2,
14+
young,
15+
sigma=0.49,
16+
spatial_filter="gaussian",
17+
fs=None,
1118
):
1219
"""
1320
fourier transform based calculation of the traction force. U and v must be given as deformations in pixel. Size of
@@ -281,12 +288,20 @@ def ffttc_traction_finite_thickness(
281288

282289

283290
def TFM_tractions(
284-
u, v, pixel_size1, pixel_size2, h, young, sigma=0.49, spatial_filter="gaussian", fs=6
291+
u,
292+
v,
293+
pixel_size1,
294+
pixel_size2,
295+
h,
296+
young,
297+
sigma=0.49,
298+
spatial_filter="gaussian",
299+
fs=6,
285300
):
286301
"""
287302
height correction breaks down due to numerical reasons at large gel height and small wavelengths of deformations.
288-
In this case the height corrected ffttc-function returns Nans. THis function falls back
289-
to the non height-corrected FTTC function if this happens
303+
In this case the height corrected ffttc-function returns Nans. This function falls back
304+
to the non height-corrected FTTC function if this happens
290305
:return:
291306
"""
292307
# translate the filter size to pixels of traction field

saenopy/pyTFM/calculate_strain_energy.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
import numpy as np
2+
from scipy.ndimage import binary_fill_holes
23

3-
try:
4-
from scipy.ndimage import binary_fill_holes
5-
except ImportError:
6-
from scipy.ndimage.morphology import binary_fill_holes
74
from saenopy.pyTFM.TFM_functions import strain_energy_points, contractility
8-
from saenopy.pyTFM.grid_setup_solids_py import (
9-
interpolation,
10-
) # a simple function to resize the mask
5+
from saenopy.pyTFM.calculate_stress_imports.mask_interpolation import mask_interpolation
116

127

138
def calculate_strain_energy(mask, pixel_size, shape, u, v, tx, ty):
149
mask = binary_fill_holes(
1510
mask == 1
1611
) # the mask should be a single patch without holes
1712
# changing the masks dimensions to fit to the deformation and traction fields
18-
mask = interpolation(mask, dims=u.shape)
13+
mask = mask_interpolation(mask, dims=u.shape)
1914
ps1 = pixel_size # pixel size of the image of the beads
2015
# dimensions of the image of the beads
2116
ps2 = ps1 * np.mean(

saenopy/pyTFM/calculate_stress.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
import numpy as np
2+
from scipy.ndimage import binary_fill_holes
23

3-
try:
4-
from scipy.ndimage import binary_fill_holes
5-
except ImportError:
6-
from scipy.ndimage.morphology import binary_fill_holes
4+
from saenopy.pyTFM.calculate_stress_imports.mask_interpolation import mask_interpolation
5+
from saenopy.pyTFM.calculate_stress_imports.grid_setup_solids_py import prepare_forces
6+
from saenopy.pyTFM.calculate_stress_imports.grid_setup_solids_py import grid_setup
7+
from saenopy.pyTFM.calculate_stress_imports.grid_setup_solids_py import FEM_simulation
8+
from saenopy.pyTFM.calculate_stress_imports.find_borders import find_borders
79

8-
from saenopy.pyTFM.grid_setup_solids_py import (
9-
interpolation,
10-
) # a simple function to resize the mask
11-
from saenopy.pyTFM.grid_setup_solids_py import prepare_forces
12-
from saenopy.pyTFM.grid_setup_solids_py import grid_setup, FEM_simulation
13-
from saenopy.pyTFM.grid_setup_solids_py import find_borders
14-
from saenopy.pyTFM.stress_functions import line_tension
15-
from saenopy.pyTFM.stress_functions import all_stress_measures, coefficient_of_variation
16-
from saenopy.pyTFM.stress_functions import mean_stress_vector_norm
10+
from saenopy.pyTFM.calculate_stress_imports.stress_functions import line_tension
11+
from saenopy.pyTFM.calculate_stress_imports.stress_functions import all_stress_measures
12+
from saenopy.pyTFM.calculate_stress_imports.stress_functions import (
13+
coefficient_of_variation,
14+
)
15+
from saenopy.pyTFM.calculate_stress_imports.stress_functions import (
16+
mean_stress_vector_norm,
17+
)
1718

1819

1920
def calculate_stress(mask, pixel_size, shape, u, tx, ty):
@@ -31,12 +32,12 @@ def calculate_stress(mask, pixel_size, shape, u, tx, ty):
3132
mask == 1
3233
) # the mask should be a single patch without holes
3334
# changing the masks dimensions to fit to the deformation and traction field:
34-
mask_fem = interpolation(mask_fem, dims=tx.shape)
35+
mask_fem = mask_interpolation(mask_fem, dims=tx.shape)
3536

3637
# second mask: The area of the cells. Average stresses and other values are calculated only
3738
# on the actual area of the cell, represented by this mask.
3839
mask_cells_full = binary_fill_holes(mask == 2)
39-
mask_cells = interpolation(mask_cells_full, dims=tx.shape)
40+
mask_cells = mask_interpolation(mask_cells_full, dims=tx.shape)
4041

4142
# converting traction forces (forces per surface area) to actual forces
4243
# and correcting imbalanced forces and torques
@@ -58,7 +59,9 @@ def calculate_stress(mask, pixel_size, shape, u, tx, ty):
5859
sigma_max, sigma_min, sigma_max_abs, tau_max, phi_n, phi_shear, sigma_mean = (
5960
all_stress_measures(stress_tensor, px_size=ps2 * 10**-6)
6061
)
61-
mask_int = interpolation(mask_cells_full, dims=sigma_mean.shape, min_cell_size=100)
62+
mask_int = mask_interpolation(
63+
mask_cells_full, dims=sigma_mean.shape, min_cell_size=100
64+
)
6265
res_dict["mean normal stress Cell Area"] = np.mean(np.abs(sigma_mean[mask_int]))
6366
res_dict["max normal stress Cell Area"] = np.mean(np.abs(sigma_max_abs[mask_int]))
6467
res_dict["max shear stress Cell Area"] = np.mean(np.abs(tau_max[mask_int]))

saenopy/pyTFM/calculate_stress_imports/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)