我必须从一个数据数据中计算出,零上升周期,平均超过半个小时。
时间测量是UTC-时间戳(自01.0.1970以来的秒数)。每秒钟大约有2-3次测量。每天的测量数据都存储在自己的文件中。
不幸的是,数据采集并没有同时开始。有时午夜后6秒开始,有时10秒等等。这导致在特定时间内测量的数量不正常。(在半小时内测量的次数并不总是相同)
因此,现在我必须从我的文件中加载数据,然后以某种方式在30分钟(1800秒)的间隔内找到测量值。查找所有的零上过点(值从<0到>0),然后找到所有相应的时间步骤来计算上过点的周期,并计算这些时间的平均值。然后,这需要迭代48次。
到目前为止,我已经做了两次尝试。
1
def get_T_z(filename):
#zero uprcossing period
heave=load_data_2(filename,2)
timestamp=load_data_2(filename,0)
zero_up_ind=[]
# index of zero upcrossings
zero_up=[]
#zero_upcrossing periods for each half hour
i=0
initial_time=0
day_len=int(timestamp[len(timestamp)-1]-timestamp[0])
count=0
while count<48:
period=[]
zero_up_ind=[]
#stores the sum of the periods for each half hour
while timestamp[i]-timestamp[initial_time]<int(day_len/48):
if heave[i]<0 and heave[i+1]>0:
zero_up_ind.append(i)
for c in range(0,len(zero_up_ind)-1):
periods.append(timestamp[zero_up_ind[c+1]]-timestamp[zero_up_ind[c]])
zero_up.append(mean(periods))
count+=1
return zero_up2
def get_T_z_3(filename):
heave=load_data_2(filename,2)
#loads heave data from a file
timestamp=load_data_2(filename,0)
#loads the timestamp from a file
day_len=int(timestamp[-1]-timestamp[0])
#lenght of the day (number of rows)
t_init=0
#initial time
i=0
half_hour_time=[]
zero_up_p=[]
print(heave)
print(timestamp)
#the half-hour averages of the zero-ucrossing periods will be stored here
for count in range(1,49):
zero_up_t=[]
#the timestamps of the upcrossings will be stored here
period_sum=0
#stores the sum the periods
if timestamp[i]<timestamp[t_init]+count*int(day_len/48):
i+=1
elif timestamp[i]==timestamp[t_init]+count*int(day_len/48):
half_hour_time=timestamp[t_init:i]
half_hour_heave=heave[t_init:i]
t_init=i
print(half_hour_time)
print(half_hour_heave)
for k in range(0,len(half_hour_time)):
if half_hour_heave[k]<=0 and half_hour_heave[k+1]>0:
zero_up_t.append(timestamp[k])
print(zero_up_t)
for c in range(0,len(zero_up_t)-1):
period_sum+=zero_up_t[c+1]-zero_up_t[c]
zero_up_p.append(period_sum/len(zero_up_t))
print(period_sum)
return zero_up_p当我执行第一段代码时,什么都不会发生。它只是继续运行,但什么也没有发生。我也尝试了修改版本的代码,一段时间后,我的笔记本电脑崩溃。所以也许有一个无限的循环什么的?第二段代码只是将zero_up_p作为空列表返回。我有一种感觉,它甚至没有启动for循环。
Edit1:我添加了i的增量,并改变了周期的平均方式。我的第一段代码现在似乎起作用了。
发布于 2015-07-22 17:47:50
这段代码现在似乎正在工作:
def get_T_z(filename):
#zero uprcossing period
heave=load_data_2(filename,2)
timestamp=load_data_2(filename,0)
# index of zero upcrossings
zero_up=[]
#zero_upcrossing periods for each half hour
i=0
initial_time=0
day_len=int(timestamp[len(timestamp)-1]-timestamp[0])
count=0
while count<48:
periods=[]
zero_up_ind=[]
#stores the sum of the periods for each half hour
while timestamp[i]-timestamp[initial_time]<int(day_len/48) and i<len(timestamp):
if heave[i]<0 and heave[i+1]>0:
zero_up_ind.append(i)
i+=1
for c in range(0,len(zero_up_ind)-1):
periods.append(timestamp[zero_up_ind[c+1]]-timestamp[zero_up_ind[c]])
zero_up.append(mean(periods))
count+=1
initial_time=i
return zero_uphttps://stackoverflow.com/questions/31565142
复制相似问题