-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdf_viewer.py
More file actions
82 lines (73 loc) · 2.92 KB
/
df_viewer.py
File metadata and controls
82 lines (73 loc) · 2.92 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
def visualize_combined_df(file_path):
# Load the combined DataFrame from the pickle file
try:
combined_df = pd.read_pickle(file_path)
except Exception as e:
print(f"Error loading pickle file: {e}")
return
print("Combined DataFrame loaded.")
print("Shape:", combined_df.shape)
print("\nFirst few rows:")
print(combined_df.head())
# For visualization, we use the first row (trial) as an example.
trial = combined_df.iloc[0]
# Extract the time axis. We assume this is stored under 'time_frame'
if 'time_frame' not in trial:
print("No 'time_frame' found in the trial data.")
return
time_frame = trial['time_frame']
# Ensure time_frame is a 1D numpy array
time_frame = np.array(time_frame).flatten()
# # --- Visualize EMG Data ---
# if 'EMG' in trial:
# emg_df = trial['EMG']
# # We assume emg_df is a DataFrame with columns as channel names
# plt.figure(figsize=(12, 6))
# for col in emg_df.columns:
# # Plot only a subset of the data (first 1000 samples) for clarity if needed
# plt.plot(time_frame[:1000], emg_df[col].values[:1000], label=col)
# plt.title("EMG Data (Trial 1)")
# plt.xlabel("Time")
# plt.ylabel("EMG amplitude")
# plt.legend(loc='upper right')
# plt.tight_layout()
# plt.show()
# else:
# print("No EMG data available in this trial.")
# # --- Visualize Spike Counts ---
# if 'spike_counts' in trial:
# spike_counts = trial['spike_counts']
# # Assume spike_counts is a 2D array (units x samples)
# plt.figure(figsize=(12, 6))
# # Plot first unit for demonstration; adjust index as needed
# plt.plot(time_frame[:1000], spike_counts[0, :1000], label="Unit 1")
# plt.title("Spike Counts (Trial 1)")
# plt.xlabel("Time")
# plt.ylabel("Spike Count")
# plt.legend()
# plt.tight_layout()
# plt.show()
# else:
# print("No spike counts available in this trial.")
# --- Visualize Force Data ---
if 'force' in trial:
force_data = trial['force']['x']
# Assume force_data is a 2D array (channels x samples)
plt.figure(figsize=(12, 6))
# Plot first channel for demonstration; adjust index as needed
plt.plot(time_frame[:1000], force_data[0, :1000], label="Force Channel 1")
plt.title("Force Data (Trial 1)")
plt.xlabel("Time")
plt.ylabel("Force")
plt.legend()
plt.tight_layout()
plt.show()
else:
print("No force data available in this trial.")
if __name__ == '__main__':
# Specify the path to your combined pickle file
file_path = "C:/Users/Ethier Lab/Documents/GitHub/Decoder-Processing/DataSET/Spike_ISO_2012/combined.pkl"
visualize_combined_df(file_path)