PPG数据分析命令行工具库
Project description
GHealth Tools
PPG(光电容积脉搏波)数据分析命令行工具库,支持数据转换、可视化、分类等功能。
安装
pip install ghealth-tools
或从源码安装:
git clone https://github.com/yourusername/health_tools.git
cd health_tools
pip install -e .
快速开始
# 查看帮助
ghealth_tool --help
# 查看版本
ghealth_tool --version
命令
parse - 日志解析
将原始日志文件解析为CSV格式。
# 使用解析规则文件
ghealth_tool parse -i raw.log -o output.csv -r parse/gh3220.yaml
# 使用芯片规则
ghealth_tool parse -i raw.log -o output.csv --chip gh3220
# 批量处理目录
ghealth_tool parse -i logs/ -o output/ -r parse/default.yaml -v
plot - 数据可视化
绘制PPG数据的时域/频域图。
# 绘制时域和频域图
ghealth_tool plot -i data.csv -o plots/ --type both --sample-rate 100
# 仅绘制时域图
ghealth_tool plot -i data.csv -o plots/ --type time --channels red,ir
# 指定窗口和重叠率
ghealth_tool plot -i data.csv -o plots/ --window 10 --overlap 0.75
classify - 数据分类
根据规则对数据进行分类保存。
# 使用分类规则
ghealth_tool classify -i data/ -o classified/ -r classify/default.yaml
# 生成分类报告
ghealth_tool classify -i data/ -o classified/ -r classify/default.yaml --report
# 移动文件而非复制
ghealth_tool classify -i data/ -o classified/ -r classify/default.yaml --move
convert - 格式转换
CSV格式转换(紧凑型↔展开型,芯片特定格式)。
# 转换为芯片格式
ghealth_tool convert -i input.csv -o output.csv --chip gh3220
# 合并多个文件
ghealth_tool convert -i data/ -o merged.csv --merge
# 按大小分割
ghealth_tool convert -i large.csv -o split/ --split 10000
info - 信息查看
查看数据文件或规则文件信息。
# 查看CSV文件信息
ghealth_tool info data.csv --stats --preview 20
# 查看规则文件
ghealth_tool info rules/chip/gh3220.yaml --schema
validate - 规则验证
验证YAML规则文件格式和内容。
# 验证规则文件
ghealth_tool validate rules/chip/gh3220.yaml
# 严格模式验证
ghealth_tool validate rules/parse/gh3220.yaml --strict
规则文件
芯片规则 (rules/chip/*.yaml)
定义CSV文件的格式:
version: "1.0"
chip: gh3220
csv:
header_row: 1 # 列名所在行
data_start_row: 2 # 数据开始行
delimiter: ","
encoding: "utf-8"
columns:
- timestamp
- red
- ir
- green
解析规则 (rules/parse/*.yaml)
定义如何解析日志文件:
version: "1.0"
description: "GH3220日志解析规则"
regex: '^\[(.+?)\]\s+GH3220:\s*(\d+),(\d+),(\d+),(\d+)$'
columns:
- timestamp
- red
- ir
- green
- aux
分类规则 (rules/classify/*.yaml)
定义数据分类规则:
version: "1.0"
filename:
regex: '(\d{8})_(\w+)_(\w+)\.csv'
fields:
- date
- subject
- motion
data_columns:
- name: motion
source: filename
match:
supine: ["supine", "lie"]
sit: ["sit", "sitting"]
structure:
supine: ""
sit: ""
rules:
- target: "{motion}"
use_filename: true
转换规则 (rules/convert/*.yaml)
定义CSV格式转换,支持列映射、前值填充、频率扩展:
version: "1.0"
target_chip: gh3220
csv:
info_row: 0 # 信息所在行(0=无)
header_row: 1 # 列名所在行
data_start_row: 2 # 数据开始行
delimiter: ","
column_mapping:
time: TimeStamp
acc[0]: ACCX # [] 为字面量列名
rawdata{0-15}: CH{0-15} # {} 展开为 rawdata0->CH0, rawdata1->CH1, ...
forward_fill:
- polar_HR # 0值用前一个非0值填充
expand_repeat:
polar_HR: 25 # 每个值重复25次匹配采样率
列名展开语法
支持两种范围展开语法:
# chip/parse 规则中:[] 表示范围展开
columns:
- ch[0-15] # 展开为 ch0, ch1, ..., ch15
# convert 规则中:{} 表示范围展开,[] 为字面量
column_mapping:
rawdata[{0-1}]: Rawdata{0-1} # rawdata[0]->Rawdata0, rawdata[1]->Rawdata1
acc[0]: ACCX # acc[0] 是字面量列名
内置芯片规则
| 芯片 | 文件 | 描述 |
|---|---|---|
| GH3220 | rules/chip/gh3220.yaml |
Goodix PPG传感器 |
| GH3036 | rules/chip/gh3036.yaml |
Goodix健康传感器 |
开发
环境设置
# 克隆仓库
git clone https://github.com/yourusername/health_tools.git
cd health_tools
# 创建虚拟环境
python -m venv venv
source venv/bin/activate # Linux/Mac
# 或
.\venv\Scripts\activate # Windows
# 安装开发依赖
pip install -e ".[dev]"
运行测试
pytest
代码格式化
black src/
ruff check src/
许可证
MIT License
贡献
欢迎提交 Issue 和 Pull Request!
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
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
File details
Details for the file ghealth_tools-0.2.1.tar.gz.
File metadata
- Download URL: ghealth_tools-0.2.1.tar.gz
- Upload date:
- Size: 53.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1caaea03b6d80bf301b21a61973c92ced3c58806242772304eaaf76191fb1339
|
|
| MD5 |
bf3e332fe8245dde0c148e9cfb40aaff
|
|
| BLAKE2b-256 |
486d7224ee7bbdfa6fdba25339c47c3bf4d07af5ff5001217dfb46f6ae43598b
|
Provenance
The following attestation bundles were made for ghealth_tools-0.2.1.tar.gz:
Publisher:
ci.yml on XiaoPb/health_tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ghealth_tools-0.2.1.tar.gz -
Subject digest:
1caaea03b6d80bf301b21a61973c92ced3c58806242772304eaaf76191fb1339 - Sigstore transparency entry: 1508877642
- Sigstore integration time:
-
Permalink:
XiaoPb/health_tools@0e1afd5dd11c87224f91d5869da4f92c273acd6f -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/XiaoPb
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@0e1afd5dd11c87224f91d5869da4f92c273acd6f -
Trigger Event:
push
-
Statement type:
File details
Details for the file ghealth_tools-0.2.1-py3-none-any.whl.
File metadata
- Download URL: ghealth_tools-0.2.1-py3-none-any.whl
- Upload date:
- Size: 47.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
872417ac446aef620c3c11d00506d347cba0acc7576e4189f945ab5b62f52219
|
|
| MD5 |
1884ff97fc5a93113d5037a6c2778f18
|
|
| BLAKE2b-256 |
a995fea0998ad09a47a4ccb3d53535ffc66d448ee24ed6f0b7afb5c826443eef
|
Provenance
The following attestation bundles were made for ghealth_tools-0.2.1-py3-none-any.whl:
Publisher:
ci.yml on XiaoPb/health_tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ghealth_tools-0.2.1-py3-none-any.whl -
Subject digest:
872417ac446aef620c3c11d00506d347cba0acc7576e4189f945ab5b62f52219 - Sigstore transparency entry: 1508877774
- Sigstore integration time:
-
Permalink:
XiaoPb/health_tools@0e1afd5dd11c87224f91d5869da4f92c273acd6f -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/XiaoPb
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@0e1afd5dd11c87224f91d5869da4f92c273acd6f -
Trigger Event:
push
-
Statement type: