K2data内部的设备健康分析模板工具包
Project description
K2Health
K2Health是K2Assets提供的设备健康模板开发包(以下简称SDK),它提供了一套分析流程,协助数据分析师利用从设备采集的时序数据构造数学模型,进而对设备健康状况进行评分。
一、安装
安装SDK最新版本:
pip install -U k2health
本文档中使用到的样例文件:
- 样例数据文件:baoming_sample_data.csv.zip
- 样例参数表文件:baoming_config.xlsx
二、使用SDK
2.1 SDK概述
在SDK中Pipeline
类代表整个分析流程,它由多个分析步骤组成,每个步骤也对应的类名如下:
- 数据清洗:
DataCleaner
- 工况识别:
ConditionPartitioner
- 模型训练:
ModelTrainer
- 残差分析: TODO
- 健康评分: TODO
用户通过参数表文件
向分析流程提供必要的配置参数,例如哪些测点作为要预测的测点、使用何种数学模型做预测等等。参数表文件
是一个Excel格式的文件,它包含四个sheet,每个sheet代表一组参数用于不同的分析步骤:
- 测点配置:
point_config
- 设备信息:
device_config
- 设备树:
device_tree
- 模型配置:
model_config
我们期望在大多数情况下,通过调整参数表中的配置,就可以满足设备健康分析的要求并达到较好的效果。
2.2 使用默认分析
默认方式是指按Pipeline
所定义的顺序执行每个分析步骤,并且每个步骤使用的处理逻辑也是默认的。示例代码如下:
from k2health.pipeline import *
config_file = "./health/sampledata/baoming_config.xlsx"
point_config = pd.read_excel(config_file, sheet_name='point_config')
x_col = ['motor_current', 'inlet_temperature', 'oil_temperature', 'total_inlet_flow', 'total_power']
y_col = ['motor_bearing_D_temperature', 'motor_bearing_D_vibX', 'motor_bearing_D_vibY',
'motor_bearing_ND_temperature', 'motor_bearing_ND_vibX', 'motor_bearing_ND_vibY']
cleaner = DataCleaner(point_config, y_col, x_col)
device_config = pd.read_excel(config_file, sheet_name='device_config')
device_tree = pd.read_excel(config_file, sheet_name='device_tree')
partitioner = ConditionPartitioner(device_config, device_tree)
model_config_sheet = pd.read_excel(config_file, sheet_name='model_config')
trainer = ModelTrainer(y_col, model_config_sheet)
# 使用默认的数据处理器
pipeline = Pipeline(
cleaner=cleaner,
partitioner=partitioner,
trainer=trainer
)
data = pd.read_csv("./health/sampledata/baoming_sample_data.csv")
pipeline.process(data)
2.3 定制化分析
定制化方式是指在每个分析步骤基础上增加额外的处理逻辑,或者重写原有的处理逻辑,以满足特定的业务需求。此时用户需要开发自己的分析步骤类,并将它放到分析流程里。
例如希望在默认的数据清洗完成后,额外对数据再做一次填充空值的处理。实现步骤如下:
1、首先创建一个继承DataCleaner
的子类CustomDataCleaner
,实现process
方法:
class CustomDataCleaner(DataCleaner):
def process(self, data: DataFrame) -> DataFrame:
# 先进行默认处理
data = super().process(data)
# 再进行定制处理
data = data.fillna(-1)
return data
2、在分析流程里引用CustomDataCleaner
:
from k2health.pipeline import *
config_file = "./health/sampledata/baoming_config.xlsx"
point_config = pd.read_excel(config_file, sheet_name='point_config')
x_col = ['motor_current', 'inlet_temperature', 'oil_temperature', 'total_inlet_flow', 'total_power']
y_col = ['motor_bearing_D_temperature', 'motor_bearing_D_vibX', 'motor_bearing_D_vibY',
'motor_bearing_ND_temperature', 'motor_bearing_ND_vibX', 'motor_bearing_ND_vibY']
# 使用定制的分析步骤
cleaner = CustomDataCleaner(point_config, y_col, x_col)
device_config = pd.read_excel(config_file, sheet_name='device_config')
device_tree = pd.read_excel(config_file, sheet_name='device_tree')
partitioner = ConditionPartitioner(device_config, device_tree)
model_config_sheet = pd.read_excel(config_file, sheet_name='model_config')
trainer = ModelTrainer(y_col, model_config_sheet)
pipeline = Pipeline(
cleaner=cleaner,
partitioner=partitioner,
trainer=trainer
)
data = pd.read_csv("./health/sampledata/baoming_sample_data.csv")
pipeline.process(data)
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
Built Distribution
File details
Details for the file k2health-0.0.5.tar.gz
.
File metadata
- Download URL: k2health-0.0.5.tar.gz
- Upload date:
- Size: 30.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92094939373a50b6df5d49049b39cfde590706221fb955fc1b1f77c8c0a0bdb4 |
|
MD5 | 1efdd9fdca431308e1a3438103a4161a |
|
BLAKE2b-256 | 0df40231a033467451ec0301bafdbb216e5223b3d901f9c7997c46d2b46ed67c |
File details
Details for the file k2health-0.0.5-py3-none-any.whl
.
File metadata
- Download URL: k2health-0.0.5-py3-none-any.whl
- Upload date:
- Size: 33.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d209763024bb0933c8953c0f7c4e06f16c3283e32ba8a67c402363b17a76570c |
|
MD5 | acb8d7a08c3178243f16b4eba6c909ff |
|
BLAKE2b-256 | 8594704e06063b3d997cf288b4e136f1842d2608edfdc7624b9b5301992091f7 |