def getsky(self): """Create a map of the unpolarised sky. """ lmax = 3 * self.nside - 1 cla = skysim.clarray(self.angular_powerspectrum, lmax, self.nu_pixels, zromb=self.oversample) return (self.mean_nu(self.nu_pixels)[:, np.newaxis] + skysim.mkfullsky(cla, self.nside))
def getsky(self): """Create a map of the unpolarised sky.""" lmax = 3 * self.nside - 1 cla = skysim.clarray(self.angular_powerspectrum, lmax, self.nu_pixels, zromb=self.oversample) return self.mean_nu(self.nu_pixels)[:, np.newaxis] + skysim.mkfullsky( cla, self.nside)
def gaussianfg(ctx): """Generate a full-sky Gaussian random field for synchrotron emission. """ import numpy as np from cora.core import skysim from cora.util import hputil from cora.foreground import galaxy fsyn = galaxy.FullSkySynchrotron() fpol = galaxy.FullSkyPolarisedSynchrotron() # Set frequency parameters fsyn.frequencies = ctx.obj.freq nfreq = len(fsyn.frequencies) nside = ctx.obj.nside lmax = 3 * nside npol = 4 if ctx.obj.full_pol else 1 cv_fg = np.zeros((lmax + 1, npol, nfreq, npol, nfreq)) cv_fg[:, 0, :, 0, :] = skysim.clarray(fsyn.angular_powerspectrum, lmax, fsyn.nu_pixels) if ctx.obj.full_pol: cv_fg[:, 1, :, 1, :] = skysim.clarray(fpol.angular_powerspectrum, lmax, fsyn.nu_pixels) cv_fg[:, 2, :, 2, :] = skysim.clarray(fpol.angular_powerspectrum, lmax, fsyn.nu_pixels) cv_fg = cv_fg.reshape(lmax + 1, npol * nfreq, npol * nfreq) alms = skysim.mkfullsky(cv_fg, nside, alms=True).reshape(npol, nfreq, lmax + 1, lmax + 1) alms = alms.transpose((1, 0, 2, 3)) maps = hputil.sphtrans_inv_sky(alms, nside) write_map(ctx.obj.filename, maps, fsyn.frequencies, ctx.obj.freq_width, ctx.obj.include_pol)
def foreground_model(lmax, frequencies, npol, pol_frac=1.0, pol_length=None): fsyn = galaxy.FullSkySynchrotron() fps = PointSources() nfreq = frequencies.size cv_fg = np.zeros((npol, npol, lmax+1, nfreq, nfreq)) cv_fg[0, 0] = skysim.clarray(fsyn.angular_powerspectrum, lmax, frequencies) if npol >= 3: fpol = galaxy.FullSkyPolarisedSynchrotron() if pol_length is not None: fpol.zeta = pol_length cv_fg[1, 1] = pol_frac * skysim.clarray(fpol.angular_powerspectrum, lmax, frequencies) cv_fg[2, 2] = pol_frac * skysim.clarray(fpol.angular_powerspectrum, lmax, frequencies) cv_fg[0, 0] += skysim.clarray(fps.angular_powerspectrum, lmax, frequencies) return cv_fg
def foreground_model(lmax, frequencies, npol, pol_frac=1.0, pol_length=None): fsyn = galaxy.FullSkySynchrotron() fps = PointSources() nfreq = frequencies.size cv_fg = np.zeros((npol, npol, lmax + 1, nfreq, nfreq)) cv_fg[0, 0] = skysim.clarray(fsyn.angular_powerspectrum, lmax, frequencies) if npol >= 3: fpol = galaxy.FullSkyPolarisedSynchrotron() if pol_length is not None: fpol.zeta = pol_length cv_fg[1, 1] = pol_frac * skysim.clarray(fpol.angular_powerspectrum, lmax, frequencies) cv_fg[2, 2] = pol_frac * skysim.clarray(fpol.angular_powerspectrum, lmax, frequencies) cv_fg[0, 0] += skysim.clarray(fps.angular_powerspectrum, lmax, frequencies) return cv_fg
def im21cm_model(lmax, frequencies, npol, cr = None, temponly=False): nfreq = frequencies.size if not cr: global _cr if not _cr: if not _reionisation: _cr = corr21cm.Corr21cm() else: _cr = corr21cm.EoR21cm() cr = _cr #cr._freq_window = np.abs(cr.cosmology.comoving_distance(frequencies[0]) - cr.cosmology.comoving_distance(frequencies[1])) cv_t = skysim.clarray(cr.angular_powerspectrum, lmax, frequencies) if temponly: return cv_t else: cv_sg = np.zeros((npol, npol, lmax+1, nfreq, nfreq)) cv_sg[0, 0] = cv_t return cv_sg
def im21cm_model(lmax, frequencies, npol, cr=None, temponly=False): nfreq = frequencies.size if not cr: global _cr if not _cr: if not _reionisation: _cr = corr21cm.Corr21cm() else: _cr = corr21cm.EoR21cm() cr = _cr #cr._freq_window = np.abs(cr.cosmology.comoving_distance(frequencies[0]) - cr.cosmology.comoving_distance(frequencies[1])) cv_t = skysim.clarray(cr.angular_powerspectrum, lmax, frequencies) if temponly: return cv_t else: cv_sg = np.zeros((npol, npol, lmax + 1, nfreq, nfreq)) cv_sg[0, 0] = cv_t return cv_sg
def getalms(self, lmax): cla = skysim.clarray(self.angular_powerspectrum, lmax, self.nu_pixels) return skysim.mkfullsky(cla, self.nside, alms=True)
def getsky(self, debug=False, celestial=True): """Create a realisation of the *unpolarised* sky. Parameters ---------- debug : boolean, optional Return intermediate products for debugging. Default is False. celestial : boolean, optional Maps are returned in celestial co-ordinates. Returns ------- skymap : np.ndarray[freq, pixel] """ # Read in data files. haslam = healpy.ud_grade(self._haslam, self.nside) syn = FullSkySynchrotron() lmax = 3 * self.nside - 1 efreq = np.concatenate((np.array([408.0, 1420.0]), self.nu_pixels)) ## Construct map of random fluctuations # cla = skysim.clarray(syn.angular_powerspectrum, lmax, efreq, zwidth=(self.nu_pixels[1] - self.nu_pixels[0])) cla = skysim.clarray(syn.angular_powerspectrum, lmax, efreq, zromb=0) fg = skysim.mkfullsky(cla, self.nside) ## Find the smoothed fluctuations on each scale sub408 = healpy.smoothing(fg[0], fwhm=np.radians(1.0), verbose=False) sub1420 = healpy.smoothing(fg[1], fwhm=np.radians(5.8), verbose=False) ## Make a multifrequency map constrained to look like the smoothed maps ## depending on the spectral_map apply constraints at upper and lower frequency (GSM), ## or just at Haslam map frequency if self.spectral_map == "gsm": fgs = skysim.mkconstrained(cla, [(0, sub408), (1, sub1420)], self.nside) else: fgs = skysim.mkconstrained(cla, [(0, sub408)], self.nside) # Construct maps of appropriate resolution sc = healpy.ud_grade(self._sp_ind[self.spectral_map], self.nside) am = healpy.ud_grade(self._amp_map, self.nside) ## Bump up the variance of the fluctuations according to the variance # map vm = healpy.smoothing(fg[0], sigma=np.radians(0.5), verbose=False) vm = healpy.smoothing(map_variance(vm, 16) ** 0.5, sigma=np.radians(2.0), verbose=False) mv = vm.mean() ## Construct the fluctuations map fgt = (am / mv) * (fg - fgs) ## Get the smooth, large scale emission from Haslam+spectralmap fgsmooth = haslam[np.newaxis, :] * ((efreq / 408.0)[:, np.newaxis] ** sc) # Rescale to ensure output is always positive tanh_lin = lambda x: np.where(x < 0, np.tanh(x), x) fg2 = (fgsmooth * (1.0 + tanh_lin(fgt / fgsmooth)))[2:] ## Co-ordinate transform if required if celestial: fg2 = hputil.coord_g2c(fg2) if debug: return fg2, fg, fgs, fgt, fgsmooth, am, mv return fg2
def getalms(self, lmax): cla = skysim.clarray(self.angular_powerspectrum, lmax, self.nu_pixels) return skysim.mkfullsky(cla, self.nside, alms=True)
def getsky(self, debug=False, celestial=True): """Create a realisation of the *unpolarised* sky. Parameters ---------- debug : boolean, optional Return intermediate products for debugging. Default is False. celestial : boolean, optional Maps are returned in celestial co-ordinates. Returns ------- skymap : np.ndarray[freq, pixel] """ # Read in data files. haslam = healpy.ud_grade(self._haslam, self.nside) syn = FullSkySynchrotron() lmax = 3 * self.nside - 1 efreq = np.concatenate((np.array([408.0, 1420.0]), self.nu_pixels)) # Construct map of random fluctuations cla = skysim.clarray(syn.angular_powerspectrum, lmax, efreq, zromb=0) fg = skysim.mkfullsky(cla, self.nside) # Find the smoothed fluctuations on each scale sub408 = healpy.smoothing(fg[0], fwhm=np.radians(1.0), verbose=False) sub1420 = healpy.smoothing(fg[1], fwhm=np.radians(5.8), verbose=False) # Make a multifrequency map constrained to look like the smoothed maps # depending on the spectral_map apply constraints at upper and lower # frequency (GSM), or just at Haslam map frequency if self.spectral_map == 'gsm': fgs = skysim.mkconstrained(cla, [(0, sub408), (1, sub1420)], self.nside) else: fgs = skysim.mkconstrained(cla, [(0, sub408)], self.nside) # Construct maps of appropriate resolution sc = healpy.ud_grade(self._sp_ind[self.spectral_map], self.nside) am = healpy.ud_grade(self._amp_map, self.nside) # Bump up the variance of the fluctuations according to the variance map vm = healpy.smoothing(fg[0], sigma=np.radians(0.5), verbose=False) vm = healpy.smoothing(map_variance(vm, 16)**0.5, sigma=np.radians(2.0), verbose=False) mv = vm.mean() # Construct the fluctuations map fgt = (am / mv) * (fg - fgs) if not debug: del fg, fgs # Get the smooth, large scale emission from Haslam+spectralmap fgsmooth = haslam[np.newaxis, :] * ((efreq / 408.0)[:, np.newaxis]**sc) # Rescale to ensure output is always positive, do this inplace where # possible to save memory def tanh_lin(x): return np.where(x < 0, np.tanh(x), x) fgt /= fgsmooth fgt = tanh_lin(fgt) fgt += 1 fgt *= fgsmooth fgt = fgt[2:] # Co-ordinate transform if required if celestial: fgt = hputil.coord_g2c(fgt) if debug: return fgt, fg, fgs, fgsmooth, am, mv return fgt