def rcsj(current, damping, prefix=[], fft=False,svpng=False,svvolt=False,saveplot=False,savefile=False,normalized=False,printmessg=True): ''' iv sweep for rcsj model - damping: tuple of either 'Q' or 'beta' and respective value returns IV curve with options: - svpng: save each iteration to png - svvolt: save peak detection of voltage to png - saveplot: save ivc to .png - savefile: save ivc to .dat - normalized: returns voltage/Q - printmessg: print statusmessage after iteration ''' current = current.tolist() # makes it faster ? voltage = [] freq = [] volt_fft = [] t, tsamp = timeparams(damping) y0 = (0,0) # always start at zero phase and zero current idxstart = int(-tsamp*len(t)) # only sample the last tsamp=1% of evaluated time for k,i in enumerate(current): y = odeint(rcsj_curr, y0, t, args=(i,damping)) #y0 = (0,max(y[:,1])) y0 = y[-1,:] # new initial condition based on last iteration idx = argrelextrema(y[idxstart:,1], np.greater) if len(idx[0])<2: mean = 0 voltage.append(mean) else: x1, x2 = idx[0][-2], idx[0][-1] mean = np.mean([y[x1+idxstart:x2+idxstart,1]]) voltage.append(mean) if svpng: path='../plots/voltage/{}={:E}/'.format(damping[0],damping[1]) ensure_dir(path) plt.plot(t[idxstart:],y[idxstart:,1]) plt.plot([t[x1+idxstart],t[x2+idxstart]],[y[x1+idxstart,1],y[x2+idxstart,1]],'o') plt.ylim(0,3*damping[1]) plt.savefig(path+'i={:2.3f}.png'.format(i)) plt.close() if prefix: #timedata = {'Time (wp*t)' : t, 'Phase (rad)' : y[:,0], 'AC Voltage (V)' : y[:,1]} #ivdata = {'Current (Ic)': i, 'DC Voltage (V)': mean, 'beta ()': Q} #idstring = 'beta={:.2f}'.format(ivdata['beta ()']) #savedata((k,len(current)),prefix,idstring,timedata,ivdata) data2save = {'Time (wp*t)' : t, 'Phase (rad)' : y[:,0], 'AC Voltage (V)' : y[:,1]} data2save = stlab.stlabdict(data2save) data2save.addparcolumn('Current (Ic)',i,last=False) data2save.addparcolumn('DC Voltage (V)',mean) data2save.addparcolumn('{} ()'.format(damping[0]),damping[1]) if k == 0: idstring = '{}={:2.2f}'.format(damping[0],damping[1]) ensure_dir(prefix) myfile = stlab.newfile(prefix,idstring,data2save.keys(), usedate=False,usefolder=False)#,mypath='simresults/') stlab.savedict(myfile,data2save) if k == len(current): myfile.close() if svvolt: path='../plots/sols/{}={:E}/'.format(damping[0],damping[1]) ensure_dir(path) fig, ax = plt.subplots(2,sharex=True) ax[0].plot(t,y[:,0]) ax[1].plot(t,y[:,1]) ax[0].set_ylabel(r'$\phi$') ax[1].set_ylabel(r'd$\phi$/dt') ax[1].set_xlabel(r'$\tau=t/\tau_c$') fig.subplots_adjust(hspace=0) plt.savefig(path+'i={:2.3f}.png'.format(i)) plt.close() if fft: F, signal_fft = analyze_fft(t,y[:,1]) freq.append(F) volt_fft.append(abs(signal_fft)) if printmessg: print('Done: {}={:E}, i={:2.3f}'.format(damping[0],damping[1],i)) current, voltage = np.asarray(current), np.asarray(voltage) if savefile: saveiv(current,voltage,damping,normalized) if saveplot: saveivplot(current,voltage,damping,normalized) if normalized: voltage = voltage/damping[1] if not fft: return {'Current': current, 'DC Voltage': voltage} else: return {'Current': current, 'DC Voltage': voltage, 'Frequency': freq[0], 'FFT': np.asarray(volt_fft)}
span = 10e7 # Hz npoints = 4001 power = -20 # dBm #Setup PNA sweep parameters mypna.SetIFBW(ifbw) mypna.SetCenterSpan(f0,span) mypna.SetPoints(npoints) mypna.SetPower(power) #Setup SMB frequency mysg.setCWfrequency(sgf0) #mypna.write('ROSC:SOUR EXT') for i,P in enumerate(sgpow): #Loop over desired SMB powers mysg.setCWpower(P) #Set the power to current loop value mysg.RFon() #Activate RF power on SMB data = mypna.Measure2ports() #Execute PNA sweep and return data data['Power (dBm)'] = np.full(npoints, power-20.) #Add some data columns to measured data data['SMBPower (dBm)'] = np.full(npoints, P) data['S11dB (dB)'] = 20.*np.log10( [ np.sqrt(np.power(a,2.)+np.power(b,2.)) for a,b in zip(data['S11re ()'],data['S11im ()'])] ) data['S21dB (dB)'] = 20.*np.log10( [ np.sqrt(np.power(a,2.)+np.power(b,2.)) for a,b in zip(data['S21re ()'],data['S21im ()'])] ) if i==0: #if on first measurement, create new measurement file and folder using titles extracted from measurement myfile,fullfilename,_ = stlab.newfile(prefix,idstring,data.keys()) stlab.savedict(myfile, data) #Save measured data to file. Written as a block for spyview. #Create metafile for spyview at each measurement step stlab.metagen.fromarrays(fullfilename,data['Frequency (Hz)'],sgpow[0:i+1],xtitle='Frequency (Hz)',ytitle='SMBPower (dB)',colnames=data.keys()) myfile.close()
plt.pause(0.1) if save_data: # temp = tempdev.GetTemperature() data['Power (dBm)'] = VNA.GetPower() data['Gate Voltage (V)'] = gate_voltage data['Leakage Current (A)'] = leakage_current data['Temperature (K)'] = temp if count==0: Data = stlab.newfile(prefix,'_',data.keys(),autoindex = True, mypath= path) stlab.savedict(Data, data) for event in pygame.event.get(): # stopping if 's' pressed if event.type == QUIT: sys.exit() if event.type == KEYDOWN and event.dict['key'] == 115: # corresponding to character "s" STOP = True if STOP: break t = time.time() print('measured gate steps:', count+1) time_passed = t - t_in
#mypna.write('ROSC:SOUR EXT') for i, P in enumerate(sgpow): #Loop over desired SMB powers mysg.setCWpower(P) #Set the power to current loop value mysg.RFon() #Activate RF power on SMB data = mypna.Measure2ports() #Execute PNA sweep and return data data['Power (dBm)'] = np.full(npoints, power - 20.) #Add some data columns to measured data data['SMBPower (dBm)'] = np.full(npoints, P) data['S11dB (dB)'] = 20. * np.log10([ np.sqrt(np.power(a, 2.) + np.power(b, 2.)) for a, b in zip(data['S11re ()'], data['S11im ()']) ]) data['S21dB (dB)'] = 20. * np.log10([ np.sqrt(np.power(a, 2.) + np.power(b, 2.)) for a, b in zip(data['S21re ()'], data['S21im ()']) ]) if i == 0: #if on first measurement, create new measurement file and folder using titles extracted from measurement myfile = stlab.newfile(prefix, idstring, data.keys()) stlab.savedict( myfile, data) #Save measured data to file. Written as a block for spyview. #Create metafile for spyview at each measurement step stlab.metagen.fromarrays(myfile, data['Frequency (Hz)'], sgpow[0:i + 1], xtitle='Frequency (Hz)', ytitle='SMBPower (dB)', colnames=data.keys()) myfile.close()