from pixell import enmap, utils, resample, curvedsky as cs, reproject, pointsrcs
import numpy as np
import healpy as hp
Testing the pixell sim_objects
functionality to create maps of point sources pre-smoothed with a gaussian beam. The purpose is to include this functionality in PySM to be able to generate on the fly maps of source starting from a catalog.
Compared to the previous notebook, here I also use reproject
to convert the map to HEALPix, plot the result and check the flux in HEALPix also agrees with the input.
= 5 * utils.degree fwhm
= enmap.fullsky_geometry(res=fwhm / 3, proj="car") shape, wcs
shape
(109, 216)
def fwhm2sigma(fwhm):
return fwhm / (2.0 * np.sqrt(2.0 * np.log(2.0)))
def flux2amp(flux, fwhm):
= fwhm2sigma(fwhm)
sigma return flux / (2 * np.pi * sigma**2)
assert flux2amp((2 * np.pi * fwhm2sigma(5) ** 2), 5) == 1
= 1
n_sources = np.arange(n_sources) + 10 flux_sources
= flux2amp(flux_sources, fwhm) amplitude_sources
= np.array([[np.pi/4], [np.pi/3]]) source_pos
= pointsrcs.expand_beam(fwhm2sigma(fwhm)) r, p
= pointsrcs.sim_objects(shape, wcs, source_pos, amplitude_sources, ((r, p))) source_map
import matplotlib.pyplot as plt
source_pos
array([[0.78539816],
[1.04719755]])
plt.imshow(source_map)
def aperture_photometry(
=None, modrmap=None, pixsizemap=None
thumbs, aperture_radius, annulus_width
):"""
Flux from aperture photometry.
from https://github.com/msyriac/orphics/blob/master/orphics/maps.py
Parameters
----------
thumb : ndmap
An (...,Ny,Nx) ndmap (i.e. a pixell enmap) containing the thumbnails.
aperture_radius : float
Aperture inner radius in radians
annulus_width : float
Annulus width for mean subtraction in radians.
Defaults to sqrt(2)-1 times the aperture inner radius.
modrmap : ndmap, optional
An (Ny,Nx) ndmap containing distances of each pixel from the center in radians.
modrmap : ndmap, optional
An (Ny,Nx) ndmap containing pixel areas in steradians.
Returns
-------
flux : ndarray
(...,) array of aperture photometry fluxes.
"""
if modrmap is None:
= thumbs.modrmap()
modrmap if annulus_width is None:
= (np.sqrt(2.0) - 1.0) * aperture_radius
annulus_width # Get the mean background level from the annulus
= thumbs[
mean
...,
np.logical_and(> aperture_radius, modrmap < (aperture_radius + annulus_width)
modrmap
),
].mean()if pixsizemap is None:
= thumbs.pixsizemap()
pixsizemap # Subtract the mean, multiply by pixel areas and sum
return (((thumbs - mean) * pixsizemap)[..., modrmap <= aperture_radius]).sum(
=-1
axis )
from astropy import units as u
= 2 * fwhm
box_half_size_rad = [source_pos[0, -1], source_pos[1, -1]]
box_center = np.array(
box
[0] - box_half_size_rad, box_center[1] - box_half_size_rad],
[box_center[0] + box_half_size_rad, box_center[1] + box_half_size_rad],
[box_center[
]# in radians )
box_center
[0.7853981633974483, 1.0471975511965976]
= source_map.submap(box) cutout
plt.imshow(cutout)
2 * fwhm) aperture_photometry(cutout,
9.982631206252375
/3 fwhm
0.02908882086657216
from pixell import reproject
= reproject.map2healpix(source_map) source_map_healpix
hp.npix2nside(source_map_healpix.size)
64
hp.nside2resol(_)
0.015989479811663883
hp.mollview(source_map_healpix)
=hp.vec2ang(hp.ang2vec(source_pos[0], source_pos[1]), lonlat=True), xsize=1900, reso=.5) hp.gnomview(source_map_healpix, rot
from pysm3.utils import healpix_aperture_photometry
0,0], source_pos[1,0], 2 * fwhm) healpix_aperture_photometry(source_map_healpix, source_pos[
9.995092243734167