cals=['cal1','cal2','cal3','cal4','cal5'] vcal=20./(2.**16) f10=open('cal10ghz.pkl','rb') f15=open('cal15ghz.pkl','rb') cal10ghz=cPickle.load(f10) cal15ghz=cPickle.load(f15) f10.close() f15.close() f10a=open('cal10ghz_b.pkl','wb') f15a=open('cal15ghz_b.pkl','wb') for cal in cals: cal10ghz[cal]['loss']={} cal10ghz[cal]['loss2']={} for chan in chans10ghz: fp=util.linfit(cal10ghz[cal]['on'][chan],cal10ghz[cal]['off1'][chan]) cal10ghz[cal]['loss'][chan]=1.- 1./fp[1] fp2=util.linfit(cal10ghz[cal]['off1'][chan],cal10ghz[cal]['on'][chan]) cal10ghz[cal]['loss2'][chan]=1.-fp2[1] plt.figure() plt.plot(cal10ghz[cal]['off1'][chan]*vcal-10.,label='Pre-calibration') plt.plot(cal10ghz[cal]['off2'][chan]*vcal-10.0,label='Post-calibration') plt.plot((fp[0]+fp[1]*(cal10ghz[cal]['on'][chan]))*vcal-10.0,label='Cal, scaled by '+str(fp[1])[0:4]) plt.title('10 GHz calibration of loss by fit. cal: '+str(cal)+ ' Channel: '+ chan) plt.xlabel('Sector');plt.ylabel('Volts');plt.grid();plt.legend(loc=0) plotfilename='cal_loss_10ghz_'+str(cal)+'_'+str(chan)+'.png' plt.savefig(plotfilename) cPickle.dump(cal10ghz,f10a) f10.close() for cal in cals:
aztargetdic = {1:np.zeros(3), 3:np.zeros(3), 5:np.zeros(3) } utcrossdic = { 1:np.zeros(3), 3:np.zeros(3), 5:np.zeros(3) } targs=['Sun','Sun','Moon'] chans=[1,3,5] for c,ch in enumerate(chans): for crossn, targ in enumerate(targs): print c,ch,crossn,targ,'now the lengths' azoffdic[ch][crossn],aztargetdic[ch][crossn],eltargetdic[ch][crossn],utcrossdic[ch][crossn]=util.get_cofe_crossing(ut,d10[ch+2].data['T'],gaz,lat,lon,utcrossings[ch][crossn],targ) #fitdic = { 'offset':np.zeros(5), 'slope':np.zeros(5) } fitdic={} for ch in chans: fitdic[ch]=util.linfit(utcrossdic[ch],azoffdic[ch]) f=open(wd+'azoff_10.pkl','wb') cPickle.dump(azoffdic,f) f.close() f=open(wd+'eltarget_10.pkl','wb') cPickle.dump(eltargetdic,f) f.close() f=open(wd+'aztarget_10.pkl','wb') cPickle.dump(aztargetdic,f) f.close() f=open(wd+'utcrossings_10.pkl','wb') cPickle.dump(utcrossdic,f) f.close() f=open(wd+'fitparams_10.pkl','wb')
for crossn, targ in enumerate(targs): print c, ch, crossn, targ, 'now the lengths' azoffdic[ch][crossn], aztargetdic[ch][crossn], eltargetdic[ch][ crossn], utcrossdic[ch][crossn] = util.get_cofe_crossing( ut, d15[ch + 2].data['T'], gaz, lat, lon, utcrossings[ch][crossn], targ) #fitdic = { 'offset':np.zeros(5), 'slope':np.zeros(5) } fitdic = {} for ch in chans: for i, target in enumerate(targs): loncrossdic[ch][i] = lon[abs(uts15 - utcrossdic[ch][i]) == min( abs(uts15 - utcrossdic[ch][i]))] for ch in chans: fitdic[ch] = util.linfit(loncrossdic[ch], azoffdic[ch]) f = open(wd + 'azoff_15_mag.pkl', 'wb') cPickle.dump(azoffdic, f) f.close() f = open(wd + 'eltarget_15_mag.pkl', 'wb') cPickle.dump(eltargetdic, f) f.close() f = open(wd + 'aztarget_15_mag.pkl', 'wb') cPickle.dump(aztargetdic, f) f.close() f = open(wd + 'utcrossings_15_mag.pkl', 'wb') cPickle.dump(utcrossdic, f) f.close() f = open(wd + 'fitparams_15_mag.pkl', 'wb')
targs = ['Sun', 'Sun', 'Moon'] chans = [1, 3, 5] for c, ch in enumerate(chans): for crossn, targ in enumerate(targs): print c, ch, crossn, targ, 'now the lengths' azoffdic[ch][crossn], aztargetdic[ch][crossn], eltargetdic[ch][ crossn], utcrossdic[ch][crossn] = util.get_cofe_crossing( ut, d10[ch + 2].data['T'], gaz, lat, lon, utcrossings[ch][crossn], targ) #fitdic = { 'offset':np.zeros(5), 'slope':np.zeros(5) } fitdic = {} for ch in chans: fitdic[ch] = util.linfit(utcrossdic[ch], azoffdic[ch]) f = open(wd + 'azoff_10.pkl', 'wb') cPickle.dump(azoffdic, f) f.close() f = open(wd + 'eltarget_10.pkl', 'wb') cPickle.dump(eltargetdic, f) f.close() f = open(wd + 'aztarget_10.pkl', 'wb') cPickle.dump(aztargetdic, f) f.close() f = open(wd + 'utcrossings_10.pkl', 'wb') cPickle.dump(utcrossdic, f) f.close() f = open(wd + 'fitparams_10.pkl', 'wb')
# this loop runs get_cofe_crossing for all three targets for all channels for c,ch in enumerate(chans): for crossn, targ in enumerate(targs): print c,ch,crossn,targ,'now the lengths' azoffdic[ch][crossn],aztargetdic[ch][crossn],eltargetdic[ch][crossn],utcrossdic[ch][crossn]=util.get_cofe_crossing(ut,d10[ch+2].data['T'],gaz,lat,lon,utcrossings[ch][crossn],targ) #fitdic = { 'offset':np.zeros(5), 'slope':np.zeros(5) } fitdic={} for ch in chans: for i,target in enumerate(targs): loncrossdic[ch][i]=lon[abs(uts10-utcrossdic[ch][i])==min(abs(uts10-utcrossdic[ch][i]))] for ch in chans: fitdic[ch]=util.linfit(loncrossdic[ch],azoffdic[ch]) f=open(wd+'azoff_10_mag.pkl','wb') cPickle.dump(azoffdic,f) f.close() f=open(wd+'eltarget_10_mag.pkl','wb') cPickle.dump(eltargetdic,f) f.close() f=open(wd+'aztarget_10_mag.pkl','wb') cPickle.dump(aztargetdic,f) f.close() f=open(wd+'utcrossings_10_mag.pkl','wb') cPickle.dump(utcrossdic,f) f.close() f=open(wd+'fitparams_10_mag.pkl','wb')
cals = ['cal1', 'cal2', 'cal3', 'cal4', 'cal5'] vcal = 20. / (2.**16) f10 = open('cal10ghz.pkl', 'rb') f15 = open('cal15ghz.pkl', 'rb') cal10ghz = cPickle.load(f10) cal15ghz = cPickle.load(f15) f10.close() f15.close() f10a = open('cal10ghz_b.pkl', 'wb') f15a = open('cal15ghz_b.pkl', 'wb') for cal in cals: cal10ghz[cal]['loss'] = {} cal10ghz[cal]['loss2'] = {} for chan in chans10ghz: fp = util.linfit(cal10ghz[cal]['on'][chan], cal10ghz[cal]['off1'][chan]) cal10ghz[cal]['loss'][chan] = 1. - 1. / fp[1] fp2 = util.linfit(cal10ghz[cal]['off1'][chan], cal10ghz[cal]['on'][chan]) cal10ghz[cal]['loss2'][chan] = 1. - fp2[1] plt.figure() plt.plot(cal10ghz[cal]['off1'][chan] * vcal - 10., label='Pre-calibration') plt.plot(cal10ghz[cal]['off2'][chan] * vcal - 10.0, label='Post-calibration') plt.plot((fp[0] + fp[1] * (cal10ghz[cal]['on'][chan])) * vcal - 10.0, label='Cal, scaled by ' + str(fp[1])[0:4]) plt.title('10 GHz calibration of loss by fit. cal: ' + str(cal) + ' Channel: ' + chan) plt.xlabel('Sector') plt.ylabel('Volts')