Skip to main content

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:

  • pandas
  • numpy
  • matplotlib

Optional Dependencies:

  • Animation Output (.mp4): For generating animated plots, ffmpeg is 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.
  • Development/Testing: For running tests, pytest is required. Install it with:
    pip install -e ".[dev]"
    

How It Works

  1. Loads raw CSV data from ./data/ (relative to the calling script).
  2. Standardizes column names and units (based on selected software profile).
  3. Splits data into segments by time (based on test recipe).
  4. Applies phase-specific analysis functions (axial or torsional).
  5. 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:

  1. Create a new module function:
    def my_new_analysis(df, geometry):
        # ... implement analysis logic ...
        return df
    
  2. Add it to the registry in matmech/workflow.py:
    ANALYSIS_REGISTRY["NEW_TYPE"] = my_new_analysis
    
  3. 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.py defines 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

matmech-1.0.0.tar.gz (21.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

matmech-1.0.0-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

Details for the file matmech-1.0.0.tar.gz.

File metadata

  • Download URL: matmech-1.0.0.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

Hashes for matmech-1.0.0.tar.gz
Algorithm Hash digest
SHA256 187d40ad258cca0802bc1cd2a6976300f13585f633ee178cc9e271fbe5892e55
MD5 3158b94ac8554b2b9b17900a880e8415
BLAKE2b-256 53ed507b215148f34a013b3a1dbccb01c2bd9ed8f3ca8d32d3bbd243bfe3b343

See more details on using hashes here.

Provenance

The following attestation bundles were made for matmech-1.0.0.tar.gz:

Publisher: python-publish.yml on WhiteRabbit2006/matmech

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file matmech-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: matmech-1.0.0-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

Hashes for matmech-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 710a641a4d5aa4ce7e18b0f345b805287151f877523b29bf16353ea8e2dbc3ad
MD5 bd8220019c5f8b109cbf2ad20ee7d8f3
BLAKE2b-256 cc13ee30cd27ccdce4cbc14904a2f52e73212a027cf1947e898b2e259e74a7d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for matmech-1.0.0-py3-none-any.whl:

Publisher: python-publish.yml on WhiteRabbit2006/matmech

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page