Commit cb941b31 authored by Peter Jansweijer's avatar Peter Jansweijer

python 2/3 issues, typo's

parent 4587c77f
...@@ -21,10 +21,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/> ...@@ -21,10 +21,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Usage: Usage:
edge_edge.py IP# [-m=<number>] edge_edge.py IP# [-m <number>]
edge_edge.py -h | --help edge_edge.py -h | --help
IP IP number of the instrument [default 192.168.32.248] IP IP number of the oscilloscope [default 192.168.32.248]
Options: Options:
-m <intr> number of measurements to be taken [default: 1] -m <intr> number of measurements to be taken [default: 1]
...@@ -38,6 +38,7 @@ import vxi11 ...@@ -38,6 +38,7 @@ import vxi11
import scipy import scipy
import numpy import numpy
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
plt.rcParams['lines.linewidth'] = 1
# Add parent directory (containing 'lib') to the module search path # Add parent directory (containing 'lib') to the module search path
lib_path = (os.path.dirname(os.path.abspath(__file__))) lib_path = (os.path.dirname(os.path.abspath(__file__)))
...@@ -46,6 +47,7 @@ sys.path.insert(0,lib_path) ...@@ -46,6 +47,7 @@ sys.path.insert(0,lib_path)
# private imports: # private imports:
import lib.LeCroy8254 as DSO import lib.LeCroy8254 as DSO
#import lib.Keysight_DSO_S_254A as DSO
#import lib.Agilent_DSO6104A as DSO #import lib.Agilent_DSO6104A as DSO
import lib.pat_gen as pat_gen import lib.pat_gen as pat_gen
import lib.delay_determination as dd import lib.delay_determination as dd
...@@ -60,7 +62,7 @@ D5_6 = "1010010110" # = 0xC5 (both +RD and -RD) ...@@ -60,7 +62,7 @@ D5_6 = "1010010110" # = 0xC5 (both +RD and -RD)
D16_2p = "1001000101" # = 0x50 (+RD) D16_2p = "1001000101" # = 0x50 (+RD)
D16_2m = "0110110101" # = 0x50 (-RD) D16_2m = "0110110101" # = 0x50 (-RD)
D21_2 = "1010100101" # = 0x55 is last preamble (both +RD and -RD) D21_2 = "1010100101" # = 0x55 is last preamble (both +RD and -RD)
D21_6 = "1010100110" # = 0xD5 is Start of Frame Delimitter (both +RD and -RD) D21_6 = "1010100110" # = 0xD5 is Start of Frame Delimiter (both +RD and -RD)
D1_0p = "1000101011" D1_0p = "1000101011"
D1_0m = "0111010100" D1_0m = "0111010100"
D27_7p = "0010011011" D27_7p = "0010011011"
...@@ -89,25 +91,25 @@ def average_edge_to_edge(scope, num_meas, expect_max, estimate, tolerance = 1.0e ...@@ -89,25 +91,25 @@ def average_edge_to_edge(scope, num_meas, expect_max, estimate, tolerance = 1.0e
delay values for the time between the SFD and Edge. delay values for the time between the SFD and Edge.
scope -- instance of python-vxi connected to scope625Zi oscilloscope scope -- instance of python-vxi connected to scope625Zi oscilloscope
num_meas -- nuber of measurement to be taken. num_meas -- number of measurement to be taken.
expect_max -- edge correlation result sample number maximum is expected expect_max -- edge correlation result sample number maximum is expected
estimate -- a delay estimate, used to verify proper measurements and enable estimate -- a delay estimate, used to verify proper measurements and enable
to skip outliers (due to wrong automatic correlation maximum to skip outliers (due to wrong automatic correlation maximum
determination) determination)
tollerance -- delay measurements outside tollerance are skiped (default 1 ns) tolerance -- delay measurements outside tolerance are skipped (default 1 ns)
returns: <type 'numpy.ndarray'> -- an array of measured delay values returns: <type 'numpy.ndarray'> -- an array of measured delay values
samples -- amount of samples in one waveform samples -- amount of samples in one waveform
sample_period -- the timebase used sample_period -- the timebase used
firts_filename -- name of the first wavform file that contributed firts_filename -- name of the first waveform file that contributed
last_filename -- name of the last wavform file that contributed last_filename -- name of the last waveform file that contributed
""" """
lst_meas = [] lst_meas = []
once = True once = True
for i in range(num_meas): for i in range(num_meas):
d,filename = DSO.get_waveforms(scope, '1,3') d,filename = DSO.get_waveforms(scope, [1,3])
wf_data = DSO.file_to_waveform(filename) wf_data = DSO.file_to_waveform(filename)
samples = DSO.check_waveforms(wf_data) samples = DSO.check_waveforms(wf_data)
# Make sure the buffer holds an even number of samples # Make sure the buffer holds an even number of samples
...@@ -117,7 +119,9 @@ def average_edge_to_edge(scope, num_meas, expect_max, estimate, tolerance = 1.0e ...@@ -117,7 +119,9 @@ def average_edge_to_edge(scope, num_meas, expect_max, estimate, tolerance = 1.0e
if once == True: if once == True:
#once = False #once = False
# extract the sample frequency from the preamble of the first enabled channel # extract the sample frequency from the preamble of the first enabled channel
first_channel = wf_data.keys()[0] #first_channel = wf_data.keys()[0] # Worked for Python 2...
channel_list = list(wf_data.keys())
first_channel = channel_list[0]
sample_period = wf_data[first_channel]["preamble"]["x_increment"] sample_period = wf_data[first_channel]["preamble"]["x_increment"]
first_filename = filename first_filename = filename
...@@ -154,7 +158,7 @@ def average_edge_to_edge(scope, num_meas, expect_max, estimate, tolerance = 1.0e ...@@ -154,7 +158,7 @@ def average_edge_to_edge(scope, num_meas, expect_max, estimate, tolerance = 1.0e
## ##
""" """
Usage: Usage:
edge_edge.py IP# [-m=<number>] edge_edge.py IP# [-m <number>]
edge_edge.py -h | --help edge_edge.py -h | --help
IP IP number of the instrument [default 192.168.32.248] IP IP number of the instrument [default 192.168.32.248]
...@@ -164,40 +168,34 @@ Options: ...@@ -164,40 +168,34 @@ Options:
measured delay may be off target. Tolerance helps you to measured delay may be off target. Tolerance helps you to
skip outliers in your measurements. skip outliers in your measurements.
-timebase <float> time base [default: 20.0e-8] # 20 ns/div -timebase <float> time base [default: 20.0e-8] # 20 ns/div
-m <intr> number of measurements to be taken [default: 1] -m <int> number of measurements to be taken [default: 1]
-h --help Show help -h --help Show help
""" """
if __name__ == "__main__": if __name__ == "__main__":
import argparse import argparse
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("IP", help="IP number of the instrument", default="192.168.32.248") parser.add_argument("scope", type=str, help="IP number of the oscilloscope", default="192.168.32.248")
parser.add_argument("-peak", help="expected sample number for peak", default=0) parser.add_argument("-peak", type=int, help="expected sample number for peak", default=0)
parser.add_argument("-delay", help="estimated delay", default=0) parser.add_argument("-delay", type=float, help="estimated delay", default=0)
parser.add_argument("-tol", help="outliers tolerance", default=10.0e-9) parser.add_argument("-tol", type=float, help="outliers tolerance", default=10.0e-9)
parser.add_argument("-timebase", help="DSO timbase", default=20.0e-9) parser.add_argument("-timebase", type=float, help="DSO timebase", default=20.0e-9)
parser.add_argument("-m", help="number of measurements", default=1) parser.add_argument("-m", type=int, help="number of measurements", default=1)
args = parser.parse_args() args = parser.parse_args()
# When oscilloscope triggers on Channel 1 and trigger is set to the middle # When oscilloscope triggers on Channel 1 and trigger is set to the middle
# of the screen then the expected edge maximum for edge and SFD are at: # of the screen then the expected edge maximum for edge and SFD are at:
IP = str(args.IP) scope = vxi11.Instrument(args.scope)
expect_max = int(args.peak)
estimated_delay = float(args.delay)
tolerance = float(args.tol)
time_base = float(args.timebase)
num_meas = int(args.m)
scope = vxi11.Instrument(IP)
# Initialize oscilloscope # Initialize oscilloscope
# Use Channel 1 pulse input # Use Channel 1 pulse input
# use Channel 3-4 Ethernet Frame input # use Channel 3-4 Ethernet Frame input
DSO.osc_init(scope, time_base) DSO.osc_init(scope, args.timebase)
meas, samples, sample_period, first_filename, last_filename = average_edge_to_edge(scope, num_meas=args.m, expect_max=args.peak, estimate=args.delay, tolerance=args.tol)
meas, samples, sample_period, first_filename, last_filename = average_edge_to_edge(scope, num_meas, expect_max, estimated_delay, tolerance)
print("Samples:",samples) print("Samples:",samples)
print("Sample Period:",sample_period) print("Sample Period:",sample_period)
print("first_filename:",first_filename) print("first_filename:",first_filename)
...@@ -211,7 +209,7 @@ if __name__ == "__main__": ...@@ -211,7 +209,7 @@ if __name__ == "__main__":
for i in meas: for i in meas:
file.write(str(i)+"\n") file.write(str(i)+"\n")
file.write("# Above are measured delays values exracted from the following range\n") file.write("# Above are measured delays values extracted from the following range\n")
file.write("# of waveform files:\n") file.write("# of waveform files:\n")
file.write("# First file: "+first_filename+"\n") file.write("# First file: "+first_filename+"\n")
file.write("# Last file: "+last_filename+"\n") file.write("# Last file: "+last_filename+"\n")
...@@ -223,14 +221,14 @@ if __name__ == "__main__": ...@@ -223,14 +221,14 @@ if __name__ == "__main__":
stdev_delay = numpy.std(meas, ddof = 1) stdev_delay = numpy.std(meas, ddof = 1)
print("Delay between oscilloscope channels:") print("Delay between oscilloscope channels:")
print("number of measurements:", num_meas) print("number of measurements:", args.m)
print("mean:", mean_delay) print("mean:", mean_delay)
print("max:", max_delay) print("max:", max_delay)
print("min:", min_delay) print("min:", min_delay)
print("width:",max_delay-min_delay) print("width:",max_delay-min_delay)
print("st-dev:", stdev_delay) print("st-dev:", stdev_delay)
hist_edge_edge = plt.figure("Historam delay edge -> edge") hist_edge_edge = plt.figure("Histogram delay edge -> edge")
ax = hist_edge_edge.add_subplot(111) ax = hist_edge_edge.add_subplot(111)
ax.set_xlabel('Time') ax.set_xlabel('Time')
ax.set_ylabel('Count') ax.set_ylabel('Count')
...@@ -238,7 +236,7 @@ if __name__ == "__main__": ...@@ -238,7 +236,7 @@ if __name__ == "__main__":
ax.text(0.01,0.90,'std = {0:.6g}'.format(stdev_delay), transform=ax.transAxes) ax.text(0.01,0.90,'std = {0:.6g}'.format(stdev_delay), transform=ax.transAxes)
ax.text(0.01,0.85,'max = {0:.6g}'.format(max_delay), transform=ax.transAxes) ax.text(0.01,0.85,'max = {0:.6g}'.format(max_delay), transform=ax.transAxes)
ax.text(0.01,0.80,'min = {0:.6g}'.format(min_delay), transform=ax.transAxes) ax.text(0.01,0.80,'min = {0:.6g}'.format(min_delay), transform=ax.transAxes)
ax.text(0.01,0.75,'n = {0:d}'.format(num_meas), transform=ax.transAxes) ax.text(0.01,0.75,'n = {0:d}'.format(args.m), transform=ax.transAxes)
ax.hist(meas,20) ax.hist(meas,20)
plt.show() plt.show()
else: else:
......
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