Skip to main content
Change of provenance

The repository or configuration that created this release differ from a previous release. View details.

tc-cwi

Python 3.11+ Build System License: MIT

Lightweight Python toolbox for Environmental and Operational Condition (EoC) compensation in ultrasonic Structural Health Monitoring (SHM), using Coda Wave Interferometry (CWI) and the Time-Stretching method.

Temperature variations change the apparent wave velocity of ultrasonic guided waves, which can mask structural damage. tc-cwi estimates the stretch factor (eps) and/or time shift (dt) that best realign a measured signal with a reference, and reports the remaining decorrelation.

Authors & Attribution

  • Arnaud Deraemaeker (ULB)
  • Damiano Gianotti (Zensor)
  • Jitendra Kumar Sharma (ULB)
  • Luigi Trezza (Airbus)

Developed as part of WP3, Deliverable D3.3.

The core Time-Stretching CWI algorithm and original code were developed in MATLAB by Arnaud Deraemaeker, Jitendra Kumar Sharma, and the BATir research group at ULB (Université Libre de Bruxelles). Python translation, packaging, test harness, and ongoing maintenance are performed by Zensor (Damiano Gianotti and Arthur Gossuin).


Installation

Requirements: Python ≥ 3.11 (dependencies: numpy, scipy)

pip install tc-cwi

Quickstart

import numpy as np
from tc_cwi import tc_cwi

t = np.linspace(0, 1e-3, 1000)
reference = np.sin(2 * np.pi * 50e3 * t)
current = np.sin(2 * np.pi * 50e3 * t * (1 + 1e-4))  # slightly stretched

# Correlation coefficient without compensation (one value per signal)
baseline = tc_cwi("getccns", reference, current)
print(f"Baseline CC: {baseline.CC[0]:.4f}")

# Optimal stretch factor (Nelder-Mead from eps = 0) and remaining decorrelation
result = tc_cwi("findeps", reference, current, t, 0.0, 2)
print(f"eps: {result.eps:.6e}, decorrelation after stretching: {result.DC:.2e}")

Several signals can be processed at once by passing a 2D array with one signal per column (n_samples × n_signals):

signals = np.column_stack([current, current, current])
batch = tc_cwi("findeps", reference, signals, t, (-1e-2, 1e-2))  # bounded search
print(batch.EPSf, batch.DCsf)

API

The package exposes two layers.

MATLAB-compatible dispatch: tc_cwi(cmd, *args, **kwargs)

Mirrors the original MATLAB toolbox. Results are returned as a Struct (types.SimpleNamespace), so fields are accessed MATLAB-style with out.field.

Command Arguments Output fields (single signal / multiple signals)
getccns y0, y1, ind=None CC, DC
getccs y0, y1, t, eps, ind=None CC, DC
getccdt y0, y1, t, dt, ind=None CC, DC
getccepsdt y0, y1, t, eps, dt, ind=None CC, DC
getdcs / getdcdt / getdcepsdt same as getcc* DC array (returned directly)
findeps y1, y2, t, e0, method=1, ind=None eps, DC, y, y0 / EPSf, DCsf, ysf, y0
finddt y1, y2, t, dt0, method=1, ind=None dt, DC, y, y0 / DTf, DCdtf, ydtf, y0
findepsdt y1, y2, t, e0, dt0, method=2, ind=None eps, dt, DC, y, y0 / EPSf, DTf, DCsdtf, ysdtf, y0
findeps -ma y1, y2, t, e0, method=1, ind=None, ma=5 multiple signals only: EPSma, DCma, ysma, y0, yma
stretch y, t, eps stretched signal
shift y, t, dt, method="interp" shifted signal ("point", "interp" or "fft")
stretchshift y, t, eps, dt shifted, then stretched signal

Conventions:

  • CC is the absolute Pearson correlation coefficient, DC = 1 - CC the decorrelation.

  • ind restricts the correlation to a window (index array or slice). The stretch/shift is always applied to the full signal.

  • method selects the optimizer:

    • 1: bounded scalar search, the start value is an interval (lower, upper).
    • 2: Nelder-Mead, the start value is a starting point. findepsdt only supports this method.

    When processing several signals, each fit is seeded with the result of the previous one.

  • eps > 0 compresses the wave (t → t·(1+eps)), dt > 0 moves it forward (t → t−dt).

  • findeps -ma compares each signal against the mean of the last ma compensated signals instead of a fixed reference. ma is either a window size, or the yma returned by a previous call to continue the same window.

Core functions

For direct use in Python code, without the MATLAB-style dispatch:

Function Description
correlation_coefficient(y0, y1) Absolute correlation coefficient between two signals
stretch(y, t, eps) Stretch a signal (not-a-knot cubic spline, zero outside t)
shift(y, t, dt, method="interp") Shift a signal by dt
stretchshift(y, t, eps, dt) Shift, then stretch a signal
find_optimum(y0, y, t, process, x0, method=1, ind=None, xatol=1e-8) Parameters of process(y, t, *x) minimizing the decorrelation with y0; returns (x, decorrelation)
MovingAverageReference(n, y_init=None) Rolling window of the last n signals; .reference is their mean, .update(y) adds a signal
from tc_cwi import find_optimum, stretch

x, decorrelation = find_optimum(reference, current, t, stretch, (-1e-2, 1e-2))

Development

This project uses uv with the uv_build backend:

git clone https://github.com/aderaema/tc-cwi.git tc-cwi
cd tc-cwi
uv sync
├── src/tc_cwi/
│   ├── __init__.py      # Public API
│   ├── core.py          # Stretching, shifting and optimization
│   └── matlab.py        # MATLAB-compatible tc_cwi() dispatch
├── tests/
│   ├── test_core.py     # Core functions
│   ├── test_matlab.py   # Every tc_cwi command: fields and error paths
│   └── test_package.py  # Public API
└── pyproject.toml

Tests, coverage and linting:

uv run pytest
uv run pytest --cov   # statements + branches, with the missing lines
uv run ruff check .

Releasing to PyPI: bump version in pyproject.toml, build, and push a matching tag. The publish workflow lints, builds, tests the built distributions in isolation, and publishes them to PyPI:

git commit -am "chore: release v0.1.3"
git tag -a v0.1.3 -m "v0.1.3"
git push origin main
git push origin v0.1.3

Alternatively, build and publish manually with uv:

uv build
uv publish

License

MIT

Metadata

Release files for tc-cwi 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Change of provenance

The repository or configuration that created these release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Source distribution (sdist)

Source distribution for tc-cwi 0.1.4
File Size Uploaded Provenance Actions
tc_cwi-0.1.4.tar.gz 8.7 kB With provenance Details for tc_cwi-0.1.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tc-cwi 0.1.4
File Interpreter ABI Platform Actions
tc_cwi-0.1.4-py3-none-any.whl Python 3 none any Details for tc_cwi-0.1.4-py3-none-any.whl

Total release size: 17.8 kB

Release files / tc_cwi-0.1.4.tar.gz

Change of provenance

This file belongs to a release with changed provenance: the repository or configuration that created the release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Download URL tc_cwi-0.1.4.tar.gz
Size 8.7 kB
Tags Source
SHA-256 checksum
How to use checksums
fa83080aad0dd7d9092474018724e102d3eedf06a4150bc8ac90038674f5c22c
BLAKE2b-256 checksum
How to use checksums
90c4e68c0a9469fd3bce88fa9410660735257a15425075e7d3b4544413fa00a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

Release files / tc_cwi-0.1.4-py3-none-any.whl

Change of provenance

This file belongs to a release with changed provenance: the repository or configuration that created the release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Download URL tc_cwi-0.1.4-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
43288ebe3f8540bae5859ba5f01d027191be9221d1c7c5159d337dbdbe031e7b
BLAKE2b-256 checksum
How to use checksums
419ed0b0c72559826945d2ee6580fca6df79b6de18ce15cc67f4f106cf9edbe7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

Security for tc-cwi 0.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Change of provenance

The repository and configuration that created this release differ from a previous release.

While this could reflect a routine change by the project maintainers, it may also indicate that the release files have been compromised.

Select from 2 files

Attestation for tc_cwi-0.1.4.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page