Commit fe5e9869 authored by Peter Jansweijer's avatar Peter Jansweijer

calc_diff added: calculates the difference between the reference setup and fiber…

calc_diff added: calculates the difference between the reference setup and fiber spool setup PPS measurements
parent cd706b7c
#!/usr/bin/python
"""
calc_diff.py: Does multiple PPS difference measurements
-------------------------------------------------------------------------------
Copyright (C) 2016 Peter Jansweijer, Henk Peek
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
-------------------------------------------------------------------------------
Usage:
calc_difff.py -name DeltaDelay_meas -nameref DeltaDelay_meas_ref [-o <dir>]
calc_difff.py -h | --help
Options:
-h --help Show this screen.
-name pointer to a "DeltaDelay_meas" file to be taken as input for measurements
-name_ref pointer to a "DeltaDelay_meas" file to be taken as input for measurements on the reference setup
-o <dir> optional directory for output file storage, default: "data/"
"""
import os
import sys
import numpy
import scipy
import time
import pdb
###############################################
# Main
###############################################
"""
Usage:
calc_difff.py -name DeltaDelay_meas -nameref DeltaDelay_meas_ref [-o <dir>]
calc_difff.py -h | --help
Options:
-h --help Show this screen.
-name pointer to a "DeltaDelay_meas" file to be taken as input for measurements
-name_ref pointer to a "DeltaDelay_meas" file to be taken as input for measurements on the reference setup
-o <dir> optional directory for output file storage, default: "data/"
"""
if __name__ == "__main__":
#arguments = docopt(__doc__,version='White Rabbit controled via serial port')
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("name", help="file containing DeltaDelay_measurement results")
parser.add_argument("nameref", help="file containing DeltaDelay_measurement results from reference setup")
parser.add_argument("-output_dir", default="data")
args = parser.parse_args()
name = args.name
nameref = args.nameref
print("Used DeltaDelay_meas input file: ",name)
print("Used DeltaDelay_meas reference input file: ",nameref)
print("Output directory: ",args.output_dir)
if os.path.exists(name) == True and os.path.isfile(name) == True:
pass
#measure, pairs = file_to_array(name)
else:
print("DeltaDelay_meas input file not found")
sys.exit()
if os.path.exists(nameref) == True and os.path.isfile(nameref) == True:
pass
#measure, pairs = file_to_array(name)
else:
print("DeltaDelay_meas reference input file not found")
sys.exit()
meas_out_file = open(name,"r")
line_meas = meas_out_file.readline()
if line_meas.strip() != "# Delta Delay measurements":
print(name + " is not a Delta Delay measurements file.")
meas_out_file.close()
sys.exit()
meas_ref_file = open(nameref,"r")
line_ref = meas_ref_file.readline()
if line_ref.strip() != "# Delta Delay measurements":
print(nameref + " is not a Delta Delay measurements file.")
meas_ref_file.close()
sys.exit()
# add trailing slash if not present
output_dir = os.path.join(args.output_dir,'')
if os.path.exists(output_dir) != True:
os.mkdir(output_dir)
print("Output directory does not exist => created: "+output_dir)
timestamp = time.localtime()
filename=output_dir+time.strftime(format("%y%m%d_%H_%M_%S"),timestamp)+"_DeltaDelayDifference"
print("save difference results into file:",filename)
out_file = open(filename,"w")
out_file.write("# Difference results for {Delta Delay measurements fiber spool} - {Delta Delay measurements reference setup}\n")
out_file.write("# date:"+time.strftime(format("%d %b %Y"),timestamp)+"\n")
out_file.write("# time:"+time.strftime(format("%H:%M:%S"),timestamp)+"\n")
out_file.write("# diff_delta delay, StdDev, measurement\n")
measurement_str = ""
while 1:
line_meas = meas_out_file.readline()
line_ref = meas_ref_file.readline()
if (line_meas[:len("#")] != "#" and line_ref[:len("#")] == "#") or (line_meas[:len("#")] == "#" and line_ref[:len("#")] != "#"): # one file has comment while the other not
print(name + " and " + nameref + " comment lines in measurement files do not align.")
sys.exit()
if line_meas[:len("# Selected")] == "# Selected" and line_ref[:len("# Selected")] == "# Selected": # Check if both comments are the same
measurement_str = line_meas
if line_meas != line_ref:
print(name + " and " + nameref + " measurements in files do not align.")
sys.exit()
if line_meas[:len("#")] != "#" and line_ref[:len("#")] != "#": # Skip lines that are commented out
meas_lst = line_meas.split(",")
ref_lst = line_ref.split(",")
if len(meas_lst) < 3 or len(ref_lst) < 3:
break
meas_diff = float(meas_lst[0]) - float(ref_lst[0])
meas_std = numpy.sqrt( float(meas_lst[1])**2 + float(ref_lst[1])**2)
print(meas_lst[0],ref_lst[0], meas_diff)
out_file.write(str(meas_diff)+", "+str(meas_std)+", "+str(measurement_str))
meas_out_file.close()
meas_ref_file.close()
out_file.close()
sys.exit()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment