Skip to content

Instantly share code, notes, and snippets.

@sverhoeven
Last active November 30, 2017 14:13
Show Gist options
  • Select an option

  • Save sverhoeven/652b367a5fab0854584b1bf31f4491ff to your computer and use it in GitHub Desktop.

Select an option

Save sverhoeven/652b367a5fab0854584b1bf31f4491ff to your computer and use it in GitHub Desktop.
eEcology-Annotation-demo for odessei

Convert GENEActiv file to json for use in https://github.com/NLeSC/eEcology-Annotation-UI

Requirements

R libraries:

  • GENEAread
  • littler
  • docopt

Install

pip install -r requirements.txt

Usage

./geneactiv2csv.r --start <start> --end <end> --file <file> | ./csv2json.py --bin 60 > data.json

Example run:

./geneactiv2csv.r --start "2012-09-16 9:59:00" --end "2012-09-16 11:59:00" --file 804394_left\ wrist_013378_2012-10-01\ 13-19-51.bin | ./csv2json.py > 804394_2012-09-16T09:59:00_2012-09-16T11:59:00.json

This will

  • group all accelerations per second
  • put light value in altitude chart
  • because input file is missing GPS, it generates GPS points around equator for each timepoint

Visualization

Requires:

  • tool zip file
  • json data file with acceleration, gps, sensor data points

Steps to run visualization

  1. Unpack tool zip file
  2. Run web server in root directory (directory with demo-liss.html file), for example using
# For Python2
python -m SimpleHTTPServer 8000
# For Python3
python3 -m http.server 8000
  1. Open demo-liss.html in web browser by opening http://localhost:8000/demo-liss.html
  2. Configure classes by uploading new classifier labels
  3. Load annotations

Use other dataset

You must have run the scripts as described in the Usage chapter to generate a new json data file.

You must edit the demo-liss.html file.

  1. Copy json data file to root directory (directory with demo-liss.html file)
  2. Set the second argument of the setupUrls method to the json data file
  3. Set the tracker id
  4. Set the from and to date in ISO8601 format

You must edit the liss-ids.json file, by setting the tracker id.

#!/usr/bin/env python
from collections import OrderedDict
from datetime import datetime
import argparse
import json
import sys
import pytz
timezone = 'Europe/Paris'
line_counter = 0
rows_per_second = OrderedDict()
for line in sys.stdin:
line_counter += 1
if line_counter < 5:
# skip header
continue
(seqnr, timestamp, x, y, z, light, button, temperature) = line.strip().split(',')
dt = datetime.fromtimestamp(float(timestamp), pytz.timezone(timezone))
rounded_dt = dt.replace(microsecond=0).isoformat()
if rounded_dt in rows_per_second:
row = rows_per_second[rounded_dt]
row['x_acceleration'].append(float(x))
row['y_acceleration'].append(float(y))
row['z_acceleration'].append(float(z))
row['time_acceleration'].append(dt.microsecond)
row['light'].add(float(light))
row['temperature'].add(float(temperature))
else:
row = {
"date_time": rounded_dt,
"x_acceleration": [float(z)],
"y_acceleration": [float(y)],
"z_acceleration": [float(z)],
"time_acceleration": [dt.microsecond],
"light": {float(light)},
"temperature": {float(temperature)},
}
rows_per_second[rounded_dt] = row
data = []
i = 0
for key, val in rows_per_second.items():
max_light = sorted(val['light'])[0]
max_temp = sorted(val['temperature'])[0]
lon = 359 * i / len(rows_per_second)
i += 1
record = {
"date_time": key,
"lon": lon - 180,
"lat": 0,
"x_acceleration": val['x_acceleration'],
"y_acceleration": val['y_acceleration'],
"z_acceleration": val['z_acceleration'],
"time_acceleration": val['time_acceleration'],
"altitude": max_light,
"ground_elevation": 0,
"temperature": max_temp,
'speed': 0.0,
'tspeed': 0.0,
}
data.append(record)
print(json.dumps(data, indent=2))
#!/usr/bin/env r
suppressPackageStartupMessages(library("argparse"))
parser <- ArgumentParser()
parser$add_argument("--start", help="A representation of when in the file to begin processing")
parser$add_argument("--end", help="A representation of when in the file to end processing")
parser$add_argument("--file", help="Binary file")
opt <- parser$parse_args(argv)
library("GENEAread", quietly=TRUE)
P = read.bin(opt$file, start=opt$start, end=opt$end, verbose=FALSE)
write.csv(P$data.out, file="", quote=FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment