Last active
August 29, 2015 14:04
-
-
Save christakahashi/3a59e5b9c7863c0e6104 to your computer and use it in GitHub Desktop.
Example Flexostat plotting code.
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
#!/usr/bin/env python | |
#Above line will ensure python is envoked on mac/linux | |
import json | |
#if we're running in canopy then everything is already imported AND we're in | |
# interactive mode for matplotlib (meaning you don't need the show() command). | |
try: | |
np | |
no_show = True | |
except NameError: | |
from pylab import * | |
no_show = False | |
#Some constants | |
log_file = "log.dat" #assumes log is named log.dat and in the current directory. | |
#note: there are more advanced ways to do the stuff below, but it has been | |
# been written this way to make it easier to understand. | |
data = [] | |
with open(log_file,'r') as f: #open log.dat and assign that to the variable f | |
for line in f: #loop over each line in f. | |
data.append(json.loads(line)) | |
#go through each data point in the collected data and construct time and | |
#OD vectors | |
t0 = data[0]["timestamp"] #experiment start time | |
t = [] | |
u = [] | |
od = [] | |
for datum in data: | |
#convert time to hours since start | |
t.append((datum["timestamp"]-t0)/60.0/60.0) | |
u.append(datum["u"]) | |
od.append(datum["ods"]) | |
#plotting code | |
legend_names = [] | |
for chamber in range(1,9): | |
legend_names.append("Chamber " + str(chamber)) | |
plot(t,od) #can replace od with u for plotting dilution rate | |
legend(legend_names,"best") | |
xlabel("Time hr") | |
ylabel("OD$_{650}$") | |
if not no_show: | |
show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment