Created
February 6, 2023 17:12
-
-
Save N-M-T/2b61dc0a8a2533bb43934c965bb7e35e to your computer and use it in GitHub Desktop.
Parse eda data from avro and plot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from avro.datafile import DataFileReader | |
from avro.io import DatumReader | |
import matplotlib.pyplot as plt | |
from datetime import datetime | |
import json | |
avro_file = "/Users/neilthomas/Downloads/1-1-PILOT_1675422454.avro" | |
# Read Avro file | |
reader = DataFileReader(open(avro_file, "rb"), DatumReader()) | |
schema = json.loads(reader.meta.get('avro.schema').decode('utf-8')) | |
data = [] | |
for datum in reader: | |
data = datum | |
reader.close() | |
# Print the Avro schema | |
print(schema) | |
print(" ") | |
eda = data["rawData"]["eda"] | |
# Print structure | |
print("eda fields:") | |
for key, val in eda.items(): | |
print("- " + key) | |
if type(val) is dict: | |
for k in val.keys(): | |
print(" - " + k) | |
print(" ") | |
skr = eda["values"] | |
# Create time vector (in your local timezone) | |
startSeconds = eda["timestampStart"] / 1000000 | |
timeSeconds = list(range(0, len(skr))) | |
timeUNIX = [t/eda["samplingFrequency"]+startSeconds for t in timeSeconds] | |
datetime_time = [datetime.fromtimestamp(x) for x in timeUNIX] | |
# Plot | |
plt.figure() | |
plt.plot(datetime_time, skr, label="skr") | |
plt.ylabel("Value") | |
plt.grid(True) | |
plt.legend(loc="best") | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment