Skip to content

Commit

Permalink
Add scripts and notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Bola Malek committed Apr 17, 2019
1 parent 3f7451d commit 4c2cf47
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
63 changes: 63 additions & 0 deletions desktop/scripts/plot_saved.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import dataset
import datafreeze
from matplotlib import pyplot as plt

plot_db = True
plot_txt = False
output_csv = True

xs = []
ys = []



if plot_db:
db = dataset.connect('sqlite:///day_run_9_18.db')
if output_csv:
result = db['T_115_fringes'].all()
dataset.freeze(result, format='csv', filename='for_zack.csv')

table = db['T_115_fringes']
# plt.ion()
query1 = "SELECT DISTINCT chirp FROM T_115_fringes"

for row in db.query(query1):
xs.append(row['chirp'])
query2 = 'SELECT pd FROM T_115_fringes WHERE chirp = %f' % (row['chirp'])
for pd in db.query(query2):
try:
ys[xs.index(row['chirp'])].append(pd['pd'])
except IndexError:
ys.append([pd['pd']])



if plot_txt:
file = "T_115.txt"
x, y = 0, 0
for line in open(file, 'r'):
l = line.strip()
if l.startswith("rd"):
_, x = l.split(":")
x = float(x)
xs.append(x)
elif l.startswith("fr"):
_, y = l.split(":")
y = float(y)
try:
ys[xs.index(x)].append(y)
except IndexError:
ys.append([y])

for xe, ye in zip(xs, ys):
plt.scatter([xe] * len(ye), ye)

plt.xlim(min(xs) - 0.00001, max(xs) + 0.00001)
plt.show()

while True:
continue


if __name__ == '__main__':
pass
42 changes: 42 additions & 0 deletions desktop/scripts/record.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import serial
import dataset
import datetime

db = dataset.connect('sqlite:///t_130.db')

table = db['16_fringes']

stream = serial.Serial('COM5', 112500)

# num_pts_fringe = 16
#
# from matplotlib import pyplot as plt
# plt.xlim(22.993603 - 0.0000001, 22.993760 + 0.0000001)
# plt.ion()
# plt.show()

def values():
x = 0
y = 0
while True:
l = stream.readline()
l = l.strip()
if l.startswith("rd"):
_, x = l.split(":")
elif l.startswith("fr"):
_, y = l.split(":")
yield (float(x), float(y))
print l

if __name__ == '__main__':
data = values()
while True:
x, y = data.next()
table.insert(dict(chirp=x, pd=y, timestamp=datetime.datetime.utcnow()))
db.commit()
# plt.scatter(x, y, color='r', marker='.')
#
# plt.draw()
# plt.pause(0.001)
# xs, ys = [], []

58 changes: 58 additions & 0 deletions desktop/scripts/serial_to_plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import serial
import signal
import sys
import time

# orig_stdout = sys.stdout
# filename = time.asctime(time.localtime(time.time())).replace(' ', '_').replace(':', '_') + '.txt'
# f = open(filename, 'w')
# sys.stdout = f

def signal_handler():
print('You pressed Ctrl+C!')
# TODO(bsm): Save data here


# sys.stdout = orig_stdout
# f.flush()
# f.close()
sys.exit(0)


stream = serial.Serial('COM5', 112500)

from matplotlib import pyplot as plt
plt.ion()
plt.show()

def values():
x = 0
y = 0
while True:
l = stream.readline()
l = l.strip()
if l.startswith("rd"):
_, x = l.split(":")
elif l.startswith("fr"):
_, y = l.split(":")
yield (float(x), float(y))
print l

xs = set()

if __name__ == '__main__':
try:
xs = []
ys = []
data = values()
while True:
x, y = data.next()
xs.append(x)
plt.scatter(x, y)
plt.xlim(min(xs) - 0.0000001, max(xs) + 0.0000001)
plt.draw()
plt.pause(0.005)
except:
signal_handler()


27 changes: 27 additions & 0 deletions desktop/scripts/spec_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from matplotlib import pyplot as plt

def values():
with open('super_nice_spectroscopy.txt') as f:
for l in f:
if l.startswith("rd"):
_, x = l.split(":")
elif l.startswith("fr"):
_, y = l.split(":")
yield (float(x), float(y))

xs = []
ys = []
data = values()
while True:
try:
x, y = data.next()
if x not in xs:
xs.append(x)
ys.append([y])
else:
ys[xs.index(x)].append(y)
except:
break
for xe, ye in zip(xs, ys):
plt.scatter([xe] * len(ye), ye)
plt.show()

0 comments on commit 4c2cf47

Please sign in to comment.