python.d查询

2024-06-02 13:09:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个从线性位置传感器捕获的数据集,如下所示,我想查询。我导入的pandas数据帧有包括线性位置传感器数据以及其他数据列的列。由于数据是通过DAC获得的信号,因此它不平滑(噪声),并且值未知(采样率)。我想能够查询数据帧报告的时间和位置的线性位置传感器开始移动(大约1.8秒),再次报告撞击前的时间和线性位置(大约2.08秒标记)

enter image description here

前5行数据:

     Time   Ch0_LC1   Ch1_LC2   Ch2_LC3  Ch3_Posi  Ch4_Accel   LC1_Cal  
1  0.0000 -0.001179  0.015223 -0.013722  4.755466   4.670560 -0.009261   
2  0.0001 -0.001822  0.016188 -0.012114  4.754823   4.676027 -0.002510   
3  0.0002 -0.001179  0.016188 -0.012757  4.754501   4.680208 -0.009261   
4  0.0003 -0.000858  0.016509 -0.015008  4.754823   4.683746 -0.012632   
5  0.0004 -0.001179  0.016188 -0.013400  4.755466   4.686962 -0.009261   

    LC2_Cal   LC3_Cal    LC_Tot     Posi_Cal  Accel_Cal  Posi_Vel  
1  0.014619 -0.002637  0.002721  1422.726220  -1.067844    0.0000  
2  0.004876 -0.018576 -0.016209  1422.845175  -0.958777    0.4825  
3  0.004876 -0.012202 -0.016587  1422.904745  -0.875366    0.0000  
4  0.001636  0.010111 -0.000886  1422.845175  -0.804783   -0.4825  
5  0.004876 -0.005829 -0.010213  1422.726220  -0.740624   -1.1255  

当Chx列是直接DAC数据时,校准列已经过校正,最后一列是瞬时速度位置的双导数

当值与查询值完全相等时,可以使用query函数和.loc函数来报告此类数据,但我无法使用相同的方法来处理<;参数,因为它返回所有后续样本。例如Select rows from a DataFrame based on values in a column in pandas

如果有人能帮忙,我们将不胜感激

链接到DSP文件:https://www.dropbox.com/s/z9xs3te23xet1lz/R16-03_moving.dat?dl=0

用于导入上述文件并创建附加列的代码段

from IPython import get_ipython
get_ipython().magic('reset -sf') 

import numpy as np
import matplotlib.pyplot as plt
import scipy.fftpack
import pandas as pd
#from scipy import interpolate
from scipy.interpolate import splrep, splev
from scipy.signal import butter, filtfilt, freqz, sosfiltfilt, sosfilt, cheby2, sosfreqz

Start_line = 15
file = 'C:/Users/wesley.heckendorf/Downloads/R84-02_moving.dat' 
output1 = pd.read_csv(file, "r", delimiter=' ', skiprows=Start_line, usecols=[0,1,2,3,4,5], error_bad_lines=False)
#io = pd.read_csv('D:/UCRF_Drop_Commissioning/16.run/R16-03_moving.dat', "r", delimiter=' ', skiprows=21, index_col=False, usecols=[1,2,3,4,5]).to_records() # To read 1st,2nd columns
io2 = pd.read_csv(file, "r", delimiter=' ', skiprows=(Start_line+7), index_col=False, names=['Time', 'Ch0_LC1', 'Ch1_LC2', 'Ch2_LC3', 'Ch3_Posi', 'Ch4_Accel']) # To read 1st,2nd columns

io2[:] = io2[:].convert_objects(convert_numeric=True)

"""constants"""
T = (io2.loc[2,'Time'] - io2.loc[1,'Time'])
fs = 1/T
nyq = 0.5 * (1/T)

""" Extract Calibration Factors and create columns for calibrated and Zero'd data"""
LC1_cal = float(output1.iloc[2,1])
LC2_cal = float(output1.iloc[2,2])
LC3_cal = float(output1.iloc[2,3])
Posi_cal = float(output1.iloc[2,4])
Accel_cal = float(output1.iloc[2,5])
print (LC1_cal, LC2_cal, LC3_cal, Posi_cal, Accel_cal) 
io2["LC1_Cal"] = (io2["Ch0_LC1"]-float(output1.iloc[1,1])) * LC1_cal
io2["LC2_Cal"] = (io2["Ch1_LC2"]-float(output1.iloc[1,2])) * LC2_cal
io2["LC3_Cal"] = (io2["Ch2_LC3"]-float(output1.iloc[1,3])) * LC3_cal
io2["LC_Tot"] = (io2["LC1_Cal"]+io2["LC2_Cal"]+io2["LC3_Cal"])
io2["Posi_Cal"] = ((io2["Ch3_Posi"] - io2["Ch3_Posi"].max())-float(output1.iloc[1,4])) * Posi_cal * -1
io2["Accel_Cal"] = (io2["Ch4_Accel"]-float(output1.iloc[1,5])) * Accel_cal
io2["Posi_Vel"] = (np.nan_to_num(np.gradient(io2["Ch3_Posi"]/-10,T)))
print (io2[1:6])

Tags: 数据fromimportfloatcalaccellc3iloc
1条回答
网友
1楼 · 发布于 2024-06-02 13:09:40

我已经想出了一个解决方案感谢大卫的评论和我之前发布的链接。它可能不是最有效的方法,但似乎确实有效,下面的代码可供参考

a_start_pos = io2.loc[io2["Posi_Fil"]<(pressure_smooth[1:15001].mean()-(pressure_smooth[1:15001].mean()-pressure_smooth[1:15001].min())*10),"Posi_Fil"].max().item() a_start_time = io2.loc[io2["Posi_Fil"]<(pressure_smooth[1:15001].mean()-(pressure_smooth[1:15001].mean()-pressure_smooth[1:15001].min())10),"Time"].min().item() a_finish_pos = io2.loc[1:,"Posi_Fil"].min()+20 a_finish_time = io2.loc[io2["Posi_Fil"]<(io2.loc[1:,"Posi_Fil"].min()+20), "Time"].min() a = 2(a_finish_pos-a_start_pos)/1000/(a_finish_time-a_start_time)**2 print ("Drop Carriage Acceleration =", a, "m/s2", a/-9.81*100, "%g")

其中:

开始位置-是车厢开始移动的位置

开始时间-车厢开始移动的时间

a_finish_pos-是车厢接近其行程终点的位置

完成时间-马车到达终点的时间

干杯

相关问题 更多 >