def test_beam2bl(self): """ Test beam2bl against analytical transform of Gaussian beam. """ theta = np.linspace(0, np.radians(1.), 1000) sigma = np.radians(10. / 60.) / np.sqrt(8. * np.log(2.)) gaussian_beam = np.exp(-.5 * (theta / sigma) ** 2) / (2 * np.pi * sigma ** 2) ell = np.arange(512 + 1.) gaussian_window = np.exp(-.5 * ell * (ell + 1) * sigma ** 2) bl = hp.beam2bl(gaussian_beam, theta, 512) np.testing.assert_allclose(gaussian_window, bl, rtol=1e-5)
def test_beam2bl(self): """ Test beam2bl against analytical transform of Gaussian beam. """ theta = np.linspace(0, np.radians(1.0), 1000) sigma = np.radians(10.0 / 60.0) / np.sqrt(8.0 * np.log(2.0)) gaussian_beam = np.exp(-0.5 * (theta / sigma) ** 2) / (2 * np.pi * sigma ** 2) ell = np.arange(512 + 1.0) gaussian_window = np.exp(-0.5 * ell * (ell + 1) * sigma ** 2) bl = hp.beam2bl(gaussian_beam, theta, 512) np.testing.assert_allclose(gaussian_window, bl, rtol=1e-5)
def __call__(self, frequencies): """ Create Realistic beam models """ lmax = 5 * self.nside - 1 self.nfreqs = len(frequencies) nsamples = 2048 self.model = np.zeros((self.nfreqs, nsamples)) self.tfunc = np.zeros((self.nfreqs, lmax + 1)) self.fwhm = np.zeros(self.nfreqs) self.fwhm_frequencies = frequencies * 1. # setup wls = self.c / frequencies / 1e6 r = np.linspace(0, self.dish_diameter / 2., 1000) # m # First create beam model, then the equivalent transfer function for i, wl in enumerate(tqdm(wls)): # self.clats in degrees self.model[i, :], self.clats = self.BeamFunction( self.ApertureFunc, r, self.aperture_taper_width, wl, thetamax=self.thetamax, nsamples=self.nsamples) good = self.model[i, :] > 0.4 pmdl = interp1d(self.model[i, good], self.clats[good]) self.fwhm[i] = pmdl(0.5) * 2 self.tfunc[i, :] = hp.beam2bl(self.model[i, :], self.clats * np.pi / 180., lmax=lmax) self.tfunc[i, :] /= self.tfunc[i, 1] self.diffraction_constant = np.polyfit( wls / self.dish_diameter * 180. / np.pi, self.fwhm, 1)[1] self.data['model'] = self.model self.data['theta'] = self.clats self.data['beam_cl'] = self.tfunc self.info['theta'] = {'Unit': 'degrees'} self.data['diffraction_constant'] = (self.diffraction_constant, ) self.data['FWHM'] = self.fwhm
def __call__(self, frequencies, fwhm=None): """ Create the gaussian beam models """ gauss = lambda x, sigma: np.exp(-0.5 * (x / sigma)**2) lmax = 5 * self.nside self.nfreqs = len(frequencies) nsamples = 2048 thetamax = 5 self.model = np.zeros((self.nfreqs, nsamples)) self.tfunc = np.zeros((self.nfreqs, lmax + 1)) wls = self.c / frequencies / 1e6 if isinstance(fwhm, type(None)): fwhm = wls / self.dish_diameter * self.diffraction_constant * 180. / np.pi else: self.diffraction_constant = np.polyfit( wls / self.dish_diameter * 180. / np.pi, fwhm, 1)[1] self.clats = np.linspace(0, thetamax, nsamples) # First create beam model, then the equivalent transfer function for i, wl in enumerate(tqdm(wls)): # self.clats are calculate by BeamFunction in degrees, thus FWHM in degrees self.model[i, :] = gauss(self.clats, fwhm[i] / 2.355) self.tfunc[i, :] = hp.beam2bl(self.model[i, :], self.clats * np.pi / 180., lmax=lmax) self.tfunc[i, :] /= self.tfunc[i, 1] self.data['model'] = self.model self.data['theta'] = self.clats self.data['beam_cl'] = self.tfunc self.data['FWHM'] = fwhm self.info['theta'] = {'Unit': 'degrees'} self.data['diffraction_constant'] = (self.diffraction_constant, )