def fnoise_list(mode = 'GFields'): filelist = np.loadtxt(sys.argv[1],dtype=str) obsid = np.array([int(f.split('-')[1]) for f in filelist]) filelist = filelist[np.argsort(obsid)] obsid = np.sort(obsid) fnoise = np.zeros(filelist.size) enoise = np.zeros(filelist.size) feed = None ifeed = 0 isfg4 = np.zeros(filelist.size,dtype=bool) dist = np.zeros(filelist.size) pyplot.figure(figsize=(20,5)) for ifile, filename in enumerate(filelist): print(filename) try: data = h5py.File(filename,'r') except OSError: print('{} cannot be opened (Resource unavailable)'.format(filename)) fnoise[ifile] = np.nan if mode.lower() in data['level1/comap'].attrs['source'].decode('utf-8').lower(): isfg4[ifile] = True try: fits = data['level2/fnoise_fits'][ifeed,-1,1:-2,:] fnoise[ifile] = np.median(fits[:,1]) enoise[ifile] = np.sqrt(np.median(np.abs(fits[:,1]-fnoise[ifile])**2))*1.4826 except: print('{} not processed'.format(filename.split('/')[-1])) fnoise[ifile] = np.nan if isinstance(feed, type(None)): feed = data['level1/spectrometer/feeds'][ifeed] # Calculate sun distance mjd = data['level1/spectrometer/MJD'][0:1] lon=-118.2941 lat=37.2314 ra_sun, dec_sun, raddist = Coordinates.getPlanetPosition('SUN', lon, lat, mjd) az_sun, el_sun = Coordinates.e2h(ra_sun, dec_sun, mjd, lon, lat) ra = data['level1/spectrometer/pixel_pointing/pixel_ra'][0,0:1] dec = data['level1/spectrometer/pixel_pointing/pixel_dec'][0,0:1] dist[ifile] = el_sun[0]#angular_seperation(ra_sun, ra, dec_sun, dec) data.close() good = (fnoise > -1.2) & (fnoise < -0.5) & np.isfinite(fnoise) & (fnoise != -1) with open('Plots/{}_good.list'.format(mode),'w') as f: for line in filelist[good]: f.write('{}\n'.format(line)) pyplot.errorbar(np.arange(fnoise.size),fnoise,fmt='.',yerr=enoise,capsize=3) pyplot.errorbar(np.arange(fnoise.size)[good],fnoise[good],fmt='.',yerr=enoise[good],capsize=3) pyplot.xticks(np.arange(fnoise.size),obsid, rotation=90,size=8) pyplot.ylim(-2,-0.8) pyplot.grid() pyplot.savefig('Plots/Fnoise_feed{}_{}.png'.format(feed,mode),bbox_inches='tight') pyplot.savefig('Plots/Fnoise_feed{}_{}.pdf'.format(feed,mode),bbox_inches='tight') pyplot.clf()
def fnoise_plots(mode,ifeed): filelist = np.loadtxt(sys.argv[1],dtype=str) obsid = np.array([int(f.split('-')[1]) for f in filelist]) filelist = filelist[np.argsort(obsid)] obsid = np.sort(obsid) fnoise = np.zeros(filelist.size) enoise = np.zeros(filelist.size) feed = None isfg4 = np.zeros(filelist.size,dtype=bool) dist = np.zeros(filelist.size) fnoise_power = np.zeros((filelist.size,64*4)) alphas = np.zeros((filelist.size,64*4)) for ifile, filename in enumerate(filelist): try: data = h5py.File(filename,'r') except OSError: print('{} cannot be opened (Resource unavailable)'.format(filename)) fnoise[ifile] = np.nan if mode.lower() in data['level1/comap'].attrs['source'].decode('utf-8').lower(): isfg4[ifile] = True try: fits = data['level2/fnoise_fits'][ifeed,:,:,:] fnoise[ifile] = np.median(fits[:,1]) enoise[ifile] = np.sqrt(np.median(np.abs(fits[:,1]-fnoise[ifile])**2))*1.4826 ps = data['level2/powerspectra'][ifeed,:,:,:] rms = data['level2/wnoise_auto'][ifeed,:,:,:] nu = data['level2/freqspectra'][ifeed,:,:,:] freq = data['level1/spectrometer/frequency'][...] bw = 16 freq = np.mean(np.reshape(freq, (freq.shape[0],freq.shape[1]//bw, bw)),axis=-1).flatten() sfreq = np.argsort(freq) fnoise_power[ifile,:] = (rms[:,:,0]**2 * (1/fits[:,:,0])**fits[:,:,1]).flatten()[sfreq] alphas[ifile,:] = (fits[:,:,1]).flatten()[sfreq] #print(nu.shape,ps.shape, rms.shape, fits.shape) #pyplot.plot(freq[sfreq],fnoise_power[ifile,:]) except IOError: print('{} not processed'.format(filename.split('/')[-1])) fnoise[ifile] = np.nan if isinstance(feed, type(None)): feed = data['level1/spectrometer/feeds'][ifeed] # Calculate sun distance mjd = data['level1/spectrometer/MJD'][0:1] lon=-118.2941 lat=37.2314 ra_sun, dec_sun, raddist = Coordinates.getPlanetPosition('SUN', lon, lat, mjd) az_sun, el_sun = Coordinates.e2h(ra_sun, dec_sun, mjd, lon, lat) ra = data['level1/spectrometer/pixel_pointing/pixel_ra'][0,0:1] dec = data['level1/spectrometer/pixel_pointing/pixel_dec'][0,0:1] dist[ifile] = el_sun[0]#angular_seperation(ra_sun, ra, dec_sun, dec) data.close() # Plot obs ID vs fnoise power pyplot.imshow(np.log10(fnoise_power*1e3),aspect='auto',origin='lower', extent=[np.min(freq),np.max(freq),-.5,fnoise_power.shape[0]-0.5]) pyplot.yticks(np.arange(fnoise_power.shape[0])-0.5, obsid, rotation=0, ha='right',va='center',size=10) ax = pyplot.gca() fig = pyplot.gcf() offset = ScaledTranslation(-0.08,0.02,fig.transFigure) for label in ax.yaxis.get_majorticklabels(): label.set_transform(label.get_transform() + offset) pyplot.grid() pyplot.xlabel('Frequency (GHz)') pyplot.ylabel('obs ID') pyplot.colorbar(label=r'$\mathrm{log}_{10}$(mK)') pyplot.title('Feed {}'.format(feed)) pyplot.savefig('Plots/fnoise_gfields_Feed{}.png'.format(feed),bbox_inches='tight') pyplot.clf() # Plot obs ID vs fnoise power pyplot.imshow(alphas,aspect='auto',origin='lower',vmin=-1.5,vmax=-0.9, extent=[np.min(freq),np.max(freq),-.5,fnoise_power.shape[0]-0.5]) pyplot.yticks(np.arange(fnoise_power.shape[0])-0.5, obsid, rotation=0, ha='right',va='center',size=10) ax = pyplot.gca() fig = pyplot.gcf() for label in ax.yaxis.get_majorticklabels(): label.set_transform(label.get_transform() + offset) pyplot.grid() pyplot.xlabel('Frequency (GHz)') pyplot.ylabel('obs ID') pyplot.colorbar(label=r'$\alpha$') pyplot.title('Feed {}'.format(feed)) pyplot.savefig('Plots/alphas_gfields_Feed{}.png'.format(feed),bbox_inches='tight') pyplot.clf()