Mach-1 Analysis Functions
Project description
© Biomomentum Inc - All rights reserved
Biomomentum-functions
This repository contains multiple python scripts used for data analysis in mechanical testing with mach-1 testers from Biomomentum. To use this library, it recommended to use conda environments.
Installation
- Install Anaconda on your computer.
- Open Anaconda Powershell Prompt by searching in the taskbar.
- Create a new environment using the following command on an Anaconda Powershell Prompt (use python 3.11 for most stable release):
conda create --name env python=3.11
- From the /dist directory of this repository, download the WHL file
- Activate the newly created environment:
conda activate env
- Install directly from PIP:
pip install "biomomentum"
- Import the library into a Python script or notebook:
Import biomomentum
Testing
A jupyter notebook is provided for testing some functions. Follow these steps to try out the notebook on your computer.
- Open Anaconda Powershell Prompt by searching in the taskbar.
- Activate the newly created environment:
conda activate env
- Install jupyter package in the created environment using
conda install jupyter
- Install matplotlib package in the created environment using
conda install matplotlib
- Download and install VsCode
- On the left tab of the software go to extensions and download Python and Jupyter.
- Download the folder \examples to test the library.
Documentation
The following section presents each function incorporated into the biomomentum Python library.
Utils
sorted_alphanumeric
def sorted_alphanumeric(files) -> list
Sorts alpha numerically files from directory.
Arguments:
fileslist - Files from directory to sort.
Returns:
- list - Files from directory to sort.
get_super
def get_super(x) -> str
Insert super script char on string
Arguments:
xstr - Character to super script.
Returns:
- str - Char in super script format.
inDict
def inDict(dict, key) -> Bool
Checks if key is in dictionary.
Arguments:
dictDict - Dictionary to check keys.keystr - Key to check if is in dictionary.
Returns:
- Bool - True if key is in dictionary, false otherwise.
select_data_file
def select_data_file(file_extension = ".txt") -> str
Function that brings a pop up prompt to select the mach-1 file or MAP file.
Arguments:
file_extensionstr - File extention from file either .txt (Mach-1 files) or .map (MAP files).
Returns:
filenamestr - Directory of the selected file.
select_data_file_dir
def select_data_file_dir(keyword = None, read_MAP = False) -> List
Function that brings a pop up prompt to select a folder contaning multiple mach-1 files or MAP files.
Arguments:
keywordstr - String Name of group of mach-1 files to load in folder.read_MAPBool - Bool to indicate whether to select mach_1 files or MAP files.
Returns:fileslist - Files of the mach-1 from the folder or MAP files.
stats
ResidualStandardError
def ResidualStandardError(x, xfit, predictors) -> float
Insert super script char on string
Arguments:
xnp.array - Independent variable values (assumed to be error-free).xfitnp.array - Signal fit of xfit.predictorint - Number of predictors of the function.
Returns:
serfloat - Standard residual error.
rsquared
def rsquared(Y, mse, poly_order) -> float
Extracts statistical R-squared.
Arguments:
Ynp.array - Signal Fitted .msenp.array - Mean Squared Error of the fit.poly_orderint - Number of predictors of the function.
Returns:
Rsq_adjint - Adjusted R-squared.
interpolation
linear_least_square
def linear_least_square(x,y)
Least square algorithm.
Arguments:
xnp.array - independent variable (data units).ynp.array - dependent variable (data units).
Returns:
Anp.array - Parameters of linear model (A[0] slope, A[1] intercept).curveFitnp.array - Linear fit.Rsq_adjfloat - Adjusted R-squared.
interpolateMAP
def interpolateMAP(subSurfaces, interpolate_to_bounds = False, smooth_data = False, threshold = 4, keyword = "")
Function to apply 2D linear interpolation into the data.
Arguments:
subSurfacesdict - Dictionary of all the surfaces identified in the MAP file.thresholdfloat - threshold standard deviation to control smoothing.interpolate_to_boundsbool - Flag to indicate whether to extrapolate values to surface bound.thresholdfloat - threshold standard deviation to control smoothing.keywordstr - Name given to the measurements in the MAP file.
Returns:
QP_2Dlist of np.array - List of 2D array of the interpolated values into the subSurface.triangleslist of scipy.Delaunay - List of Triangles used for the interpolation (see Delaunay).grid_Xlist of np.array - List of 2D array of the X values used to construct the interpolation.grid_Ylist of np.array - List of 2D array of the Y values used to construct the interpolation.
smoothMAP
def smoothMAP(QP, triangles, threshold)
Function to smooth data for interpolation.
Arguments:
QPnp.array - independent variable (data units).triangleslist[list] - list of lists, each sublist contains the indices of neighbors for each data point.thresholdnp.array - threshold standard deviation to control smoothing.
Returns:
smoothed_mapnp.array - Smoothed data.
ios
read_mach_1_file
def read_mach_1_file(file_path: Union[str, Path], read_data: bool = True, data_headers: Optional[List[str]] = None, show_progress: bool = True) -> Dict[str, Any]
Parse a Mach-1 Motion .txt file into a nested dictionary structure.
Arguments:
file_pathstr - .txt file name generated by Mach-1 Motion .read_dataint - Integer indicating if the numerical data in the Mach-1 .txt file should be read. Default value is 1. 0: Read only the infos.data_headerslist - List of specific data headers to load.show_progressbool - Flag to show progress bar on command prompt.
Returns:
resultdict - A mapping from function instance keys to a dictionary containing:<INFO>: core info key-values1<FunctionName>: metadata for each function<DATA>: parsed measurement data (numpy arrays)
read_mach_1_files
def read_mach_1_files(sources: Union[str, Path, List[Tuple[Path, str]]], read_data: bool = True, data_headers: Optional[List[str]] = None, pattern: str = "*.txt", show_progress: bool = True, use_multiprocessing: bool = False) -> Tuple[Dict[str, Any], Path]
Read Mach-1 .txt files into a dictionary using the refactored reader.
Arguments:
read_dataint - Integer indicating if the numerical data in the Mach-1 .txt file should be read. Default value is 1. 0: Read only the infos.data_headersList - List of specific data headers to load.show_progressBool - Flag to show progress bar on command prompt.use_multiprocessingBool - Flag to indicate whether to use multiprocessing to load mach-1 files.
Returns:
- Tuple:
- Dict mapping each key to its parsed content.
- Path of the processed directory (parent of first file).
get_subSurfaces
def get_subSurfaces(MAP_file, keyword = "", scanFlag = False) -> dict
Function to separate surfaces from MAP in dictionary.
Arguments:
MAP_filestr - Map file directory.keywordstr - Name given to the measurements in the MAP file.scanFlagbool - Indicate whether MAP file contains scan data
Returns:
subSurfacesdict - Dictionary of all the surfaces identified in the MAP file.
analysis_static
compliance_correction
def compliance_correction(displacement, load, criteria = 1, interval = None) -> float
Extracts compliance correction factor for compression tests in mach-1.
Arguments:
displacementnp.array - Displacement of sample in mm.loadnp.array - Load of sample in N.criteriafloat - Criteria to select data.intervallist - Interval to extract correction factor.
Returns:
correction_factorfloat - Correction for compliance.
HayesElasticModel
def HayesElasticModel(posZ, loadZ, gf_flag, maxStrain, R, v, Rsq_req, sampleThickness = None, origin_set=False, eqModulus=False, spherical_indenter=False)
Extracts Elastic Properties from Indentation.
Arguments:
posZnp.array - Array Z-position (mm).loadZnp.array - Array Z-load (gf or N).gf_flagBool - Indicate whether loadZ units is gf.maxStrainfloat - Radius of indenter in mm.Rflaot - Poisson's ratio.vfloat - Interval to extract correction factor.Rsq_reqfloat - Required fit R square value (usually 0.95).sampleThicknessfloat - Sample thickness in mm.origin_setbool - Indicate whether signal starts at origin.eqModulusbool - Indicate whether signal only fits 2 points.spherical_indenterbool - Indicate wheter to use cylinder Hayes model or spherical model.
Returns:
Gfloat - Indentation Shear Modulus in MPa.Efloat - Indentation Elastic Modulus in MPa.Fitnp.array - Fit for posZ and loadZ using Hayes spherical model 1972.Rsq_adjfloat - Adjusted R-squared for the fit.
relaxation_constant
def relaxation_constant(data, time, startIdx) -> float
Extracts Relaxation Constant from time data.
Arguments:
datanp.array - Data to extract tau.timenp.array - Time (s).startIdxint - Index to indicate where to start the analysis.
Returns:
taufloat - Time constant.
stressrelaxation_fit
def stressrelaxation_fit(t, sz, r0, e0, vm, t0in = None, filemat = None
Function to fit stress relaxation curves and extract mechanical properties.
Arguments:
tnp.array - Data array (s).sznp.array - Stress array (MPa).r0Bool - Disk radius (mm).e0float - Disk stress.vmflaot - Poisson's ratio.t0infloat - Compression time (s).filematfloat - Matlab file (sveff_tab.mat).
Returns:
szfitnp.array - Stress array fit (MPa).effloat - Elastic Fibril Modulus (MPa).k0float - Hydraulic permeability (mm2/MPa.s).e33float - Elastic Equilibrium Modulus (MPa).t0float - Compression time (s).S11float - Elastic Modulus S11 (MPa).szequfloat - Equilibrium stress (MPa).Kfloat - Coefficient (MPa.s).taufloat - Time constant (s).emfloat - Elastic Modulus of isotropic matrix (MPa).nmfloat - Poisson coefficient of isotropic matrix.msefloat - Mean quadratic error .
get_cartilage_index
def get_cartilage_index(Fz, Time) -> np.array
Function to extract cartilage index from signal
Arguments:
Fznp.array - Normal force from automatic thickness indentation.Timenp.array - Time (s).
Returns:
index_interest_meannp.array - Begin and end of cartilage layer of surface.
analysis_dynamic
FitSinusoid
def FitSinusoid(time, freq, data_1, data_2 = None, method = "trf", lossType = "soft_l1", fscale = 0.001, trim_data = False)
Sinusoid fit on data using least-squares and extract dynamic modulus.
Arguments:
timenp.array - time vector (s).freqfloat - frequency guess (Hz).data_1np.array - data vector (data units) .data_2np.array - data vector (data units) to sync with data_1 (None by default).methodnp.array - method for the least-squares (least_squares).lossTypenp.array - loss for the method applied (least_squares).fscalenp.array - weight for the loss function (least_squares).trim_databool - bool to indicate whether to trim the data or not.
Returns:
Paramsstructure - If data_2 is not given then.Params[0]float - Sin offset of data_1.Params[1]float - Sin amplitude of data_1.Params[2]float - Sin frequency of data_1.Params[3]float - Sin phase of data_1.
Paramsstructure - If data_2 is given then.Params[2]float - Sin frequency of data_1 and data_2.Params[4]float - Sin offset of data_2.Params[5]float - Sin amplitude of data_2.Params[6]float - Sin phase of data_2.
data_sinnp.array - Sin fit into data_1.data_sin_2np.array - Sin fit into data_2 (if passed in arguments).data_extranp.array - Data trimmed if flag passed (for plotting) for data_1.data_extra_2np.array - Data trimmed if flag passed (for plotting) for data_2 (if passed in arguments).ser_datafloat - Residual standard error of the fit for data_1.ser_data_2float - Residual standard error of the fit for data_2 (if passed in arguments).
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file biomomentum-0.1.7.tar.gz.
File metadata
- Download URL: biomomentum-0.1.7.tar.gz
- Upload date:
- Size: 43.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61d8bbf075566de8e1f05ce59434b5f91d1699b22c14a1762fde88904156e3cb
|
|
| MD5 |
86ff6a2b630a74772b838102feaf5ee4
|
|
| BLAKE2b-256 |
59c292e9de3e064bddf27bd192a89d6ca79cea71d2e41766a64d4dc74d45eb98
|
File details
Details for the file biomomentum-0.1.7-py3-none-any.whl.
File metadata
- Download URL: biomomentum-0.1.7-py3-none-any.whl
- Upload date:
- Size: 39.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2aea82506728087d32cd76ba741ade0c6c5fb4aab0610e3c21d710a4d03db9b0
|
|
| MD5 |
84375ebb1e3c80aa1583b6a1942a4008
|
|
| BLAKE2b-256 |
91ba0c56603a59d741b0bfe6ec3ada45eca662f89d689e8c822d408f56ccc37c
|