File size: 1,585 Bytes
41ed540
 
b5cac07
 
 
41ed540
b5cac07
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json

import numpy as np 
import pandas as pd
import matplotlib.pyplot as plt

sensor = 'GZ1'
slice_select = 2

json_file = '/Users/ankit/Documents/cabasus/output.json'
# Read the JSON file
try:
    with open(json_file, "r") as f:
        slices = json.load(f)
except:
    with open(json_file.name, "r") as f:
        slices = json.load(f)

# Concatenate the slices and create a new timestamp series with 20ms intervals
timestamps = []
sensor_data = []
slice_item = []
temp_end = 0
for slice_count, slice_dict in enumerate(slices):
    start_timestamp = slice_dict["timestamp"]
    slice_length = len(slice_dict[sensor])

    slice_timestamps = [start_timestamp + 20 * i for i in range(temp_end, slice_length + temp_end)]
    timestamps.extend(slice_timestamps)
    sensor_data.extend(slice_dict[sensor])

    temp_end += slice_length
    slice_item.extend([slice_count+1]*len(slice_timestamps))

# Create a DataFrame with the sensor data
data = pd.DataFrame({sensor: sensor_data, 'slice selection': slice_item, 'time': timestamps})

# Plot the sensor data
fig, ax = plt.subplots(figsize=(12, 6))
ax = plt.plot(data['time'].to_list(), data[sensor].to_list(), '-b')

df_temp = data[data['slice selection'] == int(slice_select)].reset_index()
ax = plt.plot(df_temp['time'].to_list(), df_temp[sensor].to_list(), '-r')

plt.xlabel("Timestamp")
plt.ylabel(sensor)
plt.legend()
plt.tight_layout()

fig1, ax1 = plt.subplots(figsize=(12, 6))
ax1 = plt.plot(df_temp['time'].to_list(), df_temp[sensor].to_list())

plt.xlabel("Timestamp")
plt.ylabel(sensor)
plt.legend()
plt.tight_layout()