A library for analyzing data from universal test machines.
Project description
matmech
Overview
The matmech Python library processes, analyzes, and visualizes mechanical testing data (e.g., from Instron devices using WaveMatrix or BlueHill software).
It automates the workflow from:
- Raw CSV import
- Standardized data cleanup
- Phase-based analysis
- Graph generation (static and animated)
Supported Features
- Axial Stress–Strain calculations (rectangular cross-sections)
- Torsional Shear Stress–Strain calculations (rectangular cross-sections)
- Multi-phase test segmentation by time
- Plotting with autoscaling, linear fits, and animations
Library Structure
matmech/
│
├── __init__.py # Package initialization
├── common_utils.py # General utility functions like data loading and splitting
├── axial_analysis.py # Functions for calculating axial material properties
├── torsional_analysis.py # Functions for calculating torsional material properties
├── plotting_tools.py # Functions for generating static and animated plots
├── config_defaults.py # Default configurations and registries for software profiles, data columns, and plot settings
└── workflow.py # Orchestrates the entire data analysis process
Installation
To install the matmech package, navigate to the root of the matmech repository and install it in editable mode within your development environment:
pip install -e .
This command installs the package in "editable" mode, meaning that changes to the source code in your matmech repository will immediately affect the installed package without needing to reinstall.
Requirements
The core matmech library requires the following Python packages, which will be installed automatically:
pandasnumpymatplotlib
Optional Dependencies:
- Animation Output (
.mp4): For generating animated plots,ffmpegis required. This is a system dependency, not a Python package.- On Ubuntu/Debian, install it using:
sudo apt install ffmpeg - On Windows, download it from the FFmpeg website and add it to your system's PATH.
- On Ubuntu/Debian, install it using:
- Development/Testing: For running tests,
pytestis required. Install it with:pip install -e ".[dev]"
How It Works
- Loads raw CSV data from
./data/(relative to the calling script). - Standardizes column names and units (based on selected software profile).
- Splits data into segments by time (based on test recipe).
- Applies phase-specific analysis functions (axial or torsional).
- Generates static and/or animated plots saved to
./graphs/.
Example Directory Layout
matmech/
│
├── data/
│ └── my_test_run.csv
│
├── matmech/
│ └── (library modules...)
│
└── main.py
Full Example: main.py
The following example shows ALL available configuration options.
import os
from matmech.workflow import run_analysis_workflow
if __name__ == "__main__":
# Path configuration
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
user_config = {
# --- Software Profile (choose 'wavematrix' or 'bluehill') ---
"software_type": "bluehill",
# --- Input CSV file name (inside ./data) ---
"data_file_name": "my_test_run.csv",
# --- Geometry (in millimeters) ---
"geometry": {
"axial_width_mm": 10.0,
"axial_thickness_mm": 2.0,
"gauge_length_mm": 25.0,
"torsional_side1_mm": 10.0,
"torsional_side2_mm": 5.0
},
# --- Optional inversion and taring settings ---
"inversion_flags": {
"force": False,
"torque": False
},
"tare_options": {
"position": True,
"force": True
},
# --- Test Phases (with end times in seconds) ---
"test_recipe": [
{"name": "Axial Calibration", "end_time": 5.0, "type": "AXIAL"},
{"name": "Torsion Loading", "end_time": 10.0, "type": "TORSIONAL"}
],
# --- Plot definitions ---
"plots": [
# Static plot with fit
{
"title": "Axial Stress vs. Axial Strain ({phase_name})",
"output_filename": "axial_stress_strain_{phase_name}",
"phases": ["Axial Calibration"],
"x_col": "axial_strain",
"y_col": "axial_stress",
"fit_line": True,
"fit_bounds": (0.0, 0.002),
"x_units": "auto",
"y_units": "auto",
"type": "static"
},
# Animated plot
{
"title": "Shear Stress vs. Shear Strain ({phase_name})",
"output_filename": "shear_stress_strain_{phase_name}",
"phases": ["Torsion Loading"],
"x_col": "shear_strain",
"y_col": "shear_stress",
"type": "animated",
"animation_options": {
"target_duration_s": 8,
"target_fps": 24,
"snap_x_to_zero": True,
"snap_y_to_zero": True
}
}
]
}
# Run the full workflow
run_analysis_workflow(SCRIPT_DIR, user_config)
Configuration Reference
| Key | Type | Description |
|---|---|---|
software_type |
str |
"wavematrix" or "bluehill" |
data_file_name |
str |
Name of the CSV file inside ./data/ |
geometry |
dict |
Required dimensions for calculations (in millimeters) |
inversion_flags |
dict |
Optional channel sign reversals (force, torque) |
tare_options |
dict |
Taring channels to zero at start (position, force) |
test_recipe |
list |
Phases with "name", "end_time" (seconds), "type" |
plots |
list |
One or more plot configs, may include animation |
fit_bounds |
tuple |
(x_min, x_max) bounds for linear fitting |
animation_options |
dict |
Parameters for animations (fps, duration, snap_to_zero) |
Output Files
All output graphs and videos are written to:
./graphs/
Files include:
*.png(static plots)*.mp4(animated plots)
Logging
Progress and analysis info will appear as console logs, including steps such as:
- File loading
- Data standardization
- Axial/Torsional calculations
- Linear modulus fitting results
- Plot saving
Example Log Output
INFO: Using software profile: 'bluehill'
INFO: Loading data from: my_test_run.csv
INFO: Axial stress calculated.
INFO: Linear Fit Analysis — Modulus: 1.98 GPa
INFO: Static plot saved to: axial_stress_strain_Axial Calibration.png
INFO: Animation saved: shear_stress_strain_Torsion Loading.mp4
Extending the Library
To register a new analysis type:
- Create a new module function:
def my_new_analysis(df, geometry): # ... implement analysis logic ... return df
- Add it to the registry in
matmech/workflow.py:ANALYSIS_REGISTRY["NEW_TYPE"] = my_new_analysis
- Reference it in your
test_recipe:{"name": "My New Phase", "end_time": 12.0, "type": "NEW_TYPE"}
Notes
- The data column naming conventions differ between software types. The file
matmech/config_defaults.pydefines these profiles for both WaveMatrix and BlueHill. - Axis units and autoscaling are handled automatically but can be overridden per plot.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Copyright (c) 2025 Mitchell Blaha
Project details
Release history Release notifications | RSS feed
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 matmech-1.0.6.tar.gz.
File metadata
- Download URL: matmech-1.0.6.tar.gz
- Upload date:
- Size: 21.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7462bf340aae66ffe88f8a17cfe224bec8f7d0c0401e8e481587e00b1b3354cb
|
|
| MD5 |
4323cefece49ac12e5324a4555ad1140
|
|
| BLAKE2b-256 |
258c85a105bea88ae3f6c59c503861ada5e197b11c749d019749b0318da928f6
|
Provenance
The following attestation bundles were made for matmech-1.0.6.tar.gz:
Publisher:
python-publish.yml on WhiteRabbit2006/matmech
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
matmech-1.0.6.tar.gz -
Subject digest:
7462bf340aae66ffe88f8a17cfe224bec8f7d0c0401e8e481587e00b1b3354cb - Sigstore transparency entry: 690675304
- Sigstore integration time:
-
Permalink:
WhiteRabbit2006/matmech@8486f27039a6d99ccc73f7dac049c11676667370 -
Branch / Tag:
refs/tags/1.0.6 - Owner: https://github.com/WhiteRabbit2006
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@8486f27039a6d99ccc73f7dac049c11676667370 -
Trigger Event:
release
-
Statement type:
File details
Details for the file matmech-1.0.6-py3-none-any.whl.
File metadata
- Download URL: matmech-1.0.6-py3-none-any.whl
- Upload date:
- Size: 20.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
34d56eb2ef1d837370559cb034475abc8b8d7e55179f0197eca509810d5cee41
|
|
| MD5 |
e69dcd5d406762998360cfcfa002c6fe
|
|
| BLAKE2b-256 |
dbce8875eaa77dc801438730e1bd1118b7692f3af6e5823e0049e68e53bbe008
|
Provenance
The following attestation bundles were made for matmech-1.0.6-py3-none-any.whl:
Publisher:
python-publish.yml on WhiteRabbit2006/matmech
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
matmech-1.0.6-py3-none-any.whl -
Subject digest:
34d56eb2ef1d837370559cb034475abc8b8d7e55179f0197eca509810d5cee41 - Sigstore transparency entry: 690675307
- Sigstore integration time:
-
Permalink:
WhiteRabbit2006/matmech@8486f27039a6d99ccc73f7dac049c11676667370 -
Branch / Tag:
refs/tags/1.0.6 - Owner: https://github.com/WhiteRabbit2006
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@8486f27039a6d99ccc73f7dac049c11676667370 -
Trigger Event:
release
-
Statement type: