Skip to content

utils

A set of utility functions and constants used for unit conversions and cosmology as well as some generically useful math functions.

K_CMB2K_RJ(freq)

Convert from K_CMB to K_RJ.

Parameters:

Name Type Description Default
freq float

The observing frequency in Hz.

required

Returns:

Name Type Description
K_CMB2K_RJ float

Conversion factor from K_CMB to K_RJ.

Source code in witch/utils.py
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
@partial(jax.jit, static_argnums=(0,))
def K_CMB2K_RJ(freq: float) -> float:
    """
    Convert from K_CMB to K_RJ.

    Parameters
    ----------
    freq : float
        The observing frequency in Hz.

    Returns
    -------
    K_CMB2K_RJ : float
        Conversion factor from K_CMB to K_RJ.
    """
    x = freq * h / kb / Tcmb
    return jnp.exp(x) * x * x / jnp.expm1(x) ** 2

K_RJ2Jy_beam(freq, omega)

Convert from K_RJ to Jy/beam. This is monochromatic, no bandpass integration is done.

Parameters:

Name Type Description Default
freq float

The observing frequency in Hz.

required
omega float

The beam solid angle in square arcseconds. For a single gaussian beam this is gauss_solid_angle([fwhm], [1]).

required

Returns:

Name Type Description
K_RJ2Jy_beam float

Conversion factor from K_RJ to Jy/beam.

Source code in witch/utils.py
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
def K_RJ2Jy_beam(freq: float, omega: float) -> float:
    """
    Convert from K_RJ to Jy/beam.
    This is monochromatic, no bandpass integration is done.

    Parameters
    ----------
    freq : float
        The observing frequency in Hz.
    omega : float
        The beam solid angle in square arcseconds.
        For a single gaussian beam this is `gauss_solid_angle([fwhm], [1])`.

    Returns
    -------
    K_RJ2Jy_beam : float
        Conversion factor from K_RJ to Jy/beam.
    """
    omega_sr = omega / rad_to_arcsec**2
    return 2 * kb * freq**2 / const.c.value**2 * omega_sr * 1e26

beam_double_gauss(dr, fwhm1, amp1, fwhm2, amp2, max_npix=None)

Helper function to generate a double gaussian beam. This is beam_multi_gauss with two components.

Parameters:

Name Type Description Default
dr float

Pixel size.

required
fwhm1 float

Full width half max of the primary gaussian in the same units as dr.

required
amp1 float

Amplitude of the primary gaussian.

required
fwhm2 float

Full width half max of the secondairy gaussian in the same units as dr.

required
amp2 float

Amplitude of the secondairy gaussian.

required
max_npix int | None

Maximum size of the beam in pixels, usually the size of the model grid. See beam_multi_gauss.

None

Returns:

Type Description
beam: Double gaussian beam, normalized to unit sum.
Source code in witch/utils.py
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
def beam_double_gauss(
    dr: float,
    fwhm1: float,
    amp1: float,
    fwhm2: float,
    amp2: float,
    max_npix: int | None = None,
) -> jax.Array:
    """
    Helper function to generate a double gaussian beam.
    This is `beam_multi_gauss` with two components.

    Parameters
    ----------
    dr : float
        Pixel size.
    fwhm1 : float
        Full width half max of the primary gaussian in the same units as `dr`.
    amp1 : float
        Amplitude of the primary gaussian.
    fwhm2 : float
        Full width half max of the secondairy gaussian in the same units as `dr`.
    amp2 : float
        Amplitude of the secondairy gaussian.
    max_npix : int | None, default: None
        Maximum size of the beam in pixels, usually the size of the model grid.
        See `beam_multi_gauss`.

    Returns
    -------
        beam: Double gaussian beam, normalized to unit sum.
    """
    return beam_multi_gauss(dr, [fwhm1, fwhm2], [amp1, amp2], max_npix=max_npix)

beam_multi_gauss(dr, fwhms, amps, extent=1.5, max_npix=None)

Generate a beam made of concentric gaussians, normalized to unit sum.

Parameters:

Name Type Description Default
dr float

Pixel size.

required
fwhms Sequence[float]

FWHM of each gaussian in the same units as dr.

required
amps Sequence[float]

Relative peak amplitude of each gaussian.

required
extent float

The beam is evaluated out to extent times the largest FWHM of the gaussians with non-zero amplitude.

1.5
max_npix int | None

Maximum size of the beam in pixels, usually the size of the model grid since beam_conv can't use a beam larger than the grid. If the beam would be larger it is cropped to this size (with a warning) and renormalized.

None

Returns:

Name Type Description
beam Array

The beam, normalized to sum to 1. This has an even shape with the peak at index shape // 2, which is where beam_conv expects it for (the usual) even sized grids.

Source code in witch/utils.py
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
def beam_multi_gauss(
    dr: float,
    fwhms: Sequence[float],
    amps: Sequence[float],
    extent: float = 1.5,
    max_npix: int | None = None,
) -> jax.Array:
    """
    Generate a beam made of concentric gaussians, normalized to unit sum.

    Parameters
    ----------
    dr : float
        Pixel size.
    fwhms : Sequence[float]
        FWHM of each gaussian in the same units as `dr`.
    amps : Sequence[float]
        Relative peak amplitude of each gaussian.
    extent : float, default: 1.5
        The beam is evaluated out to `extent` times the largest FWHM
        of the gaussians with non-zero amplitude.
    max_npix : int | None, default: None
        Maximum size of the beam in pixels, usually the size of the model grid
        since `beam_conv` can't use a beam larger than the grid.
        If the beam would be larger it is cropped to this size (with a warning)
        and renormalized.

    Returns
    -------
    beam : jax.Array
        The beam, normalized to sum to 1.
        This has an even shape with the peak at index `shape // 2`,
        which is where `beam_conv` expects it for (the usual) even sized grids.
    """
    fwhms = np.atleast_1d(np.asarray(fwhms, dtype=float))
    amps = np.atleast_1d(np.asarray(amps, dtype=float))
    if len(fwhms) != len(amps):
        raise ValueError("fwhms and amps must have the same length")
    if not np.any(amps != 0):
        raise ValueError("At least one beam component needs a non-zero amplitude")
    half = int(np.ceil(extent * np.max(fwhms[amps != 0]) / dr))
    if max_npix is not None and 2 * half > max_npix:
        new_half = int(max_npix) // 2
        print(
            f"Warning: beam with FWHMs {fwhms.tolist()} needs {2 * half} pixels "
            f"but the grid only has {max_npix}, cropping the beam to {2 * new_half} pixels"
        )
        half = new_half
    x = jnp.arange(-half, half) * dr
    beam_xx, beam_yy = jnp.meshgrid(x, x)
    beam_rr2 = beam_xx**2 + beam_yy**2
    beam = jnp.zeros_like(beam_rr2)
    for fwhm, amp in zip(fwhms, amps):
        beam += amp * jnp.exp(-4 * jnp.log(2) * beam_rr2 / fwhm**2)
    return beam / jnp.sum(beam)

bilinear_interp(x, y, xp, yp, fp)

JAX implementation of bilinear interpolation. Out of bounds values are set to 0. Using the repeated linear interpolation method here, see https://en.wikipedia.org/wiki/Bilinear_interpolation#Repeated_linear_interpolation.

Parameters:

Name Type Description Default
x Array

X values to return interpolated values at.

required
y Array

Y values to return interpolated values at.

required
xp Array

X values to interpolate with, should be 1D. Assumed to be sorted and within one cell of uniformly spaced.

required
yp Array

Y values to interpolate with, should be 1D. Assumed to be sorted and within one cell of uniformly spaced.

required
fp Array

Functon values at (xp, yp), should have shape (len(xp), len(yp)). Note that if you are using meshgrid, we assume 'ij' indexing.

required

Returns:

Name Type Description
f Array

The interpolated values.

Source code in witch/utils.py
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
@jax.jit
def bilinear_interp(
    x: jax.Array, y: jax.Array, xp: jax.Array, yp: jax.Array, fp: jax.Array
) -> jax.Array:
    """
    JAX implementation of bilinear interpolation.
    Out of bounds values are set to 0.
    Using the repeated linear interpolation method here,
    see https://en.wikipedia.org/wiki/Bilinear_interpolation#Repeated_linear_interpolation.

    Parameters
    ----------
    x : jax.Array
        X values to return interpolated values at.
    y : jax.Array
        Y values to return interpolated values at.
    xp : jax.Array
        X values to interpolate with, should be 1D.
        Assumed to be sorted and within one cell of uniformly spaced.
    yp : jax.Array
        Y values to interpolate with, should be 1D.
        Assumed to be sorted and within one cell of uniformly spaced.
    fp : jax.Array
        Functon values at `(xp, yp)`, should have shape `(len(xp), len(yp))`.
        Note that if you are using meshgrid, we assume `'ij'` indexing.

    Returns
    -------
    f : jax.Array
        The interpolated values.
    """
    if len(xp.shape) != 1:
        raise ValueError("xp must be 1D")
    if len(yp.shape) != 1:
        raise ValueError("yp must be 1D")
    if fp.shape != xp.shape + yp.shape:
        raise ValueError(
            "Incompatible shapes for fp, xp, yp: %s, %s, %s",
            fp.shape,
            xp.shape,
            yp.shape,
        )

    # Figure out bounds and mapping
    # This breaks if xp, yp is not sorted and approximately uniform
    ix = _cell_index(x, xp)
    iy = _cell_index(y, yp)
    q_11 = fp[ix - 1, iy - 1]
    q_21 = fp[ix, iy - 1]
    q_12 = fp[ix - 1, iy]
    q_22 = fp[ix, iy]

    # Interpolate in x to start
    denom_x = xp[ix] - xp[ix - 1]
    dx_1 = x - xp[ix - 1]
    dx_2 = xp[ix] - x
    f_xy1 = (dx_2 * q_11 + dx_1 * q_21) / denom_x
    f_xy2 = (dx_2 * q_12 + dx_1 * q_22) / denom_x

    # Now do y as well
    denom_y = yp[iy] - yp[iy - 1]
    dy_1 = y - yp[iy - 1]
    dy_2 = yp[iy] - y
    f = (dy_2 * f_xy1 + dy_1 * f_xy2) / denom_y

    # Zero out the out of bounds values
    f = jnp.where((x < xp[0]) + (x > xp[-1]) + (y < yp[0]) + (y > yp[-1]), 0.0, f)

    return f

bin_map(data, pixsize)

Bins data radially.

Parameters:

Name Type Description Default
data ArrayLike

Data to be radially binned

required
pixsize float

Pixel spacing for data

required

Returns:

Name Type Description
rs array

Left bin edges

bin1d array

Mean of pixels in bin

var1d array

Variance of pixels in bin

Source code in witch/utils.py
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
def bin_map(data: ArrayLike, pixsize: float) -> tuple[np.array, np.array, np.array]:
    """
    Bins data radially.

    Parameters
    ----------
    data : ArrayLike
        Data to be radially binned
    pixsize : float
        Pixel spacing for data

    Returns
    -------
    rs : np.array
        Left bin edges
    bin1d : np.array
        Mean of pixels in bin
    var1d : np.array
        Variance of pixels in bin
    """
    x = np.linspace(
        -data.shape[1] / 2 * pixsize, data.shape[1] / 2 * pixsize, data.shape[1]
    )
    y = np.linspace(
        -data.shape[0] / 2 * pixsize, data.shape[0] / 2 * pixsize, data.shape[0]
    )

    X, Y = np.meshgrid(x, y)
    R = np.sqrt(X**2 + Y**2)  # TODO: miscentering?

    rs = np.arange(0, np.amax(R), pixsize)
    rs = np.append(rs, 999999)
    bin1d = np.zeros(len(rs) - 1)
    var1d = np.zeros(len(rs) - 1)

    for k in range(len(rs) - 1):
        pixels = [
            data[i, j]
            for i in range(len(y))
            for j in range(len(x))
            if rs[k] < R[i, j] <= rs[k + 1]
        ]
        if len(pixels) == 0:
            bin1d[k] = 0
            var1d[k] = 0
        else:
            bin1d[k] = np.mean(pixels)
            var1d[k] = np.var(pixels)
    rs = rs[:-1]

    return rs, bin1d, var1d

fft_conv(image, kernel)

Perform a convolution using FFTs for speed with jax.

Parameters:

Name Type Description Default
image ArrayLike

Data to be convolved.

required
kernel ArrayLike

Convolution kernel.

required

Returns:

Name Type Description
convolved_map Array

Image convolved with kernel.

Source code in witch/utils.py
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
@jax.jit
def fft_conv(image: ArrayLike, kernel: ArrayLike) -> jax.Array:
    """
    Perform a convolution using FFTs for speed with jax.

    Parameters
    ----------
    image : ArrayLike
        Data to be convolved.
    kernel : ArrayLike
        Convolution kernel.

    Returns
    -------
    convolved_map : jax.Array
        Image convolved with kernel.
    """
    Fmap = jnp.fft.fft2(jnp.fft.fftshift(image))
    Fkernel = jnp.fft.fft2(jnp.fft.fftshift(kernel))
    convolved_map = jnp.fft.fftshift(jnp.real(jnp.fft.ifft2(Fmap * Fkernel)))

    return convolved_map

fft_deconv(image, kernel)

Perform a convolution using FFTs for speed with jax.

Parameters:

Name Type Description Default
image ArrayLike

Data to be convolved.

required
kernel ArrayLike

Convolution kernel.

required

Returns:

Name Type Description
convolved_map Array

Image convolved with kernel.

Source code in witch/utils.py
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
@jax.jit
def fft_deconv(image: ArrayLike, kernel: ArrayLike) -> jax.Array:
    """
    Perform a convolution using FFTs for speed with jax.

    Parameters
    ----------
    image : ArrayLike
        Data to be convolved.
    kernel : ArrayLike
        Convolution kernel.

    Returns
    -------
    convolved_map : jax.Array
        Image convolved with kernel.
    """
    Fmap = jnp.fft.fft2(jnp.fft.fftshift(image))
    Fkernel = jnp.fft.fft2(jnp.fft.fftshift(kernel))
    convolved_map = jnp.fft.fftshift(jnp.real(jnp.fft.ifft2(Fmap / Fkernel)))

    return convolved_map

gauss_solid_angle(fwhms, amps)

Solid angle of a beam made of concentric gaussians, normalized to a peak of 1.

Parameters:

Name Type Description Default
fwhms Sequence[float]

FWHM of each gaussian in arcseconds.

required
amps Sequence[float]

Relative peak amplitude of each gaussian.

required

Returns:

Name Type Description
omega float

The beam solid angle in square arcseconds.

Source code in witch/utils.py
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
def gauss_solid_angle(fwhms: Sequence[float], amps: Sequence[float]) -> float:
    """
    Solid angle of a beam made of concentric gaussians, normalized to a peak of 1.

    Parameters
    ----------
    fwhms : Sequence[float]
        FWHM of each gaussian in arcseconds.
    amps : Sequence[float]
        Relative peak amplitude of each gaussian.

    Returns
    -------
    omega : float
        The beam solid angle in square arcseconds.
    """
    fwhms = np.atleast_1d(np.asarray(fwhms, dtype=float))
    amps = np.atleast_1d(np.asarray(amps, dtype=float))
    sigmas = fwhms / np.sqrt(8 * np.log(2))
    return float(2 * np.pi * np.sum(amps * sigmas**2) / np.sum(amps))

get_da(z)

Get factor to convert from arcseconds to MPc.

Parameters:

Name Type Description Default
z ArrayLike

The redshift at which to compute the factor.

required

Returns:

Name Type Description
da Array

Conversion factor from arcseconds to MPc.

Source code in witch/utils.py
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
@jax.jit
def get_da(z: ArrayLike) -> jax.Array:
    """
    Get factor to convert from arcseconds to MPc.

    Parameters
    ----------
    z : ArrayLike
        The redshift at which to compute the factor.

    Returns
    -------
    da : jax.Array
        Conversion factor from arcseconds to MPc.
    """
    return jnp.interp(z, zline, daline)

get_hz(z)

Get the dimensionless hubble constant, h, at a given redshift.

Parameters:

Name Type Description Default
z ArrayLike

The redshift at which to compute h.

required

Returns:

Name Type Description
hz Array

h at the given z.

Source code in witch/utils.py
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
@jax.jit
def get_hz(z: ArrayLike) -> jax.Array:
    """
    Get the dimensionless hubble constant, h, at a given redshift.

    Parameters
    ----------
    z : ArrayLike
        The redshift at which to compute h.

    Returns
    -------
    hz : jax.Array
        h at the given z.
    """
    return jnp.interp(z, zline, hzline)

get_nz(z)

Get the critical density at a given redshift.

Parameters:

Name Type Description Default
z ArrayLike

The redshift at which to compute the critical density.

required

Returns:

Name Type Description
nz Array

Critical density at the given z. This is in units of solar masses per cubic Mpc.

Source code in witch/utils.py
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
@jax.jit
def get_nz(z: ArrayLike) -> jax.Array:
    """
    Get the critical density at a given redshift.

    Parameters
    ----------
    z : ArrayLike
        The redshift at which to compute the critical density.

    Returns
    -------
    nz : jax.Array
        Critical density at the given z.
        This is in units of solar masses per cubic Mpc.
    """
    return jnp.interp(z, zline, nzline)

tod_hi_pass(tod, N_filt)

High pass a tod with a tophat

Parameters:

Name Type Description Default
tod Array

TOD to high pass.

required
N_filt int

N_filt of tophat.

required

Returns:

Name Type Description
tod_filtered Array

High pass filtered TOD

Source code in witch/utils.py
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
@partial(jax.jit, static_argnums=(1,))
def tod_hi_pass(tod: jax.Array, N_filt: int) -> jax.Array:
    """
    High pass a tod with a tophat

    Parameters
    ----------
    tod : jax.Array
        TOD to high pass.
    N_filt : int
        N_filt of tophat.

    Returns
    -------
    tod_filtered : jax.Array
        High pass filtered TOD
    """
    mask = jnp.ones(tod.shape)
    mask = mask.at[..., :N_filt].set(0.0)

    ## apply the filter in fourier space
    Ftod = jnp.fft.fft(tod)
    Ftod_filtered = Ftod * mask
    tod_filtered = jnp.fft.ifft(Ftod_filtered).real
    return tod_filtered

y2Jy_beam(freq, Te, omega, colour_corr=1.0)

Convert from compton y to Jy/beam. This is monochromatic, no bandpass integration is done.

Parameters:

Name Type Description Default
freq float

The observing frequency in Hz.

required
Te float

Electron temperature

required
omega float

The beam solid angle in square arcseconds.

required
colour_corr float

Colour correction C_s defined as S_true = S_measured * C_s, so the measured signal is the true signal divided by this. See eq. 17 of Perotto et al. 2020 for NIKA2.

1.0

Returns:

Name Type Description
y2Jy_beam float

Conversion factor from compton y to Jy/beam.

Source code in witch/utils.py
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
def y2Jy_beam(freq: float, Te: float, omega: float, colour_corr: float = 1.0) -> float:
    """
    Convert from compton y to Jy/beam.
    This is monochromatic, no bandpass integration is done.

    Parameters
    ----------
    freq : float
        The observing frequency in Hz.
    Te : float
        Electron temperature
    omega : float
        The beam solid angle in square arcseconds.
    colour_corr : float, default: 1.0
        Colour correction C_s defined as S_true = S_measured * C_s,
        so the measured signal is the true signal divided by this.
        See eq. 17 of Perotto et al. 2020 for NIKA2.

    Returns
    -------
    y2Jy_beam : float
        Conversion factor from compton y to Jy/beam.
    """
    return float(y2K_RJ(freq, Te)) * K_RJ2Jy_beam(freq, omega) / colour_corr

y2K_CMB(freq, Te)

Convert from compton y to K_CMB.

Parameters:

Name Type Description Default
freq float

The observing frequency in Hz.

required
Te float

Electron temperature

required

Returns:

Name Type Description
y2K_CMB float

Conversion factor from compton y to K_CMB.

Source code in witch/utils.py
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
@partial(jax.jit, static_argnums=(0, 1))
def y2K_CMB(freq: float, Te: float) -> float:
    """
    Convert from compton y to K_CMB.

    Parameters
    ----------
    freq : float
        The observing frequency in Hz.
    Te : float
        Electron temperature

    Returns
    -------
    y2K_CMB : float
        Conversion factor from compton y to K_CMB.
    """
    x = freq * h / kb / Tcmb
    xt = x / jnp.tanh(0.5 * x)
    st = x / jnp.sinh(0.5 * x)
    # fmt:off
    Y0 = -4.0 + xt
    Y1 = (-10.0
        + ((47.0 / 2.0) + (-(42.0 / 5.0) + (7.0 / 10.0) * xt) * xt) * xt
        + st * st * (-(21.0 / 5.0) + (7.0 / 5.0) * xt)
    )
    Y2 = ((-15.0 / 2.0)
        + ((1023.0 / 8.0) + ((-868.0 / 5.0) + ((329.0 / 5.0) + ((-44.0 / 5.0) + (11.0 / 30.0) * xt) * xt) * xt) * xt) * xt
        + ((-434.0 / 5.0) + ((658.0 / 5.0) + ((-242.0 / 5.0) + (143.0 / 30.0) * xt) * xt) * xt
        + (-(44.0 / 5.0) + (187.0 / 60.0) * xt) * (st * st)) * st * st
    )
    Y3 = ((15.0 / 2.0)
        + ((2505.0 / 8.0) + ((-7098.0 / 5.0) + ((14253.0 / 10.0) + ((-18594.0 / 35.0) 
         + ((12059.0 / 140.0) + ((-128.0 / 21.0) + (16.0 / 105.0) * xt) * xt) * xt) * xt) * xt) * xt) * xt
        + (((-7098.0 / 10.0) + ((14253.0 / 5.0) + ((-102267.0 / 35.0) + ((156767.0 / 140.0)
         + ((-1216.0 / 7.0) + (64.0 / 7.0) * xt) * xt) * xt) * xt) * xt)
         + (((-18594.0 / 35.0) + ((205003.0 / 280.0) + ((-1920.0 / 7.0) + (1024.0 / 35.0) * xt) * xt) * xt)
          + ((-544.0 / 21.0) + (992.0 / 105.0) * xt) * st * st) * st * st) * st * st
    )
    Y4 = ((-135.0 / 32.0)
        + ((30375.0 / 128.0) + ((-62391.0 / 10.0) + ((614727.0 / 40.0) + ((-124389.0 / 10.0) + ((355703.0 / 80.0) + ((-16568.0 / 21.0)
         + ((7516.0 / 105.0) + ((-22.0 / 7.0) + (11.0 / 210.0) * xt) * xt) * xt) * xt) * xt) * xt) * xt) * xt) * xt
        + ((-62391.0 / 20.0) + ((614727.0 / 20.0) + ((-1368279.0 / 20.0) + ((4624139.0 / 80.0) + ((-157396.0 / 7.0) + ((30064.0 / 7.0)
         + ((-2717.0 / 7.0) + (2761.0 / 210.0) * xt) * xt) * xt) * xt) * xt) * xt) * xt
         + ((-124389.0 / 10.0)
          + ((6046951.0 / 160.0) + ((-248520.0 / 7.0) + ((481024.0 / 35.0) + ((-15972.0 / 7.0) + (18689.0 / 140.0) * xt) * xt) * xt) * xt) * xt
          + ((-70414.0 / 21.0) + ((465992.0 / 105.0) + ((-11792.0 / 7.0) + (19778.0 / 105.0) * xt) * xt) * xt
           + ((-682.0 / 7.0) + (7601.0 / 210.0) * xt) * st * st) * st * st) * st * st) * st * st
    )
    # fmt:on
    factor = Y0 + (Te / me) * (
        Y1 + (Te / me) * (Y2 + (Te / me) * (Y3 + (Te / me) * Y4))
    )
    return factor * Tcmb

y2K_RJ(freq, Te)

Convert from compton y to K_RJ.

Parameters:

Name Type Description Default
freq float

The observing frequency in Hz.

required
Te float

Electron temperature

required

Returns:

Name Type Description
y2K_RJ float

Conversion factor from compton y to K_RJ.

Source code in witch/utils.py
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
@partial(jax.jit, static_argnums=(0, 1))
def y2K_RJ(freq: float, Te: float) -> float:
    """
    Convert from compton y to K_RJ.

    Parameters
    ----------
    freq : float
        The observing frequency in Hz.
    Te : float
        Electron temperature

    Returns
    -------
    y2K_RJ : float
        Conversion factor from compton y to K_RJ.
    """
    factor = y2K_CMB(freq, Te)
    return factor * K_CMB2K_RJ(freq)

y2uK_CMB(freq, Te)

Convert from compton y to uK_CMB.

Parameters:

Name Type Description Default
freq float

The observing frequency in Hz.

required
Te float

Electron temperature

required

Returns:

Name Type Description
y2uK_RJ float

Conversion factor from compton y to uK_CMB.

Source code in witch/utils.py
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
@partial(jax.jit, static_argnums=(0, 1))
def y2uK_CMB(freq: float, Te: float) -> float:
    """
    Convert from compton y to uK_CMB.

    Parameters
    ----------
    freq : float
        The observing frequency in Hz.
    Te : float
        Electron temperature

    Returns
    -------
    y2uK_RJ : float
        Conversion factor from compton y to uK_CMB.
    """
    factor = y2K_CMB(freq, Te)
    return 1e6 * factor