ds.spec['rr'], 1, 1 / rms**2 ) # compute variance-weighted RR tseries (so RFI doesn't dominate) t = ds.time.mjds() print 't0:', ds.t0() print 'Saving tseries to', savefile save(savefile, tseries) print 'Saving times to', timefile, '\n' save(timefile, t) else: t = load(timefile) tseries = load(savefile) t = mjds_to_hjds(t, sb) ind = find(tseries != 0) times[band] += t[ind].tolist() flux[band] += tseries[ind].tolist() plot(t[ind] - t[0], tseries[ind]) leg.append(obs + band) legend(leg) filename = 'tseries/' + band + 'band_tseries.dat' savetxt(filename, column_stack((times[band], flux[band]))) savefig('tseries/tseries_band.pdf', bbox_inches='tight') figure() for band in bands: plot(times[band], flux[band]) legend(bands) savefig('tseries/long.pdf', bbox_inches='tight') # frequency range to search w/ LS periodogram Pmin = 1. # hrs Pmax = 25.
yfit_imag = intercept_imag + slope_imag * f clf() #dsR.plot_dynspec(plot_params={'pol':'rr','smin':0.01}) #plot(f/1.e3,treal,'.b') #plot(f/1.e3,yfit,'-b') drift_rate = 1 / slope # MHz/sec print 'Drift rate:', drift_rate, 'MHz/sec' #show() tseries1 = dsR.tseries(fmin=1.6e9, fmax=1.8e9) tseries2 = dsR.tseries(fmin=1.8e9, fmax=2.0e9) t = tseries1.get_tlist() * tseries1.dt() plot(t, tseries1.spec['rr']) plot(t, tseries2.spec['rr']) xlabel('Time in seconds') ylabel('Flux (mJy) in RCP') legend(('1.6-1.8 GHz', '1.8-2 GHz')) savefig('plots/drift.pdf', bbox_inches='tight') ### LCP portion of burst ### dsL = ds_bin.clip(tmin=0, tmax=8, fmin=1.6e9, fmax=4.0e9) dsL = dsL.bin_dynspec(nt=2, nf=2) clf() dsL.plot_dynspec( plot_params={ 'pol': 'v', 'smin': -0.015,
SI = spec.spec['i'] SI_err = spec_err['i'] rc_mask = ~ (~SI.mask * ~SV.mask) rc_min = ma.masked_array(zeros(len(SV)),mask=rc_mask) rc_best = ma.masked_array(zeros(len(SV)),mask=rc_mask) rc_max = ma.masked_array(zeros(len(SV)),mask=rc_mask) for i in range(len(SV)): if ~rc_mask[i]: rc_min[i],rc_max[i],rc_best[i] = rc_conf_int({'I':real(SI[i]),'Ierr':SI_err[i],'V':real(SV[i]),'Verr':SV_err[i]},conf=0.68) f = spec.f/1.e9 close('all') figure(figsize=(3,4)) subplot(211) plot(f,real(rr),'b') fill_between(f, real(rr)-rr_err, real(rr)+rr_err,alpha=0.3, facecolor='b',linewidth=0) plot(f,real(ll),'g') fill_between(f, real(ll)-ll_err, real(ll)+ll_err,alpha=0.3, facecolor='g',linewidth=0) #plot(f,imag(rr),'b--') #plot(f,imag(ll),'g--') xlim([1,4]) legend(('RCP','LCP')) gca().axhline(0,color='k') ylabel('Time-avg Flux Density (mJy)') #axis([1,4,-18,18]) #show() subplot(212) #plot(f,rc_best,'k') fill_between(f, rc_min, rc_max, alpha=0.5, facecolor='k',linewidth=0)
RA_hms=RA_hms_UVCet, dec_dms=dec_dms_UVCet, site_name='vla', doprint=True) # just to print light travel time t_TDB_hours = array([t.value * 24. for t in t_TDB]) # select only the times that are not masked ind = find(~tseries.spec[pol].mask) # add those points to the times and flux lists for all obs together (for this band) times[band] += t_TDB_hours[ind].tolist() flux[band] += real(tseries.spec[pol])[ind].tolist() # plot this obs/band's tseries so I can see what they all look like # (time axis is relative to obs start time so they won't be phased) plot(t_TDB_hours[ind] - t_TDB_hours[0], real(tseries.spec[pol])[ind]) obs = dsfile.split('/')[5] leg.append(obs + band) # label the plot of all time series from this band legend(leg) # save a time series of all observations from this band together # ! look at this file ! this may already be what I need. tseries_filename = mydir + 'tseries/' + band + 'band_' + pol + '_doclip' + str( do_clip) + '_tseries.dat' savetxt(tseries_filename, column_stack((times[band], flux[band]))) # save a figure of the time series in both bands (one subplot per band) savefig(mydir + 'tseries/tseries_band_' + pol + '_doclip' + str(do_clip) + '.pdf',
if ~rc_mask[i]: rc_min[i], rc_max[i], rc_best[i] = rc_conf_int( { 'I': real(SI[i]), 'Ierr': SI_err[i], 'V': real(SV[i]), 'Verr': SV_err[i] }, conf=0.68) f = spec.f / 1.e9 close('all') figure(figsize=(3, 4)) subplot(211) plot(f, real(rr), 'b') fill_between(f, real(rr) - rr_err, real(rr) + rr_err, alpha=0.3, facecolor='b', linewidth=0) plot(f, real(ll), 'g') fill_between(f, real(ll) - ll_err, real(ll) + ll_err, alpha=0.3, facecolor='g', linewidth=0) #plot(f,imag(rr),'b--') #plot(f,imag(ll),'g--')
def flin(C, x): return C[0] * x linear = odrpack.Model(flin) sx = std(imag(rr)) * ones(len(x)) sy = std(imag(ll)) * ones(len(y)) mydata = odrpack.RealData(x, y, sx=sx, sy=sy) myodr = odrpack.ODR(mydata, linear, beta0=[1.]) #,0.]) myoutput = myodr.run() C = myoutput.beta Cerr = myoutput.sd_beta print 'chi2, I think (\"residual variance\"):', myoutput.res_var plot(x, y, '.') xmax = max(ma.max(real(rr)), ma.max(real(ll))) xmin = min(ma.min(real(rr)), ma.min(real(ll))) dx = (xmax - xmin) / 10 xmax += dx xmin -= dx ylin1 = C[0] * xmin #+ C[1] ylin2 = C[0] * xmax #+ C[1] plot([xmin, xmax], [ylin1, ylin2], 'k-') axis([xmin, xmax, xmin, xmax]) gca().set_aspect(1) rc = (1 - C[0]) / (1 + C[0]) print 'rc:', rc xplt = sort(x) mA = C[0] + Cerr[0]
rms = std(ds.spec['ll'],0) # rms for each frequency tseries = average(ds.spec['rr'],1,1/rms**2) # compute variance-weighted RR tseries (so RFI doesn't dominate) t = ds.time.mjds() print 't0:',ds.t0() print 'Saving tseries to',savefile save(savefile,tseries) print 'Saving times to',timefile,'\n' save(timefile,t) else: t = load(timefile) tseries = load(savefile) t = mjds_to_hjds(t,sb) ind = find( tseries != 0 ) times[band] += t[ind].tolist() flux[band] += tseries[ind].tolist() plot(t[ind]-t[0],tseries[ind]) leg.append(obs+band) legend(leg) filename='tseries/'+band+'band_tseries.dat' savetxt(filename,column_stack((times[band],flux[band]))) savefig('tseries/tseries_band.pdf',bbox_inches='tight') figure() for band in bands: plot(times[band],flux[band]) legend(bands) savefig('tseries/long.pdf',bbox_inches='tight') # frequency range to search w/ LS periodogram Pmin = 1. # hrs Pmax = 25.
yfit_imag = intercept_imag + slope_imag * f clf() #dsR.plot_dynspec(plot_params={'pol':'rr','smin':0.01}) #plot(f/1.e3,treal,'.b') #plot(f/1.e3,yfit,'-b') drift_rate = 1/slope # MHz/sec print 'Drift rate:', drift_rate, 'MHz/sec' #show() tseries1 = dsR.tseries(fmin=1.6e9,fmax=1.8e9) tseries2 = dsR.tseries(fmin=1.8e9,fmax=2.0e9) t = tseries1.get_tlist() * tseries1.dt() plot(t,tseries1.spec['rr']) plot(t,tseries2.spec['rr']) xlabel('Time in seconds') ylabel('Flux (mJy) in RCP') legend(('1.6-1.8 GHz','1.8-2 GHz')) savefig('plots/drift.pdf',bbox_inches='tight') ### LCP portion of burst ### dsL = ds_bin.clip(tmin=0,tmax=8,fmin=1.6e9,fmax=4.0e9) dsL = dsL.bin_dynspec(nt=2,nf=2) clf() dsL.plot_dynspec(plot_params={'pol':'v','smin':-0.015,'smax':0.015,'df':0.1,'dx':0.5,'dy':0.1,'scale':'linear'}) savefig('plots/dsL.pdf',bbox_inches='tight')
x = real(rr).compressed() y = real(ll).compressed() def flin(C,x): return C[0]*x linear = odrpack.Model(flin) sx = std(imag(rr)) * ones(len(x)) sy = std(imag(ll)) * ones(len(y)) mydata = odrpack.RealData(x,y,sx=sx,sy=sy) myodr = odrpack.ODR(mydata,linear,beta0=[1.]) #,0.]) myoutput = myodr.run() C = myoutput.beta Cerr = myoutput.sd_beta print 'chi2, I think (\"residual variance\"):', myoutput.res_var plot(x,y,'.') xmax = max(ma.max(real(rr)),ma.max(real(ll))) xmin = min(ma.min(real(rr)),ma.min(real(ll))) dx = (xmax-xmin)/10 xmax += dx xmin -= dx ylin1 = C[0]*xmin #+ C[1] ylin2 = C[0]*xmax #+ C[1] plot([xmin,xmax],[ylin1,ylin2],'k-') axis([xmin,xmax,xmin,xmax]) gca().set_aspect(1) rc = (1-C[0])/(1+C[0]) print 'rc:', rc xplt = sort(x) mA = C[0] + Cerr[0]