def run(self, lo_freq, if_start, if_stop, if_step, thot): # Initialization Section # ====================== # Check other operation # --------------------- self.check_other_operation() # Generate file path # ------------------ fpg = forest.filepath_generator(self.method) savedir = fpg(' ') logpath = fpg('log.%s.txt') logname = os.path.basename(logpath) datapath = fpg('irr.data.%s') dataname = os.path.basename(datapath) figpath = fpg('irr.fig.%s') figname = os.path.basename(figpath) ts = os.path.basename(fpg('%s')) # Start operation # --------------- args = { 'if_start': if_start, 'if_stop': if_stop, 'if_step': if_step, 'lo_freq': lo_freq, 'thot': thot } argstxt = str(args) self.operation_start(argstxt, logfile=logpath) # Print welcome message # --------------------- self.stdout.p('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=') self.stdout.p('FOREST : IRR with IF Freq sweep') self.stdout.p('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=') self.stdout.p('ver.%s' % (self.ver)) self.stdout.nextline() # Open devices # ------------ self.stdout.p('Open Devices') self.stdout.p('============') slider = self.open_slider() sp = self.open_speana() sw = self.open_switch() lo_sg = self.open_lo_sg() ref_sg = self.open_irr_sg() self.stdout.nextline() # Operation Section # ================= self.stdout.p('IRR') self.stdout.p('===') self.stdout.p('lo_freq = %f GHz' % (lo_freq)) self.stdout.p('if_start = %f GHz' % (if_start)) self.stdout.p('if_stop = %f GHz' % (if_stop)) self.stdout.p('if_step = %f MHz' % (if_step)) self.stdout.p('thot = %f K' % (thot)) self.stdout.nextline() self.stdout.p('Device configurations') self.stdout.p('---------------------') self.stdout.p('1st LO SG : Set %f GHz.' % (lo_freq / 6.)) lo_sg.freq_set(lo_freq / 6., 'GHz') self.stdout.p('1st LO SG : Set 18 dBm.') lo_sg.power_set(18) self.stdout.p('1st LO SG : Set output on.') lo_sg.output_on() self.stdout.p('IRR Ref SG : Set %f GHz.' % ((lo_freq + if_start) / 6.)) ref_sg.freq_set((lo_freq + if_start) / 6., 'GHz') self.stdout.p('IRR Ref SG : Set output off.') ref_sg.output_off() self.stdout.p('Speana : Preset.') sp.scpi_reset() self.stdout.p('Speana : Set freq span 1 MHz.') sp.frequency_span_set(1, 'MHz') self.stdout.p('Speana : Set center freq %f GHz.' % (if_start)) sp.frequency_center_set(if_start, 'GHz') self.stdout.p('Speana : Set res. BW 1 kHz.') sp.resolution_bw_set(1, 'kHz') self.stdout.p('Speana : Set attenuation 0 dB.') sp.attenuation_set(0) self.stdout.p('Speana : Set average 5.') sp.average_set(5) sp.average_onoff_set('ON') sweeptime = sp.sweep_time_query()[0] acquiretime = (sweeptime + 0.07) * 5 self.stdout.p('Speana : acquiretime = %.3f sec.' % (acquiretime)) self.stdout.p('IF Switch : Set ch 1.') sw.ch_set_all(1) freq = sp.sp[0].gen_xaxis() self.stdout.p('Save : %s' % (dataname + '.freq.npy')) numpy.save(datapath + '.freq.npy', freq) x = (freq - numpy.average(freq)) / 1e6 self.stdout.nextline() if_list = numpy.arange(if_start, if_stop + if_step, if_step) dcold = [] dhot = [] dsig_u = [] dsig_l = [] self.stdout.p('Get SKY data') self.stdout.p('------------') self.stdout.p('Slider : Move to SKY.') slider.move_sky() for if_freq in if_list: self.stdout.p('Speana : Set center freq %f GHz.' % (if_freq)) sp.frequency_center_set(if_freq, 'GHz') for ch in [1, 2, 3, 4]: self.stdout.p('IF Switch : Set ch %d.' % (ch)) sw.ch_set_all(ch) time.sleep(0.05) self.stdout.p('Speana : Acquire. waittime=%.1f' % (acquiretime)) sp.average_restart() time.sleep(acquiretime) _d = sp.trace_data_query() dcold.append(_d) continue continue dcold = numpy.array(dcold) self.stdout.p('Save : %s' % (dataname + '.cold.npy')) numpy.save(datapath + '.cold.npy', dcold) self.stdout.nextline() self.stdout.p('Get R data') self.stdout.p('----------') self.stdout.p('Slider : Move to R.') slider.move_r() for if_freq in if_list: self.stdout.p('Speana : Set center freq %f GHz.' % (if_freq)) sp.frequency_center_set(if_freq, 'GHz') for ch in [1, 2, 3, 4]: self.stdout.p('IF Switch : Set ch %d.' % (ch)) sw.ch_set_all(ch) time.sleep(0.05) self.stdout.p('Speana : Acquire. waittime=%.1f' % (acquiretime)) sp.average_restart() time.sleep(acquiretime) _d = sp.trace_data_query() dhot.append(_d) continue continue dhot = numpy.array(dhot) self.stdout.p('Save : %s' % (dataname + '.hot.npy')) numpy.save(datapath + '.hot.npy', dhot) self.stdout.nextline() self.stdout.p('Get SIG data') self.stdout.p('------------') self.stdout.p('Slider : Move to R.') slider.move_r() self.stdout.p('IRR Ref SG : Set output on.') ref_sg.output_on() for if_freq in if_list: self.stdout.p('INFO : IF freq = %f GHz.' % (if_freq)) self.stdout.p('INFO : (Upper Side Band)') self.stdout.p('IRR Ref SG : Set %f GHz.' % ((lo_freq + if_freq) / 6.)) ref_sg.freq_set((lo_freq + if_freq) / 6., 'GHz') self.stdout.p('Speana : Set center freq %f GHz.' % (if_freq)) sp.frequency_center_set(if_freq, 'GHz') for ch in [1, 2, 3, 4]: self.stdout.p('IF Switch : Set ch %d.' % (ch)) sw.ch_set_all(ch) time.sleep(0.05) self.stdout.p('Speana : Acquire. waittime=%.1f' % (acquiretime)) sp.average_restart() time.sleep(acquiretime) _d = sp.trace_data_query() dsig_u.append(_d) continue self.stdout.p('INFO : (Lower Side Band)') self.stdout.p('IRR Ref SG : Set %f GHz.' % ((lo_freq - if_freq) / 6.)) ref_sg.freq_set((lo_freq - if_freq) / 6., 'GHz') for ch in [1, 2, 3, 4]: self.stdout.p('IF Switch : Set ch %d.' % (ch)) sw.ch_set_all(ch) time.sleep(0.05) self.stdout.p('Speana : Acquire. waittime=%.1f' % (acquiretime)) sp.average_restart() time.sleep(acquiretime) _d = sp.trace_data_query() dsig_l.append(_d) continue continue dsig_u = numpy.array(dsig_u) dsig_l = numpy.array(dsig_l) self.stdout.p('Save : %s' % (dataname + '.dsig_u.npy')) self.stdout.p('Save : %s' % (dataname + '.dsig_l.npy')) numpy.save(datapath + '.dsig_u.npy', dsig_u) numpy.save(datapath + '.dsig_l.npy', dsig_l) self.stdout.nextline() self.stdout.p('IRR Ref SG : Set output off.') ref_sg.output_off() self.stdout.p('IF Switch : Set ch 1.') sw.ch_set_all(1) self.stdout.p('Slider : Move to SKY.') slider.move_sky() self.stdout.nextline() self.stdout.p('Calc IRR') self.stdout.p('--------') dcold_db = dcold.reshape((-1, 4, 4, 461)) dhot_db = dhot.reshape((-1, 4, 4, 461)) dsig_l_db = dsig_l.reshape((-1, 4, 4, 461)) dsig_u_db = dsig_u.reshape((-1, 4, 4, 461)) dcold = 10**(dcold_db / 10.) dhot = 10**(dhot_db / 10.) dsig_l = 10**(dsig_l_db / 10.) dsig_u = 10**(dsig_u_db / 10.) dc_u = dcold[:, :2, :, :] dh_u = dhot[:, :2, :, :] dl_u = dsig_l[:, :2, :, :] du_u = dsig_u[:, :2, :, :] dc_l = dcold[:, 2:, :, :] dh_l = dhot[:, 2:, :, :] dl_l = dsig_l[:, 2:, :, :] du_l = dsig_u[:, 2:, :, :] M_u = du_u / du_l M_l = dl_l / dl_u dP_u = numpy.average(dh_u - dc_u, axis=-1) dP_l = numpy.average(dh_l - dc_l, axis=-1) M_dsb = (dP_u / dP_l)[:, :, :, None] R_u = M_u * (M_l * M_dsb - 1.) / (M_u - M_dsb) R_l = M_l * (M_u - M_dsb) / (M_l * M_dsb - 1.) IRR_u = 10 * numpy.log10(R_u) IRR_l = 10 * numpy.log10(R_l) IRR = numpy.concatenate([IRR_u, IRR_l], axis=1) self.stdout.p('Save : %s' % (dataname + '.IRR_spec.npy')) numpy.save(datapath + '.IRR_spec.npy', IRR) ind_sig_u = numpy.nanargmax(du_u, axis=-1) ind_sig_l = numpy.nanargmax(dl_l, axis=-1) x1, x2, x3 = numpy.indices(ind_sig_u.shape) p_IRR_u = IRR_u[x1, x2, x3, ind_sig_u] p_IRR_l = IRR_u[x1, x2, x3, ind_sig_l] p_IRR = numpy.concatenate([p_IRR_u, p_IRR_l], axis=1) self.stdout.p('Save : %s' % (dataname + '.IRR.npy')) numpy.save(datapath + '.IRR.npy', p_IRR) self.stdout.nextline() self.stdout.p('Plot') self.stdout.p('----') self.stdout.p('Save : %s' % (figname)) [ irr_spec_plot(x, _c, _h, _u, _l, _i, '%s.IF%.1fGHz' % (figpath, freq)) for i, (_c, _h, _u, _l, _i, freq) in enumerate( zip(dcold_db, dhot_db, dsig_u_db, dsig_l_db, IRR, if_list)) ] irr_summary_plot(if_list, p_IRR, dcold_db, dhot_db, thot, '%s.IRR.png' % (figpath)) self.stdout.nextline() # Finalization Section # ==================== # Close devices # ------------- self.stdout.p('Close Devices') self.stdout.p('=============') # TODO: implement close method. """ sis.close() #lo_sg.close() lo_att.close() #irr_sg.close() rxrot.close() slider.close() """ self.stdout.p('All devices are closed.') self.stdout.nextline() # Stop operation # -------------- self.stdout.p('//// Operation is done. ////') self.operation_done() return
args = p.parse_args() # main # ==== print('~~~~~~~~~~~~~~~~~~~~~~~~~') print('FOREST : Y-factor by hand') print('~~~~~~~~~~~~~~~~~~~~~~~~~') forest.print_timestamp() print('') # create save directory # --------------------- fp = forest.filepath_generator(name) # handling args # ------------- if args.start is not None: f_start = args.start if args.stop is not None: f_stop = args.stop if args.resbw is not None: resbw = args.resbw if args.average is not None: average = args.average if args.ch is not None: if args.ch.find('[') != -1: eval_ch = eval(args.ch) else: eval_ch = int(args.ch) pass if args.thot is not None: thot = args.thot params = 'f_start = %f\n'%(f_start)
def run(self, f_start, f_stop, f_resbw, f_average, thot): # Initialization Section # ====================== # Check other operation # --------------------- self.check_other_operation() # Generate file path # ------------------ fpg = forest.filepath_generator(self.method) savedir = fpg(' ') logpath = fpg('log.%s.txt') logname = os.path.basename(logpath) datapath = fpg('rsky.data.%s') dataname = os.path.basename(datapath) figpath = fpg('rsky.fig.%s.png') figname = os.path.basename(figpath) ts = os.path.basename(fpg('%s')) # Start operation # --------------- args = { 'f_start': f_start, 'f_stop': f_stop, 'f_resbw': f_resbw, 'f_average': f_average, 'thot': thot } argstxt = str(args) self.operation_start(argstxt, logfile=logpath) # Print welcome message # --------------------- self.stdout.p('=-=-=-=-=-=-=-=-=-=-=-=-=-=') self.stdout.p('FOREST : R-SKY with slider ') self.stdout.p('=-=-=-=-=-=-=-=-=-=-=-=-=-=') self.stdout.p('ver.%s' % (self.ver)) self.stdout.nextline() # Open devices # ------------ self.stdout.p('Open Devices') self.stdout.p('============') slider = self.open_slider() sp = self.open_speana() sw = self.open_switch() self.stdout.nextline() # Operation Section # ================= self.stdout.p('R-SKY') self.stdout.p('=====') self.stdout.p('f_start = %f GHz' % (f_start)) self.stdout.p('f_stop = %f GHz' % (f_stop)) self.stdout.p('f_resbw = %f MHz' % (f_resbw)) self.stdout.p('f_average = %d' % (f_average)) self.stdout.p('thot = %f K' % (thot)) self.stdout.nextline() self.stdout.p('Device configurations') self.stdout.p('---------------------') self.stdout.p('Speana : Preset.') sp.scpi_reset() self.stdout.p('Speana : Set start freq %f GHz.' % (f_start)) sp.frequency_start_set(f_start, 'GHz') self.stdout.p('Speana : Set stop freq %f GHz.' % (f_stop)) sp.frequency_stop_set(f_stop, 'GHz') self.stdout.p('Speana : Set res. BW %f MHz.' % (f_resbw)) sp.resolution_bw_set(f_resbw, 'MHz') self.stdout.p('Speana : Set attenuation 0 dB.') sp.attenuation_set(0) self.stdout.p('Speana : Set average %d.' % (f_average)) sp.average_set(f_average) sp.average_onoff_set('ON') sweeptime = sp.sweep_time_query()[0] acquiretime = sweeptime * f_average self.stdout.p('Speana : acquiretime = %.3f sec.' % (acquiretime)) self.stdout.p('IF Switch : Set ch 1.') sw.ch_set_all(1) freq = sp.sp[0].gen_xaxis() self.stdout.p('Save : %s' % (dataname + '.freq.npy')) numpy.save(datapath + '.freq.npy', freq) self.stdout.nextline() dcold = [] dhot = [] self.stdout.p('Get SKY data') self.stdout.p('------------') self.stdout.p('Slider : Move to SKY.') slider.move_sky() for ch in [1, 2, 3, 4]: self.stdout.p('IF Switch : Set ch %d.' % (ch)) sw.ch_set_all(ch) time.sleep(0.05) self.stdout.p('Speana : Acquire. waittime=%.1f' % (acquiretime)) sp.average_restart() time.sleep(acquiretime) _d = sp.trace_data_query() dcold.append(_d) continue dcold = numpy.array(dcold) self.stdout.p('Save : %s' % (dataname + '.cold.npy')) numpy.save(datapath + '.cold.npy', dcold) self.stdout.nextline() self.stdout.p('Get R data') self.stdout.p('----------') self.stdout.p('Slider : Move to R.') slider.move_r() for ch in [1, 2, 3, 4]: self.stdout.p('IF Switch : Set ch %d.' % (ch)) sw.ch_set_all(ch) time.sleep(0.05) self.stdout.p('Speana : Acquire. waittime=%.1f' % (acquiretime)) sp.average_restart() time.sleep(acquiretime) _d = sp.trace_data_query() dhot.append(_d) continue dhot = numpy.array(dhot) self.stdout.p('Save : %s' % (dataname + '.hot.npy')) numpy.save(datapath + '.hot.npy', dhot) self.stdout.nextline() self.stdout.p('IF Switch : Set ch 1.') sw.ch_set_all(1) self.stdout.p('Slider : Move to SKY.') slider.move_sky() self.stdout.nextline() self.stdout.p('Calc Tsys') self.stdout.p('---------') tsys = forest.rsky_dB(dhot, dcold, thot) self.stdout.p('Save : %s' % (dataname + '.Tsys.npy')) numpy.save(datapath + '.Tsys.npy', tsys) self.stdout.nextline() self.stdout.p('Plot') self.stdout.p('----') self.stdout.p('Save : %s' % (figname)) tsys_plot(freq, dhot.reshape([16, -1]), dcold.reshape([16, -1]), tsys.reshape([16, -1]), figpath, 'Tsys (%s)' % (ts), smooth=11) self.stdout.nextline() # Finalization Section # ==================== # Close devices # ------------- self.stdout.p('Close Devices') self.stdout.p('=============') # TODO: implement close method. """ sis.close() #lo_sg.close() lo_att.close() #irr_sg.close() rxrot.close() slider.close() """ self.stdout.p('All devices are closed.') self.stdout.nextline() # Stop operation # -------------- self.stdout.p('//// Operation is done. ////') self.operation_done() return
type=float, help='Step to sweep bias in mV. default is %.2f mV' % (step)) args = p.parse_args() # main # ==== print('~~~~~~~~~~~~~~~~~~~') print('FOREST : Bias Sweep') print('~~~~~~~~~~~~~~~~~~~') forest.print_timestamp() # create save directory # --------------------- fp = forest.filepath_generator(name) print('INFO: saveto %s' % (fp(' '))) print('') # handling args # ------------- if args.start is not None: v_start = args.start if args.stop is not None: v_stop = args.stop if args.step is not None: step = args.step params = 'v_start = %f\n' % (v_start) params += 'v_stop = %f\n' % (v_stop) params += 'step = %f\n' % (step) open(fp('log.params.%s.txt'), 'w').writelines(params) # open devices
def run(self, step, thot, plot_tsys_min, plot_tsys_max, if_freq=8): # Initialization Section # ====================== # Check other operation # --------------------- self.check_other_operation() # Generate file path # ------------------ fpg = forest.filepath_generator(self.method) savedir = fpg(' ') logpath = fpg('log.%s.txt') logname = os.path.basename(logpath) datapath = fpg('rsky.data.%s') dataname = os.path.basename(datapath) figpath = fpg('rsky.fig.%s') figname = os.path.basename(figpath) ts = os.path.basename(fpg('%s')) # Start operation # --------------- args = {'thot': thot} argstxt = str(args) self.operation_start(argstxt, logfile=logpath) # Print welcome message # --------------------- self.stdout.p('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=') self.stdout.p('FOREST : R-SKY with SIS Bias Sweep ') self.stdout.p('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=') self.stdout.p('ver.%s' % (self.ver)) self.stdout.nextline() # Open devices # ------------ self.stdout.p('Open Devices') self.stdout.p('============') sis = self.open_sis_biasbox() sp = self.open_speana() sw = self.open_switch() self.stdout.nextline() # Operation Section # ================= self.stdout.p('R-SKY') self.stdout.p('=====') self.stdout.p('thot = %f K' % (thot)) self.stdout.nextline() self.stdout.p('Device configurations') self.stdout.p('---------------------') self.stdout.p('Speana : Preset.') sp.scpi_reset() self.stdout.p('Speana : Set center freq %f GHz.' % (if_freq)) sp.frequency_center_set(if_freq, 'GHz') self.stdout.p('Speana : Set span 0 Hz.') sp.frequency_span_set(0, 'Hz') self.stdout.p('Speana : Set res. BW 3 MHz.') sp.resolution_bw_set(3, 'MHz') self.stdout.p('Speana : Set Video BW 100 Hz.') sp.video_bw_set(100, 'Hz') self.stdout.p('Speana : Set reference level -55 dBm.') sp.reference_level_set(-55) self.stdout.p('Speana : Set scale 1 dB/div.') sp.scalediv_set(1) self.stdout.p('Speana : Set attenuation 0 dB.') sp.attenuation_set(0) self.stdout.p('Speana : Set sweep time 0.1 sec.') sp.sweep_time_set(0.1) self.stdout.p('Speana : Set average OFF.') sp.average_onoff_set('OFF') self.stdout.p('IF Switch : Set ch 1.') sw.ch_set_all(1) self.stdout.p('SIS Bias : Set 0 mV.') sis.bias_set(0) self.stdout.nextline() self.stdout.p('Prepare Sweep Bias Set') self.stdout.p('----------------------') bias_3j = [float(_d) for _d in numpy.arange(6.0, 8.01, step)] bias_4j = [float(_d) for _d in numpy.arange(8.0, 10.01, step)] #bias_3j = [float(_d) for _d in numpy.arange(6.0, 8.01, 0.2)] #bias_4j = [float(_d) for _d in numpy.arange(8.0, 10.01, 0.2)] #bias_3j = [float(_d) for _d in numpy.arange(6.0, 8.01, 1)] # for test #bias_4j = [float(_d) for _d in numpy.arange(8.0, 10.01, 1)] # for test biasx_num = len(bias_3j) bias_3j1 = [_x for _x in bias_3j for _y in bias_3j] bias_3j2 = [_y for _x in bias_3j for _y in bias_3j] bias_4j1 = [_x for _x in bias_4j for _y in bias_4j] bias_4j2 = [_y for _x in bias_4j for _y in bias_4j] bias_num = len(bias_3j1) sisp = forest.load_sis_config() j_type = [] sweep_data = [] beam_pol = [] for unit in sorted(sisp.keys()): _j_type = sisp[unit]['J-type'] j_type.append(_j_type) beam = sisp[unit]['beam'] pol = sisp[unit]['pol'] self.stdout.p('Junction Type of %s is %s.' % (unit, _j_type)) if _j_type == '3J': sweep_data.append([bias_3j1, bias_3j2]) elif _j_type == '4J': sweep_data.append([bias_4j1, bias_4j2]) else: sweep_data.append([bias_3j1, bias_3j2]) pass beam_pol.append([beam, pol]) continue self.stdout.p('Sorting sweep data by ch.') biasch = forest.biasbox_ch_mapper() sweep_data_ch = biasch.sort_sweep_data_by_ch(sweep_data, beam_pol) self.stdout.p('SIS Bias : Set sweep data.') sis.bias_series_set(sweep_data_ch) self.stdout.nextline() self.stdout.p('Get R and SKY') self.stdout.p('-------------') spdata = [] bias_ret = [] rsky_info = [] tsys = [] for ch in [1, 2, 3, 4]: self.stdout.p('IF Switch : Set ch %d.' % (ch)) sw.ch_set_all(ch) time.sleep(0.1) for i, (b31, b32, b41, b42) in enumerate( zip(bias_3j1, bias_3j2, bias_4j1, bias_4j2)): self.stdout.p( 'SIS Bias : Set 3J = %.2f, %.2f; 4J = %.2f, %.2f. [%d/%d]' % (b31, b32, b41, b42, i, bias_num)) sis.bias_series_next() time.sleep(0.01) self.stdout.p('Speana : Average restart.') sp.average_restart() self.stdout.p('Wait 0.1 sec.') time.sleep(0.13) self.stdout.p('SIS Bias : Get biases.') sis_vi = sis.bias_get() bias_ret.append(sis_vi) self.stdout.p('Speana : Get spectra.') d = sp.trace_data_query() spdata.append(d[0]) spdata.append(d[1]) spdata.append(d[2]) spdata.append(d[3]) self.stdout.p('Calc Tsys ...') _tsys1, _info1 = forest.evaluate_rsky_from_rotating_chopper_data( d[0], thot) _tsys2, _info2 = forest.evaluate_rsky_from_rotating_chopper_data( d[1], thot) _tsys3, _info3 = forest.evaluate_rsky_from_rotating_chopper_data( d[2], thot) _tsys4, _info4 = forest.evaluate_rsky_from_rotating_chopper_data( d[3], thot) tsys.append(_tsys1) tsys.append(_tsys2) tsys.append(_tsys3) tsys.append(_tsys4) rsky_info.append(_info1) rsky_info.append(_info2) rsky_info.append(_info3) rsky_info.append(_info4) continue continue self.stdout.p('IF Switch : Set ch 1.') sw.ch_set_all(1) self.stdout.p('SIS Bias : Set 0 mV.') sis.bias_set(0) spdata = numpy.array(spdata) bias_ret = numpy.array(bias_ret) tsys = numpy.array(tsys) rsky_info = numpy.array(rsky_info, dtype=object) self.stdout.p('Save : %s' % (dataname + '.spdata.npy')) numpy.save(datapath + '.spdata.npy', spdata) self.stdout.p('Save : %s' % (dataname + '.bias.npy')) numpy.save(datapath + '.bias.npy', bias_ret) self.stdout.p('Save : %s' % (dataname + '.tsys.npy')) numpy.save(datapath + '.tsys.npy', tsys) self.stdout.p('Save : %s' % (dataname + '.info.npy')) numpy.save(datapath + '.info.npy', rsky_info) self.stdout.nextline() # Finalization Section # ==================== # Close devices # ------------- self.stdout.p('Close Devices') self.stdout.p('=============') # TODO: implement close method. """ sis.close() #lo_sg.close() lo_att.close() #irr_sg.close() rxrot.close() slider.close() """ self.stdout.p('All devices are closed.') self.stdout.nextline() # Stop operation # -------------- self.stdout.p('//// Operation is done. ////') self.operation_done() # Plotting # -------- #self.stdout.p('Plot') #self.stdout.p('----') print('Plot') print('----') pylab.rcParams['image.interpolation'] = 'none' pylab.rcParams['image.origin'] = 'lower' pylab.rcParams['font.size'] = 8 # -- tshape = (4, biasx_num, biasx_num, 4) tsys_reshape = tsys.reshape(tshape) tsys_swap = numpy.swapaxes(tsys_reshape, 1, 3) tsys_plot = tsys_swap.reshape([16, biasx_num, biasx_num]) delt3 = (bias_3j[1] - bias_3j[0]) / 2. ext3 = [ bias_3j[0] - delt3, bias_3j[-1] + delt3, bias_3j[0] - delt3, bias_3j[-1] + delt3 ] delt4 = (bias_4j[1] - bias_4j[0]) / 2. ext4 = [ bias_4j[0] - delt4, bias_4j[-1] + delt4, bias_4j[0] - delt4, bias_4j[-1] + delt4 ] extentions = [] for _jt in j_type: if _jt == '3J': extentions.append(ext3) extentions.append(ext3) elif _jt == '4J': extentions.append(ext4) extentions.append(ext4) else: extentions.append(ext3) extentions.append(ext3) pass continue cbarticks = range(100, 1001, 100) #self.stdout.p('Plot : %s.tsysmap.png'%(figname)) print('Plot : %s.tsysmap.png' % (figname)) fig = pylab.figure() ax = [fig.add_subplot(4, 4, i + 1) for i in range(16)] im = [ _a.imshow(_t, extent=_ex, vmin=plot_tsys_min, vmax=plot_tsys_max) for _a, _t, _ex in zip(ax, tsys_plot, extentions) ] [ fig.colorbar(_im, ax=_a, ticks=[]) for i, (_im, _a) in enumerate(zip(im, ax)) if i % 4 != 3 ] [ fig.colorbar(_im, ax=_a, ticks=cbarticks) for i, (_im, _a) in enumerate(zip(im, ax)) if i % 4 == 3 ] [_a.set_xlabel('Bias1 (mV)') for i, _a in enumerate(ax) if i / 4 > 2] [_a.set_ylabel('Bias2 (mV)') for i, _a in enumerate(ax) if i % 4 == 0] [_a.set_ylabel('Bias2 (mV)') for i, _a in enumerate(ax) if i % 4 == 0] fig.savefig(figpath + '.tsysmap.png') pylab.close(fig) # -- sshape = (4, biasx_num, biasx_num, 4, -1) spdata_reshape = spdata.reshape(sshape) spdata_swap = numpy.swapaxes(spdata_reshape, 1, 3) spdata_plot = spdata_swap.reshape((16, biasx_num * biasx_num, -1)) for ch, d in enumerate(spdata_plot): #self.stdout.p('Plot : %s.speana.%02d.png'%(figname, ch)) print('Plot : %s.speana.%02d.png' % (figname, ch)) loc = matplotlib.ticker.MultipleLocator(1) fig = pylab.figure() ax = [ fig.add_subplot(biasx_num, biasx_num, i + 1) for i in range(biasx_num * biasx_num) ] [_a.plot(_d) for _a, _d in zip(ax, d)] [_a.set_xticklabels('') for _a in ax] [_a.set_yticklabels('') for _a in ax] [_a.yaxis.set_major_locator(loc) for _a in ax] [_a.grid(True) for _a in ax] fig.savefig(figpath + '.speana.%02d.png' % (ch)) pylab.close(fig) continue #self.stdout.nextline() print('') print('//// plotting is done. ////') return
def run(self, start, stop, step, thot, if_freq=8): # Initialization Section # ====================== # Check other operation # --------------------- self.check_other_operation() # Generate file path # ------------------ fpg = forest.filepath_generator(self.method) savedir = fpg(' ') logpath = fpg('log.%s.txt') logname = os.path.basename(logpath) datapath = fpg('rsky.data.%s') dataname = os.path.basename(datapath) figpath = fpg('rsky.fig.%s') figname = os.path.basename(figpath) ts = os.path.basename(fpg('%s')) # Start operation # --------------- args = {'start': start, 'stop': stop, 'step': step, 'thot': thot} argstxt = str(args) self.operation_start(argstxt, logfile=logpath) # Print welcome message # --------------------- self.stdout.p('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=') self.stdout.p('FOREST : R-SKY with LO Att Sweep ') self.stdout.p('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=') self.stdout.p('ver.%s' % (self.ver)) self.stdout.nextline() # Open devices # ------------ self.stdout.p('Open Devices') self.stdout.p('============') lo_att = self.open_lo_att() sp = self.open_speana() sw = self.open_switch() self.stdout.nextline() # Operation Section # ================= self.stdout.p('R-SKY') self.stdout.p('=====') self.stdout.p('start = %f mA' % (start)) self.stdout.p('stop = %f mA' % (stop)) self.stdout.p('step = %f mA' % (step)) self.stdout.p('thot = %f K' % (thot)) self.stdout.nextline() self.stdout.p('Device configurations') self.stdout.p('---------------------') self.stdout.p('Speana : Preset.') sp.scpi_reset() self.stdout.p('Speana : Set center freq %f GHz.' % (if_freq)) sp.frequency_center_set(if_freq, 'GHz') self.stdout.p('Speana : Set span 0 Hz.') sp.frequency_span_set(0, 'Hz') self.stdout.p('Speana : Set res. BW 3 MHz.') sp.resolution_bw_set(3, 'MHz') self.stdout.p('Speana : Set Video BW 100 Hz.') sp.video_bw_set(100, 'Hz') self.stdout.p('Speana : Set reference level -55 dBm.') sp.reference_level_set(-55) self.stdout.p('Speana : Set scale 1 dB/div.') sp.scalediv_set(1) self.stdout.p('Speana : Set attenuation 0 dB.') sp.attenuation_set(0) self.stdout.p('Speana : Set sweep time 0.1 sec.') sp.sweep_time_set(0.1) self.stdout.p('Speana : Set average OFF.') sp.average_onoff_set('OFF') self.stdout.p('IF Switch : Set ch 1.') sw.ch_set_all(1) self.stdout.p('LO Att : Set 0 mV.') lo_att.bias_set(0) self.stdout.nextline() self.stdout.p('Create sweep data.') sweep_data = numpy.arange(start, stop + step, step) sweep_num = len(sweep_data) self.stdout.nextline() self.stdout.p('Get R and SKY') self.stdout.p('-------------') spdata = [] rsky_info = [] tsys = [] for ch in [1, 2, 3, 4]: self.stdout.p('IF Switch : Set ch %d.' % (ch)) sw.ch_set_all(ch) time.sleep(0.1) for i, _att in enumerate(sweep_data): self.stdout.p('LO Att : Set bias %.2f mA. [%d/%d]' % (_att, i, sweep_num)) lo_att.bias_set(_att) self.stdout.p('Wait 2 sec...') time.sleep(2) self.stdout.p('Speana : Average restart.') sp.average_restart() self.stdout.p('Wait 0.15 sec.') time.sleep(0.15) self.stdout.p('Speana : Get spectra.') d = sp.trace_data_query() spdata.append(d[0]) spdata.append(d[1]) spdata.append(d[2]) spdata.append(d[3]) self.stdout.p('Calc Tsys ...') _tsys1, _info1 = forest.evaluate_rsky_from_rotating_chopper_data( d[0], thot) _tsys2, _info2 = forest.evaluate_rsky_from_rotating_chopper_data( d[1], thot) _tsys3, _info3 = forest.evaluate_rsky_from_rotating_chopper_data( d[2], thot) _tsys4, _info4 = forest.evaluate_rsky_from_rotating_chopper_data( d[3], thot) tsys.append(_tsys1) tsys.append(_tsys2) tsys.append(_tsys3) tsys.append(_tsys4) rsky_info.append(_info1) rsky_info.append(_info2) rsky_info.append(_info3) rsky_info.append(_info4) continue continue self.stdout.p('IF Switch : Set ch 1.') sw.ch_set_all(1) self.stdout.p('LO Att : Set 200 mV.') lo_att.bias_set(200) spdata = numpy.array(spdata) tsys = numpy.array(tsys) rsky_info = numpy.array(rsky_info, dtype=object) self.stdout.p('Save : %s' % (dataname + '.spdata.npy')) numpy.save(datapath + '.spdata.npy', spdata) self.stdout.p('Save : %s' % (dataname + '.loatt.npy')) numpy.save(datapath + '.loatt.npy', sweep_data) self.stdout.p('Save : %s' % (dataname + '.tsys.npy')) numpy.save(datapath + '.tsys.npy', tsys) self.stdout.p('Save : %s' % (dataname + '.info.npy')) numpy.save(datapath + '.info.npy', rsky_info) self.stdout.nextline() # Finalization Section # ==================== # Close devices # ------------- self.stdout.p('Close Devices') self.stdout.p('=============') # TODO: implement close method. """ sis.close() #lo_sg.close() lo_att.close() #irr_sg.close() rxrot.close() slider.close() """ self.stdout.p('All devices are closed.') self.stdout.nextline() # Stop operation # -------------- self.stdout.p('//// Operation is done. ////') self.operation_done() # plotting # --------- #self.stdout.p('Plot') #self.stdout.p('----') print('Plot') print('----') pylab.rcParams['font.size'] = 8 # -- tshape = (4, sweep_num, 4) tsys_reshape = tsys.reshape(tshape) tsys_swap = numpy.swapaxes(tsys_reshape, 1, 2) tsys_plot = tsys_swap.reshape((16, sweep_num)) #self.stdout.p('Plot : %s.tsys.png'%(figname)) print('Plot : %s.tsys.png' % (figname)) fig = pylab.figure() ax = [fig.add_subplot(4, 4, i + 1) for i in range(16)] im = [_a.plot(sweep_data, _t) for _a, _t in zip(ax, tsys_plot)] [_a.set_xlabel('LO Att. (mA)') for i, _a in enumerate(ax) if i / 4 > 2] [_a.set_ylabel('Tsys* (K)') for i, _a in enumerate(ax) if i % 4 == 0] fig.savefig(figpath + '.tsysmap.png') pylab.close(fig) # -- sshape = (4, sweep_num, 4, -1) spdata_reshape = spdata.reshape(sshape) spdata_swap = numpy.swapaxes(spdata_reshape, 0, 1) spdata_plot = spdata_swap.reshape((sweep_num, 16, -1)) for ch, d in enumerate(spdata_plot): print('Plot : %s.speana.%02d.png' % (figname, ch)) #self.stdout.p('Plot : %s.speana.%02d.png'%(figname, ch)) fig = pylab.figure() ax = [fig.add_subplot(4, 4, i + 1) for i in range(16)] [_a.plot(_d) for _a, _d in zip(ax, d)] fig.suptitle('LO att = %.2f' % (sweep_data[ch])) fig.savefig(figpath + '.speana.%04d.png' % (ch)) pylab.close(fig) continue #self.stdout.nextline() print('') print('//// plotting is done ////') return
def run(self, start, stop, step): # Initialization Section # ====================== # Check other operation # --------------------- self.check_other_operation() # Generate file path # ------------------ fpg = forest.filepath_generator(self.method) savedir = fpg(' ') logpath = fpg('log.%s.txt') logname = os.path.basename(logpath) datapath = fpg('biassweep.data.%s.npy') dataname = os.path.basename(datapath) figpath = fpg('biassweep.fig.%s.png') figname = os.path.basename(figpath) ts = os.path.basename(fpg('%s')) # Start operation # --------------- args = {'start': start, 'stop': stop, 'step': step} argstxt = str(args) self.operation_start(argstxt, logfile=logpath) # Print welcome message # --------------------- self.stdout.p('=-=-=-=-=-=-=-=-=-=-=-=-=-=') self.stdout.p('FOREST : Get SIS Bias Curve') self.stdout.p('=-=-=-=-=-=-=-=-=-=-=-=-=-=') self.stdout.p('ver.%s'%(self.ver)) self.stdout.p('savedir : %s'%(savedir)) self.stdout.p('logfile : %s'%(logname)) self.stdout.nextline() # Open devices # ------------ self.stdout.p('Open Devices') self.stdout.p('============') sis = self.open_sis_biasbox() self.stdout.nextline() # Operation Section # ================= # Operation part # -------------- self.stdout.p('Get SIS Bias Curve') self.stdout.p('==================') self.stdout.p('start = %f'%(start)) self.stdout.p('stop = %f'%(stop)) self.stdout.p('step = %f'%(step)) self.stdout.nextline() self.stdout.p('SIS Bias : Set 0 mV.') sis.bias_set(0) self.stdout.p('Generate input bias array ...') inp = numpy.arange(start, stop+step, step) self.stdout.p('inp : [%s %s %s ... %s %s %s]'%( inp[0], inp[1], inp[2], inp[-3], inp[-2], inp[-1])) inp = map(float, inp) self.stdout.write('SIS Bias : Sweep start ...') v, i = sis.bias_sweep(inp) self.stdout.write('done') self.stdout.nextline() self.stdout.p('v0 : [%.1f %.1f %.1f ... %.1f %.1f %.1f]'%( v[0,0], v[1,0], v[2,0], v[-3,0], v[-2,0], v[-1,0])) self.stdout.p('i0 : [%.1f %.1f %.1f ... %.1f %.1f %.1f]'%( i[0,0], i[1,0], i[2,0], i[-3,0], i[-2,0], i[-1,0])) self.stdout.p('SIS Bias : Set 0 mV.') sis.bias_set(0) self.stdout.p('Save : %s'%(dataname)) numpy.save(datapath, (v, i)) self.stdout.p('Plot : %s'%(figname)) iv_plot(v.T, i.T, figpath, 'Bias Sweep (%s)'%(ts)) self.stdout.nextline() # Finalization Section # ==================== # Close devices # ------------- self.stdout.p('Close Devices') self.stdout.p('=============') # TODO: implement close method. """ sis.close() #lo_sg.close() lo_att.close() #irr_sg.close() rxrot.close() slider.close() """ self.stdout.p('All devices are closed.') self.stdout.nextline() # Stop operation # -------------- self.stdout.p('//// Operation is done. ////') self.operation_done() return
def run(self, att_start, att_stop, att_step, sis_start, sis_stop, sis_step): # Initialization Section # ====================== # Check other operation # --------------------- self.check_other_operation() # Generate file path # ------------------ fpg = forest.filepath_generator(self.method) savedir = fpg(' ') logpath = fpg('log.%s.txt') logname = os.path.basename(logpath) datapath = fpg('biassweep.data.%s') dataname = os.path.basename(datapath) figpath = fpg('biassweep.fig.%s') figname = os.path.basename(figpath) ts = os.path.basename(fpg('%s')) # Start operation # --------------- args = {'att_start': att_start, 'att_stop': att_stop, 'att_step': att_step, 'sis_start': sis_start, 'sis_stop': sis_stop, 'sis_step': sis_step} argstxt = str(args) self.operation_start(argstxt, logfile=logpath) # Print welcome message # --------------------- self.stdout.p('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=') self.stdout.p('FOREST : Get SIS Bias Curve with LO Att Sweep') self.stdout.p('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=') self.stdout.p('ver.%s'%(self.ver)) self.stdout.p('savedir : %s'%(savedir)) self.stdout.p('logfile : %s'%(logname)) self.stdout.nextline() # Open devices # ------------ self.stdout.p('Open Devices') self.stdout.p('============') sis = self.open_sis_biasbox() lo_att = self.open_lo_att() self.stdout.nextline() # Operation Section # ================= # Operation part # -------------- self.stdout.p('Get SIS Bias Curve') self.stdout.p('==================') self.stdout.p('att_start = %f'%(att_start)) self.stdout.p('att_stop = %f'%(att_stop)) self.stdout.p('att_step = %f'%(att_step)) self.stdout.p('sis_start = %f'%(sis_start)) self.stdout.p('sis_stop = %f'%(sis_stop)) self.stdout.p('sis_step = %f'%(sis_step)) self.stdout.nextline() self.stdout.p('1st LO Att : Set 200 mA.') lo_att.bias_set(200) self.stdout.p('SIS Bias : Set 0 mV.') sis.bias_set(0) self.stdout.p('Generate input Att bias array ...') att_inp = numpy.arange(att_start, att_stop+att_step, att_step) self.stdout.p('att_inp : [%s %s %s ... %s %s %s]'%( att_inp[0], att_inp[1], att_inp[2], att_inp[-3], att_inp[-2], att_inp[-1])) self.stdout.p('Generate input SIS bias array ...') sis_inp = numpy.arange(sis_start, sis_stop+sis_step, sis_step) self.stdout.p('sis_inp : [%s %s %s ... %s %s %s]'%( sis_inp[0], sis_inp[1], sis_inp[2], sis_inp[-3], sis_inp[-2], sis_inp[-1])) att_inp = map(float, att_inp) sis_inp = map(float, sis_inp) self.stdout.nextline() for count, abias in enumerate(att_inp): self.stdout.p('1st LO Att : Set %f mA. (%d/%d)'%(abias, count+1, len(att_inp))) lo_att.bias_set(abias) self.stdout.write('Wait 2 sec ... ') time.sleep(2) self.stdout.write('SIS Bias : Sweep start ... ') v, i = sis.bias_sweep(sis_inp) self.stdout.write('done') self.stdout.nextline() self.stdout.p('v0 : [%.1f %.1f %.1f ... %.1f %.1f %.1f]'%( v[0,0], v[1,0], v[2,0], v[-3,0], v[-2,0], v[-1,0])) self.stdout.p('i0 : [%.1f %.1f %.1f ... %.1f %.1f %.1f]'%( i[0,0], i[1,0], i[2,0], i[-3,0], i[-2,0], i[-1,0])) self.stdout.p('SIS Bias : Set 0 mV.') sis.bias_set(0) self.stdout.p('Save : %s'%(dataname + '.%04d.npy'%(count))) numpy.save(datapath + '.%04d.npy'%(count), (v, i)) self.stdout.p('Plot : %s'%(figname + '.%04d.png'%(count))) fpath = figpath + '.%04d.png'%(count) plotargs = (v.T, i.T, fpath, 'Bias Sweep @ att=%.2f (%s)'%(abias, ts)) self.detach_process(iv_plot, plotargs) self.stdout.nextline() continue self.stdout.p('1st LO Att : Set 200 mA.') lo_att.bias_set(200) self.stdout.p('SIS Bias : Set 0 mV.') sis.bias_set(0) self.stdout.nextline() # Finalization Section # ==================== # Close devices # ------------- self.stdout.p('Close Devices') self.stdout.p('=============') # TODO: implement close method. """ sis.close() #lo_sg.close() lo_att.close() #irr_sg.close() rxrot.close() slider.close() """ self.stdout.p('All devices are closed.') self.stdout.nextline() # Stop operation # -------------- self.stdout.p('//// Operation is done. ////') self.operation_done() return
def run(self, start, stop, step): # Initialization Section # ====================== # Check other operation # --------------------- self.check_other_operation() # Generate file path # ------------------ fpg = forest.filepath_generator(self.method) savedir = fpg(' ') logpath = fpg('log.%s.txt') logname = os.path.basename(logpath) datapath = fpg('biassweep.data.%s.npy') dataname = os.path.basename(datapath) figpath = fpg('biassweep.fig.%s.png') figname = os.path.basename(figpath) ts = os.path.basename(fpg('%s')) # Start operation # --------------- args = {'start': start, 'stop': stop, 'step': step} argstxt = str(args) self.operation_start(argstxt, logfile=logpath) # Print welcome message # --------------------- self.stdout.p('=-=-=-=-=-=-=-=-=-=-=-=-=-=') self.stdout.p('FOREST : Get SIS Bias Curve') self.stdout.p('=-=-=-=-=-=-=-=-=-=-=-=-=-=') self.stdout.p('ver.%s' % (self.ver)) self.stdout.p('savedir : %s' % (savedir)) self.stdout.p('logfile : %s' % (logname)) self.stdout.nextline() # Open devices # ------------ self.stdout.p('Open Devices') self.stdout.p('============') sis = self.open_sis_biasbox() self.stdout.nextline() # Operation Section # ================= # Operation part # -------------- self.stdout.p('Get SIS Bias Curve') self.stdout.p('==================') self.stdout.p('start = %f' % (start)) self.stdout.p('stop = %f' % (stop)) self.stdout.p('step = %f' % (step)) self.stdout.nextline() self.stdout.p('SIS Bias : Set 0 mV.') sis.bias_set(0) self.stdout.p('Generate input bias array ...') inp = numpy.arange(start, stop + step, step) self.stdout.p('inp : [%s %s %s ... %s %s %s]' % (inp[0], inp[1], inp[2], inp[-3], inp[-2], inp[-1])) inp = map(float, inp) self.stdout.write('SIS Bias : Sweep start ...') v, i = sis.bias_sweep(inp) self.stdout.write('done') self.stdout.nextline() self.stdout.p( 'v0 : [%.1f %.1f %.1f ... %.1f %.1f %.1f]' % (v[0, 0], v[1, 0], v[2, 0], v[-3, 0], v[-2, 0], v[-1, 0])) self.stdout.p( 'i0 : [%.1f %.1f %.1f ... %.1f %.1f %.1f]' % (i[0, 0], i[1, 0], i[2, 0], i[-3, 0], i[-2, 0], i[-1, 0])) self.stdout.p('SIS Bias : Set 0 mV.') sis.bias_set(0) self.stdout.p('Save : %s' % (dataname)) numpy.save(datapath, (v, i)) self.stdout.p('Plot : %s' % (figname)) iv_plot(v.T, i.T, figpath, 'Bias Sweep (%s)' % (ts)) self.stdout.nextline() # Finalization Section # ==================== # Close devices # ------------- self.stdout.p('Close Devices') self.stdout.p('=============') # TODO: implement close method. """ sis.close() #lo_sg.close() lo_att.close() #irr_sg.close() rxrot.close() slider.close() """ self.stdout.p('All devices are closed.') self.stdout.nextline() # Stop operation # -------------- self.stdout.p('//// Operation is done. ////') self.operation_done() return
def run(self, att_start, att_stop, att_step, sis_start, sis_stop, sis_step): # Initialization Section # ====================== # Check other operation # --------------------- self.check_other_operation() # Generate file path # ------------------ fpg = forest.filepath_generator(self.method) savedir = fpg(' ') logpath = fpg('log.%s.txt') logname = os.path.basename(logpath) datapath = fpg('biassweep.data.%s') dataname = os.path.basename(datapath) figpath = fpg('biassweep.fig.%s') figname = os.path.basename(figpath) ts = os.path.basename(fpg('%s')) # Start operation # --------------- args = { 'att_start': att_start, 'att_stop': att_stop, 'att_step': att_step, 'sis_start': sis_start, 'sis_stop': sis_stop, 'sis_step': sis_step } argstxt = str(args) self.operation_start(argstxt, logfile=logpath) # Print welcome message # --------------------- self.stdout.p('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=') self.stdout.p('FOREST : Get SIS Bias Curve with LO Att Sweep') self.stdout.p('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=') self.stdout.p('ver.%s' % (self.ver)) self.stdout.p('savedir : %s' % (savedir)) self.stdout.p('logfile : %s' % (logname)) self.stdout.nextline() # Open devices # ------------ self.stdout.p('Open Devices') self.stdout.p('============') sis = self.open_sis_biasbox() lo_att = self.open_lo_att() self.stdout.nextline() # Operation Section # ================= # Operation part # -------------- self.stdout.p('Get SIS Bias Curve') self.stdout.p('==================') self.stdout.p('att_start = %f' % (att_start)) self.stdout.p('att_stop = %f' % (att_stop)) self.stdout.p('att_step = %f' % (att_step)) self.stdout.p('sis_start = %f' % (sis_start)) self.stdout.p('sis_stop = %f' % (sis_stop)) self.stdout.p('sis_step = %f' % (sis_step)) self.stdout.nextline() self.stdout.p('1st LO Att : Set 200 mA.') lo_att.bias_set(200) self.stdout.p('SIS Bias : Set 0 mV.') sis.bias_set(0) self.stdout.p('Generate input Att bias array ...') att_inp = numpy.arange(att_start, att_stop + att_step, att_step) self.stdout.p('att_inp : [%s %s %s ... %s %s %s]' % (att_inp[0], att_inp[1], att_inp[2], att_inp[-3], att_inp[-2], att_inp[-1])) self.stdout.p('Generate input SIS bias array ...') sis_inp = numpy.arange(sis_start, sis_stop + sis_step, sis_step) self.stdout.p('sis_inp : [%s %s %s ... %s %s %s]' % (sis_inp[0], sis_inp[1], sis_inp[2], sis_inp[-3], sis_inp[-2], sis_inp[-1])) att_inp = map(float, att_inp) sis_inp = map(float, sis_inp) self.stdout.nextline() for count, abias in enumerate(att_inp): self.stdout.p('1st LO Att : Set %f mA. (%d/%d)' % (abias, count + 1, len(att_inp))) lo_att.bias_set(abias) self.stdout.write('Wait 2 sec ... ') time.sleep(2) self.stdout.write('SIS Bias : Sweep start ... ') v, i = sis.bias_sweep(sis_inp) self.stdout.write('done') self.stdout.nextline() self.stdout.p( 'v0 : [%.1f %.1f %.1f ... %.1f %.1f %.1f]' % (v[0, 0], v[1, 0], v[2, 0], v[-3, 0], v[-2, 0], v[-1, 0])) self.stdout.p( 'i0 : [%.1f %.1f %.1f ... %.1f %.1f %.1f]' % (i[0, 0], i[1, 0], i[2, 0], i[-3, 0], i[-2, 0], i[-1, 0])) self.stdout.p('SIS Bias : Set 0 mV.') sis.bias_set(0) self.stdout.p('Save : %s' % (dataname + '.%04d.npy' % (count))) numpy.save(datapath + '.%04d.npy' % (count), (v, i)) self.stdout.p('Plot : %s' % (figname + '.%04d.png' % (count))) fpath = figpath + '.%04d.png' % (count) plotargs = (v.T, i.T, fpath, 'Bias Sweep @ att=%.2f (%s)' % (abias, ts)) self.detach_process(iv_plot, plotargs) self.stdout.nextline() continue self.stdout.p('1st LO Att : Set 200 mA.') lo_att.bias_set(200) self.stdout.p('SIS Bias : Set 0 mV.') sis.bias_set(0) self.stdout.nextline() # Finalization Section # ==================== # Close devices # ------------- self.stdout.p('Close Devices') self.stdout.p('=============') # TODO: implement close method. """ sis.close() #lo_sg.close() lo_att.close() #irr_sg.close() rxrot.close() slider.close() """ self.stdout.p('All devices are closed.') self.stdout.nextline() # Stop operation # -------------- self.stdout.p('//// Operation is done. ////') self.operation_done() return
def run(self, lo_freq, if_start, if_stop, if_step, thot): # Initialization Section # ====================== # Check other operation # --------------------- self.check_other_operation() # Generate file path # ------------------ fpg = forest.filepath_generator(self.method) savedir = fpg(' ') logpath = fpg('log.%s.txt') logname = os.path.basename(logpath) datapath = fpg('irr.data.%s') dataname = os.path.basename(datapath) figpath = fpg('irr.fig.%s') figname = os.path.basename(figpath) ts = os.path.basename(fpg('%s')) # Start operation # --------------- args = {'if_start': if_start, 'if_stop': if_stop, 'if_step': if_step, 'lo_freq': lo_freq, 'thot': thot} argstxt = str(args) self.operation_start(argstxt, logfile=logpath) # Print welcome message # --------------------- self.stdout.p('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=') self.stdout.p('FOREST : IRR with IF Freq sweep') self.stdout.p('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=') self.stdout.p('ver.%s'%(self.ver)) self.stdout.nextline() # Open devices # ------------ self.stdout.p('Open Devices') self.stdout.p('============') slider = self.open_slider() sp = self.open_speana() sw = self.open_switch() lo_sg = self.open_lo_sg() ref_sg = self.open_irr_sg() self.stdout.nextline() # Operation Section # ================= self.stdout.p('IRR') self.stdout.p('===') self.stdout.p('lo_freq = %f GHz'%(lo_freq)) self.stdout.p('if_start = %f GHz'%(if_start)) self.stdout.p('if_stop = %f GHz'%(if_stop)) self.stdout.p('if_step = %f MHz'%(if_step)) self.stdout.p('thot = %f K'%(thot)) self.stdout.nextline() self.stdout.p('Device configurations') self.stdout.p('---------------------') self.stdout.p('1st LO SG : Set %f GHz.'%(lo_freq/6.)) lo_sg.freq_set(lo_freq/6., 'GHz') self.stdout.p('1st LO SG : Set 18 dBm.') lo_sg.power_set(18) self.stdout.p('1st LO SG : Set output on.') lo_sg.output_on() self.stdout.p('IRR Ref SG : Set %f GHz.'%((lo_freq+if_start)/6.)) ref_sg.freq_set((lo_freq+if_start)/6., 'GHz') self.stdout.p('IRR Ref SG : Set output off.') ref_sg.output_off() self.stdout.p('Speana : Preset.') sp.scpi_reset() self.stdout.p('Speana : Set freq span 1 MHz.') sp.frequency_span_set(1, 'MHz') self.stdout.p('Speana : Set center freq %f GHz.'%(if_start)) sp.frequency_center_set(if_start, 'GHz') self.stdout.p('Speana : Set res. BW 1 kHz.') sp.resolution_bw_set(1, 'kHz') self.stdout.p('Speana : Set attenuation 0 dB.') sp.attenuation_set(0) self.stdout.p('Speana : Set average 5.') sp.average_set(5) sp.average_onoff_set('ON') sweeptime = sp.sweep_time_query()[0] acquiretime = (sweeptime+0.07) * 5 self.stdout.p('Speana : acquiretime = %.3f sec.'%(acquiretime)) self.stdout.p('IF Switch : Set ch 1.') sw.ch_set_all(1) freq = sp.sp[0].gen_xaxis() self.stdout.p('Save : %s'%(dataname + '.freq.npy')) numpy.save(datapath + '.freq.npy', freq) x = (freq - numpy.average(freq)) / 1e6 self.stdout.nextline() if_list = numpy.arange(if_start, if_stop + if_step, if_step) dcold = [] dhot = [] dsig_u = [] dsig_l = [] self.stdout.p('Get SKY data') self.stdout.p('------------') self.stdout.p('Slider : Move to SKY.') slider.move_sky() for if_freq in if_list: self.stdout.p('Speana : Set center freq %f GHz.'%(if_freq)) sp.frequency_center_set(if_freq, 'GHz') for ch in [1,2,3,4]: self.stdout.p('IF Switch : Set ch %d.'%(ch)) sw.ch_set_all(ch) time.sleep(0.05) self.stdout.p('Speana : Acquire. waittime=%.1f'%(acquiretime)) sp.average_restart() time.sleep(acquiretime) _d = sp.trace_data_query() dcold.append(_d) continue continue dcold = numpy.array(dcold) self.stdout.p('Save : %s'%(dataname + '.cold.npy')) numpy.save(datapath + '.cold.npy', dcold) self.stdout.nextline() self.stdout.p('Get R data') self.stdout.p('----------') self.stdout.p('Slider : Move to R.') slider.move_r() for if_freq in if_list: self.stdout.p('Speana : Set center freq %f GHz.'%(if_freq)) sp.frequency_center_set(if_freq, 'GHz') for ch in [1,2,3,4]: self.stdout.p('IF Switch : Set ch %d.'%(ch)) sw.ch_set_all(ch) time.sleep(0.05) self.stdout.p('Speana : Acquire. waittime=%.1f'%(acquiretime)) sp.average_restart() time.sleep(acquiretime) _d = sp.trace_data_query() dhot.append(_d) continue continue dhot = numpy.array(dhot) self.stdout.p('Save : %s'%(dataname + '.hot.npy')) numpy.save(datapath + '.hot.npy', dhot) self.stdout.nextline() self.stdout.p('Get SIG data') self.stdout.p('------------') self.stdout.p('Slider : Move to R.') slider.move_r() self.stdout.p('IRR Ref SG : Set output on.') ref_sg.output_on() for if_freq in if_list: self.stdout.p('INFO : IF freq = %f GHz.'%(if_freq)) self.stdout.p('INFO : (Upper Side Band)') self.stdout.p('IRR Ref SG : Set %f GHz.'%((lo_freq+if_freq)/6.)) ref_sg.freq_set((lo_freq+if_freq)/6., 'GHz') self.stdout.p('Speana : Set center freq %f GHz.'%(if_freq)) sp.frequency_center_set(if_freq, 'GHz') for ch in [1,2,3,4]: self.stdout.p('IF Switch : Set ch %d.'%(ch)) sw.ch_set_all(ch) time.sleep(0.05) self.stdout.p('Speana : Acquire. waittime=%.1f'%(acquiretime)) sp.average_restart() time.sleep(acquiretime) _d = sp.trace_data_query() dsig_u.append(_d) continue self.stdout.p('INFO : (Lower Side Band)') self.stdout.p('IRR Ref SG : Set %f GHz.'%((lo_freq-if_freq)/6.)) ref_sg.freq_set((lo_freq-if_freq)/6., 'GHz') for ch in [1,2,3,4]: self.stdout.p('IF Switch : Set ch %d.'%(ch)) sw.ch_set_all(ch) time.sleep(0.05) self.stdout.p('Speana : Acquire. waittime=%.1f'%(acquiretime)) sp.average_restart() time.sleep(acquiretime) _d = sp.trace_data_query() dsig_l.append(_d) continue continue dsig_u = numpy.array(dsig_u) dsig_l = numpy.array(dsig_l) self.stdout.p('Save : %s'%(dataname + '.dsig_u.npy')) self.stdout.p('Save : %s'%(dataname + '.dsig_l.npy')) numpy.save(datapath + '.dsig_u.npy', dsig_u) numpy.save(datapath + '.dsig_l.npy', dsig_l) self.stdout.nextline() self.stdout.p('IRR Ref SG : Set output off.') ref_sg.output_off() self.stdout.p('IF Switch : Set ch 1.') sw.ch_set_all(1) self.stdout.p('Slider : Move to SKY.') slider.move_sky() self.stdout.nextline() self.stdout.p('Calc IRR') self.stdout.p('--------') dcold_db = dcold.reshape((-1, 4, 4, 461)) dhot_db = dhot.reshape((-1, 4, 4, 461)) dsig_l_db = dsig_l.reshape((-1, 4, 4, 461)) dsig_u_db = dsig_u.reshape((-1, 4, 4, 461)) dcold = 10**(dcold_db/10.) dhot = 10**(dhot_db/10.) dsig_l = 10**(dsig_l_db/10.) dsig_u = 10**(dsig_u_db/10.) dc_u = dcold[:,:2,:,:] dh_u = dhot[:,:2,:,:] dl_u = dsig_l[:,:2,:,:] du_u = dsig_u[:,:2,:,:] dc_l = dcold[:,2:,:,:] dh_l = dhot[:,2:,:,:] dl_l = dsig_l[:,2:,:,:] du_l = dsig_u[:,2:,:,:] M_u = du_u / du_l M_l = dl_l / dl_u dP_u = numpy.average(dh_u - dc_u, axis=-1) dP_l = numpy.average(dh_l - dc_l, axis=-1) M_dsb = (dP_u / dP_l)[:,:,:,None] R_u = M_u * (M_l * M_dsb - 1.) / (M_u - M_dsb) R_l = M_l * (M_u - M_dsb) / (M_l * M_dsb - 1.) IRR_u = 10 * numpy.log10(R_u) IRR_l = 10 * numpy.log10(R_l) IRR = numpy.concatenate([IRR_u, IRR_l], axis=1) self.stdout.p('Save : %s'%(dataname + '.IRR_spec.npy')) numpy.save(datapath + '.IRR_spec.npy', IRR) ind_sig_u = numpy.nanargmax(du_u, axis=-1) ind_sig_l = numpy.nanargmax(dl_l, axis=-1) x1, x2, x3 = numpy.indices(ind_sig_u.shape) p_IRR_u = IRR_u[x1, x2, x3, ind_sig_u] p_IRR_l = IRR_u[x1, x2, x3, ind_sig_l] p_IRR = numpy.concatenate([p_IRR_u, p_IRR_l], axis=1) self.stdout.p('Save : %s'%(dataname + '.IRR.npy')) numpy.save(datapath + '.IRR.npy', p_IRR) self.stdout.nextline() self.stdout.p('Plot') self.stdout.p('----') self.stdout.p('Save : %s'%(figname)) [irr_spec_plot(x, _c, _h, _u, _l, _i, '%s.IF%.1fGHz'%(figpath, freq)) for i, (_c, _h, _u, _l, _i, freq) in enumerate(zip(dcold_db, dhot_db, dsig_u_db, dsig_l_db, IRR, if_list))] irr_summary_plot(if_list, p_IRR, dcold_db, dhot_db, thot, '%s.IRR.png'%(figpath)) self.stdout.nextline() # Finalization Section # ==================== # Close devices # ------------- self.stdout.p('Close Devices') self.stdout.p('=============') # TODO: implement close method. """ sis.close() #lo_sg.close() lo_att.close() #irr_sg.close() rxrot.close() slider.close() """ self.stdout.p('All devices are closed.') self.stdout.nextline() # Stop operation # -------------- self.stdout.p('//// Operation is done. ////') self.operation_done() return