def __init__(self,d,path='~/comm/catalogues/TBGAL_CONVL.FITS'):#d, nu, pol """ First extract total power in each scan (both mean and standard deviation) """ T_skytemp = Sky_temp(inputfile=path) T_skytemp.set_freq( d.freqs[0]) T_sky = T_skytemp.Tsky self.units = d.data_unit self.name = d.antenna.name self.filename = args[0] self.elevation = {} self.Tsys = {} self.sigma_Tsys = {} self.Tsys_sky = {} self.T_sky = [] # Sort data in the order of ascending elevation elevation = np.array([np.average(scan_el) for scan_el in scape.extract_scan_data(d.scans,'el').data]) ra = np.array([np.average(scan_ra) for scan_ra in scape.extract_scan_data(d.scans,'ra').data]) dec = np.array([np.average(scan_dec) for scan_dec in scape.extract_scan_data(d.scans,'dec').data]) sort_ind = elevation.argsort() elevation,ra,dec = elevation[sort_ind],ra[sort_ind],dec[sort_ind] valid_el = (elevation >= 10) self.elevation = elevation[valid_el] self.ra = ra[valid_el] self.dec = dec[valid_el] self.surface_temperature = np.mean(d.enviro['temperature']['value'])# Extract surface temperature from weather data self.freq = d.freqs[0] #MHz Centre frequency of observation for pol in ['HH','VV']: power_stats = [scape.stats.mu_sigma(s.pol(pol)[:, 0]) for s in d.scans] tipping_mu, tipping_sigma = np.array([s[0] for s in power_stats]), np.array([s[1] for s in power_stats]) tipping_mu, tipping_sigma = tipping_mu[sort_ind], tipping_sigma[sort_ind] self.Tsys[pol] = tipping_mu[valid_el] self.sigma_Tsys[pol] = tipping_sigma[valid_el] self.Tsys_sky[pol] = [] self.T_sky = [] for val_el,ra,dec,el in zip(sort_ind,self.ra,self.dec,self.elevation): self.T_sky.append( T_sky(ra,dec)) self.Tsys_sky[pol].append(tipping_mu[val_el]-T_sky(ra,dec)) TmpSky = scape.fitting.PiecewisePolynomial1DFit() TmpSky.fit(self.elevation, self.T_sky) self.Tsky = TmpSky T_skytemp.plot_sky(self.ra,self.dec)
aperture_efficiency_v = "%s/ant_eff_%s_V_AsBuilt.csv"%(opts.aperture_efficiency,str.upper(Band)) aperture_efficiency = aperture_efficiency_models(filenameH=aperture_efficiency_h,filenameV=aperture_efficiency_v) spill_over_model_path = "%s/MK_%s_Tspill_AsBuilt_atm_mask.dat"%(spill_over_models,str.upper(Band)) SpillOver = Spill_Temp(filename=spill_over_model_path) #/var/kat/katconfig/user/spillover-models/mkat/MK_L_Tspill_AsBuilt_atm_mask.dat num_channels = np.int(channel_bw/(h5.channel_width/1e6)) #number of channels per band chunks=[h5.channels[x:x+num_channels] for x in range(0, len(h5.channels), num_channels)] print("Selecting channel data to form %f MHz Channels"%(channel_bw) ) d = load_cal(filename, "%s" % (ant.name,), nd_models, chunks,channel_mask=channel_mask,n_chan=n_chans,channel_range=freq_chans,band_input=Band.lower()) if not d is None: tsys = np.zeros((len(d.scans),len(d.freqs[:]),5))#*np.NaN tant = np.zeros((len(d.scans),len(d.freqs[:]),5))#*np.NaN receiver = Rec_Temp(receiver_model_H, receiver_model_V) elevation = np.array([np.average(scan_el) for scan_el in scape.extract_scan_data(d.scans,'el').data]) ra = np.array([np.average(scan_ra) for scan_ra in scape.extract_scan_data(d.scans,'ra').data]) dec = np.array([np.average(scan_dec) for scan_dec in scape.extract_scan_data(d.scans,'dec').data]) sort_ind = elevation.argsort() elevation,ra,dec = elevation[sort_ind],ra[sort_ind],dec[sort_ind] surface_temperature = np.mean(d.enviro['temperature']['value']) air_relative_humidity = h5.humidity.mean()/100. # Fractional length = 0 #freq loop for i,freq_val in enumerate(d.freqs): if not d is None: d.filename = [filename] nu = d.freqs #MHz Centre frequency of observation #print("PreLoad T_sysTemp = %.2f Seconds"%(time.time()-time_start)) T_SysTemp = System_Temp(d,d.freqs[i],freq_index=i,elevation=elevation,ra=ra,dec=dec,surface_temperature = surface_temperature,air_relative_humidity=air_relative_humidity) #print("Load T_sysTemp = %.2f Seconds"%(time.time()-time_start))
else: ant = opts.ant #h5.select(ants=ant) d = scape.DataSet(filename, baseline="%s,%s" % (ant, ant)) d = d.select(freqkeep=range(start_freq_channel, end_freq_channel + 1)) d = remove_rfi(d, width=21, sigma=5) # rfi flaging #Leave the d dataset unchanged after this so that it can be examined interactively if necessary antenna = d.antenna d_uncal = d.select(copy=True) d_uncal.average() d_cal = d.select(copy=True) print("do selects") #extract timestamps from data timestampfile = np.hstack([scan.timestamps for scan in d_cal.scans]) #get a user-friendly time axis that will plot in the same way as plot_xyz time = scape.extract_scan_data(d_cal.scans, 'time') tmin = np.min(np.hstack(time.data)) tmax = np.max(np.hstack(time.data)) #Get the gain from the noise diodes g_hh, g_vv, delta_re_hv, delta_im_hv = scape.gaincal.estimate_gain(d_cal) gain_hh = np.r_[gain_hh, g_hh(timestampfile, d.freqs).mean(axis=1)] gain_vv = np.r_[gain_vv, g_vv(timestampfile, d.freqs).mean(axis=1)] timestamps = np.r_[timestamps, timestampfile] print("Applied gains") print " gain_hh %i, gain_vv %i, timestamps %i" % ( gain_hh.shape[0], gain_vv.shape[0], timestamps.shape[0]) #Apply noise diode calibration if False: d_cal.convert_power_to_temperature(min_samples=opts.min_nd, time_width=opts.time_width) d_cal.average()