TensileTest
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
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 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()
test = TensileTest()
test.load("data/specimen.csv")
# With custom delimiter
test.load("data/specimen.csv", delimiter=',')
validate()
Run validation checks on loaded data. Checks column existence, data quality, completeness, and physical reasonableness.
Updates: quality_report with validation results:
is_valid: bool - Overall validity flagvalidation_issues: list - Specific problems foundis_complete: bool - Whether test reached fracturecompletion_confidence: float - Confidence score (0-1)
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()
Execute cleaning pipeline to detect and correct measurement errors.
Processing steps:
- Trim initial slack (pre-test data)
- Detect strain jumps and slippages
- Correct correctable slippages
- Detect incomplete tests
- Truncate post-fracture data
Updates:
cleaned_data: DataFrame with corrected dataquality_report['num_slippages_detected']: intquality_report['num_slippages_corrected']: intquality_report['slippage_details']: list of dicts
test.clean()
print(f"Slippages: {test.quality_report['num_slippages_detected']}")
print(f"Corrected: {test.quality_report['num_slippages_corrected']}")
segment()
Identify test phases using automated statistical segmentation. Finds elastic, plastic, and necking regions.
Updates: segments dictionary with keys:
elastic_start: int - Start index of elastic regionelastic_end: int - End index of elastic regionyield_index: int - Approximate yield pointplastic_start: int - Start of plastic deformationnecking_start: int - Start of necking phase (if detected)
test.segment()
print(f"Elastic: {test.segments['elastic_start']} to {test.segments['elastic_end']}")
analyze()
Calculate all mechanical properties from stress-strain data.
Updates: results dictionary with calculated properties:
youngs_modulus_GPa: float - Young's modulus (E)Rp02_MPa: float - 0.2% offset yield strengthRp02_strain: float - Strain at Rp0.2Rm_MPa: float - Ultimate tensile strengthRm_strain: float - Strain at maximum stressAt_percent: float - Total elongation at fractureelastic_modulus_r_squared: float - R² of elastic fitanalysis_successful: bool - Success flag
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()
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
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 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()
Get formatted string summary of analysis results.
print(test.summary())
from_csv() [classmethod]
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
test = TensileTest.from_csv(
"specimen.csv",
metadata={'material': '316L', 'batch': 'A'}
)