Skip to main content

自动化时间常数tau拟合工具,支持并行处理

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。

协议

MIT

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

autotau-0.1.2.tar.gz (25.3 kB view details)

Uploaded Source

Built Distribution

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

autotau-0.1.2-py3-none-any.whl (27.6 kB view details)

Uploaded Python 3

File details

Details for the file autotau-0.1.2.tar.gz.

File metadata

  • Download URL: autotau-0.1.2.tar.gz
  • Upload date:
  • Size: 25.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for autotau-0.1.2.tar.gz
Algorithm Hash digest
SHA256 67629deb3769cd3c28f431c3ddcc4e3ec5791566454f468c4d74c7488b00f0c8
MD5 9526fa9152fdbd8b3cd9fd81e7864035
BLAKE2b-256 e8f3666a1105bd8e372f92c5da76e3e9a892d9f2ec209b0a574968401324968d

See more details on using hashes here.

File details

Details for the file autotau-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: autotau-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 27.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for autotau-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a14251f363db4549d39543db53ae5ec6481c967f5f55dfaa56cb433218bdc020
MD5 ae25127611141a871076fc4601dc6bed
BLAKE2b-256 5aa129df60e6c28468842d32a38fca269908acd1f058b0980a29cf15317f18d0

See more details on using hashes here.

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