material_mapping module

material_mapping.__computePHI__(ROI)[source]

Compute the bone partial volume.

Parameters: ROI (ndarray): The array containing the ROI of the image.

Returns: PHI (float): The PHI value.

material_mapping.__compute_eval_evect__(MSL_kernel_list, elms, BVseg, projection=True)[source]

Computes Eigenvalues and Eigenvectors for a given element using MSL_kernel_list, which is a return value of preprocessing.compute_local_MSL (stored in bone: dict)

Can be used for cortical or trabecular phase. Note that for cortical phase projection = True!

Parameters:
  • MSL_kernel_list (List with areaweighted dyadic products of triangulation, after kernel homogenization)

  • phase (BVseg bone volume from segmentation for specific bone)

  • main (projection Defines if projection of global Z on plane of MSL (used for cortical phase to have) – orientation along cortical shell

Returns:

  • eval Eigenvalues

  • evect Eigenvectors

material_mapping.__compute_eval_evect_projection__(elms, _evect)[source]
material_mapping.__get_fe_dims__(img_shape: tuple, FEelSize: float, Spacing: float)[source]

Helper function to retrieve same dimensions as FE mesh in Denis’ mesh construction Simone Poncioni, MSB, 17.08.2023

Args: - img_shape (tuple): shape of the original image - FEelSize (float): size of the finite elements in the FE mesh –> consistent with Denis’s mesh construction - Spacing (float): voxel spacing of the original image

Returns: - MESH_centroids_mm (numpy.ndarray): array of centroids of each element in the FE mesh, in millimeters - FEdimX (int): dimension of the FE mesh in the X direction - FEdimY (int): dimension of the FE mesh in the Y direction - FEdimZ (int): dimension of the FE mesh in the Z direction - CoarseFactor (float): coarsening factor used to construct the FE mesh

material_mapping.__get_masks__(cog, spacing, VOI_mm, seg_array, mask_array)[source]
material_mapping.__material_mapping__(cog, spacing, VOI_mm, mask_array, seg_array, SEG_correction, all_mask: bool, compartment_s: str)[source]

Compartment agnostic material mapping function Simone Poncioni, MSB, 08.2023

material_mapping._bmc_compensation(BMD: ndarray, CORTMASK: ndarray, TRABMASK: ndarray, cort_elms: dict, trab_elms: dict, RHOc: ndarray, RHOt: ndarray, PHIc: ndarray, PHIt: ndarray, FEelSize, Spacing, BMC_conservation: bool)[source]

# BMC compensation for all BVTV values in order to conserve bone mass during homogenization

material_mapping.cai_evalues()[source]

Returns evalues of Cai et al. (2019) adapted for transverse isotropy. From human cortical bone of the proximal femur. https://doi.org/10.1016/j.actbio.2019.03.043 :rtype: Evalues E1, E2, E3

material_mapping.calculate_bvtv(seg_array, mask_array, spacing, VOI_mm, cog)[source]

POS, 06.02.2024 Calculate the bone volume to total volume (BV/TV) ratio.

This function calculates the BV/TV ratio, which is a measure of bone density. It does this by first calculating the region of interest (ROI) in the given 3D array (seg_array), then computing the bone partial volume (PHI), and finally computing the BV/TV ratio.

Parameters: seg_array (np.array): The 3D array representing the segmented image. mask_array (np.array): The 3D array representing the mask image. spacing (np.array): The spacing between voxels in the 3D image. VOI_mm (float): The size of the Volume of Interest in millimeters. cog (np.array): The center of gravity of the FE element.

Returns: tuple: A tuple containing the PHI and RHO values.

material_mapping.compute_isoFAB()[source]

Returns isotropic fabric return [eval1, eval2, eval3], [evecxx, evecxy, evecxz], [evecyx, evecyy, evecyz], [eveczx, eveczy, eveczz]]

material_mapping.correspondence_dict(centroids_mesh, closest_phys_points)[source]

Creates a correspondence dictionary between physical points and centroids in the mesh.

Args: - centroids_mesh (numpy.ndarray): array of centroids of each element in the mesh, in millimeters - closest_phys_points (numpy.ndarray): array of indices of the closest physical point for each centroid in the MSL kernel

Returns: - correspondence_dict (dict): dictionary mapping each physical point index to its corresponding centroid in the mesh

material_mapping.getClosestPhysPoint(centroids_mesh, phys_points)[source]

Finds the closest physical point to each centroid in the cortical mesh. You can then mask the physical points with this array to get the closest physical point for each centroid

Args: - centroids_mesh (numpy.ndarray): array of centroids of each element in the cortical mesh, in millimeters (m, 3) - phys_points (numpy.ndarray): array of physical points, in millimeters (n, 3)

Returns: - distances (numpy.ndarray): array of distances between each centroid and its closest physical point - indices (numpy.ndarray): array of indices of the closest physical point for each centroid

material_mapping.get_bone_dict(basepath, meshpath, _mesh)[source]
material_mapping.material_mapping_spline(bone: dict, cfg, filenames: FileConfig)[source]

Material Mapping, including PSL ghost padding layers as copy of most distal and proximal layers For accurate PSL pipeline Additionaly, the optional BMC conversion can be specified in config.yaml. This function will conserve BMC from image to hFE model to ensure, no mass conservation.

Included new MSL fabric evaluation with separation between cortex and trabecular bone Version adapted for spline meshing algorithm (POS, 08.2023)

Parameters: # ? add parameters

Returns: # ? add returns

material_mapping.vectoronplane(evect_max, evect_mid, evect_min, direction)[source]
Parameters:
  • evect_max

  • evect_mid

  • evect_min

  • direction

Returns:

  • 3 numpy arrays in order evect min, evect mid, evect max

  • evect_max_projected is computed by projection of direction (usually [0,0,1]) into the plane evect_max, evect_mid.

  • evect_min_projected is orthogonal to max and mid, so computed from their cross product

  • evect_mid_projected is orthogonal to max and min, so computed from their cross produc

  • Old implementation

  • normal = numpy.cross(evect_max, evect_mid)

  • normalized = normal / numpy.linalg.norm(normal)

  • evect_max_projected_normalized = ( – direction - numpy.dot(direction, normalized) * normalized

  • )

  • evect_max_projected = evect_max_projected_normalized * numpy.linalg.norm(evect_max)

  • evect_min_projected = normalized

  • evect_mid_projected = numpy.cross(evect_max_projected, normalized)

  • evect_max_proj = direction - numpy.dot(direction, normal)

  • Projection acc. https (//www.maplesoft.com/support/help/maple/view.aspx?path=MathApps%2FProjectionOfVectorOntoPlane)