else: lst = 0.5 * (lst_edges_left + lst_edges_right) t_snap = (lst_edges_right - lst_edges_left) / 15.0 * 3.6e3 else: t_snap = 112.0 + NP.zeros( n_snaps) # in seconds (needs to be generalized) lst = lst_wrapped + 0.5 * t_snap / 3.6e3 * 15.0 # pointings_dircos_orig = GEOM.altaz2dircos(pointings_altaz_orig, units='degrees') # pointings_hadec_orig = GEOM.altaz2hadec(pointings_altaz_orig, latitude, units='degrees') # pointings_radec_orig = NP.hstack(((lst-pointings_hadec_orig[:,0]).reshape(-1,1), pointings_hadec_orig[:,1].reshape(-1,1))) # pointings_radec_orig[:,0] = pointings_radec_orig[:,0] % 360.0 pointings_dircos = GEOM.altaz2dircos(pointings_altaz, units='degrees') pointings_hadec = GEOM.altaz2hadec(pointings_altaz, latitude, units='degrees') pointings_radec = NP.hstack(((lst - pointings_hadec[:, 0]).reshape(-1, 1), pointings_hadec[:, 1].reshape(-1, 1))) pointings_radec[:, 0] = pointings_radec[:, 0] % 360.0 t_obs = NP.sum(t_snap) elif pointing_info is not None: pointing_init = NP.asarray(pointing_info[1:]) lst_init = pointing_info[0] pointing_file = None if t_snap is None: raise NameError( 't_snap must be provided for an automated observing run') if (n_snaps is None) and (t_obs is None): raise NameError(
n_sky_sectors = 1 sky_sector = None # if None, use all sky sector. Accepted values are None, 0, 1, 2, or 3 if sky_sector is None: sky_sector_str = '_all_sky_' n_sky_sectors = 1 sky_sector = 0 else: sky_sector_str = '_sky_sector_{0:0d}_'.format(sky_sector) pointing_file = '/data3/t_nithyanandan/project_MWA/Aug23_obsinfo.txt' pointing_info_from_file = NP.loadtxt(pointing_file, skiprows=2, comments='#', usecols=(1,2,3), delimiter=',') obs_id = NP.loadtxt(pointing_file, skiprows=2, comments='#', usecols=(0,), delimiter=',', dtype=str) lst = 15.0 * pointing_info_from_file[:,2] pointings_altaz = OPS.reverse(pointing_info_from_file[:,:2].reshape(-1,2), axis=1) pointings_dircos = GEOM.altaz2dircos(pointings_altaz, units='degrees') pointings_hadec = GEOM.altaz2hadec(pointings_altaz, latitude, units='degrees') max_abs_delay = 2.5 # in micro seconds nside = 128 use_GSM = True use_DSM = False use_CSM = False use_NVSS = False use_SUMSS = False use_MSS = False use_GLEAM = False use_PS = False if use_GSM: fg_str = 'asm'
def observe( self, timestamp, Tsys, bandpass, pointing_center, skymodel, tobs, pb_min=0.1, fov_radius=None, lst=None ): if bandpass.size != self.bp.shape[1]: raise ValueError("bandpass length does not match.") self.Tsys = self.Tsys + [Tsys] self.vis_rms_freq = self.vis_rms_freq + [ 2.0 * FCNST.k * Tsys / self.A_eff / self.eff_Q / NP.sqrt(2) / tobs / self.freq_resolution / CNST.Jy ] self.tobs = self.tobs + [tobs] self.lst = self.lst + [lst] if self.timestamp == []: self.bp = NP.asarray(bandpass).reshape(1, -1) self.pointing_center = NP.asarray(pointing_center).reshape(1, -1) else: self.bp = NP.vstack((self.bp, NP.asarray(bandpass).reshape(1, -1))) self.pointing_center = NP.vstack((self.pointing_center, NP.asarray(pointing_center).reshape(1, -1))) pointing_lon = self.pointing_center[-1, 0] pointing_lat = self.pointing_center[-1, 1] if self.skycoords == "radec": if self.pointing_coords == "hadec": if lst is not None: pointing_lon = lst - self.pointing_center[-1, 0] pointing_lat = self.pointing_center[-1, 1] else: raise ValueError( "LST must be provided. Sky coordinates are in RA-Dec format while pointing center is in HA-Dec format." ) elif self.pointing_coords == "altaz": pointing_lonlat = lst - GEOM.altaz2hadec(self.pointing_center[-1, :], self.latitude, units="degrees") pointing_lon = pointing_lonlat[0] pointing_lat = pointing_lonlat[1] elif self.skycoords == "hadec": if self.pointing_coords == "radec": if lst is not None: pointing_lon = lst - self.pointing_center[-1, 0] pointing_lat = self.pointing_center[-1, 1] else: raise ValueError( "LST must be provided. Sky coordinates are in RA-Dec format while pointing center is in HA-Dec format." ) elif self.pointing_coords == "altaz": pointing_lonlat = lst - GEOM.altaz2hadec(self.pointing_center[-1, :], self.latitude, units="degrees") pointing_lon = pointing_lonlat[0] pointing_lat = pointing_lonlat[1] else: if self.pointing_coords == "radec": if lst is not None: pointing_lonlat = GEOM.hadec2altaz( NP.asarray([lst - self.pointing_center[-1, 0], self.pointing_center[-1, 1]]), self.latitude, units="degrees", ) pointing_lon = pointing_lonlat[0] pointing_lat = pointing_lonlat[1] else: raise ValueError( "LST must be provided. Sky coordinates are in Alt-Az format while pointing center is in RA-Dec format." ) elif self.pointing_coords == "hadec": pointing_lonlat = GEOM.hadec2altaz(self.pointing_center, self.latitude, units="degrees") pointing_lon = pointing_lonlat[0] pointing_lat = pointing_lonlat[1] pointing_phase = 0.0 baseline_in_local_frame = self.baseline if self.baseline_coords == "equatorial": baseline_in_local_frame = GEOM.xyz2enu(self.baseline, self.latitude, "degrees") ptmp = self.pointing_center[-1, :] # Convert pointing center to Alt-Az coordinates if self.pointing_coords == "hadec": ptmp = GEOM.hadec2altaz(self.pointing_center[-1, :], self.latitude, units="degrees") elif self.pointing_coords == "radec": if lst is not None: ptmp = GEOM.hadec2altaz( NP.asarray([lst - self.pointing_center[-1, 0], self.pointing_center[-1, 1]]), self.latitude, units="degrees", ) else: raise ValueError( "LST must be provided. Sky coordinates are in Alt-Az format while pointing center is in RA-Dec format." ) ptmp = GEOM.altaz2dircos(ptmp, "degrees") # Convert pointing center to direction cosine coordinates pointing_phase = ( 2.0 * NP.pi * NP.dot(baseline_in_local_frame.reshape(1, -1), ptmp.reshape(-1, 1)) * self.channels.reshape(1, -1) / FCNST.c ) if fov_radius is None: fov_radius = 90.0 # PDB.set_trace() m1, m2, d12 = GEOM.spherematch( pointing_lon, pointing_lat, skymodel.catalog.location[:, 0], skymodel.catalog.location[:, 1], fov_radius, maxmatches=0, ) # if fov_radius is not None: # m1, m2, d12 = GEOM.spherematch(pointing_lon, pointing_lat, skymodel.catalog.location[:,0], skymodel.catalog.location[:,1], fov_radius, maxmatches=0) # else: # m1 = [0] * skymodel.catalog.location.shape[0] # m2 = xrange(skymodel.catalog.location.shape[0]) # d12 = GEOM.sphdist(NP.empty(skymodel.catalog.shape[0]).fill(pointing_lon), NP.empty(skymodel.catalog.shape[0]).fill(pointing_lat), skymodel.catalog.location[:,0], skymodel.catalog.location[:,1]) if len(d12) != 0: pb = NP.empty((len(d12), len(self.channels))) fluxes = NP.empty((len(d12), len(self.channels))) coords_str = self.skycoords if self.skycoords == "radec": coords_str = "altaz" source_positions = GEOM.hadec2altaz( NP.hstack( ( NP.asarray(lst - skymodel.catalog.location[m2, 0]).reshape(-1, 1), skymodel.catalog.location[m2, 1].reshape(-1, 1), ) ), self.latitude, "degrees", ) for i in xrange(len(self.channels)): # pb[:,i] = PB.primary_beam_generator(d12, self.channels[i]/1.0e9, 'degrees', self.telescope) pb[:, i] = PB.primary_beam_generator( source_positions, self.channels[i] / 1.0e9, "altaz", self.telescope ) fluxes[:, i] = ( skymodel.catalog.flux_density[m2] * (self.channels[i] / skymodel.catalog.frequency) ** skymodel.catalog.spectral_index[m2] ) geometric_delays = DLY.geometric_delay( baseline_in_local_frame, source_positions, altaz=(coords_str == "altaz"), hadec=(coords_str == "hadec"), latitude=self.latitude, ) self.geometric_delays = self.geometric_delays + [geometric_delays.reshape(len(source_positions))] phase_matrix = 2.0 * NP.pi * NP.repeat( geometric_delays.reshape(-1, 1), len(self.channels), axis=1 ) * NP.repeat(self.channels.reshape(1, -1), len(d12), axis=0) - NP.repeat(pointing_phase, len(d12), axis=0) skyvis = NP.sum( pb * fluxes * NP.repeat(NP.asarray(bandpass).reshape(1, -1), len(d12), axis=0) * NP.exp(-1j * phase_matrix), axis=0, ) if fov_radius is not None: self.obs_catalog_indices = self.obs_catalog_indices + [m2] # self.obs_catalog = self.obs_catalog + [skymodel.catalog.subset(m2)] else: print "No sources found in the catalog within matching radius. Simply populating the observed visibilities with noise." skyvis = NP.zeros((1, len(self.channels))) if self.timestamp == []: self.skyvis_freq = skyvis.reshape(1, -1) self.vis_noise_freq = self.vis_rms_freq[-1] * ( NP.random.randn(len(self.channels)).reshape(1, -1) + 1j * NP.random.randn(len(self.channels)).reshape(1, -1) ) self.vis_freq = self.skyvis_freq + self.vis_noise_freq else: self.skyvis_freq = NP.vstack((self.skyvis_freq, skyvis.reshape(1, -1))) self.vis_noise_freq = NP.vstack( ( self.vis_noise_freq, self.vis_rms_freq[-1] * ( NP.random.randn(len(self.channels)).reshape(1, -1) + 1j * NP.random.randn(len(self.channels)).reshape(1, -1) ), ) ) self.vis_freq = NP.vstack( (self.vis_freq, (self.skyvis_freq[-1, :] + self.vis_noise_freq[-1, :]).reshape(1, -1)) ) self.timestamp = self.timestamp + [timestamp]