Spaces:
Build error
Build error
| 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() |