API
Under Construction
Core Module (serval.core.py)
PowerBeamVisProjector
Bases: VisProjector
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latitude
|
float
|
|
required |
longitude
|
float
|
|
required |
baseline_enu
|
tuple[float, float, float]
|
|
required |
power_beam_lmax
|
int
|
|
required |
frequencies_MHz
|
ndarray
|
|
required |
baseline_lmax
|
int | None
|
|
None
|
sky_lmax
|
int | None
|
|
None
|
sky_absm_limits
|
list[int | None]
|
|
[0, None]
|
generate_gaunt_cache_on_init
|
bool
|
|
False
|
generate_baseline_cache_on_init
|
bool
|
|
False
|
generate_pointing_contractor_on_init
|
bool
|
|
False
|
batch_parallel_mode
|
Literal['channel-opt', 'channel', 'gaunt', 'gaunt-opt']
|
|
'gaunt-opt'
|
pointing_contract
|
bool
|
|
False
|
pointing_altitude
|
float | None
|
|
None
|
pointing_azimuth
|
float | None
|
|
None
|
pointing_boresight
|
float | None
|
|
None
|
pointed_beam_mmax
|
int | None
|
|
None
|
aberrate_baseline
|
bool
|
|
False
|
Attributes:
| Name | Type | Description |
|---|---|---|
pointing_contractor |
ndarray | None
|
|
Source code in src/serval/core.py
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 | |
PowerFromVoltageBeams
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
voltage_beam_lmax
|
int
|
|
required |
voltage_beam_mmax
|
int | None
|
|
None
|
power_beam_lmax
|
int | None
|
|
None
|
power_beam_mmax
|
int | None
|
|
None
|
generate_cache_on_init
|
bool
|
|
True
|
Attributes:
| Name | Type | Description |
|---|---|---|
triple_sh_integrator |
TripleSHIntegrator
|
|
Source code in src/serval/core.py
1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 | |
SingleVisibilityGenerator
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latitude
|
float
|
|
required |
longitude
|
float
|
|
required |
baseline_enu
|
tuple[float, float, float]
|
|
required |
frequency_MHz
|
float
|
|
required |
power_beam_alm
|
ndarray[tuple[Any, ...], dtype[complex128]]
|
|
required |
sky_alm
|
ndarray[tuple[Any, ...], dtype[complex128]]
|
|
required |
method
|
Literal['gaunt', 'gaunt_sparse', 'grid']
|
|
'gaunt'
|
baseline_lmax
|
int | None
|
|
None
|
aberrate_baseline
|
bool
|
|
False
|
sky_absm_limits
|
tuple[int, int | None]
|
|
(0, None)
|
baseline_alm
|
None | ndarray[tuple[Any, ...], dtype[complex128]]
|
|
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
sky_lmax |
int
|
|
power_beam_lmax |
int
|
|
triple_sh_integrator |
TripleSHIntegrator
|
|
Source code in src/serval/core.py
685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 | |
SkyVisProjector
Bases: VisProjector
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latitude
|
float
|
|
required |
longitude
|
float
|
|
required |
baseline_enu
|
tuple[float, float, float]
|
|
required |
sky_lmax
|
int
|
|
required |
frequencies_MHz
|
ndarray
|
|
required |
baseline_lmax
|
int | None
|
|
None
|
power_beam_lmax
|
int | None
|
|
None
|
sky_absm_limits
|
list[int | None]
|
|
[0, None]
|
generate_gaunt_cache_on_init
|
bool
|
|
False
|
generate_baseline_cache_on_init
|
bool
|
|
False
|
batch_parallel_mode
|
Literal['channel', 'gaunt']
|
|
'channel'
|
aberrate_baseline
|
bool
|
|
False
|
Source code in src/serval/core.py
1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 | |
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. |
(0, None)
|
generate_cache_on_init
|
bool
|
Whether to generate the Gaunt coefficient cache during initialization, by default False. |
False
|
Attributes:
| Name | Type | Description |
|---|---|---|
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. |
linear_integrator_cache_12 |
ndarray[tuple[Any, ...], dtype[complex128]] | None
|
|
linear_integrator_cache_23 |
ndarray[tuple[Any, ...], dtype[complex128]] | None
|
|
gaunt_cache |
CachingGauntContractor | CachingGauntContractorOpt12 | None
|
|
m1_global_index |
list[int]
|
|
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
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 524 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 580 581 582 583 584 585 586 587 588 589 590 591 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 | |
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(cache_type_tag='generic')
Generates the Gaunt coefficient cache.
Source code in src/serval/core.py
generate_integrator_cache_12(alm1, alm2, contract3=None, release_gaunt_cache=True, batch_parallel_mode='channel-opt', alm1_transposed=None, alm2_transposed=None)
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-opt', 'channel', 'gaunt', 'gaunt-opt']
|
description, by default "channel-opt" |
'channel-opt'
|
alm1_transposed
|
NDArray[complex128] | None
|
Pre-transposed alm1 in (m, l, batch) layout, by default None |
None
|
alm2_transposed
|
NDArray[complex128] | None
|
Pre-transposed alm2 in (m, l, batch) layout, by default None |
None
|
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
VisProjector
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latitude
|
float
|
|
required |
longitude
|
float
|
|
required |
baseline_enu
|
tuple[float, float, float]
|
|
required |
frequencies_MHz
|
ndarray
|
|
required |
power_beam_lmax
|
int | None
|
|
None
|
baseline_lmax
|
int | None
|
|
None
|
sky_lmax
|
int | None
|
|
None
|
sky_absm_limits
|
list[int | None]
|
|
[0, None]
|
generate_gaunt_cache_on_init
|
bool
|
|
False
|
generate_baseline_cache_on_init
|
bool
|
|
False
|
batch_parallel_mode
|
Literal['channel-opt', 'channel', 'gaunt', 'gaunt-opt']
|
|
'channel'
|
Attributes:
| Name | Type | Description |
|---|---|---|
baseline_mmax |
int | None
|
|
baseline_cache |
ndarray | None
|
|
integrator_cache |
ndarray | None
|
|
triple_sh_integrator |
TripleSHIntegrator
|
|
Source code in src/serval/core.py
782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 | |
extend_dimensions_if_one_batch(arr, dim)
If a single frequency is calculated then the alms and cache matrices will be missing the first dimension that corresponds to the number of frequencies. This function takes the arrays and adds a (1, ...) dimension
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
NDArray[complex128]
|
The input array. |
required |
dim
|
int
|
The desired number of dimensions. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[complex128]
|
The array with the correct number of dimensions. |
Source code in src/serval/core.py
Rotation Utilities (serval.rotate.py)
batch_rotate_alm(alm, lmax, mmax, eulers_or_rotation)
Rotate a batch of SERVAL alm arrays using two calls to ducc0.sht.rotate_alm.
Converts the input to the ducc0 real-field decomposition, applies the rotation
in batch, and converts back. The output always has mmax = lmax because a
rotation generically populates all m-modes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alm
|
NDArray[complex128]
|
SERVAL alm array of shape |
required |
lmax
|
int
|
Maximum degree. |
required |
mmax
|
int
|
Maximum order of the input. |
required |
eulers_or_rotation
|
tuple[float, float, float] | Rotation
|
Passive ZYZ Euler angles |
required |
Returns:
| Type | Description |
|---|---|
NDArray[complex128]
|
SERVAL alm of shape |
Source code in src/serval/rotate.py
boresight_for_fixed_pol_ref(alt, az, ref_alt=np.pi / 2, ref_az=np.pi, ref_boresight=0.0)
Boresight angle that aligns the feed co-pol axis with a reference pointing orientation.
When a dish is tilted away from a nominal pointing direction, the ZYZ Euler
parameterisation induces an apparent rotation of the X/Y polarisation axes in TIRS.
This function computes the boresight correction that eliminates that rotation, so
that boresight = boresight_for_fixed_pol_ref(alt, az) + chi gives a pointing whose
feed orientation differs from the reference only by the controllable roll chi.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alt
|
float
|
Pointing altitude in radians. |
required |
az
|
float
|
Pointing azimuth in radians. |
required |
ref_alt
|
float
|
Reference pointing altitude in radians. Defaults to |
pi / 2
|
ref_az
|
float
|
Reference pointing azimuth in radians. Defaults to |
pi
|
ref_boresight
|
float
|
Reference boresight in radians. Defaults to |
0.0
|
Returns:
| Type | Description |
|---|---|
float
|
Boresight angle in radians to pass to :func: |
Source code in src/serval/rotate.py
cirs_to_cirs(source_epoch, target_epoch)
Return a passive rotation from CIRS at one epoch to CIRS at another.
Routes through GCRS using both CIO-based matrices: CIRS(source) \(\to\) GCRS \(\to\) CIRS(target).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_epoch
|
str
|
The source epoch string (e.g. |
required |
target_epoch
|
str
|
The target epoch string, parsed by |
required |
Returns:
| Type | Description |
|---|---|
Rotation
|
A |
Source code in src/serval/rotate.py
diurnal_aberrate_tirs(n, latitude, longitude)
Apply diurnal-aberration to TIRS unit directions.
Transforms unit direction vector(s) \(\hat{n}\) in the TIRS frame to account for the special-relativistic aberration caused by Earth's diurnal rotation. The observer velocity \(\boldsymbol{\beta} = \mathbf{v}/c\) in TIRS is exactly constant (independent of ERA or epoch), given by \(\boldsymbol{\beta} = (-\omega r_y,\; \omega r_x,\; 0) / c\) where \((r_x, r_y)\) are the WGS84 coordinates of the observer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
NDArray[float64]
|
Unit direction vector(s) in the TIRS frame. Shape |
required |
latitude
|
float
|
Geodetic latitude in radians. |
required |
longitude
|
float
|
Geodetic longitude in radians. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
Aberrated unit direction vector(s). Same shape as |
Source code in src/serval/rotate.py
enu_to_tirs(latitude, longitude)
Creates a rotation object for basis rotations from the ENU coordinate frame of an observer at the specified latitude and longitude to the TIRS frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latitude
|
float
|
The latitude in radians. |
required |
longitude
|
float
|
The longitude in radians. |
required |
Returns:
| Type | Description |
|---|---|
Rotation
|
A Rotation object representing the ENU to TIRS basis rotation. |
Source code in src/serval/rotate.py
enu_to_zenith()
Provides a rotation object converting from the ENU basis to the local Zenith basis.
Returns:
| Type | Description |
|---|---|
Rotation
|
A Rotation object. |
Source code in src/serval/rotate.py
eulers_from_rotation(rotation)
Extracts the ZYZ Euler angles from a rotation object.
The convention used here and throughout is that of ZYZ passive (basis) rotations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rotation
|
Rotation
|
A Rotation object. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float, float]
|
The Euler angles (alpha, beta, gamma) specifying the rotation. |
Source code in src/serval/rotate.py
frame_rotation_to_cirs(source_basis, epoch)
Return a passive rotation from a celestial coordinate frame to CIRS.
Dispatches to :func:icrs_to_cirs, :func:galactic_to_cirs, or
:func:cirs_to_cirs based on source_basis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_basis
|
``"ICRS"``, ``"Galactic"``, or ``"CIRS:<epoch>"``
|
The source coordinate frame. For CIRS input, append the old
epoch after a colon, e.g. |
required |
epoch
|
str
|
The target epoch string (e.g. |
required |
Returns:
| Type | Description |
|---|---|
Rotation
|
A |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/serval/rotate.py
galactic_to_cirs(epoch)
Return a passive rotation from Galactic coordinates to CIRS.
The Galactic-to-ICRS rotation (from astropy) is composed with the CIO-based celestial-to-intermediate matrix. Aberration is not included.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
epoch
|
str
|
The target epoch string (e.g. |
required |
Returns:
| Type | Description |
|---|---|
Rotation
|
A |
Source code in src/serval/rotate.py
gcrs_to_cirs(epoch)
Creates a rotation object for basis rotations from the GCRS frame to CIRS.
Uses the IAU 2006/2000A CIO-based celestial-to-intermediate matrix
(via ERFA's c2i06a).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
epoch
|
str
|
The epoch string (e.g. |
required |
Returns:
| Type | Description |
|---|---|
Rotation
|
A |
Source code in src/serval/rotate.py
generate_telescope_wigner_ds(beam_lmax, beam_mmax, baseline_lmax, latitude, longitude, altitude, azimuth, baseline_enu)
Generates Wigner-D matrices for the TIRS to telescope pointing frame and T IRS to baseline frame basis rotations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
beam_lmax
|
int
|
The maximum degree of the beam Wigner-D matrix. |
required |
beam_mmax
|
int
|
The maximum order of m' for the beam Wigner-D matrix. |
required |
baseline_lmax
|
int
|
The maximum degree of the baseline Wigner-D matrix. |
required |
latitude
|
float
|
The latitude in radians. |
required |
longitude
|
float
|
The longitude in radians. |
required |
altitude
|
float
|
The altitude angle in radians. |
required |
azimuth
|
float
|
The azimuth angle in radians. |
required |
baseline_enu
|
tuple[float, float, float]
|
The baseline vector components in the ENU frame (east, north, up). |
required |
Returns:
| Type | Description |
|---|---|
tuple[NDArray[complex128], NDArray[complex128]]
|
The Wigner-D matrices for the TIRS to telescope pointing frame and TIRS to baseline frame basis rotations. |
Source code in src/serval/rotate.py
icrs_to_cirs(epoch)
Return a passive rotation from ICRS to CIRS at the given epoch.
Delegates to :func:gcrs_to_cirs as for the purposes of this code,
the GCRS to ICRS transformation is neglible, mainly aberration is
not ignored limiting the accuracy to ~20.5 arcsec.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
epoch
|
str
|
The target epoch string (e.g. |
required |
Returns:
| Type | Description |
|---|---|
Rotation
|
A |
Source code in src/serval/rotate.py
inv_eulers(eulers)
Provides the Euler angles corresponding to the inverse rotation of those given.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
eulers
|
tuple[float, float, float]
|
The Euler angles (alpha, beta, gamma) specifying the rotation. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float, float]
|
The Euler angles (alpha, beta, gamma) specifying the inverse rotation. |
Source code in src/serval/rotate.py
itrs_enu_to_tirs_enu(geodetic_lat, geodetic_lon, enu, epoch)
Convert an ENU vector from the ITRS frame to its TIRS-frame ENU components.
Computes \(W^\top \mathbf{v}_\mathrm{ITRS}\) (the exact TIRS Cartesian vector) then
re-expresses it as ENU components in the TIRS frame at the polar-motion-corrected
(lat_tirs, lon_tirs). The result satisfies:
enu_to_tirs(lat_tirs, lon_tirs).apply(enu_tirs) == W^T @ enu_to_tirs(lat, lon).apply(enu)
so that passing (lat_tirs, lon_tirs, enu_tirs) to SERVAL functions that internally
call enu_to_tirs yields the physically correct TIRS
Cartesian vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geodetic_lat
|
float
|
Observer WGS84 geodetic latitude in radians. |
required |
geodetic_lon
|
float
|
Observer WGS84 geodetic longitude in radians. |
required |
enu
|
(array - like, shape(3))
|
ENU vector in the ITRS frame (e.g. baseline in metres). |
required |
epoch
|
Time
|
Epoch at which the IERS polar motion is evaluated. |
required |
Returns:
| Type | Description |
|---|---|
(ndarray, shape(3))
|
ENU components in the TIRS frame at |
Source code in src/serval/rotate.py
itrs_pointing_to_tirs_pointing(geodetic_lat, geodetic_lon, altitude, azimuth, boresight, epoch)
Convert an ITRS-frame pointing direction and boresight to their TIRS equivalents.
Converts (altitude, azimuth) by expressing the pointing unit vector in ITRS ENU,
applying itrs_enu_to_tirs_enu, and extracting
TIRS spherical coordinates. The boresight is corrected by tracking the ITRS
pointing-frame x-axis into TIRS ENU and extracting the equivalent angle — the same
technique used by boresight_for_fixed_pol_ref.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geodetic_lat
|
float
|
Observer WGS84 geodetic latitude in radians. |
required |
geodetic_lon
|
float
|
Observer WGS84 geodetic longitude in radians. |
required |
altitude
|
float
|
Pointing altitude in the ITRS ENU frame, in radians. |
required |
azimuth
|
float
|
Pointing azimuth (North through East) in the ITRS ENU frame, in radians. |
required |
boresight
|
float
|
Feed boresight rotation around the pointing axis in radians. |
required |
epoch
|
Time
|
Epoch at which the IERS polar motion is evaluated. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float, float]
|
|
Source code in src/serval/rotate.py
itrs_to_tirs(epoch)
Rotation from ITRS to TIRS at a given epoch, applying IERS polar motion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
epoch
|
Time
|
Epoch at which the IERS polar motion is evaluated. |
required |
Returns:
| Type | Description |
|---|---|
Rotation
|
Rotation that maps ITRS Cartesian vectors to TIRS Cartesian vectors. |
Source code in src/serval/rotate.py
itrs_to_tirs_inputs(geodetic_lat, geodetic_lon, altitude, azimuth, boresight, baselines_enu, epoch)
Convert all ITRS observer inputs to their TIRS equivalents in one call.
Applies the IERS polar motion matrix \(W^\top\) to the site location, each baseline ENU vector, and the pointing direction.
Delegates to itrs_to_tirs_latlon, itrs_pointing_to_tirs_pointing, and itrs_enu_to_tirs_enu.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geodetic_lat
|
float
|
Observer WGS84 geodetic latitude in radians. |
required |
geodetic_lon
|
float
|
Observer WGS84 geodetic longitude in radians. |
required |
altitude
|
float
|
Pointing altitude in the ITRS ENU frame, in radians. |
required |
azimuth
|
float
|
Pointing azimuth (North through East) in the ITRS ENU frame, in radians. |
required |
boresight
|
float
|
Feed boresight rotation around the pointing axis, in radians. |
required |
baselines_enu
|
list of array-like, each shape (3,)
|
Baseline ENU vectors in the ITRS frame. |
required |
epoch
|
Time
|
Epoch at which the IERS polar motion is evaluated. |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
|
Source code in src/serval/rotate.py
itrs_to_tirs_latlon(geodetic_lat, geodetic_lon, epoch)
TIRS geocentric latitude and longitude for an ITRS observer at a given epoch.
Applies the IERS polar motion matrix \(W = \mathrm{erfa.pom00}\) to the geodetic zenith direction in ITRS, then returns its TIRS spherical coordinates. Passing the returned angles to enu_to_tirs or tirs_to_zenith makes those functions consistent with Astropy's ITRS coordinate chain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geodetic_lat
|
float
|
Observer WGS84 geodetic latitude in radians. |
required |
geodetic_lon
|
float
|
Observer WGS84 geodetic longitude in radians. |
required |
epoch
|
Time
|
Epoch at which the IERS polar motion is evaluated. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
|
Source code in src/serval/rotate.py
offset_pointing(offset_magnitude, offset_direction, offset_boresight=0.0, ref_alt=np.pi / 2, ref_az=np.pi, ref_boresight=0.0)
Convert a pointing offset to an absolute (alt, az, boresight).
The position angle offset_direction uses geographic North/East as reference,
which is well-defined at the zenith (over-the-top convention).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
offset_magnitude
|
float
|
Angular offset magnitude from the reference pointing, in radians. |
required |
offset_direction
|
float
|
Position angle of the offset in radians, measured from North (0) toward East (\(\pi/2\)). |
required |
offset_boresight
|
float
|
Boresight roll in radians, relative to the polarisation-stabilised reference.
|
0.0
|
ref_alt
|
float
|
Reference pointing altitude and azimuth in radians. Default: zenith (\(\pi/2\), \(\pi\)). |
pi / 2
|
ref_az
|
float
|
Reference pointing altitude and azimuth in radians. Default: zenith (\(\pi/2\), \(\pi\)). |
pi / 2
|
ref_boresight
|
float
|
Reference boresight in radians. Default: 0. |
0.0
|
Returns:
| Type | Description |
|---|---|
alt, az, boresight : tuple[float, float, float]
|
New pointing parameters in radians, suitable for :func: |
Notes
The (alt, az) computation uses the spherical law of cosines on the triangle formed by
the zenith P (alt = \(\pi/2\)), the reference pointing A, and the new pointing B.
The sides are the co-altitudes \(b = \pi/2 - \text{ref\_alt}\) and \(a = \pi/2 - \text{alt}\),
and the offset magnitude \(\rho\). The angle at A is the position angle \(\psi\)
(offset_direction), measured from the great circle toward the zenith (North) toward
increasing azimuth (East):
arctan2 handles the over-the-top case naturally.
Source code in src/serval/rotate.py
rotation_from_eulers(eulers, degrees=False)
Creates a rotation object from a set of Euler angles.
The convention used here and throughout is that of ZYZ passive (basis) rotations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
eulers
|
tuple[float, float, float]
|
The Euler angles (alpha, beta, gamma) specifying the rotation. |
required |
degrees
|
bool
|
Whether the input angles are in degrees, by default False. |
False
|
Returns:
| Type | Description |
|---|---|
Rotation
|
The Rotation object. |
Source code in src/serval/rotate.py
tirs_to_baseline_direc(latitude, longitude, east, north, up)
Creates a rotation object for basis rotations from the TIRS frame to a frame aligned with the direction of the baseline vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latitude
|
float
|
The latitude in radians. |
required |
longitude
|
float
|
The longitude in radians. |
required |
east
|
float
|
The East component of the baseline vector. |
required |
north
|
float
|
The North component of the baseline vector. |
required |
up
|
float
|
The Up component of the baseline vector. |
required |
Returns:
| Type | Description |
|---|---|
Rotation
|
A Rotation object representing the TIRS to baseline direction frame basis rotation. |
Source code in src/serval/rotate.py
tirs_to_baseline_direc_eulers(latitude, longitude, east, north, up)
Returns the Euler angles for basis rotations from the TIRS frame to a frame aligned with the direction of the baseline vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latitude
|
float
|
The latitude in radians. |
required |
longitude
|
float
|
The longitude in radians. |
required |
east
|
float
|
The East component of the baseline vector. |
required |
north
|
float
|
The North component of the baseline vector. |
required |
up
|
float
|
The Up component of the baseline vector. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float, float]
|
The Euler angles (alpha, beta, gamma) specifying the TIRS to baseline frame basis rotation. |
Source code in src/serval/rotate.py
tirs_to_cirs(era)
Creates a rotation object corresponding to the basis rotation from the TIRS frame to the CIRS frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
era
|
float
|
The Earth Rotation Angle in radians. |
required |
Returns:
| Type | Description |
|---|---|
Rotation
|
A Rotation object representing the TIRS to CIRS basis rotation. |
Source code in src/serval/rotate.py
tirs_to_cirs_eulers(era)
Provides the Euler angles corresponding to the basis rotation from the TIRS frame to the CIRS frame.
The convention used here and throughout is that of ZYZ passive (basis) rotations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
era
|
float
|
The Earth Rotation Angle in radians. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float, float]
|
The Euler angles (alpha, beta, gamma) specifying the TIRS to CIRS basis rotation. |
Source code in src/serval/rotate.py
tirs_to_pointing(latitude, longitude, altitude=np.pi / 2, azimuth=np.pi, boresight=0.0)
Creates a rotation object for basis rotations from the TIRS frame to a frame aligned with the telescope pointing direction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latitude
|
float
|
The latitude in radians. |
required |
longitude
|
float
|
The longitude in radians. |
required |
altitude
|
float
|
The altitude angle in radians, by default np.pi / 2. |
pi / 2
|
azimuth
|
float
|
The azimuth angle in radians, by default np.pi. |
pi
|
boresight
|
float
|
The boresight angle in radians, by default 0.0. |
0.0
|
Returns:
| Type | Description |
|---|---|
Rotation
|
A Rotation object representing the TIRS to telescope pointing frame basis rotation. |
Source code in src/serval/rotate.py
tirs_to_pointing_eulers(latitude, longitude, altitude=np.pi / 2, azimuth=np.pi, boresight=0.0)
Returns the Euler angles for basis rotations from the TIRS frame to a frame aligned with the telescope pointing direction.
The convention used here and throughout is that of ZYZ passive (basis) rotations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latitude
|
float
|
The latitude in radians. |
required |
longitude
|
float
|
The longitude in radians. |
required |
altitude
|
float
|
The altitude angle in radians, by default np.pi / 2. |
pi / 2
|
azimuth
|
float
|
The azimuth angle in radians, by default np.pi. |
pi
|
boresight
|
float
|
The boresight angle in radians, by default 0.0. |
0.0
|
Returns:
| Type | Description |
|---|---|
tuple[float, float, float]
|
The Euler angles (alpha, beta, gamma) specifying the TIRS to telescope pointing basis rotation. |
Source code in src/serval/rotate.py
tirs_to_zenith(latitude, longitude)
Creates a rotation object for basis rotations from the TIRS frame to the local Zenith frame for an observer at a given latitude and longitude.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latitude
|
float
|
The latitude in radians. |
required |
longitude
|
float
|
The longitude in radians. |
required |
Returns:
| Type | Description |
|---|---|
Rotation
|
A Rotation object representing the TIRS to local Zenith basis rotation. |
Source code in src/serval/rotate.py
tirs_to_zenith_eulers(latitude, longitude)
Returns the Euler angles for basis rotations from the TIRS frame to the local Zenith frame for an observer at a given latitude and longitude.
The convention used here and throughout is that of ZYZ passive (basis) rotations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latitude
|
float
|
The latitude in radians. |
required |
longitude
|
float
|
The longitude in radians. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float, float]
|
The Euler angles (alpha, beta, gamma) specifying the TIRS to local Zenith basis rotation. |
Source code in src/serval/rotate.py
wigner_d(lmax, mprime_max, eulers_or_rotation)
Generates Wigner-D matrices up to a given lmax for specified Euler angles or a Rotation object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lmax
|
int
|
The maximum degree of the Wigner-D matrices. |
required |
mprime_max
|
int
|
The maximum order of m' for the Wigner-D matrices. |
required |
eulers_or_rotation
|
tuple[float, float, float] | Rotation
|
The Euler angles (alpha, beta, gamma) specifying the rotation, or a Rotation object. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[complex128]
|
An array of shape |
Source code in src/serval/rotate.py
zenith_to_baseline_direc(east, north, up)
Creates a rotation object for basis rotations from the local Zenith frame to a frame aligned with the direction of the baseline vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
east
|
float
|
The East component of the baseline vector. |
required |
north
|
float
|
The North component of the baseline vector. |
required |
up
|
float
|
The Up component of the baseline vector. |
required |
Returns:
| Type | Description |
|---|---|
Rotation
|
A Rotation object representing the local Zenith to baseline direction frame basis rotation. |
Source code in src/serval/rotate.py
zenith_to_baseline_direc_eulers(east, north, up)
Returns the Euler angles for basis rotations from the local Zenith frame to a frame aligned with the direction of the baseline vector.
The convention used here and throughout is that of ZYZ passive (basis) rotations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
east
|
float
|
The East component of the baseline vector. |
required |
north
|
float
|
The North component of the baseline vector. |
required |
up
|
float
|
The Up component of the baseline vector. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float, float]
|
The Euler angles (alpha, beta, gamma) specifying the local Zenith to baseline direction frame basis rotation. |
Source code in src/serval/rotate.py
zenith_to_pointing(altitude=np.pi / 2, azimuth=np.pi, boresight=0.0)
Creates a rotation object from the local Zenith frame to the to a frame aligned with the telescope pointing direction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
altitude
|
float
|
The altitude angle in radians , by default np.pi / 2. |
pi / 2
|
azimuth
|
float
|
The azimuth angle in radians, by default np.pi. |
pi
|
boresight
|
float
|
The boresight angle in radians, by default 0. |
0.0
|
Returns:
| Type | Description |
|---|---|
Rotation
|
A Rotation object representing the local Zenith to telescope pointing frame basis rotation. |
Source code in src/serval/rotate.py
zenith_to_pointing_eulers(altitude=None, azimuth=None, boresight=None)
Returns the Euler angles for basis rotations from the local Zenith frame to a frame aligned with the telescope pointing direction.
The convention used here and throughout is that of ZYZ passive (basis) rotations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
altitude
|
float
|
The altitude angle in radians, by default np.pi / 2. |
None
|
azimuth
|
float
|
The azimuth angle in radians, by default np.pi. |
None
|
boresight
|
float
|
The boresight angle in radians, by default 0.0. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[float, float, float]
|
The Euler angles (alpha, beta, gamma) specifying the local Zenith to pointing frame basis rotation. |
Source code in src/serval/rotate.py
Spherical Harmonic Transform Utilities (serval.sht.py)
alm_from_healpix(healpix_alm, return_sparse=True)
Transforms spherical harmonics coefficients from healpy format (1D) to standard Fourier order format (2D). It can return either a sparse or dense array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
healpix_alm
|
NDArray[complex128]
|
A spherical harmonics coefficients array in healpy format (1D). |
required |
return_sparse
|
bool
|
Whether to return a sparse array or a dense one. |
True
|
Returns:
| Type | Description |
|---|---|
COO | NDArray[complex128]
|
A spherical harmonics coefficients array in standard Fourier order (2D), in sparse or dense form. |
Source code in src/serval/sht.py
analysis(grid, threshold=SPARSE_THRESHOLD, conjugate=False, return_sparse=True)
Transforms a pyshtools grid to the corresponding spherical harmonics coefficients or their conjugates in standard Fourier order. It can return either a sparse or dense array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
SHGrid
|
A spherical harmonic grid object. |
required |
threshold
|
float
|
The threshold below which coefficients are set to zero. |
SPARSE_THRESHOLD
|
conjugate
|
bool
|
Whether to return the conjugate spherical harmonics coefficients. |
False
|
return_sparse
|
bool
|
Whether to return a sparse array or a dense one. |
True
|
Returns:
| Type | Description |
|---|---|
COO | NDArray[complex128]
|
The spherical harmonics coefficients array or their conjugates in standard Fourier order, in sparse or dense form. |
Source code in src/serval/sht.py
array_synthesis(array_coeff)
Transfomrs spherical harmonics coefficients from a pyshtools array to a pyshtools grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array_coeff
|
NDArray[complex128]
|
A spherical harmonics coefficients array in pytshtools format. Its shape should be (lmax + 1, 2 * mmax + 1). |
required |
Returns:
| Type | Description |
|---|---|
SHGrid
|
A spherical harmonic grid object. |
Source code in src/serval/sht.py
batch_array_analysis(map_batch, lmax)
Batch-analyze complex DH grids to SERVAL alm arrays via pyshtools.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
map_batch
|
NDArray[complex128]
|
Complex grid data of shape |
required |
lmax
|
int
|
Maximum spherical harmonic degree. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[complex128]
|
SERVAL alm array of shape |
Source code in src/serval/sht.py
batch_array_synthesis(alm_batch, lmax, nthreads=0)
Batch-synthesize complex SH alm arrays to complex DH grids via ducc0.
Uses ducc0.sht.experimental.synthesis with ntrans=2n (real and imaginary
components stacked) to replace n separate pyshtools synthesis calls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alm_batch
|
NDArray[complex128]
|
SERVAL alm array of shape |
required |
lmax
|
int
|
Maximum spherical harmonic degree. |
required |
nthreads
|
int
|
Number of threads for ducc0 (0 = all hardware threads). |
0
|
Returns:
| Type | Description |
|---|---|
NDArray[complex128]
|
Complex grid data of shape |
Source code in src/serval/sht.py
broadcast_bandlimits(*coeffs, lmax=None)
Broadcasts a set of spherical harmonics coefficients to common bandlimits. These are either given or inferred from the maximum lmax among the inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*coeffs
|
Coeffs
|
A variable set of sparse or dense spherical harmonics coefficients arrays in standard Fourier order. The shape or array i in the set should be (lmax_i + 1, 2 * mmax_i + 1) for each i. |
()
|
lmax
|
int | None
|
The target maximum spherical harmonic degree. If None, it is inferred from the maximum lmax among the input coefficients. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Coeffs, ...]
|
A tuple containing the input spherical harmonics coefficients arrays reshaped to the common target bandlimits. |
Source code in src/serval/sht.py
compute_mmodes(coeffs1, coeffs2)
Computes the mmodes between two spherical harmonics coefficients sparse or dense arrays. The relative formula is given by:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coeffs1
|
Coeffs
|
A sparse or dense spherical harmonics coefficients array in standard Fourier order. Its shape should be (lmax1 + 1, 2 * mmax1 + 1). |
required |
coeffs2
|
Coeffs
|
A sparse or dense spherical harmonics coefficients array in standard Fourier order. Its shape should be (lmax2 + 1, 2 * mmax2 + 1). |
required |
Returns:
| Type | Description |
|---|---|
Coeffs
|
A sparse or dense spherical harmonics mmodes array resulting from the inner product of the input coefficients. Its shape will be (2 * max(mmax1, mmax2) + 1,). |
Source code in src/serval/sht.py
ducc0_alm2map(alms, kwargs)
Calculate the maps for the provided alms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alms
|
NDArray[complex128]
|
Collection of 1D alms. |
required |
kwargs
|
dict
|
Dictionary of arguments for the ducc0 function. |
required |
Returns:
| Type | Description |
|---|---|
npt.NDArray[np.float64]
|
The corresponding 1D maps for the alms. |
Source code in src/serval/sht.py
ducc0_map2alm(maps, kwargs)
Calculate the Spherical Harmonic coefficients alm for the provided maps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
maps
|
NDArray[float64]
|
Collection of 1D Healpix maps of size npix = 12 * nside ** 2. |
required |
kwargs
|
dict
|
Dictionary of arguments for the ducc0 function. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[complex128]
|
The corresponding 1D alms for the maps. |
Source code in src/serval/sht.py
ducc0_to_serval_alm(aR, aI, lmax)
Convert the (aR, aI) pair from ducc0.sht.rotate_alm back to SERVAL format.
This is the inverse of :func:serval_to_ducc0_alm. The output always has
mmax = lmax because a rotation generically populates all m-modes.
The reconstruction follows:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aR
|
NDArray[complex128]
|
Arrays of shape |
required |
aI
|
NDArray[complex128]
|
Arrays of shape |
required |
lmax
|
int
|
Maximum degree. Output |
required |
Returns:
| Type | Description |
|---|---|
NDArray[complex128]
|
SERVAL alm of shape |
Source code in src/serval/sht.py
empty_complex_array(shape)
Generates a zero numpy complex array for the given shape.
Args: shape (tuple): dimensions of the array.
Returns: npt.NDArray[np.complex128]: zero numpy array
Source code in src/serval/sht.py
from_sparse(sparse_coeffs, lmax=None)
Transfomrs spherical harmonics coefficients from a sparse array in standard Fourier order to a pyshtools SHCoeffs object of given bandlimits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sparse_coeffs
|
COO
|
A sparse spherical harmonics coefficients array in standard Fourier order. Its shape should be (lmax_sparse + 1, 2 * mmax_sparse + 1). |
required |
lmax
|
int | None
|
The target maximum spherical harmonic degree. If None, it is inferred from the input sparse coefficients lmax_sparse. |
None
|
Returns:
| Type | Description |
|---|---|
SHCoeffs
|
A spherical harmonics coefficients object in pyshtools format. Its shape will be (2, lmax + 1, mmax + 1). |
Source code in src/serval/sht.py
get_alm_ls_ms(lmax)
Get the l and m pairs for specific lmax. It is assumed mmax = lmax.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lmax
|
int
|
The maximum l defining the alm layout |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ls |
NDArray[int]
|
The ls corresponding to all the ms. |
ms |
NDArray[int]
|
The ms for mmax = lmax. |
Source code in src/serval/sht.py
get_lmax_from_1D_alm(size)
Returns the lmax for a given spherical harmonics coefficients array in healpy format (1D). It is assumed mmax = lmax.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
Size of the array |
required |
Returns:
| Name | Type | Description |
|---|---|---|
lmax |
int
|
The maximum l of the array, or None if it is not a valid size. |
Source code in src/serval/sht.py
grid_template(lmax)
Creates a spherical harmonic grid object of degree lmax filled with complex zeros.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lmax
|
int
|
The maximum spherical harmonic degree of the grid. |
required |
Returns:
| Type | Description |
|---|---|
SHGrid
|
A spherical harmonic grid object with data set to (complex) zeros. |
Source code in src/serval/sht.py
healpix_from_alm(serval_alm)
Transforms spherical harmonics coefficients from standard Fourier order format (2D)
to healpy format (1D). This is the inverse of :func:alm_from_healpix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
serval_alm
|
NDArray[complex128]
|
A spherical harmonics coefficients array in standard Fourier order (2D),
shape |
required |
Returns:
| Type | Description |
|---|---|
NDArray[complex128]
|
A spherical harmonics coefficients array in healpy format (1D), containing only the m >= 0 entries with the Condon-Shortley phase included. |
Source code in src/serval/sht.py
healpix_map_base(nside, lmax, spin=0, nthreads=0)
Create the base for the transformation of the 1D healpix map to spherical coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nside
|
int
|
The map size. |
required |
lmax
|
int
|
The maximum degree of the alms. |
required |
spin
|
int
|
The weights used for the map or alms. Default 0. |
0
|
nthreads
|
int
|
The number of threads for parallelization. Default 0 allows ducc0 to parallelize. |
0
|
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with all arguments for the ducc0 synthesis and adjoint_synthesis. |
Source code in src/serval/sht.py
healpix_map_to_alm(map1D, lmax, niter=3)
Calculate the Spherical Harmonics coeffeicients (alm) corresponding to the inputted 1D HEALPix map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
map1D
|
NDArray[float64]
|
1D Healpix map of size npix = 12 * nside ** 2. |
required |
lmax
|
int
|
The maximum degree of the alms. |
required |
niter
|
int
|
The number of iterations for the convergence to the solution. healpy uses default 3 so the default for this function is also set to 3. |
3
|
Returns:
| Name | Type | Description |
|---|---|---|
alm |
NDArray[complex128]
|
A 1D array with the Spherical Harmonics coefficients derived from the map. |
Source code in src/serval/sht.py
make_conjugate(sparse_coeff, return_sparse=True)
Transforms spherical harmonics coefficients to their conjugate form. It can return either a sparse or dense array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sparse_coeff
|
COO
|
A sparse spherical harmonics coefficients array in standard Fourier order. Its shape should be (lmax + 1, 2 * mmax + 1). |
required |
return_sparse
|
bool
|
Whether to return a sparse array or a dense one. |
True
|
Returns:
| Type | Description |
|---|---|
COO | NDArray[complex128]
|
The conjugate spherical harmonics coefficients array in standard Fourier order, in sparse or dense form. |
Source code in src/serval/sht.py
ms_from_array(arr)
Creates a range of integers corresponding to the m values of spherical harmonics from -mmax to +mmax according to the order lmax of the input array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
NDArray[complex128]
|
Any array of shape compatible with spherical harmonics coefficients where the first dimension corresponds to lmax + 1. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[int_]
|
An array of integers representing the m values from -mmax to +mmax. |
Source code in src/serval/sht.py
nonzero_bandlimits(coeff)
Computes the bandlimits lmax, mmax of spherical harmonics coefficients from a sparse array based on the non-zero entries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coeff
|
COO | NDArray[complex128]
|
A spherical harmonics coefficients sparse array in standard Fourier order. Its shape should be (lmax + 1, 2 * mmax + 1). |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, int]
|
A tuple containing the maximum spherical harmonic degree lmax and maximum order mmax based on the non-zero coefficients. |
Source code in src/serval/sht.py
serval_to_ducc0_alm(alm, lmax, mmax)
Convert SERVAL alm to the (aR, aI) pair expected by ducc0.sht.rotate_alm.
SERVAL stores complex SH coefficients in a dense (..., lmax+1, 2*mmax+1) array
indexed as alm[..., l, m + mmax]. ducc0.sht.rotate_alm internally
decomposes a complex field into two real fields whose m >= 0 triangular
coefficients are stored flat. This function performs that decomposition and
the associated normalization conversion (pyshtools ortho + csphase=1 → ducc0
internal 4Ï€ norm).
The decomposition follows the relation used by pyshtools' ducc0 backend:
with \(a_{R,\ell 0} = \mathrm{Re}(c_{\ell,0})\), \(a_{I,\ell 0} = \mathrm{Im}(c_{\ell,0})\). The normalization factors cancel between the ortho→4π conversion and the real-field reconstruction, yielding the compact expressions above.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alm
|
NDArray[complex128]
|
SERVAL alm array of shape |
required |
lmax
|
int
|
Maximum degree. |
required |
mmax
|
int
|
Maximum order stored in alm (may be less than lmax). |
required |
Returns:
| Type | Description |
|---|---|
aR, aI : npt.NDArray[np.complex128]
|
Both have shape |
Source code in src/serval/sht.py
set_bandlimits(coeffs, lmax, mmax=None)
Reshapes sparse or dense spherical harmonics coefficients to given bandlimits.
Operates on the last two axes of coeffs, treating any preceding axes as
batch dimensions. Sparse (sparse.COO) inputs are supported only for 2-D
arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coeffs
|
Coeffs
|
A sparse or dense spherical harmonics coefficients array in standard Fourier order.
The last two axes should have shape |
required |
lmax
|
int
|
The target maximum spherical harmonic degree. |
required |
mmax
|
int | None
|
The target maximum spherical harmonic order. If None, it is set equal to lmax. |
None
|
Returns:
| Type | Description |
|---|---|
Coeffs
|
A sparse or dense spherical harmonics coefficients array reshaped to the target bandlimits. |
Source code in src/serval/sht.py
sparse_synthesis(sparse_coeff)
Transfomrs spherical harmonics coefficients from a sparse array to a pyshtools grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sparse_coeff
|
COO
|
A sparse spherical harmonics coefficients array in standard Fourier order. Its shape should be (lmax + 1, 2 * mmax + 1). |
required |
Returns:
| Type | Description |
|---|---|
SHGrid
|
A spherical harmonic grid object. |
Source code in src/serval/sht.py
stack_ms(coeffs)
Reorganizes spherical harmonics coefficients from the pyshtools format to the standard Fourrier order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coeffs
|
NDArray[complex128]
|
A spherical harmonics coefficients array in pyshtools format. Its shape should be (2, lmax + 1, mmax + 1), where the first dimension corresponds to negative and positive m values. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[complex128]
|
A spherical harmonics coefficients array in standard Fourier order. Its shape will be (lmax + 1, 2 * mmax + 1), with m values ranging from -mmax to +mmax. |
Source code in src/serval/sht.py
threshold_bandlimits(coeff, threshold=SPARSE_THRESHOLD)
Computes the bandlimits lmax, mmax of spherical harmonics coefficients from a sparse or dense array based on the non-zero entries, after setting the coefficients below a given threshold to zero.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coeff
|
COO | NDArray[complex128]
|
A sparse or dense spherical harmonics coefficients array in standard Fourier order. Its shape should be (lmax + 1, 2 * mmax + 1). |
required |
threshold
|
float
|
The threshold below which coefficients are set to zero. |
SPARSE_THRESHOLD
|
Returns:
| Type | Description |
|---|---|
tuple[int, int]
|
A tuple containing the maximum spherical harmonic degree lmax and maximum order mmax based on the filtered coefficients. |
Source code in src/serval/sht.py
to_sparse(coeffs, threshold=SPARSE_THRESHOLD)
Transfomrs spherical harmonics coefficients from pyshtools format to a sparse array in standard Fourier order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coeffs
|
SHCoeffs
|
A spherical harmonics coefficients object in pyshtools format. Its shape should be (2, lmax + 1, mmax + 1). |
required |
threshold
|
float
|
The threshold below which coefficients are set to zero. |
SPARSE_THRESHOLD
|
Returns:
| Type | Description |
|---|---|
COO
|
A sparse spherical harmonics coefficients array in standard Fourier order. Its shape will be (lmax + 1, 2 * mmax + 1). |
Source code in src/serval/sht.py
unstack_ms(coeffs)
Reorganizes spherical harmonics coefficients from the standard Fourier order to the pyshtools format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coeffs
|
NDArray[complex128]
|
A spherical harmonics coefficients array in standard Fourier order. Its shape should be (lmax + 1, 2 * mmax + 1), with m values ranging from -mmax to +mmax. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[complex128]
|
A spherical harmonics coefficients array in pyshtools format. Its shape will be (2, lmax + 1, mmax + 1), where the first dimension corresponds to negative and positive m values. |
Source code in src/serval/sht.py
General Utilities (serval.utils.py)
airy_pattern(freq, theta, phi, D_eff, asymmetry_ratio=1.0, asymmetry_angle=0.0, power=False, fwhm_fac=AIRY_FWHM_FACTOR)
Evaluate an Airy disk beam pattern in pointing-frame coordinates.
The voltage pattern is \(2 J_1(x) / x\) with
\(x = \pi \cdot \mathrm{AIRY\_FWHM\_FACTOR} \cdot D_\mathrm{eff} \sin\theta
/ (\mathrm{fwhm\_fac} \cdot \lambda)\), so the power-beam FWHM equals
\(\mathrm{fwhm\_fac} \cdot \lambda / D_\mathrm{eff}\) exactly in \(\sin\theta\).
Use gaussian_pattern with use_sin_theta=True
for a Gaussian whose FWHM is defined in the same \(\sin\theta\) coordinate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
freq
|
float or array_like
|
Frequency in MHz, broadcastable to |
required |
theta
|
array_like
|
Pointing-frame colatitude in radians, shape |
required |
phi
|
array_like
|
Pointing-frame azimuth in radians, shape |
required |
D_eff
|
float
|
Effective dish diameter in metres. |
required |
asymmetry_ratio
|
float
|
Ratio of semi-major to semi-minor aperture (\(\geq 1\)). Default 1.0. |
1.0
|
asymmetry_angle
|
float
|
Orientation of the major axis from \(\phi = 0\), in radians. Default 0.0. |
0.0
|
power
|
bool
|
If |
False
|
fwhm_fac
|
float
|
Power-beam FWHM in units of \(\lambda / D_\mathrm{eff}\). Default
|
AIRY_FWHM_FACTOR
|
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
Beam pattern evaluated on the input grid. |
Source code in src/serval/utils.py
analytic_plane_wave_al(ells, kz)
Computes the analytic spherical harmonic coefficients of a plane wave propagating in the z-direction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ells
|
NDArray[int64]
|
The spherical harmonic degrees at which to evaluate the coefficients. |
required |
kz
|
NDArray[float64]
|
The wavevector magnitudes at which to evaluate the coefficients. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[complex128]
|
The spherical harmonic coefficients of the plane wave at the specified degrees and wavevector magnitudes. |
Source code in src/serval/utils.py
bandlimited_random_plane_wave(lmax, template_grid, rng, threshold=SPARSE_THRESHOLD)
Generates a random band-limited plane wave on the sphere evaluated on the grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lmax
|
int
|
The maximum spherical harmonic degree for band-limiting. |
required |
template_grid
|
SHGrid
|
A pyshtools SHGrid object that serves as a template for the output grid. |
required |
rng
|
Generator | None
|
An optional random number generator for reproducibility. If None, a new generator will be created. Default is None. |
required |
threshold
|
float
|
The threshold for determining the plane wave magnitude from the bandlimit. |
SPARSE_THRESHOLD
|
Returns:
| Type | Description |
|---|---|
tuple[SHGrid, NDArray[float64]]
|
A tuple containing the generated band-limited plane wave grid and the corresponding wavevector. |
Source code in src/serval/utils.py
gaussian_pattern(freq, theta, phi, D_eff, asymmetry_ratio=1.0, asymmetry_angle=0.0, power=False, fwhm_fac=AIRY_FWHM_FACTOR, use_sin_theta=False)
Evaluate a Gaussian beam pattern in pointing-frame coordinates.
The FWHM of the power beam along the major axis is \(\mathrm{fwhm\_fac} \cdot
\lambda / D_\mathrm{eff}\), exact in \(\theta\) by default. Setting
use_sin_theta=True replaces \(\theta\) with \(\sin\theta\) throughout, making
the FWHM exact in \(\sin\theta\) — directly comparable to
airy_pattern. An optional elliptical asymmetry
stretches the beam along a specified axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
freq
|
float or array_like
|
Frequency in MHz, broadcastable to |
required |
theta
|
array_like
|
Pointing-frame colatitude in radians, shape |
required |
phi
|
array_like
|
Pointing-frame azimuth in radians, shape |
required |
D_eff
|
float
|
Effective dish diameter in metres. |
required |
asymmetry_ratio
|
float
|
Ratio of semi-major to semi-minor beam width (\(\geq 1\)). Default 1.0. |
1.0
|
asymmetry_angle
|
float
|
Orientation of the major axis from \(\phi = 0\), in radians. Default 0.0. |
0.0
|
power
|
bool
|
If |
False
|
fwhm_fac
|
float
|
Power-beam FWHM in units of \(\lambda / D_\mathrm{eff}\). Default
|
AIRY_FWHM_FACTOR
|
use_sin_theta
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
Beam pattern evaluated on the input grid. |
Source code in src/serval/utils.py
grid_theta_phi(grid, meshgrid=False)
Return the colatitude and azimuth arrays for a pyshtools grid.
Converts the grid latitude and longitude (in degrees) to physics convention spherical coordinates: colatitude \(\theta \in [0, \pi]\) (with \(\theta = 0\) at the north pole) and azimuth \(\phi \in [0, 2\pi)\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
SHGrid
|
A pyshtools grid object. |
required |
meshgrid
|
bool
|
If True, return 2-D arrays broadcastable to the grid shape
|
False
|
Returns:
| Name | Type | Description |
|---|---|---|
theta |
NDArray[float64]
|
Colatitude in radians. Shape |
phi |
NDArray[float64]
|
Azimuth in radians. Shape |
Source code in src/serval/utils.py
harmonic_point_source(ra_deg, dec_deg, lmax, return_sparse=True)
Generates band-limited spherical harmonic coefficients for a point source at given RA and Dec.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ra_deg
|
float
|
The right ascension of the point source in degrees. |
required |
dec_deg
|
float
|
The declination of the point source in degrees. |
required |
lmax
|
int
|
The maximum spherical harmonic degree. |
required |
return_sparse
|
bool
|
If True (default), return a sparse.COO array. If False, return a dense numpy array of shape (lmax+1, 2*lmax+1). |
True
|
Returns:
| Type | Description |
|---|---|
COO | NDArray[complex128]
|
The band-limited spherical harmonic coefficients of the point source in standard Fourier order, shape (lmax+1, 2*lmax+1). |
Source code in src/serval/utils.py
integral_from_coeff(coeff)
Computes the integral over the sphere from spherical harmonic coefficients.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coeff
|
SHCoeffs
|
The spherical harmonic coefficients to integrate in pyshtools format. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The integral of the function represented by the spherical harmonic coefficients over the unit sphere. |
Source code in src/serval/utils.py
integral_from_grid(grid_integrand)
Computes the integral over the sphere from a spherical harmonic grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coeff
|
SHGrid
|
The spherical harmonic grid to integrate in pyshtools format. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The integral of the function represented by the spherical harmonic grid over the unit sphere. |
Source code in src/serval/utils.py
integrals_from_alm(alm)
Compute the integral over the unit sphere for each frequency channel.
Reads the l=0, m=0 coefficient directly from SERVAL's Fourier-ordered alm array, consistent with the ortho+csphase=1 SHT convention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alm
|
(ndarray, shape(..., lmax + 1, 2 * mmax + 1))
|
Spherical harmonic coefficients in SERVAL Fourier format.
m=0 is at column index |
required |
Returns:
| Type | Description |
|---|---|
(ndarray, shape(...))
|
Integral of the function over the unit sphere per leading-axis element. Complex in general; real for real-valued beams. |
Source code in src/serval/utils.py
mmodes_to_visibilities(mmodes, m1max=None, ms=None)
Reconstruct a visibility timestream from m-mode amplitudes.
The output is the physical visibility timestream reconstructed from the
Fourier-series amplitudes in mmodes:
Internally this is evaluated via ifft(full_mmodes) multiplied by the
output length to undo NumPy's inverse-FFT normalisation, so that
:func:visibilities_to_mmodes and :func:mmodes_to_visibilities are true
inverses on a consistent ERA grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mmodes
|
NDArray[complex128]
|
M-mode amplitudes.
|
required |
m1max
|
int
|
Maximum absolute m-value of the output grid. Required when |
None
|
ms
|
array of int
|
M-values corresponding to the last axis of the sparse |
None
|
Returns:
| Type | Description |
|---|---|
NDArray[complex128]
|
Visibility timestream with shape |
Source code in src/serval/utils.py
normal_to_spherical(n)
Transforms arrays of Cartesian unit normal vectors to spherical coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
NDArray[float64]
|
Array of Cartesian unit normal vectors, shape |
required |
Returns:
| Name | Type | Description |
|---|---|---|
theta |
NDArray[float64]
|
Colatitude angles in radians, shape |
phi |
NDArray[float64]
|
Azimuthal angles in radians in |
Source code in src/serval/utils.py
plane_wave_bandlimits(k, threshold=SPARSE_THRESHOLD)
Computes the spherical harmonic bandlimits lmax, mmax required to represent a plane wave with wavevector k to a given threshold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
NDArray[float64]
|
The wavevector of the plane wave. |
required |
threshold
|
float
|
The threshold for determining the bandlimits. Default is SPARSE_THRESHOLD. |
SPARSE_THRESHOLD
|
Returns:
| Type | Description |
|---|---|
tuple[int, int]
|
A tuple containing the maximum spherical harmonic degree lmax and maximum absolute order mmax required to represent the plane wave. |
Source code in src/serval/utils.py
plane_wave_mag_from_bandlimit(lmax, threshold=SPARSE_THRESHOLD)
Computes the maximum usable plane-wave wavenumber |k| that can be represented on a spherical-harmonic grid of bandlimit lmax.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lmax
|
int
|
The maximum spherical harmonic degree for band-limiting. |
required |
threshold
|
float
|
The threshold for determining the plane wave magnitude from the bandlimit. |
SPARSE_THRESHOLD
|
Returns:
| Type | Description |
|---|---|
float
|
The maximum usable plane-wave wavenumber |k|. |
Source code in src/serval/utils.py
plane_waves(ks, template)
Produces a band-limited spherical plane wave evaluated on the grid from wavevectors ks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ks
|
list[NDArray[float64]]
|
A list of wavevector arrays. Each array should have shape (3,). |
required |
template
|
SHGrid
|
A pyshtools SHGrid object that serves as a template for the output grid. |
required |
Returns:
| Type | Description |
|---|---|
SHGrid
|
A pyshtools SHGrid object containing the plane wave data. |
Source code in src/serval/utils.py
plane_waves_integral(ks)
Computes the integral over the unit sphere of plane waves with wavevectors ks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ks
|
list[NDArray[float64]]
|
A list of wavevector arrays. Each array should have shape (..., 3), where ... represents any number of leading dimensions. |
required |
Returns:
| Type | Description |
|---|---|
float | NDArray[float64]
|
The integral of the product of plane waves over the unit sphere. The output shape is the broadcasted shape of the input wavevector arrays without the last dimension. |
Source code in src/serval/utils.py
plane_waves_mmodes(ks, mmax)
Computes the m-modes of a product of plane waves by rotating one of the k-vectors (the first one) through all azimuthal angles to create visibilities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ks
|
list[NDArray[float64]]
|
A list of wavevector arrays. Each array should have shape (3,). |
required |
mmax
|
int
|
The maximum absolute m-mode index. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[complex128]
|
The m-modes of the product of plane waves, with shape (2 * mmax + 1,). |
Source code in src/serval/utils.py
pointed_theta_phi(lmax, latitude, longitude, altitude, azimuth, boresight)
Compute TIRS-grid coordinates expressed in the pointing frame.
For each point on the TIRS spherical harmonic grid (determined by
lmax), computes the colatitude and azimuth as seen in the frame
of the dish pointing direction. This is the coordinate map needed
to evaluate a beam pattern (defined in pointing coordinates) over
the whole sky grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lmax
|
int
|
Band-limit of the spherical harmonic grid. |
required |
latitude
|
float
|
Geodetic latitude of the observer in radians. |
required |
longitude
|
float
|
Geodetic longitude of the observer in radians. |
required |
altitude
|
float
|
Altitude of the observer in metres. |
required |
azimuth
|
float
|
Dish azimuth in radians (North-through-East). |
required |
boresight
|
float
|
Boresight rotation angle in radians. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
pointing_theta |
NDArray[float64]
|
Colatitude in the pointing frame for every TIRS grid point,
shape |
pointing_phi |
NDArray[float64]
|
Azimuth in the pointing frame for every TIRS grid point,
shape |
Source code in src/serval/utils.py
power_law_sky(lmax, power_law_index=2.0, seed=None)
Generates a random sky realization with a power-law angular power spectrum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lmax
|
int
|
The maximum spherical harmonic degree. |
required |
power_law_index
|
float
|
The index of the power-law angular power spectrum. Default is 2.0. |
2.0
|
seed
|
int | None
|
The random seed for reproducibility. Default is None. |
None
|
Returns:
| Type | Description |
|---|---|
SHGrid
|
The generated random sky realization as a pyshtools spherical harmonic grid. |
Source code in src/serval/utils.py
spherical_tangent_vectors(theta, phi)
Computes the tangent basis vectors at the given spherical coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta
|
NDArray[float64]
|
The polar angles in radians. |
required |
phi
|
NDArray[float64]
|
The azimuthal angles in radians. |
required |
Returns:
| Type | Description |
|---|---|
tuple[NDArray[float64], NDArray[float64]]
|
The unit tangent vectors (theta_hat, phi_hat) in the directions of increasing theta and increasing phi, respectively. |
Source code in src/serval/utils.py
spherical_to_normal(theta, phi)
Transforms arrays of spherical coordinates to arrays of Cartesian unit normal vectors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta
|
NDArray[float64]
|
The polar angles in radians. |
required |
phi
|
NDArray[float64]
|
The azimuthal angles in radians. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
The Cartesian unit normal vectors corresponding to the input spherical angles. |
Source code in src/serval/utils.py
visibilities_at_eras(mmodes, m_values, era_deg)
Evaluate a visibility timestream at arbitrary ERA positions via NUDFT.
Reconstructs visibilities at arbitrary Earth Rotation Angle values using the stored m-mode amplitudes. The evaluation is exact for band-limited signals (no aliasing up to the Nyquist m-value) and periodic with period 360°.
The relationship between m-modes and visibilities is::
vis(f, φ) = Σ_m A_m(f) · exp(2πi · m · φ / 360)
where A_m = mmodes[..., mmax + m] (fftshifted storage).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mmodes
|
(ndarray, shape(..., n_era))
|
M-mode array in fftshifted order — m=0 is at index |
required |
m_values
|
ndarray of int, shape (n_m,)
|
M-values of the non-zero entries in |
required |
era_deg
|
(ndarray, shape(n_t))
|
ERA values in degrees at which to evaluate. Values outside |
required |
Returns:
| Type | Description |
|---|---|
(ndarray, shape(..., n_t))
|
Reconstructed visibilities at the requested ERA positions. |
Source code in src/serval/utils.py
visibilities_to_mmodes(vis)
Compute per-sample m-mode amplitudes from a visibility timestream.
Applies an FFT along the last axis and normalises by n_times so the
returned coefficients are the Fourier-series amplitudes \(A_m\) satisfying
The output is fftshifted: index n_times // 2 + m corresponds to
m-mode m.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vis
|
NDArray[complex128]
|
Input visibilities with shape |
required |
Returns:
| Type | Description |
|---|---|
NDArray[complex128]
|
M-mode amplitudes with shape |
Source code in src/serval/utils.py
Core Gaunt Coefficient Utilities (serval.gaunt.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([])). |