mirror of
https://github.com/Richard-Sti/csiborgtools.git
synced 2025-04-18 21:30:55 +00:00
* Add more comments * Add flow paths * Simplify paths * Update default arguemnts * Update paths * Update param names * Update some of scipts for reading files * Add the Mike method option * Update plotting * Update fnames * Simplify things * Make more default options * Add print * Update * Downsample CF4 * Update numpyro selection * Add selection fitting nb * Add coeffs * Update script * Add nb * Add label * Increase number of steps * Update default params * Add more labels * Improve file name * Update nb * Fix little bug * Remove import * Update scales * Update labels * Add script * Update script * Add more * Add more labels * Add script * Add submit * Update spacing * Update submit scrips * Update script * Update defaults * Update defaults * Update nb * Update test * Update imports * Add script * Add support for Indranil void * Add a dipole * Update nb * Update submit * Update Om0 * Add final * Update default params * Fix bug * Add option to fix to LG frame * Add Vext label * Add Vext label * Update script * Rm fixed LG * rm LG stuff * Update script * Update bulk flow plotting * Update nb * Add no field option * Update defaults * Update nb * Update script * Update nb * Update nb * Add names to plots * Update nb * Update plot * Add more latex names * Update default * Update nb * Update np * Add plane slicing * Add nb with slices * Update nb * Update script * Upddate nb * Update nb
55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
# Copyright (C) 2022 Richard Stiskalek
|
|
# This program is free software; you can redistribute it and/or modify it
|
|
# under the terms of the GNU General Public License as published by the
|
|
# Free Software Foundation; either version 3 of the License, or (at your
|
|
# option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful, but
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
# Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License along
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
"""
|
|
Utility functions used in the rest of the `field` module to avoid circular
|
|
imports.
|
|
"""
|
|
from numba import jit
|
|
import numpy as np
|
|
import healpy
|
|
|
|
|
|
def force_single_precision(x):
|
|
"""Attempt to convert an array `x` to float32."""
|
|
if x.dtype != np.float32:
|
|
x = x.astype(np.float32)
|
|
return x
|
|
|
|
|
|
@jit(nopython=True)
|
|
def divide_nonzero(field0, field1):
|
|
"""Perform in-place `field0 /= field1` but only where `field1 != 0`."""
|
|
assert field0.shape == field1.shape, "Field shapes must match."
|
|
|
|
imax, jmax, kmax = field0.shape
|
|
for i in range(imax):
|
|
for j in range(jmax):
|
|
for k in range(kmax):
|
|
if field1[i, j, k] != 0:
|
|
field0[i, j, k] /= field1[i, j, k]
|
|
|
|
|
|
def nside2radec(nside):
|
|
"""
|
|
Generate RA [0, 360] deg and declination [-90, 90] deg for HEALPix pixel
|
|
centres at a given nside.
|
|
"""
|
|
pixs = np.arange(healpy.nside2npix(nside))
|
|
theta, phi = healpy.pix2ang(nside, pixs)
|
|
|
|
ra = 180 / np.pi * phi
|
|
dec = 90 - 180 / np.pi * theta
|
|
|
|
return np.vstack([ra, dec]).T
|