Skip to content

Commit

Permalink
more refactoring of pyTFM to disentangle files
Browse files Browse the repository at this point in the history
  • Loading branch information
rgerum committed Apr 19, 2024
1 parent d10f5aa commit 796d932
Show file tree
Hide file tree
Showing 10 changed files with 1,013 additions and 1,107 deletions.
23 changes: 19 additions & 4 deletions saenopy/pyTFM/TFM_tractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@


def ffttc_traction(
u, v, pixel_size1, pixel_size2, young, sigma=0.49, spatial_filter="gaussian", fs=None
u,
v,
pixel_size1,
pixel_size2,
young,
sigma=0.49,
spatial_filter="gaussian",
fs=None,
):
"""
fourier transform based calculation of the traction force. U and v must be given as deformations in pixel. Size of
Expand Down Expand Up @@ -281,12 +288,20 @@ def ffttc_traction_finite_thickness(


def TFM_tractions(
u, v, pixel_size1, pixel_size2, h, young, sigma=0.49, spatial_filter="gaussian", fs=6
u,
v,
pixel_size1,
pixel_size2,
h,
young,
sigma=0.49,
spatial_filter="gaussian",
fs=6,
):
"""
height correction breaks down due to numerical reasons at large gel height and small wavelengths of deformations.
In this case the height corrected ffttc-function returns Nans. THis function falls back
to the non height-corrected FTTC function if this happens
In this case the height corrected ffttc-function returns Nans. This function falls back
to the non height-corrected FTTC function if this happens
:return:
"""
# translate the filter size to pixels of traction field
Expand Down
11 changes: 3 additions & 8 deletions saenopy/pyTFM/calculate_strain_energy.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import numpy as np
from scipy.ndimage import binary_fill_holes

try:
from scipy.ndimage import binary_fill_holes
except ImportError:
from scipy.ndimage.morphology import binary_fill_holes
from saenopy.pyTFM.TFM_functions import strain_energy_points, contractility
from saenopy.pyTFM.grid_setup_solids_py import (
interpolation,
) # a simple function to resize the mask
from saenopy.pyTFM.calculate_stress_imports.mask_interpolation import mask_interpolation


def calculate_strain_energy(mask, pixel_size, shape, u, v, tx, ty):
mask = binary_fill_holes(
mask == 1
) # the mask should be a single patch without holes
# changing the masks dimensions to fit to the deformation and traction fields
mask = interpolation(mask, dims=u.shape)
mask = mask_interpolation(mask, dims=u.shape)
ps1 = pixel_size # pixel size of the image of the beads
# dimensions of the image of the beads
ps2 = ps1 * np.mean(
Expand Down
35 changes: 19 additions & 16 deletions saenopy/pyTFM/calculate_stress.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import numpy as np
from scipy.ndimage import binary_fill_holes

try:
from scipy.ndimage import binary_fill_holes
except ImportError:
from scipy.ndimage.morphology import binary_fill_holes
from saenopy.pyTFM.calculate_stress_imports.mask_interpolation import mask_interpolation
from saenopy.pyTFM.calculate_stress_imports.grid_setup_solids_py import prepare_forces
from saenopy.pyTFM.calculate_stress_imports.grid_setup_solids_py import grid_setup
from saenopy.pyTFM.calculate_stress_imports.grid_setup_solids_py import FEM_simulation
from saenopy.pyTFM.calculate_stress_imports.find_borders import find_borders

from saenopy.pyTFM.grid_setup_solids_py import (
interpolation,
) # a simple function to resize the mask
from saenopy.pyTFM.grid_setup_solids_py import prepare_forces
from saenopy.pyTFM.grid_setup_solids_py import grid_setup, FEM_simulation
from saenopy.pyTFM.grid_setup_solids_py import find_borders
from saenopy.pyTFM.stress_functions import line_tension
from saenopy.pyTFM.stress_functions import all_stress_measures, coefficient_of_variation
from saenopy.pyTFM.stress_functions import mean_stress_vector_norm
from saenopy.pyTFM.calculate_stress_imports.stress_functions import line_tension
from saenopy.pyTFM.calculate_stress_imports.stress_functions import all_stress_measures
from saenopy.pyTFM.calculate_stress_imports.stress_functions import (
coefficient_of_variation,
)
from saenopy.pyTFM.calculate_stress_imports.stress_functions import (
mean_stress_vector_norm,
)


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

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

# converting traction forces (forces per surface area) to actual forces
# and correcting imbalanced forces and torques
Expand All @@ -58,7 +59,9 @@ def calculate_stress(mask, pixel_size, shape, u, tx, ty):
sigma_max, sigma_min, sigma_max_abs, tau_max, phi_n, phi_shear, sigma_mean = (
all_stress_measures(stress_tensor, px_size=ps2 * 10**-6)
)
mask_int = interpolation(mask_cells_full, dims=sigma_mean.shape, min_cell_size=100)
mask_int = mask_interpolation(
mask_cells_full, dims=sigma_mean.shape, min_cell_size=100
)
res_dict["mean normal stress Cell Area"] = np.mean(np.abs(sigma_mean[mask_int]))
res_dict["max normal stress Cell Area"] = np.mean(np.abs(sigma_max_abs[mask_int]))
res_dict["max shear stress Cell Area"] = np.mean(np.abs(tau_max[mask_int]))
Expand Down
Empty file.
Loading

0 comments on commit 796d932

Please sign in to comment.