From 4c2cf472dc229b3b2fcfa3b8aac1223fb06bba48 Mon Sep 17 00:00:00 2001 From: Bola Malek Date: Wed, 17 Apr 2019 16:52:18 -0700 Subject: [PATCH] Add scripts and notebooks --- desktop/{ => notebooks}/FindDDS.ipynb | 0 desktop/{ => notebooks}/dds_params.db | Bin desktop/{ => notebooks}/fit_minig.ipynb | 0 desktop/scripts/plot_saved.py | 63 ++++++++++++++++++++++++ desktop/scripts/record.py | 42 ++++++++++++++++ desktop/scripts/serial_to_plot.py | 58 ++++++++++++++++++++++ desktop/scripts/spec_data.py | 27 ++++++++++ 7 files changed, 190 insertions(+) rename desktop/{ => notebooks}/FindDDS.ipynb (100%) rename desktop/{ => notebooks}/dds_params.db (100%) rename desktop/{ => notebooks}/fit_minig.ipynb (100%) create mode 100644 desktop/scripts/plot_saved.py create mode 100644 desktop/scripts/record.py create mode 100644 desktop/scripts/serial_to_plot.py create mode 100644 desktop/scripts/spec_data.py diff --git a/desktop/FindDDS.ipynb b/desktop/notebooks/FindDDS.ipynb similarity index 100% rename from desktop/FindDDS.ipynb rename to desktop/notebooks/FindDDS.ipynb diff --git a/desktop/dds_params.db b/desktop/notebooks/dds_params.db similarity index 100% rename from desktop/dds_params.db rename to desktop/notebooks/dds_params.db diff --git a/desktop/fit_minig.ipynb b/desktop/notebooks/fit_minig.ipynb similarity index 100% rename from desktop/fit_minig.ipynb rename to desktop/notebooks/fit_minig.ipynb diff --git a/desktop/scripts/plot_saved.py b/desktop/scripts/plot_saved.py new file mode 100644 index 0000000..031a2ea --- /dev/null +++ b/desktop/scripts/plot_saved.py @@ -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 \ No newline at end of file diff --git a/desktop/scripts/record.py b/desktop/scripts/record.py new file mode 100644 index 0000000..bd66beb --- /dev/null +++ b/desktop/scripts/record.py @@ -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 = [], [] + diff --git a/desktop/scripts/serial_to_plot.py b/desktop/scripts/serial_to_plot.py new file mode 100644 index 0000000..8c692f5 --- /dev/null +++ b/desktop/scripts/serial_to_plot.py @@ -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() + + diff --git a/desktop/scripts/spec_data.py b/desktop/scripts/spec_data.py new file mode 100644 index 0000000..c5bd995 --- /dev/null +++ b/desktop/scripts/spec_data.py @@ -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()