API
The autodocumentation for the lsmgridtrack package is provided below.
Module: config
The config module contains functions and classes for defining analysis settings.
- class lsmgridtrack.config.GridOptions(**data)
Options defining the grid used to output calculated results.
- class lsmgridtrack.config.ImageOptions(**data)
Options to set image attributes and behavior.
- Parameters:
surface_axis (SurfaceAxis2D | None) –
-
surface_axis:
Optional[SurfaceAxis2D] Image axis to search for sample surface along
- class lsmgridtrack.config.Options(**data)
Defines configuration parameters for registration and analysis.
- Parameters:
image (ImageOptions) –
grid (GridOptions) –
registration (RegistrationOptions) –
- class lsmgridtrack.config.RegMethodEnum(value)
Optimization method to employ in image registration.
- class lsmgridtrack.config.RegMetricEnum(value)
Metric to be minimized during registration.
- class lsmgridtrack.config.RegSamplingEnum(value)
Image sampling strategy to be used when evaluating metric.
- class lsmgridtrack.config.RegistrationOptions(**data)
Options defining the registration procedure.
- Parameters:
method (RegMethodEnum) –
metric (RegMetricEnum) –
iterations (int) –
sampling_fraction (float) –
sampling_strategy (RegSamplingEnum) –
-
method:
RegMethodEnum Optimization method to employ for registration
-
metric:
RegMetricEnum Metric to minimize.
-
sampling_strategy:
RegSamplingEnum Volume sampling method to evaluate optimization metric.
- class lsmgridtrack.config.SurfaceAxis2D(value)
Axis to search for sample surface along: P suffix indicates to search forwards. N suffix indicates to search backwards.
- class lsmgridtrack.config.SurfaceAxis3D(value)
Axis to search for sample surface along: P suffix indicates to search forwards. N suffix indicates to search backwards.
Module: image
The image module contains functions and classes for reading and writing images, preprocessing the images for use in lsmgridtrack, and quantifying features like the the sample surface.
- lsmgridtrack.image.convert_image_to_vtk(img)
- Parameters:
img (
Image) –- Return type:
vtkImageData- Returns:
- lsmgridtrack.image.get_sample_surface2d(img, direction, threshold=0.25, stride=10)
- Parameters:
img (
Image) –direction (
SurfaceAxis2D) –threshold (
float) –stride (
int) –
- Return type:
vtkPolyData
- lsmgridtrack.image.get_sample_surface3d(img, direction, threshold=0.25, stride=10)
- Parameters:
img (
Image) –direction (
SurfaceAxis3D) –threshold (
float) –stride (
int) –
- Return type:
vtkPolyData
- lsmgridtrack.image.parse_image_file(filepath, options)
- Parameters:
filepath (
str) –options (
ImageOptions) –
- Return type:
Image- Returns:
- lsmgridtrack.image.parse_image_sequence(filepath, options)
- Parameters:
filepath (
str) –options (
ImageOptions) –
- Return type:
Image- Returns:
- lsmgridtrack.image.write_image_as_nii(img, name='image')
Module: registration
The registration module contains functions for defining and executing deformable image registration and saving the resulting transform.
- lsmgridtrack.registration.create_registration(options, reference_image)
- Return type:
ImageRegistrationMethod- Parameters:
options (RegistrationOptions) –
reference_image (Image) –
- Args:
options: Options for the image registration. reference_image: The reference image that will be registered.
- Returns:
A SimpleITK ImageRegistrationMethod
- lsmgridtrack.registration.register(reg, reference_image, deformed_image)
- Return type:
BSplineTransform- Parameters:
reg (ImageRegistrationMethod) –
reference_image (Image) –
deformed_image (Image) –
- Args:
reg: The image registration method to execute. reference_image: The reference image to be registered. deformed_image: The deformed image to be registered.
- Returns:
The resulting BSplineTransform from the registration.
Module: kinematics
The kinematics module provides functions for calculating the 3-D displacement field and subsequent kinematic variables on a specified rectilinear grid. These include the deformation gradient, Green-Lagrange strain, principal Green-Lagrange strains, and volumetric strains.
- class lsmgridtrack.kinematics.Kinematics(x_coordinates, y_coordinates, z_coordinates, displacements, deformation_gradients, strains, first_principal_strains, second_principal_strains, third_principal_strains, first_principal_strain_directions, second_principal_strain_directions, third_principal_strain_directions, volumetric_strains)
The calculated kinematics.
- Parameters:
x_coordinates (ndarray) –
y_coordinates (ndarray) –
z_coordinates (ndarray) –
displacements (ndarray) –
deformation_gradients (ndarray) –
strains (ndarray) –
first_principal_strains (ndarray) –
second_principal_strains (ndarray) –
third_principal_strains (ndarray) –
first_principal_strain_directions (ndarray) –
second_principal_strain_directions (ndarray) –
third_principal_strain_directions (ndarray) –
volumetric_strains (ndarray) –
- lsmgridtrack.kinematics.convert_kinematics_to_pandas(results)
- Parameters:
results (
Kinematics) –- Raises:
- Return type:
DataFrame- Returns:
- lsmgridtrack.kinematics.convert_kinematics_to_vtk(kinematics)
- Parameters:
kinematics (
Kinematics) –- Raises:
- Return type:
vtkRectilinearGrid- Returns:
- lsmgridtrack.kinematics.get_kinematics(grid_options, image_options, transform)
Calculate kinematics based on registration transform. Calculates the deformation gradient at element centroids and interpolates to the VTK grid vertices. The Green-Lagrange strain can then be calculated from the deformation gradients. The principal strains are the eigenvalues of the strain tensors directed along the eigenvectors. Assuming Einstein’s summation convention unless explicitly indicated, these calculations are as follows:
Note
Capital and lowercase letters imply reference and deformed configurations, respectively.
\[F^i_{\,J} = \sum_{a=1}^{4} x^i_{\,a}\frac{\partial N_a}{\partial X^J}.\]We therefore need to determine \(\frac{\partial N_a}{\partial X^J}\). From the chain rule,
\[\frac{\partial N_a}{\partial X^J} = \frac{\partial N_a}{\partial \eta^I} \left (\frac{\partial X^I}{\partial \eta^J} \right)^{-T}\]where
\[\frac{\partial X^I}{\partial \eta^J} = \sum_{a=1}^{4} X^I_{\,a} \frac{\partial N_a}{\partial \eta^J}.\]The Green-Lagrange strain tensor then follows as,
\[E_{IJ} = \frac{1}{2}\left(F_I^{\,i} g_{ij} F^j_{\,J} - G_{IJ}\right)\]where \(g_{ij}\) is the spatial metric tensor and \(G_{IJ}\) is the material metric tensor (both are the identity in Cartesian).
The eigenvalues * eigenvectors of this tensor ordered decreasing by eigenvalue are the principal strains.
The areal strain is,
\[E_{areal} = \det{F^i_{\,J}} - 1.0.\]- Parameters:
grid_options (
GridOptions) – Options defining properties of the grid.image_options (
ImageOptions) – Options defining properties of the registered images.transform (
Transform) – The transform calculated by the image registration.
- Return type:
- Returns:
The kinematics of the grid after deforming with the supplied transform.
- lsmgridtrack.kinematics.write_kinematics_to_excel(results, name)
Write the calculated kinematics to an excel file.
- Parameters:
results (
Kinematics) – Calculated Kinematics data object.name (
str) – Filename without extension.
- lsmgridtrack.kinematics.write_kinematics_to_vtk(data, name='output')
- Parameters:
data (
Kinematics) –name (
str) –
Module: kinematics2d
The kinematics2d module provides functions for calculating the 2-D displacement field and subsequent kinematic variables on a specified rectilinear grid. These include the deformation gradient, Green-Lagrange strain, principal Green-Lagrange strains, and volumetric strains.
- class lsmgridtrack.kinematics2d.Kinematics(x_coordinates, y_coordinates, displacements, deformation_gradients, strains, first_principal_strains, second_principal_strains, first_principal_strain_directions, second_principal_strain_directions, areal_strains)
- Parameters:
x_coordinates (ndarray) –
y_coordinates (ndarray) –
displacements (ndarray) –
deformation_gradients (ndarray) –
strains (ndarray) –
first_principal_strains (ndarray) –
second_principal_strains (ndarray) –
first_principal_strain_directions (ndarray) –
second_principal_strain_directions (ndarray) –
areal_strains (ndarray) –
- lsmgridtrack.kinematics2d.get_kinematics(grid_options, image_options, transform)
Calculate kinematics based on registration transform. Calculates the deformation gradient at element centroids and interpolates to the VTK grid vertices. The Green-Lagrange strain can then be calculated from the deformation gradients. The principal strains are the eigenvalues of the strain tensors directed along the eigenvectors. Assuming Einstein’s summation convention unless explicitly indicated, these calculations are as follows:
Note
Capital and lowercase letters imply reference and deformed configurations, respectively.
\[F^i_{\,J} = \sum_{a=1}^{8} x^i_{\,a}\frac{\partial N_a}{\partial X^J}.\]We therefore need to determine \(\frac{\partial N_a}{\partial X^J}\). From the chain rule,
\[\frac{\partial N_a}{\partial X^J} = \frac{\partial N_a}{\partial \eta^I} \left (\frac{\partial X^I}{\partial \eta^J} \right)^{-T}\]where
\[\frac{\partial X^I}{\partial \eta^J} = \sum_{a=1}^{8} X^I_{\,a} \frac{\partial N_a}{\partial \eta^J}.\]The Green-Lagrange strain tensor then follows as,
\[E_{IJ} = \frac{1}{2}\left(F_I^{\,i} g_{ij} F^j_{\,J} - G_{IJ}\right)\]where \(g_{ij}\) is the spatial metric tensor and \(G_{IJ}\) is the material metric tensor (both are the identity in Cartesian).
The eigenvalues * eigenvectors of this tensor ordered decreasing by eigenvalue are the principal strains.
The volumetric strain is,
\[E_{volumetric} = \det{F^i_{\,J}} - 1.0.\]- Parameters:
grid_options (
GridOptions) – Options defining properties of the grid.image_options (
ImageOptions) – Options defining properties of the registered images.transform (
Transform) – The transform calculated by the image registration.
- Return type:
- Returns:
The kinematics of the grid after deforming with the supplied transform.
Module: postprocessing
The postprocessing module provides functions to rotate data to new coordinate systems aligned with a provided sample surface geometry.
- lsmgridtrack.postprocessing.convert_vtk_to_dataframe(data)
Converts VTK grid to a Pandas dataframe.
- Parameters:
data (
Union[vtkImageData,vtkRectilinearGrid]) – VTK grid- Return type:
DataFrame- Returns:
Pandas dataframe with vertex coordinates and VTK data arrays.
- lsmgridtrack.postprocessing.globally_transform_2d(data, surface)
Rotate tensors stored on VTK grid to align with average orientation of provided surface.
- lsmgridtrack.postprocessing.globally_transform_3d(data, surface)
Rotate tensors stored on VTK grid to align with average orientation of provided surface.
- lsmgridtrack.postprocessing.globally_transform_dataframe_3d(data, surface)
Rotate tensors to align with the average orientation of the provided surface PolyData.
- lsmgridtrack.postprocessing.globally_transform_polydata_coordinates_3d(data, surface)
Transform coordinates of each PolyData in list to align with average orientation of provided surface.
- lsmgridtrack.postprocessing.read_stl(filename)
Read STL file as vtkPolyData
- Parameters:
filename (
str) –- Return type:
vtkPolyData- Returns:
- lsmgridtrack.postprocessing.read_vtk_grid(filename)
Read VTK grid from file.
- lsmgridtrack.postprocessing.read_vtk_surface(filename)
Read vtkPolyData from file.
- Parameters:
filename (
str) – Path to file.- Return type:
vtkPolyData- Returns:
- lsmgridtrack.postprocessing.transform_dataframe_to_local_csys_3d(data, surface)
Rotate tensors in dataframes to local coordinate systems constructed from the normals and tangent vectors of the nearest point on the provided surface.
- lsmgridtrack.postprocessing.transform_to_local_csys_2d(data, surface)
Rotate tensors stored on VTK grid to align with orientation of nearest point on provided surface.
- lsmgridtrack.postprocessing.transform_to_local_csys_3d(data, surface)
Rotate tensors stored on VTK grid to align with orientation of nearest point on provided surface.
- lsmgridtrack.postprocessing.write_dataframe_to_excel(data, name)
Write Pandas dataframe or dictionary of dataframes to an Excel file. If dictionary provided each (key, value) will be a new sheet.
- lsmgridtrack.postprocessing.write_to_vtk_grid(data, name)
Write VTK RectilinearGrid to file.
- Parameters:
data (
vtkRectilinearGrid) –name (
str) –