Automated time constant (tau) fitting tool with parallel processing support
Project description
AutoTau - 自动化时间常数τ拟合工具
AutoTau是一个用于自动拟合信号中指数上升/下降过程时间常数τ的Python库,支持并行处理以加速计算。
功能特点
- 自动寻找最佳拟合窗口,无需手动指定拟合区间
- 支持单周期和多周期信号的拟合
- 内置指数上升和下降模型: y = A(1-e^(-t/τ)) + C 和 y = Ae^(-t/τ) + C
- 提供R²和调整后R²等拟合质量指标
- 自动重新拟合质量不佳的结果
- 多种可视化方法展示拟合结果
- 支持并行处理,充分利用多核CPU提升性能
安装
从PyPI安装
pip install autotau
从GitHub安装
pip install git+https://github.com/Durian-Leader/autotau.git
从源码安装
git clone https://github.com/Durian-Leader/autotau.git
cd autotau
pip install -e .
快速开始
基本示例
import numpy as np
import pandas as pd
from autotau import TauFitter
# 加载数据
data = pd.read_csv('transient.csv')
time_data = data['Time'].values
current_data = -data['Id'].values # 反相电流
# 创建TauFitter对象
tau_fitter = TauFitter(
time_data,
current_data,
t_on_idx=[7.112, 7.151], # 开启过程时间窗口
t_off_idx=[0.41, 0.42] # 关闭过程时间窗口
)
# 拟合并获取结果
tau_fitter.fit_tau_on()
tau_fitter.fit_tau_off()
print(f"tau_on: {tau_fitter.get_tau_on()}")
print(f"tau_off: {tau_fitter.get_tau_off()}")
# 可视化结果
tau_fitter.plot_tau_on()
tau_fitter.plot_tau_off()
自动寻找最佳拟合窗口
from autotau import AutoTauFitter
# 自动寻找最佳拟合窗口
auto_fitter = AutoTauFitter(
time_data,
current_data,
sample_step=0.001,
period=0.2,
window_scalar_min=0.2,
window_scalar_max=1/3,
window_points_step=10,
window_start_idx_step=2,
normalize=False,
language='cn',
show_progress=True
)
auto_fitter.fit_tau_on_and_off()
# 获取结果
print(f"tau_on: {auto_fitter.best_tau_on_fitter.get_tau_on()}")
print(f"tau_off: {auto_fitter.best_tau_off_fitter.get_tau_off()}")
# 可视化结果
auto_fitter.best_tau_on_fitter.plot_tau_on()
auto_fitter.best_tau_off_fitter.plot_tau_off()
多周期数据处理
from autotau import CyclesAutoTauFitter
# 处理多周期数据
cycles_fitter = CyclesAutoTauFitter(
time_data,
current_data,
period=0.2,
sample_rate=1000,
window_scalar_min=0.2,
window_scalar_max=1/3,
window_points_step=10,
window_start_idx_step=2,
normalize=False,
language='cn',
show_progress=True
)
cycles_fitter.fit_all_cycles()
# 可视化结果
cycles_fitter.plot_cycle_results()
cycles_fitter.plot_windows_on_signal(num_cycles=5)
cycles_fitter.plot_all_fits(num_cycles=3)
# 获取结果摘要
summary = cycles_fitter.get_summary_data()
print(summary)
并行处理
from autotau import ParallelAutoTauFitter, ParallelCyclesAutoTauFitter
# 使用并行版自动拟合器
parallel_auto_fitter = ParallelAutoTauFitter(
time_data,
current_data,
sample_step=0.001,
period=0.2,
window_scalar_min=0.2,
window_scalar_max=1/3,
window_points_step=10,
window_start_idx_step=2,
normalize=False,
language='cn',
show_progress=True,
max_workers=None # 使用所有可用CPU核心
)
parallel_auto_fitter.fit_tau_on_and_off()
# 使用并行版多周期拟合器
parallel_cycles_fitter = ParallelCyclesAutoTauFitter(
time_data,
current_data,
period=0.2,
sample_rate=1000,
window_scalar_min=0.2,
window_scalar_max=1/3,
window_points_step=10,
window_start_idx_step=2,
normalize=False,
language='cn',
show_progress=True,
max_workers=None # 使用所有可用CPU核心
)
parallel_cycles_fitter.fit_all_cycles()
性能对比
可以使用examples.py中的compare_performance()函数来比较串行和并行处理的性能差异:
from autotau.examples import compare_performance
compare_performance()
在多核CPU上,并行处理通常可以获得2-8倍的性能提升,具体取决于CPU核心数和任务特性。
模块结构
- TauFitter: 基础拟合类,用于拟合指定窗口内的tau值
- AutoTauFitter: 自动寻找最佳拟合窗口的拟合器
- CyclesAutoTauFitter: 处理多周期数据的拟合器
- ParallelAutoTauFitter: AutoTauFitter的并行版本
- ParallelCyclesAutoTauFitter: CyclesAutoTauFitter的并行版本
依赖
- NumPy
- SciPy
- Matplotlib
- pandas
- tqdm
文档
详细文档请参见API参考文档。
贡献代码
欢迎提交Pull Request或创建Issue。
协议
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
autotau-0.2.5.tar.gz
(29.2 kB
view details)
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
autotau-0.2.5-py3-none-any.whl
(29.9 kB
view details)
File details
Details for the file autotau-0.2.5.tar.gz.
File metadata
- Download URL: autotau-0.2.5.tar.gz
- Upload date:
- Size: 29.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee7146d40584bef45499fd28da259acfd9ff773d80a5d0675c38dd1b2ddf369d
|
|
| MD5 |
0bc0885670fedaf92e5abb475f4b3452
|
|
| BLAKE2b-256 |
156bed102788b1b544046257d24d4deff7ff42e4630c103371d4b44e15e75f44
|
File details
Details for the file autotau-0.2.5-py3-none-any.whl.
File metadata
- Download URL: autotau-0.2.5-py3-none-any.whl
- Upload date:
- Size: 29.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
918b285b5ef50f93a606a317b96f73b80fad2cc143635fa9d5a2e327fe52e72d
|
|
| MD5 |
0c58decb143e3ef6a0f4d92ad6d810ed
|
|
| BLAKE2b-256 |
a0773139f022bc1bc6616d78af93b50a671c50f653d2ccdab9bd6133e9a41118
|