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.
= 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([[0], [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. ],
[1.04719755]])
plt.imshow(source_map)
="coord") source_map.argmax(unit
array([0. , 1.04719755])
="pix") source_map.argmax(unit
array([54, 72])
-1] source_pos[:,
array([0. , 1.04719755])
-source_map.argmax(unit="coord") + source_pos[:, -1]
array([ 0.00000000e+00, -6.66133815e-16])
max() source_map.
array(1158.8864, dtype=float32)
min() source_map.
array(0., dtype=float32)
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.0, 1.0471975511965976]
= source_map.submap(box) cutout
max() cutout.
array(1158.8864, dtype=float32)
min() cutout.
array(0., dtype=float32)
plt.imshow(cutout)
2 * fwhm) aperture_photometry(cutout,
9.99300220192394