Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168731
Image: ubuntu2004
# A simple function to parse our data file import os, sys import datetime class Record(): def __init__(self, timestamp, kind, values): self.timestamp = timestamp self.kind = kind self.values = values def parseRecord(timestamp, kind, rest): floats = [float(x.strip()) for x in rest.split(",")] r = Record(timestamp, kind, floats) return r def parseLog(logfile): records = [] with open(logfile, "r") as f: for l in f: e = l.split(":") r = parseRecord(float(e[0]), e[1].strip(), e[2].strip()) records.append(r) return records
recs = parseLog(DATA+"WorkToJeffs.log")
# Filter out the acceleration and GPS data acc = [r for r in recs if r.kind == "ACL"] gps = [r for r in recs if r.kind == "LOC"] speed = [r for r in recs if r.kind == "VEL"]
# Sanity check print len(acc), len(gps), len(speed)
4213 153 153
# Plot lateral acceleration t=[r.timestamp for r in acc] latAcc=[r.values[0] for r in acc] p = list_plot(zip(t,latAcc), plotjoined=True) p.axes_labels(["Time", "Lateral Acceleration (G's) (positive is left turn)"]) p.show()
# Plot front/back acceleration fbAcc=[r.values[1] for r in acc] p = list_plot(zip(t,fbAcc), plotjoined=True) p.axes_labels(["Time", "Braking/Accelerating (G's) (positive is braking)"]) p.show()
# Plot a friction circle import numpy #title = text("Acceleration (G's)", (0,1), rgbcolor='black',fontsize=15) guides = [circle((0,0), r, color='grey', zorder=1) for r in numpy.arange(0,.7501,.25)] p = scatter_plot(zip(latAcc,fbAcc), edgecolor='red', facecolor='red', marker="o", markersize=4, aspect_ratio=1, axes_labels=("left turn", "braking")) (sum(guides)+p)
# Plot GPS location long=[r.values[1] for r in gps] lat=[r.values[0] for r in gps] list_plot(zip(long,lat), plotjoined=False, aspect_ratio=1)
# Now show speed as a color along the route locPoints = [] # [point(p) for p in zip(long, lat)] allColors = [hue(x) for x in numpy.arange(0, 1, 1/len(lat))] redToGreen = [(1-x,x,0) for x in numpy.arange(0, 1, 1/len(lat))] speeds = [r.values[0] for r in speed] maxSpeed = max(speeds) for (x,y,s) in zip(long, lat, speeds): g = s/maxSpeed r = 1-g b = 0 locPoints.append(point((x, y), color=(r,g,b))) sum(locPoints)
# Plot speed vs. time x = [r.timestamp for r in speed] y = [r.values[0] for r in speed] # Convert to mph y = [s*2.23693629 for s in y] p = list_plot(zip(x,y), plotjoined=True) p.axes_labels(["Time", "Speed (mph)"]) p.show()
print "Top speed was %.2f mph." % max(y)
Top speed was 41.73 mph.
# Sage is the shit.