Skip to content

Commit c8f12f0

Browse files
committed
added documentation for data_ac.py
1 parent 62c2d47 commit c8f12f0

File tree

3 files changed

+71
-122
lines changed

3 files changed

+71
-122
lines changed

plotting_test/data_ac.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99
import os, sys, csv, re, math
1010
import numpy as np
1111

12+
# flag for if we should stop the program
1213
stop_requested = False
14+
# bc channel corrective value
1315
bc_correction = 0.88
16+
# instrument dictionary - initialized instruments are automatically added
1417
instruments = []
1518

19+
# generate a serial connection with DEVICE over baudrate BAUDRATE
1620
def serialGeneric(device,baudrate):
1721
ser = serial.Serial(port=device,
1822
baudrate=baudrate,
@@ -22,6 +26,8 @@ def serialGeneric(device,baudrate):
2226
)
2327
return ser
2428

29+
30+
# signal handler for ctrl-c (quit)
2531
def sig_handler(signum, frame):
2632
sys.stdout.write("handling signal: %s\n" % signum)
2733
sys.stdout.flush()
@@ -30,6 +36,8 @@ def sig_handler(signum, frame):
3036
stop_requested = True
3137

3238
class Instrument(object):
39+
40+
# initialize instrument with serial connection and add it to instrument dict
3341
def __init__(self, comport, baudrate):
3442
if comport:
3543
self.serial = serialGeneric(comport, baudrate)
@@ -42,6 +50,7 @@ def __str__(self):
4250
def __repr__(self):
4351
return self.__str__()
4452

53+
# dumps the serial output SER, which was received at datetime DT, into rawraw_data.csv
4554
def dumpserial(self, ser, dt):
4655
with open(filepath + 'rawraw_data.csv', mode='ab') as rawFile:
4756
fcntl.flock(rawFile, fcntl.LOCK_EX)
@@ -50,6 +59,7 @@ def dumpserial(self, ser, dt):
5059
fcntl.flock(rawFile, fcntl.LOCK_UN)
5160
return
5261

62+
# continually call Instr get_values() func to receive serial output until STOP_REQUESTED
5363
def run(self, queue):
5464
while not stop_requested:
5565
values = self.get_values()
@@ -62,6 +72,9 @@ def run(self, queue):
6272
if stop_requested:
6373
self.serial.close()
6474

75+
# def get_values(self):
76+
# exists for each defined instrument below, parses serial output to a datetime and value (sometimes includes attn and flow)
77+
6578
# BC Instr
6679

6780
class AE33_Instrument(Instrument):
@@ -411,21 +424,25 @@ def get_values(self):
411424
return None
412425
return nox_values
413426

427+
# main method for use when file is run through multiprocessing (like in this ../cli.py)
414428
def main_wrapper(q):
415429
global filepath
416430
filepath = q.get()
417431

432+
# create output dir using filepath (sent to queue Q from plotter.py)
418433
if not os.path.exists(os.path.dirname(filepath)):
419434
try:
420435
os.makedirs(os.path.dirname(filepath))
421436
except OSError as exc: # Guard against race condition
422437
if exc.errno != errno.EEXIST:
423438
raise
424439

440+
# initialize rawraw_data.py header
425441
with open(filepath + 'rawraw_data.csv', mode='wb') as rawFile:
426442
rawData = csv.writer(rawFile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
427443
rawData.writerow(['Timestamp', 'Instr', 'S#', 'Message'])
428444

445+
# dictionary mapping serial numbers to Instrument objects ** CHANGE THIS TO ADD MORE INSTRUMENTS **
429446
comport_dict = {
430447
'FTXP6UA4': AE33_Instrument,
431448
'FTXP9NHN': AE16_Instrument,
@@ -451,6 +468,8 @@ def main_wrapper(q):
451468
comport_pattern = re.compile('\/dev\/cu\.usbserial(\-(.)*)?$')
452469
serial_comlist = []
453470

471+
# initialize instrument objects for each serial connection (view in terminal with ls /dev/cu.*) that matches
472+
# comport_pattern (/dev/cu.usbserial- or /dev/cu.wchusbsereial for ABCD)
454473
for element in comlist:
455474
if comport_pattern.match(element.device):
456475
try:

plotting_test/plotter.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -374,13 +374,10 @@ def draw(self):
374374
# self.update_ambient()
375375
# self.ambient_cs = 5
376376

377-
update_am = time.time()
378-
row.append(update_am - getUpdate)
379-
380377
# plume analysis and summary write
381378
self.analyze(current_time)
382379
analyze = time.time()
383-
row.append(analyze - update_am)
380+
row.append(analyze - getUpdate)
384381
self.write_ts(current_time)
385382
write_summ = time.time()
386383
row.append(write_summ - analyze)
@@ -698,7 +695,6 @@ def get_plume_area(self, ts_dict, chan_spec, chan_id):
698695

699696
def get_ts_dict(self, start_time, stop_time):
700697
ret = collections.OrderedDict()
701-
print(start_time, stop_time)
702698
t = start_time
703699
while t != stop_time:
704700
ret[t] = self.ts_aligned_dps[t]
@@ -830,6 +826,9 @@ def reset_data(self, plot, name):
830826
plot.set_ylabel(r'$\mu g/m^3$')
831827
plot.set_xlabel('seconds ago')
832828
plot.tick_params(axis='y', left=True, right=True, labelright=True)
829+
# draw analysis horizons
830+
plot.axvline(45, c='b', linewidth=0.5, linestyle='--')
831+
833832

834833
def correct_ts(self, timestamps, chan, instr_id):
835834
start_lag = self.pip[chan][instr_id]['start_lag']

0 commit comments

Comments
 (0)