Chronaxis用户手册English
本页目录

chronaxis.core.calculation_output_numpy

源码基线:8904c2f744951857659abd40aaa3535d57faf53c

1"""将一个数组归约结果换到目标单位,不调用参考数值核。23输入为归约标量、原类型和编译期转换;用单元素typed列复用数组仿射核,4输出值与质量。这里只转换最终结果,不按样本循环或创建额外历史。5"""67import numpy as np8from .affine_numpy import affine_numpy9from .numeric_numpy import NumericArray, DTYPES10from .types import SignalDType as D, QualityFlag as Q111213def convert_result_numpy(value, input_dtype, conversion):14    """用NumPy仿射核完成一个非空结果的单位转换。1516    参数: value为int/float或None;input_dtype为原数值类型;conversion为单位描述符。17    返回: (Python数值或None, QualityFlag),空值保持空值。18    异常: 非法模型、分配或系数错误传播;数值故障写入质量。19    """20    # 空值没有数值证据,不为应用偏移制造一个零输入。21    if value is None:22        return None, Q.NONE23    if conversion.factor == 1 and conversion.offset == 0:24        return value, Q.NONE25    dtype = D.FLOAT64 if type(value) is float else input_dtype26    column = NumericArray(dtype, np.array([value], dtype=DTYPES[dtype]),27                          np.array([True]), np.array([0], dtype=np.uint16))28    converted = affine_numpy(column, conversion.factor, conversion.offset, conversion.dtype(dtype))29    return converted.values[0].item() if converted.valid[0] else None, Q(int(converted.quality[0]))30
Chronaxis 用户手册 · 离线阅读