From 64bacc20dbf769ce07463c18743c6ee582d18672 Mon Sep 17 00:00:00 2001 From: rstiskalek Date: Thu, 1 Jun 2023 22:57:29 +0100 Subject: [PATCH] Add nside2radec --- csiborgtools/field/utils.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/csiborgtools/field/utils.py b/csiborgtools/field/utils.py index 9a953d2..db20d1d 100644 --- a/csiborgtools/field/utils.py +++ b/csiborgtools/field/utils.py @@ -17,6 +17,7 @@ Utility functions for the field module. """ from warnings import warn +import healpy import numpy import smoothing_library as SL @@ -65,3 +66,23 @@ def smoothen_field(field, smooth_scale, boxsize, threads=1): W_k = SL.FT_filter(boxsize, smooth_scale, field.shape[0], "Gaussian", threads) return SL.field_smoothing(field, W_k, threads) + + +def nside2radec(nside): + """ + Generate RA and declination for HEALPix pixel centres. + + Parameters + ---------- + nside : int + HEALPix nside parameter. + + Returns + ------- + radec : array of shape `(npix, 2)` + RA and declination in degrees. + """ + pixs = numpy.arange(healpy.nside2npix(nside)) + theta, phi = healpy.pix2ang(nside, pixs) + theta -= numpy.pi / 2 + return numpy.rad2deg(numpy.vstack([phi, theta]).T)