Question/Issue: How do I export accelorometer data to csv?
**Project ID:**177354
Context/Use case:
When I export the data it exports it into testing, traininig folders and a label file which has the labels.
I tried using the ei_json_to.csv.ipynb script but it did not work.
Data was exported into .cbor format.
I’m checking internally if we have a script to convert CBOR to CSV.
I’m also creating a feature request to be able to choose the export format but not sure when/if this will be implemented.
If we don’t have a script already, I’ll write one early next week.
Here you go, feel free to modify it if needed to apply that at the folder level, I just wrote the example for a single file. It saves the csv file in the same folder with the same name as your cbor.
Save the following snippet in a cbor2csv.py script and run:
#!/usr/bin/env python3
import cbor2
import sys
import csv
import os
with open(sys.argv[1], 'rb') as f:
# Load the cbor file
obj = cbor2.load(f)
# Get the filename without extension
label = os.path.splitext(sys.argv[1])[0]
filename = str(label) + ".csv"
with open(filename, 'w') as csv_file:
writer = csv.writer(csv_file)
# uncomment to add a fixed header
# writer.writerow(['x','temp [degC]','press [kPa]','hum [%]','gas res [MOhm]'])
# or use this to read the values from edge impulse exported cbor files
header = []
header.insert(0, "timestamp")
for sensor in obj['payload']['sensors']:
header.append(sensor['name'])
writer.writerow(header)
timestamp = 0
for val in obj['payload']['values']:
val.insert(0, timestamp)
writer.writerow(val)
timestamp += int(obj['payload']['interval_ms'])
# python3 -m pip install cbor2
# python3 cbor2csv.py your-file.cbor