File size: 1,915 Bytes
2d3ff87 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
import numpy as np
import pickle
import os
import pandas as pd
root="./data"
data=[]
csi_vaid_subcarrier_index = range(0, 52)
def handle_complex_data(x, valid_indices):
real_parts = []
imag_parts = []
for i in valid_indices:
real_parts.append(x[i * 2])
imag_parts.append(x[i * 2 - 1])
return np.array(real_parts) + 1j * np.array(imag_parts)
people_id=0
for people in os.listdir(root):
print(people)
action_id=0
path_people=os.path.join(root,people)
for action in os.listdir(path_people):
count=0
print(action)
path_action=os.path.join(path_people,action)
for file in os.listdir(path_action):
count+=1
path=os.path.join(path_action,file)
df = pd.read_csv(path)
df.dropna(inplace=True)
df['data'] = df['data'].apply(lambda x: eval(x))
complex_data = df['data'].apply(lambda x: handle_complex_data(x, csi_vaid_subcarrier_index))
magnitude = complex_data.apply(lambda x: np.abs(x))
phase = complex_data.apply(lambda x: np.angle(x, deg=True))
time = np.array(df['timestamp'])
local_time = np.array(df['local_timestamp'])
data.append({
'csi_time':time,
'csi_local_time':local_time,
'volunteer_name': people,
'volunteer_id': people_id,
'action': action,
'action_id': action_id,
'magnitude': np.array([np.array(a) for a in magnitude]),
'phase': np.array([np.array(a) for a in phase])
})
# if count==4:
# break
action_id+=1
people_id+=1
# 保存全局字典为一个pickle文件
output_file = './csi_data.pkl'
with open(output_file, 'wb') as f:
pickle.dump(data, f) |