Skip to main content

tascpy

Python Version License: MIT Version

tascpy は、計測アプリケーション「tasc」などから出力される計測データの分析・可視化を効率的に行うための Python ライブラリです。直感的なインターフェースと強力なデータ処理機能を備え、メソッドチェーン形式で複雑な操作を簡潔に記述できます。

主な特徴

  • メソッドチェーンによる流れるような操作:複数のデータ処理ステップを連続して記述できます
  • イミュータブルなデータ操作:元のデータを変更せず、常に新しいデータセットを生成します
  • ドメイン特化機能:荷重-変位データや座標データなど、特定の分析領域に特化した機能を提供します
  • 柔軟なデータ選択:列名、行インデックス、ステップ値などによる多彩な選択操作をサポートします
  • 高度な数学的処理:数値演算、補間、正規化など様々な数学的操作を提供します
  • 直感的な可視化:Matplotlib と連携した簡単かつ高度なデータ可視化機能があります
  • 型ヒントと自動補完:VSCode などの IDE で自動補完や型チェックを完全サポートします

インストール方法

pip からのインストール

pip install tascpy

ソースからのインストール

git clone https://github.com/toruinaba/tascpy.git
cd tascpy
pip install -e .

使用例

基本的な使い方

import tascpy

# ファイルからデータを読み込む(format_name: "tasc_txt" または "csv")
collection = tascpy.load("data.csv", format_name="csv")

# メソッドチェーンでデータを処理
result = (
    collection.ops
    .select(columns=["Force", "Displacement"])                    # 必要な列を選択
    .filter_by_condition("Force", lambda x: x > 0)                # 正の荷重のみ抽出
    .add("Force", 10, result_column="AdjustedForce")              # 新しい列を作成
    .divide("AdjustedForce", "Displacement", result_column="Ratio")
    .end()                                                        # チェーンを終了して結果を取得
)

print(f"処理後のデータ: {len(result)} 行 × {len(result.columns)} 列")
print(f"最大値: {result['Ratio'].max():.2f}")

単位の確認

各列は単位(unit)とチャンネル名(ch)を持ちます。単位は記録・確認のためのもので、自動変換はしません。 演算結果の単位は演算の種類から決まり、自明でない場合は None(不明)になります。unit= で明示することもできます。

collection.units                 # {"Force": "kN", "Displacement": "mm", ...}
result["AdjustedForce"].unit     # "kN"(加算は元の列の単位を引き継ぐ)
result["Ratio"].unit             # None(列どうしの除算の単位は自明でない)
collection[0]                    # <Row step=1, Force=0.0 kN, Displacement=0.0 mm, ...>

# polars の DataFrame との相互変換
df = collection.df
again = tascpy.ColumnCollection.from_frame(df, units=collection.units)

# 保存
collection.io.save("out.txt")             # TASC 形式(列名・ch・単位を保持)
collection.io.to_parquet("out.parquet")   # 単位・属性・解析結果まで保持
restored = tascpy.load_parquet("out.parquet")

荷重-変位ドメインの分析

# 荷重-変位ドメインへ変換し、剛性と降伏点を計算
ld = (
    collection.ops
    .end_as(tascpy.as_load_displacement, load_column="Force", displacement_column="Displacement").ops
    .remove_consecutive_duplicates_across()
)

stiffness = ld.stiffness(range_start=0.1, range_end=0.5)        # 値を返してチェーンが終わる
print(f"初期剛性: {stiffness.value:.2f} {stiffness.unit}")      # 例: kN/mm
yield_pt = ld.yield_point(method="offset", offset_value=0.002)  # 0.2%オフセット法
print(f"降伏荷重: {yield_pt.y:.2f} {yield_pt.y_unit}")
print(f"降伏変位: {yield_pt.x:.2f} {yield_pt.x_unit}")

collection.ops が返す操作オブジェクトは通常のクラスなので、IDE の自動補完と型チェックがそのまま効きます。end_as に変換関数(tascpy.as_load_displacement など)を渡すと変換の引数が補完され、返ったドメインのコレクションの .ops ではドメイン固有の操作(yield_point など)も補完されます。

繰り返し載荷のデータでは、ld.to_skeleton_curve() でスケルトン曲線(新しい荷重-変位コレクション)にしてから yield_point などを求めます。サイクルは荷重の符号反転から数えます。元データにサイクル番号の列があっても名前から推測して使うことはないので、使うときは cycle_column="列名" で指定します。

skeleton = ld.to_skeleton_curve()                               # 新しい荷重-変位コレクションの操作
point = skeleton.yield_point(offset_value=0.5)                  # PointResult
per_cycle = ld.split_by_cycles().collect(lambda o: o.end()["Force"].max()).to_table(name="peak")  # サイクルごとの表

剛性・降伏点などの値は結果オブジェクトとして返り、コレクションの results には自動では入りません。Parquet に一緒に保存したいときは collection.with_result(point) で付けます。

可視化の例

import matplotlib.pyplot as plt

fig, ax = plt.subplots(figsize=(10, 6))
collection.plot.plot(y_column="Force", x_column="Displacement", ax=ax, marker="o", alpha=0.7)

ax.set_title("荷重-変位関係")
ax.grid(True)
plt.tight_layout()
plt.show()

ドキュメント

より詳細なドキュメントとサンプルについては、以下を参照してください:

動作環境

  • Python 3.11 以上
  • 依存ライブラリ:
    • numpy
    • polars
    • matplotlib
    • japanize-matplotlib(日本語フォントサポート用)

プロジェクト構造

tascpy/
├── src/
│   └── tascpy/
│       ├── numeric/          # numpy 配列に直接使える解析関数
│       ├── core/             # データモデル(ColumnCollection など)と汎用の操作・入出力・描画
│       └── domains/          # ドメイン(荷重-変位・座標・ひずみ)。ドメインごとに collection / ops / plotter / draw
├── tests/                    # テストコード(tests/manual/examples にサンプル)
└── docs/                     # ドキュメント

ライセンス

MIT ライセンスの下で公開されています。詳細は LICENSE ファイルを参照してください。

開発について

個人で開発・保守しているライブラリです。不具合は GitHub Issue で知らせていただければ確認しますが、対応の時期はお約束できません。開発時の規約と手順は CONTRIBUTING.md にまとめています。

著者

Metadata

Release files for tascpy 0.8.1

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

Source distribution (sdist)

Source distribution for tascpy 0.8.1
File Size Uploaded Provenance Actions
tascpy-0.8.1.tar.gz 77.8 kB With provenance Details for tascpy-0.8.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tascpy 0.8.1
File Interpreter ABI Platform Actions
tascpy-0.8.1-py3-none-any.whl Python 3 none any Details for tascpy-0.8.1-py3-none-any.whl

Total release size: 171.6 kB

Release files / tascpy-0.8.1.tar.gz

Download URL tascpy-0.8.1.tar.gz
Size 77.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b3701e49265d9bb4a33ace363b183c2dc9d364aff0765a4740eacdd775b615d6
BLAKE2b-256 checksum
How to use checksums
029507b5fd6488a921e857a1b85139ebcd00995f59482ac0b9d13f56ff4122ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 1, 2026.

Transparency log

Release files / tascpy-0.8.1-py3-none-any.whl

Download URL tascpy-0.8.1-py3-none-any.whl
Size 93.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2c78303086e7b976dcfd22dae9930ba94af646460f750849e88a0cef197c8b03
BLAKE2b-256 checksum
How to use checksums
b12935941e7e3bf045df1ab9e17831b60699dd79e0cf449b67e6373b50fb4219
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 1, 2026.

Transparency log

Security for tascpy 0.8.1

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for tascpy-0.8.1.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 Nov 1, 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