diff --git a/plot_sayma_data.py b/plot_sayma_data.py index 966605e..d40619d 100644 --- a/plot_sayma_data.py +++ b/plot_sayma_data.py @@ -3,6 +3,7 @@ import matplotlib.pyplot as plot from scipy import signal, constants import argparse import os +import datetime def rp_raw_to_numpy(rp_raw): @@ -38,11 +39,15 @@ def main(): raise ValueError("Both files are the same.") with open(os.path.join(args.dir, y1_filename), 'rb') as f: - y1_raw = f.read().decode('utf-8') + y1_now_iso, y1_raw = [l.decode('utf-8') for l in f.readlines()] with open(os.path.join(args.dir, y2_filename), 'rb') as f: - y2_raw = f.read().decode('utf-8') + y2_now_iso, y2_raw = [l.decode('utf-8') for l in f.readlines()] if None in [y1_raw, y2_raw]: raise IOError("Raw RP string files cannot be opened.") + if y1_now_iso != y2_now_iso: + raise ValueError("Timestamps of raw RP files are not identical.") + now_iso = y1_now_iso.rstrip() + print("Reading raw RP data collected at {}.".format(now_iso)) y1 = rp_raw_to_numpy(y1_raw) y2 = rp_raw_to_numpy(y2_raw) diff --git a/rp_get_sayma_data.py b/rp_get_sayma_data.py index 95f2cdd..51e3f1c 100644 --- a/rp_get_sayma_data.py +++ b/rp_get_sayma_data.py @@ -2,6 +2,7 @@ import socket import asyncio import argparse import os +import datetime class RPSCPI: @@ -57,6 +58,12 @@ async def gather_trigger(rp_list): def main(): + # Get timestamp at script start + now = datetime.datetime.now().replace( + microsecond=0, # get rid of microseconds when printed + ) + now_iso = now.isoformat(sep=' ') + parser = argparse.ArgumentParser(description="Data collection tool for Sayma DAC/TTL at RedPitaya") parser.add_argument("dir", help="output directory", type=str) parser.add_argument("rps_gains", metavar="RP_NAME:CH1_GAIN,CH2_GAIN", @@ -95,11 +102,14 @@ def main(): for rp in rps: y1_raw = rp.get_data(1) y2_raw = rp.get_data(2) + print("Data collection started at {}.".format(now_iso)) with open(os.path.join(args.dir, 'rp_{}_y1_raw.bin'.format(rp.name)), 'wb') as f: + f.write("{}\n".format(now_iso).encode('utf-8')) f.write(y1_raw.encode('utf-8')) print("Succesfully written y1 raw data from RP {}.".format(rp.name)) with open(os.path.join(args.dir, 'rp_{}_y2_raw.bin'.format(rp.name)), 'wb') as f: + f.write("{}\n".format(now_iso).encode('utf-8')) f.write(y2_raw.encode('utf-8')) print("Succesfully written y2 raw data from RP {}.".format(rp.name))