TensileTest API

🔬 Tensile
v0.4.0
Automated Tensile Test Analysis

TensileTest

class TensileTest(config=None)

Primary class for single tensile test analysis with automated processing pipeline. Follows a scikit-learn-like pattern with method chaining support.

Quick Start

from tensile import TensileTest

# Complete analysis pipeline
test = (TensileTest()
        .load("specimen.csv")
        .validate()
        .clean()
        .segment()
        .analyze())

# View results
print(test.summary())

# Create plot
fig = test.plot()
fig.show()

# Export results
test.export("results.csv")

Common Methods

load()

Load CSV data with automatic column detection

validate()

Run data quality checks

clean()

Detect and correct measurement errors

segment()

Identify elastic/plastic regions

analyze()

Calculate mechanical properties

plot()

Create interactive visualization

export()

Save results to CSV

summary()

Get formatted summary text

Constructor

__init__(config=None)

Initialize a TensileTest instance.

Parameters:
config : TensileTestConfig, optional
Configuration object for analysis parameters. If None, uses default configuration.
from tensile import TensileTest, TensileTestConfig

# With default configuration
test = TensileTest()

# With custom configuration
config = TensileTestConfig(jump_threshold=0.00001)
test = TensileTest(config=config)

Attributes

Attribute Type Description
raw_data pd.DataFrame Original loaded data from CSV
cleaned_data pd.DataFrame Data after cleaning pipeline
metadata dict Material info, specimen ID, test parameters
results dict Calculated mechanical properties
quality_report dict Validation issues, warnings, errors
segments dict Indices marking elastic/plastic regions
config TensileTestConfig Analysis configuration parameters

Methods

load()

load(filepath, delimiter=';', load_metadata=True, **kwargs)

Load CSV data from file with automatic column detection.

Parameters:
filepath : str
Path to CSV file containing tensile test data
delimiter : str, default=';'
CSV delimiter character
load_metadata : bool, default=True
If True, automatically load metadata from companion files
**kwargs
Additional arguments passed to read_tensile_csv()
Returns: self (TensileTest) - For method chaining
test = TensileTest()
test.load("data/specimen.csv")

# With custom delimiter
test.load("data/specimen.csv", delimiter=',')

validate()

validate()

Run validation checks on loaded data. Checks column existence, data quality, completeness, and physical reasonableness.

Returns: self (TensileTest) - For method chaining

Updates: quality_report with validation results:

test = TensileTest()
test.load("specimen.csv").validate()

if test.quality_report['is_valid']:
    print("Data is valid")
else:
    print("Issues:", test.quality_report['validation_issues'])

clean()

clean()

Execute cleaning pipeline to detect and correct measurement errors.

Processing steps:

  1. Trim initial slack (pre-test data)
  2. Detect strain jumps and slippages
  3. Correct correctable slippages
  4. Detect incomplete tests
  5. Truncate post-fracture data
Returns: self (TensileTest) - For method chaining

Updates:

test.clean()
print(f"Slippages: {test.quality_report['num_slippages_detected']}")
print(f"Corrected: {test.quality_report['num_slippages_corrected']}")

segment()

segment()

Identify test phases using automated statistical segmentation. Finds elastic, plastic, and necking regions.

Returns: self (TensileTest) - For method chaining

Updates: segments dictionary with keys:

test.segment()
print(f"Elastic: {test.segments['elastic_start']} to {test.segments['elastic_end']}")

analyze()

analyze()

Calculate all mechanical properties from stress-strain data.

Returns: self (TensileTest) - For method chaining

Updates: results dictionary with calculated properties:

test.analyze()
print(f"E: {test.results['youngs_modulus_GPa']:.2f} GPa")
print(f"Rp0.2: {test.results['Rp02_MPa']:.2f} MPa")
print(f"Rm: {test.results['Rm_MPa']:.2f} MPa")
print(f"At: {test.results['At_percent']:.2f}%")

plot()

plot(show_segments=True, show_properties=True, show_slippages=True, title=None, width=900, height=600)

Create an interactive Plotly visualization of the stress-strain curve.

Parameters:
show_segments : bool, default=True
Highlight elastic region with shaded area
show_properties : bool, default=True
Show markers and annotations for Rp0.2 and Rm
show_slippages : bool, default=True
Mark detected slippage locations
title : str, optional
Custom plot title. If None, auto-generated
width : int, default=900
Plot width in pixels
height : int, default=600
Plot height in pixels
Returns: plotly.graph_objects.Figure - Interactive plot
fig = test.plot()
fig.show()  # Display in browser
fig.write_html("plot.html")  # Save to file
fig.write_image("plot.png")  # Requires kaleido

export()

export(filepath, include_metadata=False)

Export results to CSV file.

Parameters:
filepath : str
Path where CSV file will be saved
include_metadata : bool, default=False
If True, include metadata columns in output
test.export("results.csv")
test.export("results_with_meta.csv", include_metadata=True)

summary()

summary()

Get formatted string summary of analysis results.

Returns: str - Formatted summary with all properties
print(test.summary())

from_csv() [classmethod]

@classmethod from_csv(cls, filepath, metadata=None, config=None, **kwargs)

Create TensileTest instance directly from CSV file.

Parameters:
filepath : str
Path to CSV file
metadata : dict, optional
Metadata dictionary to attach to test
config : TensileTestConfig, optional
Configuration object
**kwargs
Additional arguments for load() method
Returns: TensileTest - Instance with data loaded
test = TensileTest.from_csv(
    "specimen.csv",
    metadata={'material': '316L', 'batch': 'A'}
)