Serval
Main Library
Core.py
TripleSHIntegrator
A class for performing integrals of the products of three functions on the sphere expressed as their spherical harmonic transformations.
This class provides methods for this integration performed with a variety of techniques using Gaunt coefficients and grid-based approaches. It supports caching for efficient repeated computations when changing only one of the functions. Additionally it allows for computing the Fourier transform of these integrals in an azimuthal rotation angle of one of the functions (always the 1st) around the others, ie. the \(m\)-modes.
That is,
where
etc.
For the \(m\)-modes:
where \(\matr{\mathcal{R}}_Z(-\phi)\) is a passive basis rotation about the polar axis of the sphere.
Notes
The index of the functions only matters in differentiating from the others the first function/set of coefficients as the integration can be split up in \(m_1\) values. Additionally integrals can be performed rotating this function azimuthally around the others. That is, for the purposes of this code, this represents the sky.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
l1max
|
int
|
Maximum spherical harmonic degree for the first set of coefficients. |
required |
l2max
|
int
|
Maximum spherical harmonic degree for the second set of coefficients. |
required |
l3max
|
int
|
Maximum spherical harmonic degree for the third set of coefficients. |
required |
absm1_limits
|
tuple[int, int | None]
|
Inclusive lower and exclusive upper limits for the absolute value of the m1 index. Defaults to (0, None), ie, all m1 values. |
required |
generate_cache_on_init
|
bool
|
Whether to generate the Gaunt coefficient cache during initialization, by default False. |
required |
Attributes:
Name | Type | Description |
---|---|---|
l1max |
int
|
Maximum spherical harmonic degree for the first set of coefficients. |
l2max |
int
|
Maximum spherical harmonic degree for the second set of coefficients. |
l3max |
int
|
Maximum spherical harmonic degree for the third set of coefficients. |
absm1_limits |
tuple[int, int | None]
|
Inclusive lower and exclusive upper limits for the absolute value of the m1 index. |
generate_cache_on_init |
bool
|
Whether to generate the Gaunt coefficient cache during initialization. |
m1_values |
list[int]
|
List of m1 values that integrations are performed for. |
m1_index_map |
dict[int, int]
|
Mapping of m1 values to their indices in a completed set of m1 values. |
Methods:
Name | Description |
---|---|
generate_gaunt_cache |
Generates the Gaunt coefficient cache. |
clear_gaunt_cache |
Clears the Gaunt coefficient cache. |
sparse_gaunt_einsum |
Performs sparse tensor contraction using computed Gaunt coefficients. |
grid_integrate |
Performs integration using a grid-based approach. |
gaunt_integrate |
Performs integration using a direct sum over precomputed Gaunt coefficients. |
linear_gaunt_integrator_12 |
Computes a linear integrator for fixed first and second sets of coefficients. |
generate_integrator_cache_12 |
batch_parallel_mode="channel") Generates and caches the linear integrator for fixed first and second sets of coefficients. |
batch_gaunt_integrate_cached_12 |
Uses a integrator cache for fixed first and second sets of coefficients to compute integrals over a batch of the third set of coefficients. |
linear_gaunt_integrator_23 |
Computes a linear integrator for fixed second and third sets of coefficients. |
generate_integrator_cache_23 |
Generates and caches the linear integrator for fixed second and third sets of coefficients. |
batch_gaunt_integrate_cached_12 |
Uses a integrator cache for fixed second and third sets of coefficients to compute integrals over a bacth of the first set of coefficients. |
Source code in src/serval/core.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 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 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 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 488 489 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 523 |
|
clear_gaunt_cache()
gaunt_integrate(alm1, alm2, alm3, sum_m1=False)
Perform the triple integral by doing and inplace sum-product over gaunt coefficients.
Here the sum is performed inplace with no caching.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alm1
|
NDArray[complex128]
|
The first set of spherical harmonic coefficients with shape (l1max+1, Nm1). |
required |
alm2
|
NDArray[complex128]
|
The second set of spherical harmonic coefficients with shape (l2max+1, 2*l2max+1). |
required |
alm3
|
NDArray[complex128]
|
The third set of spherical harmonic coefficients with shape (l3max+1, 2*l3max+1). |
required |
sum_m1
|
bool
|
Whether to sum over the m1's before output, by default False. |
False
|
Returns:
Type | Description |
---|---|
NDArray[complex128] | complex128
|
If sum_m1 = False, Nm1 array of the m-modes, otherwise, scalar sum over all m-modes. |
Source code in src/serval/core.py
generate_gaunt_cache()
Generates the Gaunt coefficient cache.
generate_integrator_cache_12(alm1, alm2, contract3=None, release_gaunt_cache=True, batch_parallel_mode='channel')
summary
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alm1
|
NDArray[complex128]
|
description |
required |
alm2
|
NDArray[complex128]
|
description |
required |
contract3
|
NDArray[complex128] | None
|
description, by default None |
None
|
release_gaunt_cache
|
bool
|
description, by default True |
True
|
batch_parallel_mode
|
Literal['channel', 'gaunt']
|
description, by default "channel" |
'channel'
|
Source code in src/serval/core.py
grid_integrate(alm1, alm2, alm3, sum_m1=False)
Perform the triple integral using a grid-based approach.
Here the product of the second and third fields are evaluated on a consistent resolution grid, decomposed to conjugate spherical harmonics and multipled by the first set of coefficients. This more standard m-mode approach is performant for single integrals but, as implemented here, can't cache intermediate results and therefore not suitable for batching.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alm1
|
NDArray[complex128]
|
The first set of spherical harmonic coefficients with shape (l1max+1, Nm1). |
required |
alm2
|
NDArray[complex128]
|
The second set of spherical harmonic coefficients with shape (l2max+1, 2*l2max+1). |
required |
alm3
|
NDArray[complex128]
|
The third set of spherical harmonic coefficients with shape (l3max+1, 2*l3max+1). |
required |
sum_m1
|
bool
|
Whether to sum over the m1's before output, by default False. |
False
|
Returns:
Type | Description |
---|---|
NDArray[complex128] | complex128
|
If sum_m1 = False, Nm1 array of the m-modes, otherwise, scalar sum over all m-modes. |
Source code in src/serval/core.py
linear_gaunt_integrator_12(alm1, alm2, contract3=None, sum_m1=False)
Generate a linear operator that, with fixed first and second set of coefficients performs the integral when sum-producted with the third set of coefficients.
If requested, additionally contract with a linear operator along the m3 axis (e.g. a rotation with a Wigner-d matrix),
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alm1
|
NDArray[complex128]
|
The first set of spherical harmonic coefficients with shape (l1max+1, Nm1). |
required |
alm2
|
NDArray[complex128]
|
The second set of spherical harmonic coefficients with shape (l2max+1, 2*l2max+1). |
required |
contract3
|
NDArray[complex128] | None
|
An optional linear operator along the m3 axis, shape (l3max+1, 2l3max+1, Nm3prime<=2l3max+1), by default None |
None
|
sum_m1
|
bool
|
Whether to sum over the m1's before output, by default False. |
False
|
Returns:
Type | Description |
---|---|
NDArray[complex128]
|
By default (Nm1, Nl3, nm3) linear operator. If sum_m1=True, an (Nl3, Nm3) array where the m1 axis has been summed over. If contract3 is present, this will instead be an (Nm1, Nl3, Nm3prime) or (Nl3, Nm3prime) array resulting from the subsequent contraction on the m3 axis. |
Source code in src/serval/core.py
sparse_gaunt_einsum(sparse_alm1, sparse_alm2, sparse_alm3, sum_m1=False, gaunts=None)
Perform the triple integral using a sparse tensor contraction.
Compute the triple integral by generating or using a sparse representation of the Gaunt coefficients and performing the sum with a sparse einsum. This is mostly a cross-checking function and is not performant.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sparse_alm1
|
SparseArray
|
Sparse represenation of the first set of coefficients with shape (l1max+1, Nm1). |
required |
sparse_alm2
|
SparseArray
|
Sparse represenation of the second set of coefficients with shape (l2max+1, 2*l2max+1). |
required |
sparse_alm3
|
SparseArray
|
Sparse represenation of the third set of coefficients (l3max+1, 2*l3max+1). |
required |
sum_m1
|
bool
|
Whether to sum over the m1's before output, by default False. |
False
|
gaunts
|
COO | None
|
Sparse representation of the Gaunt coefficients if already. computed, by default None. |
None
|
Returns:
Type | Description |
---|---|
NDArray[complex128] | complex128
|
If sum_m1 = False, Nm1 array of the m-modes, otherwise, scalar sum over all m-modes. |
Source code in src/serval/core.py
Rotate.py
Sht.py
Uitls.py
Gaunt Library
Core.py
gaunt_dot12(alm1, alm2, l3max, sum_m1=False, absm1_lower=None, absm1_upper=None)
Compute a projector for alm3 for the integral of the triple product of spherical harmonics by computing the Gaunt co-efficients in-place and sum-producting over l1, l2, m2 and m1 (if requested).
TODO add formula.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alm1
|
NDArray[complex128]
|
Spherical harmonic co-efficients in l1, m1. |
required |
alm2
|
NDArray[complex128]
|
Spherical harmonic co-efficients in l2, m2. |
required |
l3max
|
int
|
Maximum l3 to compute co-efficients up to. |
required |
sum_m1
|
bool
|
If True, also sum over m1, otherwise return m1-modes for the m1 range specified, by default False |
False
|
absm1_lower
|
int | None
|
Lower limit in |m1| to use, by default None, ie. |m1| >= 0. |
None
|
absm1_upper
|
int | None
|
Upper limit in |m1| to use, by default None, ie. |m1| <= m1max = l1max. |
None
|
Returns:
Type | Description |
---|---|
NDArray[complex128]
|
m1-mode alm3 projector as a numpy array of shape (Nm1, l3max+1, 2l3max+1) if sum_m1 is False or (l3max+1, 2l3max+1) is sum_m1 is True. |
Source code in src/serval/gaunt/core.py
gaunt_dot123(alm1, alm2, alm3, sum_m1=False, absm1_lower=None, absm1_upper=None)
Compute the integral of the triple product of spherical harmonics by computing the Gaunt co-efficients in-place and sum-producting over all harmonic degrees and orders except m1, unless requested.
TODO add formula.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alm1
|
NDArray[complex128]
|
Spherical harmonic co-efficients in l1, m1. |
required |
alm2
|
NDArray[complex128]
|
Spherical harmonic co-efficients in l2, m2. |
required |
alm3
|
NDArray[complex128]
|
Spherical harmonic co-efficients in l3, m3. |
required |
sum_m1
|
bool
|
If True, also sum over m1, otherwise return m1-modes for the m1 range specified, by default False |
False
|
absm1_lower
|
int | None
|
Lower limit in |m1| to use, by default None, ie. |m1| >= 0. |
None
|
absm1_upper
|
int | None
|
Upper limit in |m1| to use, by default None, ie. |m1| <= m1max = l1max. |
None
|
Returns:
Type | Description |
---|---|
NDArray[complex128] | float
|
Numpy array, shape (Nm1), of m1-modes or their sum if sum_m1 is True. |
Source code in src/serval/gaunt/core.py
gaunt_dot23(alm2, alm3, l1max, sum_m1=False, absm1_lower=None, absm1_upper=None)
Compute a projector for alm1 for the integral of the triple product of spherical harmonics by computing the Gaunt co-efficients in-place and sum-producting over l2, m2, l3, m3 and m1 (if requested).
TODO add formula.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alm2
|
NDArray[complex128]
|
Spherical harmonic co-efficients in l2, m2. |
required |
alm3
|
NDArray[complex128]
|
Spherical harmonic co-efficients in l3, m3. |
required |
l1max
|
int
|
Maximum l1 to compute co-efficients up to. |
required |
sum_m1
|
bool
|
If True, also sum over m1, otherwise return m1-modes for the m1 range specified, by default False |
False
|
absm1_lower
|
int | None
|
Lower limit in |m1| to use, by default None, ie. |m1| >= 0. |
None
|
absm1_upper
|
int | None
|
Upper limit in |m1| to use, by default None, ie. |m1| <= m1max = l1max. |
None
|
Returns:
Type | Description |
---|---|
NDArray[complex128]
|
m1-mode alm1 projector as a numpy array of shape (Nm1, l1max+1) if sum_m1 is False or (l1max+1,) is sum_m1 is True. |
Source code in src/serval/gaunt/core.py
gaunts_coo(l1max, l2max, l3max)
Compute a sparse representation of all Gaunt co-efficients up to maximum harmonic degrees l1max, l2max and l3max.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
l1max
|
int
|
Maximum harmonic degree l1. |
required |
l2max
|
int
|
Maximum harmonic degree l2. |
required |
l3max
|
int
|
Maximum harmonic degree l3. |
required |
Returns:
Type | Description |
---|---|
COO
|
COO formatted sparse array of the Gaunt co-efficients. |
Source code in src/serval/gaunt/core.py
gaunts_l1m1_coo(l1, absm1, l1max, l2max, l3max)
Compute a sparse representation of all Gaunt co-efficients with given harmonic degree l1 and harmonic order |m1|, up to maximum harmonic degrees l1max, l2max and l3max. The shape of the coordinates is the same as for the full gaunt coeffcients (gaunts_coo). The only difference is that the first two indices are l1 and m1, set to the input values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
l1
|
int
|
Harmonic degree l1. |
required |
absm1
|
int
|
Harmonic order |m1|. |
required |
l1max
|
int
|
Maximum harmonic degree l1. |
required |
l2max
|
int
|
Maximum harmonic degree l2. |
required |
l3max
|
int
|
Maximum harmonic degree l3. |
required |
Returns:
Type | Description |
---|---|
COO
|
COO formatted sparse array of the Gaunt co-efficients. |
Source code in src/serval/gaunt/core.py
integrator12_contract3(int12, contract3)
(m1 l3 m3) (l3 m3' m3) -> (m1 l3 m3')
Source code in src/serval/gaunt/core.py
single_gaunt(l1, l2, l3, m1, m2)
Computes a single Gaunt co-efficient for given harmonic degrees and orders. This uses Wigner-3j family algorithms so it is not efficient for computing many Gaunts co-efficients. Primarily for testing purposes m3 is determined by m1 + m2 + m3 = 0.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
l1
|
int
|
Harmonic degree l1. |
required |
l2
|
int
|
Harmonic degree l2. |
required |
l3
|
int
|
Harmonic degree l3. |
required |
m1
|
int
|
Harmonic order m1. |
required |
m2
|
int
|
Harmonic order m2. |
required |
Returns:
Type | Description |
---|---|
float
|
Computed Gaunt co-efficient. |
Source code in src/serval/gaunt/core.py
wigner_3jj(l2, l3, m2, m3)
Compute the family of non-zero Wigner-3j terms for harmonic degrees l2 and l3 for harmonic degrees m1, m2, m3 = -m1 -m2.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
l2
|
int
|
Harmonic degree l2. |
required |
l3
|
int
|
Harmonic degree l3. |
required |
m2
|
int
|
Harmonic order m2. |
required |
m3
|
int
|
Harmonic order m3. |
required |
Returns:
Type | Description |
---|---|
tuple[int, NDArray[float64]]
|
Tuple of first non-zero harmonic degree l1min and array of Wigner-3j values of length l1max - l1min. If there are no non-zero elements of the Wigner-3j family, returns (-1, np.array([])). |
Source code in src/serval/gaunt/core.py
wigner_3jj_000(l2, l3)
Compute the family of non-zero Wigner-3j terms for harmonic degrees l2 and l3 for harmonic degrees m1 = m2 = m3 = 0.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
l2
|
int
|
Harmonic degree l2. |
required |
l3
|
int
|
Harmonic degree l3. |
required |
Returns:
Type | Description |
---|---|
tuple[int, NDArray[float64]]
|
Tuple of first non-zero harmonic order l1min and array of Wigner-3j values of length l1max - l1min. If there are no non-zero elements of the Wigner-3j family, returns (-1, np.array([])). |
Source code in src/serval/gaunt/core.py
wigner_3jm(l1, l2, l3, m1)
Compute the family of Wigner-3j terms for harmonic degrees l1, l2 and l3 all non-zero terms with harmonic order m1.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
l1
|
int
|
Harmonic degree l1. |
required |
l2
|
int
|
Harmonic degree l2. |
required |
l3
|
int
|
Harmonic degree l3. |
required |
m1
|
int
|
Harmonic order m1. |
required |
Returns:
Type | Description |
---|---|
tuple[int, NDArray[float64]]
|
Tuple of first non-zero harmonic order m2min and array of Wigner-3j values of length l2max - l2min. If there are no non-zero elements of the Wigner-3j family, returns (-1, np.array([])). |
Source code in src/serval/gaunt/core.py
Gaunt.cpp
These are the c++ functions:
Wigner.cpp
These are the c++ functions: