diff --git a/LPRDefaultPlotting.py b/LPRDefaultPlotting.py index 5420fb8..5e46dff 100644 --- a/LPRDefaultPlotting.py +++ b/LPRDefaultPlotting.py @@ -103,6 +103,14 @@ def figAnnotateCorner(hfig, msg, corner=1, ratio=0.01, clear=True): hfig.text(loc_x, loc_y, msg, transform=ax.transAxes, va=algn_v, ha=algn_h) +def addHalfTicks(haxis, gridOn=True): + ticks = haxis.get_yticks() + minor_ticks = (ticks[1:]+ticks[:-1])/2 + haxis.set_yticks(minor_ticks, minor=True) + if gridOn: + haxis.grid(gridOn, which='major') + haxis.grid(gridOn, which='minor') + def axAnnotateCorner(ha, msg, corner=1, ratio=0.01): if corner in [1,2]: loc_x = ratio @@ -137,3 +145,8 @@ def annotateArrow(ha, y, x_list, direction='right'): xy=(x[0], y), xycoords='data', xytext=(x[1], y), textcoords='data', arrowprops=dict(width=2, headwidth=8, headlength=6, facecolor='black')) + +def annotateArrowStr(ha, msg, y, x): + ha.annotate(msg, + xy=(x, y), xycoords='data', + xytext=(x, y), textcoords='data') diff --git a/parsePy.py b/parsePy.py index ff7fd80..3b0f2e9 100755 --- a/parsePy.py +++ b/parsePy.py @@ -336,7 +336,9 @@ for filename in os.listdir(source_directory): marker_height = gain_rms[marker_point] LPRDefaultPlotting.annotateArrow(aT, marker_height+0.5, \ [marker_freq+0.05+0.02, marker_freq+0.15+0.02]) - aT.set_ylim(aR.get_ylim()/np.array(1)+20) + aT.set_ylim((aR.get_ylim()/np.array(1)+20)/1) + aT.set_yticks([x for x in aT.get_yticks() if x <= 7.5]) + aR.set_yticks([x for x in aR.get_yticks() if x >= -17.5]) aT.grid() ######### FIXME ######################################################## @@ -348,9 +350,10 @@ for filename in os.listdir(source_directory): aT.set_ylabel('RMS Error (deg)') aT.plot(imeas.f, ang_rms) #marker_freq = 27.5 - marker_freq = 28.3 + #marker_freq = 28.3 + marker_freq = 27.8 marker_point = np.argmin(np.abs(imeas.f-marker_freq)) - marker_height = ang_rms[marker_point] + marker_height = ang_rms[marker_point]+2 # The goal is to take the usual step size of 50, # and then equate that with a 1-degree step in RMS Error @@ -371,8 +374,13 @@ for filename in os.listdir(source_directory): aR.set_ylim(yRscl*yXover + yRmrks) aT.set_ylim(yTscl*yXover + yTmrks) #aT.set_ylim(aR.get_ylim()/np.array(20)+9) - aT.set_ylim((0,20)) + aT.set_yticks(np.arange(0,11,5)) + aR.set_yticks(np.arange(0,361,60)) + aT.set_ylim((0,50)) + aR.set_ylim((-90,360)) aT.grid() + LPRDefaultPlotting.addHalfTicks(aT) + LPRDefaultPlotting.addHalfTicks(aR) aT.get_lines()[0].set_linewidth(2.0) aT.get_lines()[0].set_linestyle('-.') @@ -380,9 +388,9 @@ for filename in os.listdir(source_directory): LPRDefaultPlotting.annotateArrow(aT, marker_height-0.5, \ [marker_freq+0.05, marker_freq+0.15]) - ax[5].set_ylim(np.array([0, 20])) + #ax[5].set_ylim(np.array([0, 20])) #ax[3].set_ylim(np.array([0, 42])) - ax[3].set_ylim(np.array([0, 23])) + #ax[3].set_ylim(np.array([0, 23])) for aT in ax: aT.set_xlabel('Frequency (GHz)') diff --git a/rev_simplot.py b/rev_simplot.py new file mode 100755 index 0000000..454568a --- /dev/null +++ b/rev_simplot.py @@ -0,0 +1,180 @@ +#!/usr/bin/env python3 +import os +import argparse +import numpy as np +import matplotlib +################################################################################ +args_parser = argparse.ArgumentParser() +args_parser.add_argument('--save','-s', action='store_true', + help='save to files') +args_parser.add_argument('--raster','-r', action='store_true', + help='save as raster') +args_parser.add_argument('--debug','-d', action='store_true', + help='hold for debugging') +args_parser.add_argument('--headless','-q', action='store_true', + help='Remain neadless even if we aren\'t saving files.') +args_parser.add_argument('-n', type=int, default=0, + help='plot testing number') +args = args_parser.parse_args() + +################################################################################ +if args.raster: + args.save = True + fig_ext = 'png' +else: + fig_ext = 'pdf' + +################################################################################ +HEADLESS = not 'DISPLAY' in os.environ.keys() +if args.headless: HEADLESS = True # Override Manually if request +if HEADLESS: matplotlib.use('Agg') + +from matplotlib import rcParams, pyplot as pp +if not HEADLESS: pp.interactive(True) +import LPRDefaultPlotting +from tankComputers import * +import csv + +file_list = [ + ['NF_vs_Freq', + '20190727_PS_NoiseFigure_Simulation_NoBuffer_Frequency'], + ['NF_vs_Bias', + '20190727_PS_NoiseFigure_Simulation_NoBuffer'], + ['stability', + '20190727_PS_KF_Simulation_NoBuffer_BiasDP_WorstCase_C9'], + ['stability_corners', + '20190810_PS_KF_Simulation_NoBuffer_BiasDP_WorstCase_C9_Corners'] +] + +file_test = file_list[args.n] + +fig_dir='figures-revised' +fn='revisedData/clean_%s.csv' % (file_test[1]) +fo=file_test[0] + +fh=open(fn,'r') +reader=csv.reader(fh) +h1 = None + +if args.n in [0,1,2]: # X/Y data + x_dat=[] + y_dat=[] + reader.__next__() # toss the keys + + for row in reader: + x_dat.append(float(row[0])) + y_dat.append(float(row[1])) + +if args.n in [3]: # X/Y data + x_dat=[] + y_dat=[] + legend_strs = reader.__next__() # toss the keys + legend_strs = legend_strs[1:] + + for row in reader: + x_dat.append(float(row[0])) + y_dat.append(np.array([float(x) for x in row[1:]])) + +y_lims = None + +if args.n == 0: + x = 1e-9 * np.array(x_dat) + lab_x = 'Frequency (GHz)' + lab_title = 'Noise Figure vs. Frequency' + h1=pp.figure(figsize=(3.4,1.8)) + +if args.n == 1: + x = np.array(x_dat)*1e3 + lab_x = 'Bias (mV)' + lab_title = 'Noise Figure vs. Q-enhancement bias' + +if args.n in [0, 1]: + y = np.array(y_dat) + lab_y = 'Noise Figure (dB)' + y_lims = [9.7, 10.7] + x_lims = [min(x),max(x)] + +if args.n == 2: + x = np.array(x_dat) * 1e3 + y = np.array(y_dat) + lab_x = 'Bias (mV)' + lab_y = '$K_f$ (-)' + lab_title = 'Stability vs. Bias' + y_lims = [-2, 50] + x_lims = [250,500] + h1=pp.figure(figsize=(3.4,2)) + +if args.n == 3: + x = np.array(x_dat) * 1e3 + y = np.array(y_dat) + lab_x = 'Bias (mV)' + lab_y = '$K_f$ (-)' + lab_title = 'Stability vs. Bias' + y_lims = [-5, 50] + x_lims = [min(x),500] + h1=pp.figure(figsize=(3.4,2)) + + +if h1 == None: h1 = pp.figure(figsize=(3.4,2)) +ax = h1.add_subplot(1,1,1) + +ax.plot(x,y) +ax.set_title(lab_title) +ax.set_xlabel(lab_x) +ax.set_ylabel(lab_y) +ax.set_xlim(x_lims) + +if y_lims != None: ax.set_ylim(y_lims) +if args.n == 2: + nl_x = np.ones((2,1))*min(x[y <= 0]) + nl_y = ax.get_ylim() + nl_1 = matplotlib.lines.Line2D(nl_x, nl_y) + nl_x = np.ones((2,1))*400 + nl_2 = matplotlib.lines.Line2D(nl_x, nl_y) + for nl in [nl_1, nl_2]: + nl.set_color('C1') + ax.add_line(nl_1) + LPRDefaultPlotting.annotateArrow(ax, 5, [397, 381], direction='left') + LPRDefaultPlotting.annotateArrow(ax, 10, [481, 495]) + + LPRDefaultPlotting.annotateArrowStr(ax, + "Measurement\nBound", 5, 350) + LPRDefaultPlotting.annotateArrowStr(ax, + "Unstable\nRegion", 15, 475) + + ax.add_line(nl_2) + +if args.n == 3: + line = ax.get_lines()[0] + line.set_linewidth(line.get_linewidth()*2) + + nl_x = ax.get_xlim() + nl_y = np.ones((2,1))*1 + #nl_x = np.ones((2,1))*min(x[np.any(y <= 1,1)]) + nl_1 = matplotlib.lines.Line2D(nl_x, nl_y) + nl_y = ax.get_ylim() + nl_x = np.ones((2,1))*400 + nl_2 = matplotlib.lines.Line2D(nl_x, nl_y) + for nl in [nl_1, nl_2]: + nl.set_color('K') + ax.add_line(nl_1) + #legend_strs.append('Unstable') + leg=ax.legend(legend_strs, labelspacing=0) + #leg.set_frame_on(False) + LPRDefaultPlotting.annotateArrow(ax, 35.5, [395, 310], direction='left') + #LPRDefaultPlotting.annotateArrow(ax, 10, [481, 495]) + + LPRDefaultPlotting.annotateArrowStr(ax, + "Measurement\nBound", 35, 270) + #LPRDefaultPlotting.annotateArrowStr(ax, + # "Unstable\nRegion", 15, 475) + + ax.add_line(nl_2) + +ax.grid(True) +h1.tight_layout() + +if args.save: + h1.savefig('%s/%s.%s' % (fig_dir, fo, fig_ext)) +if HEADLESS: + pp.close() \ No newline at end of file diff --git a/rev_simplot_stab.py b/rev_simplot_stab.py new file mode 100755 index 0000000..41bc4a3 --- /dev/null +++ b/rev_simplot_stab.py @@ -0,0 +1,127 @@ +#!/usr/bin/env python3 +import os +import argparse +import numpy as np +import matplotlib +################################################################################ +args_parser = argparse.ArgumentParser() +args_parser.add_argument('--save','-s', action='store_true', + help='save to files') +args_parser.add_argument('--raster','-r', action='store_true', + help='save as raster') +args_parser.add_argument('--debug','-d', action='store_true', + help='hold for debugging') +args_parser.add_argument('--headless','-q', action='store_true', + help='Remain neadless even if we aren\'t saving files.') +args_parser.add_argument('-n', type=int, default=0, + help='plot testing number') +args = args_parser.parse_args() + +################################################################################ +if args.raster: + args.save = True + fig_ext = 'png' +else: + fig_ext = 'pdf' + +################################################################################ +HEADLESS = not 'DISPLAY' in os.environ.keys() +if args.headless: HEADLESS = True # Override Manually if request +if HEADLESS: matplotlib.use('Agg') + +from matplotlib import rcParams, pyplot as pp +if not HEADLESS: pp.interactive(True) +import LPRDefaultPlotting +from tankComputers import * +import csv + +file_list = [ + ['stability_corners', + '20190727_PS_KF_Simulation_NoBuffer_BiasDP_WorstCase_C9'] +] + +file_test = file_list[args.n] + +fig_dir='figures-revised' +fn='revisedData/clean_%s.csv' % (file_test[1]) +fo=file_test[0] + +fh=open(fn,'r') +reader=csv.reader(fh) +h1 = None + +if args.n in [0,1,2]: # X/Y data + x_dat=[] + y_dat=[] + reader.__next__() # toss the keys + + for row in reader: + x_dat.append(float(row[0])) + y_dat.append(float(row[1])) + +y_lims = None + +if args.n == 0: + x = 1e-9 * np.array(x_dat) + lab_x = 'Frequency (GHz)' + lab_title = 'Noise Figure vs. Frequency' + h1=pp.figure(figsize=(3.4,1.8)) + +if args.n == 1: + x = np.array(x_dat)*1e3 + lab_x = 'Bias (mV)' + lab_title = 'Noise Figure vs. Q-enhancement bias' + +if args.n in [0, 1]: + y = np.array(y_dat) + lab_y = 'Noise Figure (dB)' + y_lims = [9.7, 10.7] + x_lims = [min(x),max(x)] + +if args.n == 2: + x = np.array(x_dat) * 1e3 + y = np.array(y_dat) + lab_x = 'Bias (mV)' + lab_y = '$K_f$ (-)' + lab_title = 'Stability vs. Bias' + y_lims = [-2, 50] + x_lims = [min(x),500] + h1=pp.figure(figsize=(3.4,2)) + + +if h1 == None: h1 = pp.figure(figsize=(3.4,2)) +ax = h1.add_subplot(1,1,1) + +ax.plot(x,y) +ax.set_title(lab_title) +ax.set_xlabel(lab_x) +ax.set_ylabel(lab_y) +ax.set_xlim(x_lims) + +if y_lims != None: ax.set_ylim(y_lims) +if args.n == 2: + nl_x = np.ones((2,1))*min(x[y <= 0]) + nl_y = ax.get_ylim() + nl_1 = matplotlib.lines.Line2D(nl_x, nl_y) + nl_x = np.ones((2,1))*400 + nl_2 = matplotlib.lines.Line2D(nl_x, nl_y) + for nl in [nl_1, nl_2]: + nl.set_color('C1') + ax.add_line(nl_1) + LPRDefaultPlotting.annotateArrow(ax, 5, [397, 381], direction='left') + LPRDefaultPlotting.annotateArrow(ax, 10, [481, 495]) + + LPRDefaultPlotting.annotateArrowStr(ax, + "Measurement\nBound", 5, 350) + LPRDefaultPlotting.annotateArrowStr(ax, + "Unstable\nRegion", 15, 475) + + ax.add_line(nl_2) + +ax.grid(True) +h1.tight_layout() + +if args.save: + h1.savefig('%s/%s.%s' % (fig_dir, fo, fig_ext)) +if HEADLESS: + pp.close() \ No newline at end of file diff --git a/rev_stabplot.py b/rev_stabplot.py new file mode 100644 index 0000000..8531329 --- /dev/null +++ b/rev_stabplot.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python3 +import os +import argparse +import numpy as np +import matplotlib +################################################################################ +args_parser = argparse.ArgumentParser() +args_parser.add_argument('--save','-s', action='store_true', + help='save to files') +args_parser.add_argument('--raster','-r', action='store_true', + help='save as raster') +args_parser.add_argument('--debug','-d', action='store_true', + help='hold for debugging') +args_parser.add_argument('--headless','-q', action='store_true', + help='Remain neadless even if we aren\'t saving files.') +args = args_parser.parse_args() + +################################################################################ +if args.raster: + args.save = True + fig_ext = 'png' +else: + fig_ext = 'pdf' + +################################################################################ +HEADLESS = not 'DISPLAY' in os.environ.keys() +if args.headless: HEADLESS = True # Override Manually if request +if HEADLESS: matplotlib.use('Agg') + +from matplotlib import rcParams, pyplot as pp +if not HEADLESS: pp.interactive(True) +import LPRDefaultPlotting +import csv + +file_test = ['stability_contour', + '20190727_PS_KFMin_MatrixFine_Value'] + +fig_dir='figures-revised' +fn='revisedData/%s.csv' % (file_test[1]) +fo=file_test[0] + +fh=open(fn,'r') +reader=csv.reader(fh) +h1 = None + +d=[] +for row in reader: + d.append([float(x) for x in row]) + +d=np.array(d) +bias = d[0,1:] +code = d[1:,0] +kf = d[1:,1:] +kf[kf > 20] + +h1 = pp.figure(figsize=(3.4,3.4)) +ax = h1.add_subplot(1,1,1) +bias_m,code_m = np.meshgrid(bias,code) + +cs = ax.contour(bias_m, code_m, kf) +cl = ax.clabel(cs, inline=1) + +if False: + + ax.plot(x,y) + ax.set_title(lab_title) + ax.set_xlabel(lab_x) + ax.set_ylabel(lab_y) + ax.set_xlim(x_lims) + if y_lims != None: ax.set_ylim(y_lims) + ax.grid(True) + h1.tight_layout() + + if args.save: + h1.savefig('%s/%s.%s' % (fig_dir, fo, fig_ext)) + if HEADLESS: + pp.close() \ No newline at end of file diff --git a/runAll.sh b/runAll.sh index 301476f..375c2d2 100755 --- a/runAll.sh +++ b/runAll.sh @@ -1,6 +1,6 @@ #!/bin/bash -MAX_JOBS=4 +MAX_JOBS=8 echo "Starting:" # First run brute force misc jobs diff --git a/runParse.sh b/runParse.sh index 9b989ed..db3ee15 100755 --- a/runParse.sh +++ b/runParse.sh @@ -1,6 +1,6 @@ #!/bin/bash -MAX_JOBS=4 +MAX_JOBS=8 #for n in $(seq 1 4); do for n in 4; do diff --git a/runSome.sh b/runSome.sh index 216eb45..69a183a 100755 --- a/runSome.sh +++ b/runSome.sh @@ -1,6 +1,6 @@ #!/bin/bash -MAX_JOBS=4 +MAX_JOBS=8 for n in 2 12; do while [[ $MAX_JOBS -le $(jobs -l | wc -l) ]]; do sleep 0.1; done diff --git a/tankPlot.py b/tankPlot.py index ee5ad55..bdb927c 100755 --- a/tankPlot.py +++ b/tankPlot.py @@ -399,6 +399,12 @@ if 2 in plot_list or 12 in plot_list: ax2[2].set_ylim(ax2[0].get_ylim()/np.array(1)+4) ax2[3].set_ylim((0,20)) + ax2[1].set_ylim((-260,180)) + ax2[3].set_yticks(np.linspace(0,44,12)) + ax2[3].set_yticks([x for x in ax2[3].get_yticks() if x <= 8]) + LPRDefaultPlotting.addHalfTicks(ax2[3]) + LPRDefaultPlotting.addHalfTicks(ax2[2]) + marker_freq = 28.2 marker_point = np.argmin(np.abs(f.hz-marker_freq)) marker_height = tf_gain_pm[marker_point] @@ -406,8 +412,9 @@ if 2 in plot_list or 12 in plot_list: [marker_freq+0.05, marker_freq+0.25]) marker_freq = 28.39 + marker_freq = 27.52 marker_point = np.argmin(np.abs(f.hz-marker_freq)) - marker_height = tf_ang_rms[marker_point] + marker_height = tf_ang_rms[marker_point]+2 LPRDefaultPlotting.annotateArrow(ax2[3], marker_height, \ [marker_freq+0.05, marker_freq+0.25])