def test_sensitivity_w_rednoise(): '''Test making sensitivity curves with complex RN.''' psrs2 = hsim.sim_pta(timespan=timespan, cad=23, sigma=1e-7, phi=phi, theta=theta, A_rn=6e-16, alpha=-2 / 3., freqs=freqs) psrs3 = hsim.sim_pta(timespan=timespan, cad=23, sigma=1e-7, phi=phi, theta=theta, A_rn=A_rn, alpha=alphas, freqs=freqs) spectra2 = [] for p in psrs2: sp = hsen.Spectrum(p, freqs=freqs) _ = sp.NcalInv spectra2.append(sp) spectra3 = [] for p in psrs3: sp = hsen.Spectrum(p, freqs=freqs) _ = sp.NcalInv spectra3.append(sp) spec = spectra3[0] spec.Tf spec.S_I spec.S_R spec.h_c spec.Omega_gw sigma = spec.toaerrs.mean() dt = hsen.get_dt(spec.toas).to('s').value spec.add_white_noise_power(sigma, dt) spec.add_red_noise_power(A=6.8e-16, gamma=13 / 3.) spec.psd_prefit spec.psd_postfit spec.add_noise_power(spec.psd_prefit) hsen.corr_from_psd(freqs, spec.psd_prefit, spec.toas) sc2a = hsen.GWBSensitivityCurve(spectra2) sc2b = hsen.DeterSensitivityCurve(spectra2) sc3a = hsen.GWBSensitivityCurve(spectra3) sc3b = hsen.DeterSensitivityCurve(spectra3) sc3a.h_c sc3a.Omega_gw sc3a.S_effIJ sc3b.h_c sc3b.Omega_gw
def sc_simple(): '''Test and keep a simple sensitivity curve''' psrs = hsim.sim_pta(timespan=timespan, cad=23, sigma=1e-7, phi=phi, theta=theta) psr = psrs[0] hsen.R_matrix(psr.designmatrix, psr.N) hsen.G_matrix(psr.designmatrix) hsen.quantize_fast(psr.toas, psr.toaerrs) hsen.get_Tf(psr.designmatrix, psr.toas, psr.N, from_G=True, exact_astro_freqs=True) spectra = [] for p in psrs: sp = hsen.Spectrum(p, freqs=freqs) _ = sp.NcalInv spectra.append(sp) sc1a = hsen.GWBSensitivityCurve(spectra) sc1b = hsen.DeterSensitivityCurve(spectra) return sc1a, sc1b
def test_simple_pta(pta_simple): """Sensitivity Tests""" spectra = [] for p in pta_simple: sp = hsen.Spectrum(p, freqs=freqs) sp.Tf spectra.append(sp) hsen.GWBSensitivityCurve(spectra) hsen.DeterSensitivityCurve(spectra) hsky.SkySensitivity(spectra,theta_gw,phi_gw)
def test_nonGR(): psrs = hsim.sim_pta(timespan=timespan, cad=23, sigma=1e-7, phi=phi,theta=theta) spectra = [] for p in psrs: sp = hsen.Spectrum(p, freqs=freqs) _ = sp.NcalInv spectra.append(sp) hsen.GWBSensitivityCurve(spectra, orf='st') hsen.GWBSensitivityCurve(spectra, orf='dipole') hsen.GWBSensitivityCurve(spectra, orf='monopole')
def Init_PTA(self): """Initializes a PTA in hasasia Notes ----- See Hazboun, Romano, Smith (2019) <https://arxiv.org/abs/1907.04341> for details """ #Random Sky Locations of Pulsars phi = np.random.uniform(0, 2 * np.pi, size=self.N_p) cos_theta = np.random.uniform(-1, 1, size=self.N_p) theta = np.arccos(cos_theta) if hasattr(self, 'A_GWB'): if not hasattr(self, 'alpha_GWB'): self.alpha_GWB = -2 / 3. #Make a set of psrs with the same parameters with a GWB as red noise psrs = hassim.sim_pta(timespan=self.T_obs.value,cad=self.cadence.value,sigma=self.sigma.value,\ phi=phi, theta=theta, Npsrs=self.N_p,A_rn=self.A_GWB,alpha=self.alpha_GWB,freqs=self.fT.value) elif hasattr(self, 'A_rn_min') or hasattr(self, 'alpha_rn_min'): if not hasattr(self, 'A_rn_min'): A_rn = np.random.uniform(1e-16, 1e-12, size=self.N_p) else: A_rn = np.random.uniform(self.A_rn_min, self.A_rn_max, size=self.N_p) if not hasattr(self, 'alpha_rn_min'): alphas = np.random.uniform(-3 / 4, 1, size=self.N_p) else: alphas = np.random.uniform(self.alpha_rn_min, self.alpha_rn_max, size=self.N_p) #Make a set of psrs with uniformly sampled red noise psrs = hassim.sim_pta(timespan=self.T_obs.value,cad=self.cadence.value,sigma=self.sigma.value,\ phi=phi, theta=theta, Npsrs=self.N_p,A_rn=A_rn,alpha=alphas,freqs=self.fT.value) else: #Make a set of psrs with the same parameters psrs = hassim.sim_pta(timespan=self.T_obs.value,cad=self.cadence.value,sigma=self.sigma.value,\ phi=phi, theta=theta, Npsrs=self.N_p,freqs=self.fT.value) #Get Spectra of pulsars spectra = [] for p in psrs: sp = hassens.Spectrum(p, freqs=self.fT.value) spectra.append(sp) self._sensitivitycurve = hassens.DeterSensitivityCurve(spectra)
def sm_simple(): '''Test and keep a simple sensitivity skymap''' #Make a set of random sky positions phi = np.random.uniform(0, 2 * np.pi, size=33) cos_theta = np.random.uniform(-1, 1, size=33) theta = np.arccos(cos_theta) #Adding one well-placed sky position for plots. phi = np.append(np.array(np.deg2rad(60)), phi) theta = np.append(np.array(np.deg2rad(50)), theta) #Define the timsespans and TOA errors for the pulsars timespans = np.random.uniform(3.0, 11.4, size=34) Tspan = timespans.max() * 365.25 * 24 * 3600 sigma = 1e-7 # 100 ns #Simulate a set of identical pulsars, with different sky positions. psrs = hsim.sim_pta(timespan=11.4, cad=23, sigma=sigma, phi=phi, theta=theta) freqs = np.logspace(np.log10(1 / (5 * Tspan)), np.log10(2e-7), 500) spectra = [] for p in psrs: sp = hsen.Spectrum(p, freqs=freqs) sp.NcalInv spectra.append(sp) #Normally use the healpy functions to get the sky coordinates #Here just pull random coordinates using numpy to avoid needing healpy phi_gw = np.random.uniform(0, 2 * np.pi, size=1000) cos_theta_gw = np.random.uniform(-1, 1, size=1000) theta_gw = np.arccos(cos_theta_gw) SM = hsky.SkySensitivity(spectra, theta_gw, phi_gw) return SM
if args.A_gwb != 0.0: gwb = hsen.red_noise_powerlaw(A=args.A_gwb, gamma=13 / 3., freqs=freqs) corr += hsen.corr_from_psd(freqs=freqs, psd=gwb, toas=ePsr.toas[::thin]) if args.rednoise: Amp, gam = rn[ePsr.name] plaw = hsen.red_noise_powerlaw(A=Amp, gamma=gam, freqs=freqs) corr += hsen.corr_from_psd(freqs=freqs, psd=plaw, toas=ePsr.toas[::thin]) psr = hsen.Pulsar(toas=ePsr.toas[::thin], toaerrs=ePsr.toaerrs[::thin], phi=ePsr.phi, theta=ePsr.theta, N=corr, designmatrix=ePsr.Mmat[::thin, :]) psr.name = ePsr.name _ = psr.G if args.savepsr: with open(args.outdir + f'/{args.label}_psr_{ePsr.name}.has', 'wb') as fout: pickle.dump(psr, fout) sp = hsen.Spectrum(psr, freqs=freqs) sp.name = psr.name _ = sp.NcalInv _ = sp.P_n with open(args.outdir + f'/{args.label}_spec_{ePsr.name}.has', 'wb') as fout: pickle.dump(sp, fout)