# *** set up calibration calarr = {} cal_fi = arange(0.0, nchan / 2, 0.5) fi = arange(freqs.shape[0]) cal_freqs = NP.interp(cal_fi, fi, freqs) curr_gains = 0.25 * NP.ones((n_antennas, len(cal_freqs)), dtype=NP.complex64) freq_ave = bchan for pol in pols: calarr[pol] = EPICal.cal(cal_freqs, antpos_info['positions'], pol=pol, sim_mode=False, n_iter=cal_iter, damping_factor=0.7, inv_gains=False, sky_model=sky_model, freq_ave=bchan, exclude_autos=True, phase_fit=False, curr_gains=curr_gains, ref_ant=5, flatten_array=True, n_cal_sources=1) if scramble_gains > 0: for i in NP.arange(NP.ceil(NP.float(nchan) / freq_ave)): mini = i * freq_ave maxi = NP.min((nchan, (i + 1) * freq_ave)) calarr[pol].curr_gains[:, mini:maxi] += ( NP.random.normal(0, NP.sqrt(scramble_gains), (n_antennas, 1)) + 1j * NP.random.normal(0, NP.sqrt(scramble_gains), (n_antennas, 1)))
sky_model[:, :, 0:3] = skypos.reshape(n_src, 1, 3) sky_model[:, :, 3] = src_flux.reshape(n_src, 1) #### set up calibration calarr = {} calarr_full = {} calarr_one = {} ant_pos = ant_info[:, 1:] # I'll let the cal class put it in wavelengths. for pol in ["P1", "P2"]: calarr_full[pol] = EPICal.cal( freqs, antpos_info["positions"], pol=pol, sim_mode=True, n_iter=cal_iter, damping_factor=damping_factor, inv_gains=False, sky_model=sky_model, exclude_autos=True, n_cal_sources=1, ) calarr_full[pol].sim_gains = NP.ones(calarr_full[pol].sim_gains.shape, dtype=NP.complex64) calarr_one[pol] = EPICal.cal( freqs, antpos_info["positions"], pol=pol, sim_mode=True, n_iter=cal_iter, damping_factor=damping_factor, inv_gains=False, sky_model=sky_model[-1, :, :].reshape(1, nchan, 4),
sky_model = NP.zeros((n_src, nchan, 4)) sky_model[:, :, 0:3] = skypos.reshape(n_src, 1, 3) sky_model[:, :, 3] = src_flux.reshape(n_src, 1) # sky_model=sky_model[0,:,:].reshape(1,nchan,4) sky_model = sky_model[-ind:, :, :] # *** set up calibration calarr = {} ant_pos = ant_info[:, 1:] # I'll let the cal class put it in wavelengths. # auto_noise_model = rxr_noise for pol in ['P1', 'P2']: calarr[pol] = EPICal.cal(freqs, ant_pos, pol=pol, sim_mode=True, n_iter=cal_iter, damping_factor=0.35, inv_gains=False, sky_model=sky_model, exclude_autos=True, conv_max_try=1) # Create array of gains to watch them change ncal = itr / cal_iter cali = 0 gain_stack = NP.zeros((ncal + 1, ant_info.shape[0], nchan), dtype=NP.complex64) for i in xrange(itr): print i # simulate E_timeseries_dict = SIM.stochastic_E_timeseries(f_center, nchan / 2, 2 * channel_width, flux_ref=src_flux, skypos=skypos, antpos=antpos_info['positions'], tshift=False)
sky_model = NP.zeros((n_src,nchan,4)) sky_model[:,:,0:3] = skypos.reshape(n_src,1,3) sky_model[:,:,3] = src_flux.reshape(n_src,1) #sky_model=sky_model[0,:,:].reshape(1,nchan,4) sky_model=sky_model[-ind:,:,:] #### set up calibration calarr={} ant_pos = ant_info[:,1:] # I'll let the cal class put it in wavelengths. auto_noise_model = rxr_noise for pol in ['P1','P2']: #calarr[pol] = EPICal.cal(ant_pos,freqs,n_iter=cal_iter,sim_mode=True,sky_model=sky_model,gain_factor=0.5,pol=pol,cal_method='multi_source',inv_gains=False) calarr[pol] = EPICal.cal(freqs,antpos_info['positions'],pol=pol,sim_mode=True,n_iter=cal_iter,damping_factor=0.35,inv_gains=False,sky_model=sky_model,exclude_autos=True,n_cal_sources=1) # Create array of gains to watch them change ncal=itr/cal_iter cali=0 gain_stack = NP.zeros((ncal+1,ant_info.shape[0],nchan),dtype=NP.complex64) for i in xrange(itr): print i # simulate E_timeseries_dict = SIM.stochastic_E_timeseries(f_center, nchan/2, 2*channel_width, flux_ref=src_flux, skypos=skypos, antpos=antpos_info['positions'],tshift=False) timestamp = str(DT.datetime.now()) update_info={}
skypos = NP.hstack((lmrad * NP.cos(lmang), lmrad * NP.sin(lmang))) nvect = NP.sqrt(1.0-NP.sum(skypos**2, axis=1)).reshape(-1,1) skypos = NP.hstack((skypos,nvect)) sky_model = NP.zeros((n_src,nchan,4)) sky_model[:,:,0:3] = skypos.reshape(n_src,1,3) sky_model[:,:,3] = src_flux.reshape(n_src,1) #### set up calibration calarr={} calarr_full={} calarr_one={} ant_pos = ant_info[:,1:] # I'll let the cal class put it in wavelengths. for pol in ['P1','P2']: calarr_full[pol] = EPICal.cal(freqs,antpos_info['positions'],pol=pol,sim_mode=True,n_iter=cal_iter,damping_factor=damping_factor,inv_gains=False,sky_model=sky_model,exclude_autos=True,n_cal_sources=1) calarr_full[pol].sim_gains = NP.ones(calarr_full[pol].sim_gains.shape,dtype=NP.complex64) calarr_one[pol] = EPICal.cal(freqs,antpos_info['positions'],pol=pol,sim_mode=True,n_iter=cal_iter,damping_factor=damping_factor,inv_gains=False,sky_model=sky_model[-1,:,:].reshape(1,nchan,4),exclude_autos=True,n_cal_sources=1) calarr_one[pol].sim_gains = NP.ones(calarr_one[pol].sim_gains.shape,dtype=NP.complex64) visdata = NP.zeros((n_antennas,n_antennas,nchan),dtype=NP.complex64) for i in xrange(itr): if i == 1: print 'rxr_noise=',rxr_noise print 'cal_iter=',cal_iter # simulate if i == 0: E_timeseries_dict = SIM.stochastic_E_timeseries(f_center, nchan/2, 2*channel_width, flux_ref=src_flux, skypos=skypos, antpos=antpos_info['positions'],tshift=False,verbose=False)
sky_model[:,:,0:3] = skypos.reshape(n_src,1,3) sky_model[:,:,3] = src_flux.reshape(n_src,1) #### set up calibration calarr={} cal_fi=arange(0.0,nchan/2,0.5) fi=arange(freqs.shape[0]) cal_freqs = NP.interp(cal_fi,fi,freqs) # auto noise term auto_noise_model = 0.25 * NP.sum(sky_model[:,0,3]) # roughly rxr:sky based on Ellingson, 2013 #auto_noise_model=0.0 curr_gains = 0.25*NP.ones((n_antennas,len(cal_freqs)),dtype=NP.complex64) freq_ave = bchan for pol in pols: calarr[pol] = EPICal.cal(cal_freqs,antpos_info['positions'],pol=pol,sim_mode=False,n_iter=cal_iter,damping_factor=0.7,inv_gains=False,sky_model=sky_model,freq_ave=bchan,exclude_autos=True,phase_fit=False,curr_gains=curr_gains,ref_ant=5,flatten_array=True,n_cal_sources=1) if scramble_gains > 0: for i in NP.arange(NP.ceil(NP.float(nchan)/freq_ave)): mini = i*freq_ave maxi = NP.min((nchan,(i+1)*freq_ave)) calarr[pol].curr_gains[:,mini:maxi] += NP.random.normal(0,NP.sqrt(scramble_gains),(n_antennas,1)) + 1j * NP.random.normal(0,NP.sqrt(scramble_gains),(n_antennas,1)) if initial_gains_file is not None: calarr['P1'].curr_gains = NP.load(initial_gains_file) # Create array of gains to watch them change ncal=max_n_timestamps/cal_iter cali=0 gain_stack = NP.zeros((ncal+1,ant_info.shape[0],nchan),dtype=NP.complex64) amp_stack = NP.zeros((ncal+1,nchan),dtype=NP.float64) amp_full_stack = NP.zeros((max_n_timestamps,nchan),dtype=NP.float64)
frac_flux=NP.sum(src_flux[-ind:])/tot_flux sky_model = NP.zeros((n_src,nchan,4)) sky_model[:,:,0:3] = skypos.reshape(n_src,1,3) sky_model[:,:,3] = src_flux.reshape(n_src,1) #sky_model=sky_model[0,:,:].reshape(1,nchan,4) sky_model=sky_model[-ind:,:,:] #### set up calibration calarr={} ant_pos = ant_info[:,1:] # I'll let the cal class put it in wavelengths. #auto_noise_model = rxr_noise for pol in ['P1','P2']: calarr[pol] = EPICal.cal(freqs,ant_pos,pol=pol,sim_mode=True,n_iter=cal_iter,damping_factor=0.35,inv_gains=False,sky_model=sky_model,exclude_autos=False) # Create array of gains to watch them change ncal=itr/cal_iter cali=0 gain_stack = NP.zeros((ncal+1,ant_info.shape[0],nchan),dtype=NP.complex64) PLT.ion() PLT.show() for i in xrange(itr): print i # simulate E_timeseries_dict = SIM.stochastic_E_timeseries(f_center, nchan/2, 2*channel_width, flux_ref=src_flux, skypos=skypos, antpos=antpos_info['positions'],tshift=False)