def retrieve_vna_data(vna, vna_params): sdata = [] freq_data = [] template = ":CALC{ch}:DATA:FDAT?" for channel in [1,2,3,4]: data = vna.executor.ask(template.format(ch=str(channel))) data = data.split(',') data = [complex(float(pair[0]), float(pair[1])) for pair in chunker(data, 2)] sdata.append(data) template_freq = ":SENS{ch}:FREQ:DATA?" freq_data = vna.executor.ask(template_freq.format(ch=1)) freq_data = freq_data.split(',') freq_data = [float(fdatum) for fdatum in freq_data] ydata = y_from_s(sdata) zdata = z_from_s(sdata) cga_data = cga_from_s(freq_data, sdata) cgs_data = cgs_from_s(freq_data, sdata) capacitance = [cga_data, cgs_data] gdata["cap"] = capacitance write_vector(freq_data, vna_params["file"] + "_freqs") write_4vectors(sdata, vna_params["file"] + "_s") write_4vectors(zdata, vna_params["file"] + "_z") write_4vectors(ydata, vna_params["file"] + "_y") write_2vectors(capacitance, vna_params["file"] + "_cap") retrieve_both()
def retrieve_both(): try: cap = gdata["cap"] pol = gdata["pol"] except KeyError as e: # The other routine has not finished yet, return and wait for next call return v_cga = [pol, cap[0]] v_cgs = [pol, cap[1]] print "V_cga len" print str(len(v_cga[0])) + "," + str(len(v_cga[1])) print "V_cgs len" print str(len(v_cgs[0])) + "," + str(len(v_cgs[1])) write_2vectors(v_cga, params[0]["file"] + "_v_vs_cga") write_2vectors(v_cgs, params[0]["file"] + "_v_vs_cgs") plotter.plot(pol, cga, params[0]["file"]+ "cga_plot") plotter.plot(pol, cgs, params[0]["file"]+ "cgs_plot")