Automatic documentation generated from docstrings
This page is auto-generated from the docstrings of functions, methods, classes, and modules. Each lowest-level module in Mass2 (i.e., each python file) in mass2.core that you want documented and indexed for searching should be listed in this docstrings.md file. The non-core docstrings contain the docstrings for all modules other than mass2.core.
Core
mass2.core: Core Mass2 functionality, including file I/O, microcalorimeter channel bookkeeping, recipes, fitting, filtering, and more.
Data structures and methods for handling a single microcalorimeter channel's pulse data and metadata.
BadChannel
dataclass
A wrapper around Channel that includes error information.
Source code in mass2/core/channel.py
1496 1497 1498 1499 1500 1501 1502 1503 | |
Channel
dataclass
A single microcalorimeter channel's pulse data and associated metadata.
Source code in mass2/core/channel.py
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 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 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 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 780 781 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 996 997 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 1256 1257 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 1427 1428 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 | |
ch_num
property
Channel number, from the filename
frametime_s
property
Sample (or frame) period in seconds, from the file header
last_avg_pulse
property
Return the average pulse stored in the last recipe step that's an optimal filter step
| Returns: |
|
|---|
last_filter
property
Return the average pulse stored in the last recipe step that's an optimal filter step
| Returns: |
|
|---|
last_noise_autocorrelation
property
Return the noise autocorrelation stored in the last recipe step that's an optimal filter step
| Returns: |
|
|---|
last_noise_psd
property
Return the noise PSD stored in the last recipe step that's an optimal filter step
| Returns: |
|
|---|
last_v_over_dv
property
Return the predicted V/dV stored in the last recipe step that's an optimal filter step
| Returns: |
|
|---|
n_presamples
property
Pretrigger samples in each pulse record, from the file header
n_samples
property
Samples per pulse, from the file header
shortname
property
A short name for this channel, suitable for plot titles.
__eq__(other)
Return True if the other object is the same object (by id).
Source code in mass2/core/channel.py
1228 1229 1230 1231 1232 1233 1234 | |
__hash__()
Return a hash based on the object's id.
Source code in mass2/core/channel.py
1221 1222 1223 1224 1225 1226 | |
as_bad(error_type, error_msg, backtrace)
Return a BadChannel object, which wraps this Channel and includes error information.
Source code in mass2/core/channel.py
1411 1412 1413 | |
bad_df(cols=pl.all(), use_expr=pl.lit(True))
Return a Polars DataFrame of the given columns, filtered by the inverse of good_expr, and use_expr.
Source code in mass2/core/channel.py
1152 1153 1154 1155 1156 1157 | |
compute_ats_model(pulse_col, use_expr=pl.lit(True), limit=2000)
Compute the average pulse and arrival-time model for an ATS filter.
We use the first limit pulses that pass good_expr and use_expr.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in mass2/core/channel.py
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 | |
compute_average_pulse(pulse_col='pulse', use_expr=pl.lit(True), limit=2000)
Compute an average pulse given a use expression.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in mass2/core/channel.py
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 | |
concat_ch(ch)
Concat the given channel's dataframe to the existing dataframe, keeping all other attributes the same.
If the new channel ch has a history and/or steps, those will be lost
Source code in mass2/core/channel.py
1382 1383 1384 1385 1386 | |
concat_df(df)
Concat the given dataframe to the existing dataframe, keeping all other attributes the same.
If the new frame df has a history and/or steps, those will be lost
Source code in mass2/core/channel.py
1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 | |
correct_pretrig_mean_jumps(uncorrected='pretrig_mean', corrected='ptm_jf', period=4096)
Correct pretrigger mean jumps in the raw pulse data, writing to a new column.
Source code in mass2/core/channel.py
873 874 875 876 877 878 879 880 881 882 883 884 | |
driftcorrect(indicator_col='pretrig_mean', uncorrected_col='5lagy', corrected_col=None, use_expr=pl.lit(True))
Correct for gain drift correlated with the given indicator column.
Source code in mass2/core/channel.py
1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 | |
filter5lag(pulse_col='pulse', peak_y_col='5lagy', peak_x_col='5lagx', f_3db=25000.0, use_expr=pl.lit(True), time_constant_s_of_exp_to_be_orthogonal_to=None, fourier=False, longest_autocorr_filter=10000)
Compute a 5-lag optimal filter and apply it.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in mass2/core/channel.py
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 996 997 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 | |
filterATS(pulse_col='pulse', peak_y_col='ats_y', peak_x_col='ats_x', f_3db=25000.0, use_expr=pl.lit(True))
Compute an arrival-time-safe (ATS) optimal filter and apply it.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in mass2/core/channel.py
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 | |
fit_pulse(index=0, col='pulse', verbose=True)
Fit a single pulse to a 2-exponential-with-tail model, returning the fit result.
Source code in mass2/core/channel.py
1485 1486 1487 1488 1489 1490 1491 1492 1493 | |
from_ljh(path, noise_path=None, keep_posix_usec=False, transform_raw=None)
classmethod
Load a Channel from an LJH file, optionally with a NoiseChannel from a corresponding noise LJH file.
Source code in mass2/core/channel.py
1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 | |
from_off(off)
classmethod
Load a Channel from an OFF file.
Source code in mass2/core/channel.py
1257 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 | |
get_step(index)
Get the step at the given index, supporting negative indices.
Source code in mass2/core/channel.py
150 151 152 153 154 155 156 | |
good_df(cols=pl.all(), use_expr=pl.lit(True))
Return a Polars DataFrame of the given columns, filtered by good_expr and use_expr.
Source code in mass2/core/channel.py
1145 1146 1147 1148 1149 1150 | |
good_series(col, use_expr=pl.lit(True))
Return a Polars Series of the given column, filtered by good_expr and use_expr.
Source code in mass2/core/channel.py
605 606 607 | |
good_serieses(cols, use_expr=pl.lit(True))
Return a list of Polars Series of the given columns, filtered by good_expr and use_expr.
Source code in mass2/core/channel.py
1159 1160 1161 1162 | |
hist(col, bin_edges, use_good_expr=True, use_expr=pl.lit(True))
Compute a histogram of the given column, optionally filtering by good_expr and use_expr.
Source code in mass2/core/channel.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
linefit(line, col, use_expr=pl.lit(True), has_linear_background=False, has_tails=False, dlo=50, dhi=50, binsize=0.5, params_update=lmfit.Parameters())
Fit a spectral line to the binned data from the given column, optionally filtering by use_expr.
Source code in mass2/core/channel.py
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 | |
mo_stepplots()
Marimo UI element to choose and display step plots, with a dropdown to choose channel number.
Source code in mass2/core/channel.py
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 | |
multifit_mass_cal(multifit, previous_cal_step_index, calibrated_col, use_expr=pl.lit(True))
Fit multiple spectral lines, to create a Mass1-style gain calibration.
Source code in mass2/core/channel.py
1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 | |
multifit_quadratic_gain_cal(multifit, previous_cal_step_index, calibrated_col, use_expr=pl.lit(True))
Fit multiple spectral lines, to create a quadratic gain calibration.
Source code in mass2/core/channel.py
1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 | |
phase_correct_mass_specific_lines(indicator_col, uncorrected_col, line_names, previous_cal_step_index, corrected_col=None, use_expr=pl.lit(True))
Apply phase correction to the given uncorrected column, where specific lines are used to judge the correction.
Source code in mass2/core/channel.py
1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 | |
plot_hist(col, bin_edges, axis=None, use_good_expr=True, use_expr=pl.lit(True))
Compute and plot a histogram of the given column, optionally filtering by good_expr and use_expr.
Source code in mass2/core/channel.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
plot_hists(col, bin_edges, group_by_col, axis=None, use_good_expr=True, use_expr=pl.lit(True), skip_none=True)
Plots histograms for the given column, grouped by the specified column.
Parameters: - col (str): The column name to plot. - bin_edges (array-like): The edges of the bins for the histogram. - group_by_col (str): The column name to group by. This is required. - axis (matplotlib.Axes, optional): The axis to plot on. If None, a new figure is created.
Source code in mass2/core/channel.py
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 | |
plot_pulses(length=30, skip=0, random=False, record_numbers=None, subtract_baseline=False, derivative=False, summarize=True, summary_columns=None, pulse_field='pulse', use_expr=pl.lit(True), use_good_expr=True, axis=None, cm='viridis_r')
Plot some example pulses
| Parameters: |
|
|---|
Source code in mass2/core/channel.py
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 | |
plot_scatter(x_col, y_col, cont_color_col=None, color_col=None, use_expr=pl.lit(True), use_good_expr=True, skip_none=True, axis=None, annotate=False, max_points=None, extended_title=True)
Generate a scatter plot of y_col vs x_col, optionally colored by color_col.
| Parameters: |
|
|---|
Source code in mass2/core/channel.py
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 | |
plot_summaries(use_expr_in=None, downsample=None, log=False)
Plot a summary of the data set, including time series and histograms of key pulse properties.
| Parameters: |
|
|---|
Source code in mass2/core/channel.py
1421 1422 1423 1424 1425 1426 1427 1428 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 | |
rough_cal(line_names, uncalibrated_col='filtValue', calibrated_col=None, use_expr=pl.lit(True), max_fractional_energy_error_3rd_assignment=0.1, min_gain_fraction_at_ph_30k=0.25, fwhm_pulse_height_units=75, n_extra_peaks=10, acceptable_rms_residual_e=10)
Learn a rough calibration by trying to assign the 3 brightest peaks, then fitting a line to those and looking for other peaks that fit that line.
Source code in mass2/core/channel.py
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 | |
rough_cal_combinatoric(line_names, uncalibrated_col, calibrated_col, ph_smoothing_fwhm, n_extra=3, use_expr=pl.lit(True))
Learn a rough calibration by trying all combinatorically possible peak assignments.
Source code in mass2/core/channel.py
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 | |
rough_cal_combinatoric_height_info(line_names, line_heights_allowed, uncalibrated_col, calibrated_col, ph_smoothing_fwhm, n_extra=3, use_expr=pl.lit(True))
Learn a rough calibration by trying all combinatorically possible peak assignments, using known relative peak heights to limit the possibilities.
Source code in mass2/core/channel.py
700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 | |
save_recipes(filename)
Save the recipe steps to a pickle file, keyed by channel number.
Source code in mass2/core/channel.py
1415 1416 1417 1418 1419 | |
step_plot(step_ind, **kwargs)
Make a debug plot for the given step index, supporting negative indices.
Source code in mass2/core/channel.py
158 159 160 161 162 163 164 165 | |
step_summary()
Return a list of (step type name, elapsed time in seconds) for each step in the recipe.
Source code in mass2/core/channel.py
1217 1218 1219 | |
summarize_pulses(col='pulse', pretrigger_ignore_samples=0, peak_index=None)
Summarize the pulses, adding columns for pulse height, pretrigger mean, etc.
Source code in mass2/core/channel.py
851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 | |
typical_peak_ind(col='pulse')
cached
Return the typical peak index of the given column, using the median peak index for the first 100 pulses.
Source code in mass2/core/channel.py
843 844 845 846 847 848 849 | |
with_categorize_step(category_condition_dict, output_col='category')
Add a recipe step that categorizes pulses based on the given conditions.
Source code in mass2/core/channel.py
903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 | |
with_column_map_step(input_col, output_col, f)
f should take a numpy array and return a numpy array with the same number of elements
Source code in mass2/core/channel.py
784 785 786 787 | |
with_columns(df2)
Append columns from df2 to the existing dataframe, keeping all other attributes the same.
Source code in mass2/core/channel.py
1329 1330 1331 1332 | |
with_experiment_state_df(df_es, force_timestamp_monotonic=False)
Add experiment states from an existing dataframe
Source code in mass2/core/channel.py
1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 | |
with_external_trigger_df(df_ext)
Add external trigger times from an existing dataframe
Source code in mass2/core/channel.py
1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 | |
with_good_expr(good_expr, replace=False)
Return a new Channel with the given good_expr, combined with the existing good_expr by "and",
of by replacing it entirely if replace is True.
Source code in mass2/core/channel.py
775 776 777 778 779 780 781 782 | |
with_good_expr_below_nsigma_outlier_resistant(col_nsigma_pairs, replace=False, use_prev_good_expr=True)
Set good_expr to exclude pulses with any of the given columns above outlier-resistant thresholds. Always sets lower limit at 0, so don't use for values that can be negative
Source code in mass2/core/channel.py
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 | |
with_good_expr_nsigma_range_outlier_resistant(col_nsigma_pairs, replace=False, use_prev_good_expr=True)
Set good_expr to exclude pulses with any of the given columns above outlier-resistant thresholds. Always sets lower limit at 0, so don't use for values that can be negative
Source code in mass2/core/channel.py
824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 | |
with_good_expr_pretrig_rms_and_postpeak_deriv(n_sigma_pretrig_rms=20, n_sigma_postpeak_deriv=20, replace=False)
Set good_expr to exclude pulses with pretrigger RMS or postpeak derivative above outlier-resistant thresholds.
Source code in mass2/core/channel.py
789 790 791 792 793 794 795 796 797 798 | |
with_range_around_median(col, range_up, range_down)
Set good_expr to exclude pulses with col outside the given range around its median.
Source code in mass2/core/channel.py
800 801 802 803 | |
with_replacement_df(df2)
Replace the dataframe with a new one, keeping all other attributes the same.
Source code in mass2/core/channel.py
1322 1323 1324 1325 1326 1327 | |
with_select_step(col_expr_dict)
This step is meant for interactive exploration; it's basically like the df.select() method, but it's saved as a step.
Source code in mass2/core/channel.py
886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 | |
with_step(step)
Return a new Channel with the given step applied to generate new columns in the dataframe.
Source code in mass2/core/channel.py
753 754 755 756 757 758 759 760 761 762 763 764 765 766 | |
with_steps(steps)
Return a new Channel with the given steps applied to generate new columns in the dataframe.
Source code in mass2/core/channel.py
768 769 770 771 772 773 | |
ChannelHeader
dataclass
Metadata about a Channel, of the sort read from file header.
Source code in mass2/core/channel.py
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 | |
from_ljh_header_df(df)
classmethod
Construct from the LJH header dataframe as returned by LJHFile.to_polars()
Source code in mass2/core/channel.py
53 54 55 56 57 58 59 60 61 62 63 64 65 | |
Data structures and methods for handling a group of microcalorimeter channels.
Channels
dataclass
A collection of microcalorimeter channels, with methods to operate in parallel on all channels.
Source code in mass2/core/channels.py
33 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 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 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 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 780 781 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 | |
ch0
property
Return a representative Channel object for convenient exploration (the one with the lowest channel number).
__eq__(other)
Equality test based on object identity.
Source code in mass2/core/channels.py
421 422 423 | |
__hash__()
Hash based on the object's id (identity).
Source code in mass2/core/channels.py
414 415 416 417 418 419 | |
concat_data(other_data)
Return a new Channels object with data from this and the other Channels object concatenated together. Only channels that exist in both objects are included in the result.
Source code in mass2/core/channels.py
661 662 663 664 665 666 667 668 669 670 671 672 673 674 | |
dfg(exclude='pulse')
cached
Return a DataFrame containing good pulses from each channel. Excludes the given columns (default "pulse").
Source code in mass2/core/channels.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
from_df(df_in, frametime_s, n_presamples, n_samples, description='from Channels.channels_from_df')
classmethod
Create a Channels object from a single DataFrame that holds data from multiple channels.
Source code in mass2/core/channels.py
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 | |
from_ljh_folder(pulse_folder, noise_folder=None, limit=None, exclude_ch_nums=None, include_ch_nums=None)
classmethod
Create an instance from a directory of LJH files.
Source code in mass2/core/channels.py
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 | |
from_ljh_path_pairs(pulse_noise_pairs, description)
classmethod
Create a :class:Channels instance from pairs of LJH files.
Args:
pulse_noise_pairs (List[Tuple[str, str]]):
A list of (pulse_path, noise_path) tuples, where each entry contains
the file path to a pulse LJH file and its corresponding noise LJH file.
description (str):
A human-readable description for the resulting Channels object.
Returns:
Channels:
A Channels object with one :class:Channel per (pulse_path, noise_path) pair.
Raises: AssertionError: If two input files correspond to the same channel number.
Notes:
Each channel is created via :meth:Channel.from_ljh.
The channel number is taken from the LJH file header and used as the key
in the returned Channels mapping.
Examples: >>> pairs = [ ... ("datadir/run0000_ch0000.ljh", "datadir/run0001_ch0000.ljh"), ... ("datadir/run0000_ch0001.ljh", "datadir/run0001_ch0001.ljh"), ... ] >>> channels = Channels.from_ljh_path_pairs(pairs, description="Test run") >>> list(channels.keys()) [0, 1]
Source code in mass2/core/channels.py
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 | |
from_off_paths(off_paths, description)
classmethod
Create an instance from a sequence of OFF-file paths
Source code in mass2/core/channels.py
466 467 468 469 470 471 472 473 | |
get_an_ljh_path()
Return the path to a representative one of the LJH files used to create this Channels object.
Source code in mass2/core/channels.py
507 508 509 | |
get_experiment_state_df(experiment_state_path=None)
Return a DataFrame containing experiment state information.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in mass2/core/channels.py
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 | |
get_path_in_output_folder(filename)
Return a path in an output folder named like the run number, sibling to the LJH folder.
Source code in mass2/core/channels.py
511 512 513 514 515 516 517 518 | |
linefit(line, col, use_expr=pl.lit(True), has_linear_background=False, has_tails=False, dlo=50, dhi=50, binsize=0.5, params_update=lmfit.Parameters())
Perform a fit to one spectral line in the coadded histogram of the given column.
Source code in mass2/core/channels.py
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 | |
linefit_joblib(line, col, prefer='threads', n_jobs=4)
No one but Galen understands this function.
Source code in mass2/core/channels.py
402 403 404 405 406 407 408 409 410 411 412 | |
load_analysis(path)
staticmethod
Load an analysis-in-progress from a zipfile
| Parameters: |
|
|---|
Source code in mass2/core/channels.py
776 777 778 779 780 781 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 | |
load_recipes(filename)
Return a copy of this Channels object with Recipe objects loaded from the given pickle file and applied to each Channel.
Source code in mass2/core/channels.py
648 649 650 651 652 | |
map(f, allow_throw=False)
Map function f over all channels, returning a new Channels object containing the new Channel objects.
Source code in mass2/core/channels.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 | |
parent_folder_path()
Return the parent folder of the LJH files used to create this Channels object. Specifically, the
self.ch0 channel's directory is used (normally the answer would be the same for all channels).
Source code in mass2/core/channels.py
654 655 656 657 658 659 | |
plot_avg_pulses(limit=20, channels=None, colormap=plt.cm.viridis, axis=None)
Plot the average pulses (the signal model) for the channels in this Channels object.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in mass2/core/channels.py
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 | |
plot_filters(limit=20, channels=None, colormap=plt.cm.viridis, axis=None)
Plot the optimal filters for the channels in this Channels object.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in mass2/core/channels.py
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 | |
plot_hist(col, bin_edges, use_expr=pl.lit(True), axis=None)
Plot a histogram for the given column across all channels.
Source code in mass2/core/channels.py
118 119 120 121 122 | |
plot_hists(col, bin_edges, group_by_col, axis=None, use_expr=None, skip_none=True)
Plots histograms for the given column, grouped by the specified column.
Parameters: - col (str): The column name to plot. - bin_edges (array-like): The edges of the bins for the histogram. - group_by_col (str): The column name to group by. This is required. - axis (matplotlib.Axes, optional): The axis to plot on. If None, a new figure is created.
Source code in mass2/core/channels.py
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 | |
plot_noise_autocorr(limit=20, channels=None, colormap=plt.cm.viridis, axis=None)
Plot the noise power autocorrelation for the channels in this Channels object.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in mass2/core/channels.py
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 | |
plot_noise_spectrum(limit=20, channels=None, colormap=plt.cm.viridis, axis=None)
Plot the noise power spectrum for the channels in this Channels object.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in mass2/core/channels.py
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 | |
save_analysis(zip_path, overwrite=False, trim_debug=False, trim_timestamp_and_subframecount=False)
Save an analysis-in-progress completely to a zip file, only tested for ljh backed channels so far
| Parameters: |
|
|---|
Source code in mass2/core/channels.py
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 | |
save_recipes(filename, required_fields=None, drop_debug=True)
Pickle a dictionary (one entry per channel) of Recipe objects.
If you want to save a "recipe", a minimal series of steps required to reproduce the required field(s),
then set required_fields to be a list/tuple/set of DataFrame column names (or a single column name)
whose production from raw data should be possible.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in mass2/core/channels.py
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 | |
set_bad(ch_num, msg, require_ch_num_exists=True)
Return a copy of this Channels object with the given channel number marked as bad.
Source code in mass2/core/channels.py
389 390 391 392 393 394 395 396 397 398 399 400 | |
with_experiment_state_by_path(experiment_state_path=None)
Return a copy of this Channels object with experiment state information added to each Channel.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in mass2/core/channels.py
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 | |
with_experiment_state_df(df_es)
Return a copy of this Channels object with experiment state information added to each Channel.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in mass2/core/channels.py
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 | |
with_external_trigger_by_path(path=None)
Return a copy of this Channels object with external trigger information added, loaded from the given path or EVENTUALLY (if None) inferring it from an LJH file (not yet implemented).
Source code in mass2/core/channels.py
580 581 582 583 584 585 586 587 588 589 590 591 | |
with_external_trigger_df(df_ext)
Return a copy of this Channels object with external trigger information added to each Channel, found from the given DataFrame.
Source code in mass2/core/channels.py
593 594 595 596 597 598 599 600 601 | |
with_more_channels(more)
Return a Channels object with additional Channels in it. New channels with the same number will overrule existing ones.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in mass2/core/channels.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
with_steps_dict(steps_dict)
Return a copy of this Channels object with the given Recipe objects added to each Channel.
Source code in mass2/core/channels.py
603 604 605 606 607 608 609 610 611 612 613 614 | |
mass2.core.analysis_algorithms - main algorithms used in data analysis
Designed to abstract certain key algorithms out of the class MicrocalDataSet
and be able to run them fast.
Created on Jun 9, 2014
@author: fowlerj
HistogramSmoother
Object that can repeatedly smooth histograms with the same bin count and width to the same Gaussian width. By pre-computing the smoothing kernel for that histogram, we can smooth multiple histograms with the same geometry.
Source code in mass2/core/analysis_algorithms.py
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 | |
__call__(values)
Return a smoothed histogram of the data vector
Source code in mass2/core/analysis_algorithms.py
215 216 217 218 219 220 221 | |
__init__(smooth_sigma, limits)
Give the smoothing Gaussian's width as
Source code in mass2/core/analysis_algorithms.py
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 | |
compute_max_deriv(pulse_data, ignore_leading, spike_reject=True, kernel=None)
Computes the maximum derivative in timeseries
Args: pulse_data: ignore_leading: spike_reject: (default True) kernel: the linear filter against which the signals will be convolved (CONVOLED, not correlated, so reverse the filter as needed). If None, then the default kernel of [+.2 +.1 0 -.1 -.2] will be used. If "SG", then the cubic 5-point Savitzky-Golay filter will be used (see below). Otherwise, kernel needs to be a (short) array which will be converted to a 1xN 2-dimensional np.ndarray. (default None)
Returns:
An np.ndarray, dimension 1: the value of the maximum derivative (units of
When kernel=="SG", then we estimate the derivative by Savitzky-Golay filtering (with 1 point before/3 points after the point in question and fitting polynomial of order 3). Find the right general area by first doing a simple difference.
Source code in mass2/core/analysis_algorithms.py
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 | |
correct_flux_jumps(vals, mask, flux_quant)
Remove 'flux' jumps' from pretrigger mean.
When using umux readout, if a pulse is recorded that has a very fast rising edge (e.g. a cosmic ray), the readout system will "slip" an integer number of flux quanta. This means that the baseline level returned to after the pulse will different from the pretrigger value by an integer number of flux quanta. This causes that pretrigger mean summary quantity to jump around in a way that causes trouble for the rest of MASS. This function attempts to correct these jumps.
Arguments: vals -- array of values to correct mask -- mask indentifying "good" pulses flux_quant -- size of 1 flux quanta
Returns: Array with values corrected
Source code in mass2/core/analysis_algorithms.py
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 | |
correct_flux_jumps_original(vals, mask, flux_quant)
Remove 'flux' jumps' from pretrigger mean.
When using umux readout, if a pulse is recorded that has a very fast rising edge (e.g. a cosmic ray), the readout system will "slip" an integer number of flux quanta. This means that the baseline level returned to after the pulse will different from the pretrigger value by an integer number of flux quanta. This causes that pretrigger mean summary quantity to jump around in a way that causes trouble for the rest of MASS. This function attempts to correct these jumps.
Arguments: vals -- array of values to correct mask -- mask indentifying "good" pulses flux_quant -- size of 1 flux quanta
Returns: Array with values corrected
Source code in mass2/core/analysis_algorithms.py
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 | |
drift_correct(indicator, uncorrected, limit=None)
Compute a drift correction that minimizes the spectral entropy.
Args: indicator: The "x-axis", which indicates the size of the correction. uncorrected: A filtered pulse height vector. Same length as indicator. Assumed to have some gain that is linearly related to indicator. limit: The upper limit of uncorrected values over which entropy is computed (default None).
Generally indicator will be the pretrigger mean of the pulses, but you can experiment with other choices.
The entropy will be computed on corrected values only in the range [0, limit], so limit should be set to a characteristic large value of uncorrected. If limit is None (the default), then in will be compute as 25% larger than the 99%ile point of uncorrected.
The model is that the filtered pulse height PH should be scaled by (1 +
a*PTM) where a is an arbitrary parameter computed here, and PTM is the
difference between each record's pretrigger mean and the median value of all
pretrigger means. (Or replace "pretrigger mean" with whatever quantity you
passed in as
Source code in mass2/core/analysis_algorithms.py
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 | |
estimateRiseTime(pulse_data, timebase, nPretrig)
Computes the rise time of timeseries
If nPretrig >= 4, then the samples pulse_data[:nPretrig] are averaged to estimate the baseline. Otherwise, the minimum of pulse_data is assumed to be the baseline.
Specifically, take the first and last of the rising points in the range of 10% to 90% of the peak value, interpolate a line between the two, and use its slope to find the time to rise from 0 to the peak.
Args: pulse_data: An np.ndarray of dimension 1 (a single pulse record) or 2 (an array with each row being a pulse record). timebase: The sampling time. nPretrig: The number of samples that are recorded before the trigger.
Returns: An ndarray of dimension 1, giving the rise times.
Source code in mass2/core/analysis_algorithms.py
30 31 32 33 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 | |
filter_signal_lowpass(sig, fs, fcut)
Tophat lowpass filter using an FFT
Args: sig - the signal to be filtered fs - the sampling frequency of the signal fcut - the frequency at which to cutoff the signal
Returns: the filtered signal
Source code in mass2/core/analysis_algorithms.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | |
make_smooth_histogram(values, smooth_sigma, limit, upper_limit=None)
Convert a vector of arbitrary
This is a convenience function using the HistogramSmoother class.
Args: values: The vector of data to be histogrammed. smooth_sigma: The smoothing Gaussian's width (FWHM) limit, upper_limit: The histogram limits are [limit,upper_limit] or [0,limit] if upper_limit is None.
Returns: The smoothed histogram as an array.
Source code in mass2/core/analysis_algorithms.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
nearest_arrivals(reference_times, other_times)
Find the external trigger time immediately before and after each pulse timestamp
Args: pulse_timestamps - 1d array of pulse timestamps whose nearest neighbors need to be found. external_trigger_timestamps - 1d array of possible nearest neighbors.
Returns: (before_times, after_times)
before_times is an ndarray of the same size as pulse_timestamps. before_times[i] contains the difference between the closest lesser time contained in external_trigger_timestamps and pulse_timestamps[i] or inf if there was no earlier time in other_times Note that before_times is always a positive number even though the time difference it represents is negative.
after_times is an ndarray of the same size as pulse_timestamps. after_times[i] contains the difference between pulse_timestamps[i] and the closest greater time contained in other_times or a inf number if there was no later time in external_trigger_timestamps.
Source code in mass2/core/analysis_algorithms.py
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 | |
resample_one_pulse(pulse, shift)
Resample one pulses (in place). The data will be modified and returned.
Shift can be integer or not; if shift has a fractional part, linear interpolation is used.
Positive values of shift delay the values in a pulse record, and the initial value or values
are padded by copying the first value of the pulse record. Negative values shift the pulse earlier
in the record, and the final value is used to pad the end of the new record.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in mass2/core/analysis_algorithms.py
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 | |
resample_pulses(pulses, shifts)
Resample multiple pulses (in place). The data will be modified and returned.
Shifts can be integer or not; if shifts have a fractional part, linear interpolation is used.
Positive values of shifts delay the values in a pulse record, and the initial value or values
are padded by copying the first value of the pulse record. Negative values shift the pulse earlier
in the record, and the final value is used to pad the end of the new record.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in mass2/core/analysis_algorithms.py
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 | |
time_drift_correct(time, uncorrected, w, sec_per_degree=2000, pulses_per_degree=2000, max_degrees=20, ndeg=None, limit=None)
Compute a time-based drift correction that minimizes the spectral entropy.
Args: time: The "time-axis". Correction will be a low-order polynomial in this. uncorrected: A filtered pulse height vector. Same length as indicator. Assumed to have some gain that is linearly related to indicator. w: the kernel width for the Laplace KDE density estimator sec_per_degree: assign as many as one polynomial degree per this many seconds pulses_per_degree: assign as many as one polynomial degree per this many pulses max_degrees: never use more than this many degrees of Legendre polynomial. n_deg: If not None, use this many degrees, regardless of the values of sec_per_degree, pulses_per_degree, and max_degress. In this case, never downsample. limit: The [lower,upper] limit of uncorrected values over which entropy is computed (default None).
The entropy will be computed on corrected values only in the range [limit[0], limit[1]], so limit should be set to a characteristic large value of uncorrected. If limit is None (the default), then it will be computed as 25%% larger than the 99%%ile point of uncorrected.
Possible improvements in the future: * Use Numba to speed up. * Allow the parameters to be function arguments with defaults: photons per degree of freedom, seconds per degree of freedom, and max degrees of freedom. * Figure out how to span the available time with more than one set of legendre polynomials, so that we can have more than 20 d.o.f. eventually, for long runs.
Source code in mass2/core/analysis_algorithms.py
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 | |
unwrap_n(data, period, mask, n=3)
Unwrap data that has been restricted to a given period.
The algorithm iterates through each data point and compares it to the average of the previous n data points. It then offsets the data point by the multiple of the period that will minimize the difference from that n-point running average.
For the first n data points, there are not enough preceding points to average n of them, so the algorithm will average fewer points.
This code was written by Thomas Baker; integrated into MASS by Dan Becker. Sped up 300x by @njit.
| Parameters: |
|
|---|
Source code in mass2/core/analysis_algorithms.py
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 | |
Provide DriftCorrectStep and DriftCorrection for correcting gain drifts that correlate with pretrigger mean.
DriftCorrectStep
dataclass
Bases: RecipeStep
A RecipeStep to apply a linear drift correction to pulse data in a DataFrame.
Source code in mass2/core/drift_correction.py
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 | |
calc_from_df(df)
Apply the drift correction to the input DataFrame and return a new DataFrame with results.
Source code in mass2/core/drift_correction.py
47 48 49 50 51 52 53 54 | |
dbg_plot(df_after, **kwargs)
Plot the uncorrected and corrected values against the indicator for debugging purposes.
Source code in mass2/core/drift_correction.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
learn(ch, indicator_col, uncorrected_col, corrected_col, use_expr)
classmethod
Create a DriftCorrectStep by learning the correction from data in the given Channel.
Source code in mass2/core/drift_correction.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
DriftCorrection
dataclass
A linear correction used to attempt remove any correlation between pretrigger mean and pulse height; will work with other quantities instead.
Source code in mass2/core/drift_correction.py
93 94 95 96 97 98 99 100 101 102 103 104 105 | |
__call__(indicator, uncorrected)
Apply the drift correction to the given uncorrected values using the given indicator values.
Source code in mass2/core/drift_correction.py
101 102 103 104 105 | |
drift_correct_mass(indicator, uncorrected)
Determine drift correction parameters using mass2.core.analysis_algorithms.drift_correct.
Source code in mass2/core/drift_correction.py
20 21 22 23 24 | |
drift_correct_wip(indicator, uncorrected)
Work in progress to Determine drift correction parameters directly (??).
Source code in mass2/core/drift_correction.py
27 28 29 30 31 32 33 34 35 | |
Provide OptimalFilterStep, a step to apply an optimal filter to pulse data in a DataFrame.
OptimalFilterStep
dataclass
Bases: RecipeStep
A step to apply an optimal filter to pulse data in a DataFrame.
Source code in mass2/core/filter_steps.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
calc_from_df(df)
Apply the optimal filter to the input DataFrame and return a new DataFrame with results.
Source code in mass2/core/filter_steps.py
25 26 27 28 29 30 31 32 33 34 35 36 | |
dbg_plot(df_after, **kwargs)
Plot the filter shape for debugging purposes.
Source code in mass2/core/filter_steps.py
38 39 40 41 42 43 | |
drop_debug()
Return a copy of this step with debugging information (the NoiseResult) removed.
Source code in mass2/core/filter_steps.py
45 46 47 | |
Classes and functions for reading and handling LJH files.
LJHFile
dataclass
Bases: ABC
Represents the header and binary information of a single LJH file.
Includes the complete ASCII header stored both as a dictionary and a string, and key attributes including the number of pulses, number of samples (and presamples) in each pulse record, client information stored by the LJH writer, and the filename.
Also includes a np.memmap to the raw binary data. This memmap always starts with
pulse zero and extends to the last full pulse given the file size at the time of object
creation. To extend the memmap for files that are growing, use LJHFile.reopen_binary()
to return a new object with a possibly longer memmap.
Source code in mass2/core/ljhfiles.py
22 23 24 25 26 27 28 29 30 31 32 33 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 | |
datatimes_float
property
Compute pulse record times in floating-point (seconds since the 1970 epoch).
In mass issue #337, we found that computing on the entire memory map at once was prohibitively
expensive for large files. To prevent problems, compute on chunks of no more than
MAXSEGMENT records at once.
| Returns: |
|
|---|
datatimes_raw
abstractmethod
property
Return a copy of the raw timestamp (posix usec) memory map.
In mass issue #337, we found that computing on the entire memory map at once was prohibitively
expensive for large files. To prevent problems, copy chunks of no more than
MAXSEGMENT records at once.
| Returns: |
|
|---|
is_continuous
property
Is this LJH file made of a perfectly continuous data stream?
For pre-version 2.2 LJH files, we cannot discern from the data. So just claim False. (LJH_2_2 subtype will override by actually computing.)
| Returns: |
|
|---|
pulse_size_bytes
property
The size in bytes of each binary pulse record (including the timestamps)
subframecount
property
Return a copy of the subframecount memory map.
Old LJH versions don't have this: return zeros, unless overridden by derived class (LJHFile_2_2 will be the only one).
| Returns: |
|
|---|
__repr__()
A string that can be evaluated to re-open this LJH file.
Source code in mass2/core/ljhfiles.py
55 56 57 | |
open(filename, max_pulses=None)
classmethod
Open an LJH file, parsing its header information and returning an LJHFile object.
Source code in mass2/core/ljhfiles.py
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 | |
read_header(filename)
classmethod
Read in the text header of an LJH file. Return the header parsed into a dictionary, the complete header string (in case you want to generate a new LJH file from this one), and the size of the header in bytes. The file does not remain open after this method.
Returns: (header_dict, header_string, header_size)
Args: filename: path to the file to be opened.
Source code in mass2/core/ljhfiles.py
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 | |
read_trace(i)
Return a single pulse record from an LJH file.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in mass2/core/ljhfiles.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
read_trace_with_timing(i)
Return a single data trace as (subframecount, posix_usec, pulse_record).
Source code in mass2/core/ljhfiles.py
281 282 283 284 | |
reopen_binary(max_pulses=None)
Reopen the underlying binary section of the LJH file, in case its size has changed, without re-reading the LJH header section.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in mass2/core/ljhfiles.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |
to_polars(first_pulse=0, keep_posix_usec=False, force_continuous=False)
Convert this LJH file to two Polars dataframes: one for the binary data, one for the header.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in mass2/core/ljhfiles.py
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 | |
write_truncated_ljh(filename, npulses)
Write an LJH copy of this file, with a limited number of pulses.
| Parameters: |
|
|---|
Source code in mass2/core/ljhfiles.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 | |
LJHFile_2_0
dataclass
Bases: LJHFile
LJH files version 2.0, which have internal_ms fields only, but no subframecount and no µs information.
Source code in mass2/core/ljhfiles.py
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 | |
datatimes_raw
property
Return a copy of the raw timestamp (posix usec) memory map.
In mass issue #337, we found that computing on the entire memory map at once was prohibitively
expensive for large files. To prevent problems, copy chunks of no more than
MAXSEGMENT records at once.
| Returns: |
|
|---|
to_polars(first_pulse=0, keep_posix_usec=False, force_continuous=False)
Generate two Polars dataframes from this LJH file: one for the binary data, one for the header.
Source code in mass2/core/ljhfiles.py
513 514 515 516 517 518 | |
LJHFile_2_1
dataclass
Bases: LJHFile
LJH files version 2.1, which have internal_us and internal_ms fields, but no subframecount.
Source code in mass2/core/ljhfiles.py
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 | |
datatimes_raw
property
Return a copy of the raw timestamp (posix usec) memory map.
In mass issue #337, we found that computing on the entire memory map at once was prohibitively
expensive for large files. To prevent problems, copy chunks of no more than
MAXSEGMENT records at once.
| Returns: |
|
|---|
to_polars(first_pulse=0, keep_posix_usec=False, force_continuous=False)
Generate two Polars dataframes from this LJH file: one for the binary data, one for the header.
Source code in mass2/core/ljhfiles.py
474 475 476 477 478 479 | |
LJHFile_2_2
dataclass
Bases: LJHFile
LJH files version 2.2 and later, which have subframecount and posix_usec fields.
Source code in mass2/core/ljhfiles.py
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 | |
datatimes_raw
property
Return a copy of the raw timestamp (posix usec) memory map.
In mass issue #337, we found that computing on the entire memory map at once was prohibitively
expensive for large files. To prevent problems, copy chunks of no more than
MAXSEGMENT records at once.
| Returns: |
|
|---|
is_continuous
property
Is this LJH file made of a perfectly continuous data stream?
We generally do take noise data in this mode, and it's useful to analyze the noise data by gluing many records together. This property says whether such gluing is valid.
| Returns: |
|
|---|
subframecount
property
Return a copy of the subframecount memory map.
In mass issue #337, we found that computing on the entire memory map at once was prohibitively
expensive for large files. To prevent problems, copy chunks of no more than
MAXSEGMENT records at once.
| Returns: |
|
|---|
Utility functions for handling and finding LJH files, and opening them as Channel or Channels objects.
experiment_state_path_from_ljh_path(ljh_path)
Find the experiment_state.txt file in the directory of the given ljh file.
Source code in mass2/core/ljhutil.py
169 170 171 172 173 174 175 176 | |
external_trigger_bin_path_from_ljh_path(ljh_path)
Find the external_trigger.bin file in the directory of the given ljh file.
Source code in mass2/core/ljhutil.py
179 180 181 182 183 184 185 186 | |
extract_channel_number(file_path)
Extracts the channel number from the .ljh file name.
Args: - file_path (str): The path to the .ljh file.
Returns: - int: The channel number.
Source code in mass2/core/ljhutil.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
filename_glob_expand(pattern)
Return the result of glob-expansion on the input pattern.
:param pattern: Aglob pattern and return the glob-result as a list. :type pattern: str :return: filenames; the result is sorted first by str.sort, then by ljh_sort_filenames_numerically() :rtype: list
Source code in mass2/core/ljhutil.py
217 218 219 220 221 222 223 224 225 226 | |
find_folders_with_extension(root_path, extensions)
Finds all folders within the root_path that contain at least one file with the given extension.
Args: - root_path (str): The root directory to start the search from. - extension (str): The file extension to search for (e.g., '.txt').
Returns: - list[str]: A list of paths to directories containing at least one file with the given extension.
Source code in mass2/core/ljhutil.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
find_ljh_files(folder, ext='.ljh', search_subdirectories=False, exclude_ch_nums=[], include_ch_nums=None)
Finds all files of a specific file extension in the given folder and (optionally) its subfolders.
An optional list of channel numbers can be excluded from the results. Also optionally, the results can be restricted only to a specific list of channel numbers.
| Parameters: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
Source code in mass2/core/ljhutil.py
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 | |
helper_write_pulse(dest, src, i)
Write a single pulse from one LJHFile to another open file.
Source code in mass2/core/ljhutil.py
229 230 231 232 233 234 235 236 | |
ljh_append_traces(src_name, dest_name, pulses=None)
Append traces from one LJH file onto another. The destination file is assumed to be version 2.2.0.
Can be used to grab specific traces from some other ljh file, and append them onto an existing ljh file.
Args: src_name: the name of the source file dest_name: the name of the destination file pulses: indices of the pulses to copy (default: None, meaning copy all)
Source code in mass2/core/ljhutil.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | |
ljh_merge(out_path, filenames, overwrite)
Merge a set of LJH files to a single output file.
Source code in mass2/core/ljhutil.py
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | |
ljh_sort_filenames_numerically(fnames, inclusion_list=None)
Sort filenames of the form '_chanXXX.', according to the numerical value of channel number XXX.
Filenames are first sorted by the usual string comparisons, then by channel number. In this way, the standard sort is applied to all files with the same channel number.
:param fnames: A sequence of filenames of the form '_chan.*' :type fnames: list of str :param inclusion_list: If not None, a container with channel numbers. All files whose channel numbers are not on this list will be omitted from the output, defaults to None :type inclusion_list: sequence of int, optional :return: A list containg the same filenames, sorted according to the numerical value of channel number. :rtype: list
Source code in mass2/core/ljhutil.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | |
ljh_truncate(input_filename, output_filename, n_pulses=None, timestamp=None)
Truncate an LJH file.
Writes a new copy of an LJH file, with the same header but fewer raw data pulses.
Arguments: input_filename -- name of file to truncate output_filename -- filename for truncated file n_pulses -- truncate to include only this many pulses (default None) timestamp -- truncate to include only pulses with timestamp earlier than this number (default None)
Exactly one of n_pulses and timestamp must be specified.
Source code in mass2/core/ljhutil.py
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 | |
main_ljh_merge()
Merge all LJH files that match a pattern to a single output file.
The idea is that all such files come from a single TES and could have been (but were not) written as a single continuous file.
The pattern should be of the form "blah_blah_*_chan1.ljh" or something. The output will then be "merged_chan1.ljh" in the directory of the first file found (or alter the directory with the --outdir argument). It is not (currently) possible to merge data from LJH files that represent channels with different numbers.
Source code in mass2/core/ljhutil.py
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 | |
main_ljh_truncate()
A convenience script to truncate all LJH files that match a pattern, writing a new LJH file for each that contains only the first N pulse records.
Source code in mass2/core/ljhutil.py
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
match_files_by_channel(folder1, folder2, limit=None, exclude_ch_nums=[], include_ch_nums=None)
Matches .ljh files from two folders by channel number.
Args: - folder1 (str): The first root directory. - folder2 (str): The second root directory.
Returns: - list[Iterator[tuple[str, str]]]: A list of iterators, each containing pairs of paths with matching channel numbers.
| Raises: |
|
|---|
Source code in mass2/core/ljhutil.py
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 | |
Miscellaneous utility functions used in mass2 for plotting, pickling, statistics, and DataFrame manipulation.
alwaysTrue()
alwaysTrue: a factory function to generate a new copy of polars literal True for class construction
| Returns: |
|
|---|
Source code in mass2/core/misc.py
210 211 212 213 214 215 216 217 218 | |
concat_dfs_with_concat_state(df1, df2, concat_state_col='concat_state')
Concatenate two DataFrames vertically, adding a column concat_state (or named according to concat_state_col)
to indicate which DataFrame each row came from.
Source code in mass2/core/misc.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
extract_column_names_from_polars_expr(expr)
Recursively extract all column names from a Polars expression.
Source code in mass2/core/misc.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
good_series(df, col, good_expr, use_expr)
Return a Series from the given DataFrame column, filtered by the given good_expr and use_expr.
Source code in mass2/core/misc.py
50 51 52 53 54 55 56 57 | |
hist_of_series(series, bin_edges)
Return the bin centers and counts of a histogram of the given Series using the given bin edges.
Source code in mass2/core/misc.py
96 97 98 99 100 101 | |
launch_examples()
Launch marimo edit in the examples folder.
Source code in mass2/core/misc.py
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 | |
median_absolute_deviation(x)
Return the median absolute deviation of the input, unnormalized.
Source code in mass2/core/misc.py
60 61 62 63 | |
merge_dicts_ordered_by_keys(dict1, dict2)
Merge two dictionaries and return a new dictionary with items ordered by key.
Source code in mass2/core/misc.py
163 164 165 166 167 168 169 170 171 172 173 174 | |
midpoints_and_step_size(x)
return midpoints, step_size for bin edges x
Source code in mass2/core/misc.py
87 88 89 90 91 92 93 | |
outlier_resistant_nsigma_above_mid(x, nsigma=5)
RReturn the value that is nsigma median absolute deviations (MADs) above the median of the input.
Source code in mass2/core/misc.py
72 73 74 75 76 | |
outlier_resistant_nsigma_range_from_mid(x, nsigma=5)
Return the values that are nsigma median absolute deviations (MADs) below and above the median of the input
Source code in mass2/core/misc.py
79 80 81 82 83 84 | |
pickle_object(obj, filename)
Pickle the given object to the given filename using dill.
Mass2 Recipe objects are compatible with dill but not with the standard pickle module.
Source code in mass2/core/misc.py
25 26 27 28 29 | |
plot_a_vs_b_series(a, b, axis=None, **plotkwarg)
Plot the two given Series as a scatterplot on the given axis (or a new one if None).
Source code in mass2/core/misc.py
118 119 120 121 122 123 124 125 | |
plot_hist_of_series(series, bin_edges, axis=None, **plotkwarg)
Plot a histogram of the given Series using the given bin edges on the given axis (or a new one if None).
Source code in mass2/core/misc.py
104 105 106 107 108 109 110 111 112 113 114 115 | |
root_mean_squared(x, axis=None)
Return the root mean square of the input along the given axis or axes. Does not subtract the mean first.
Source code in mass2/core/misc.py
157 158 159 160 | |
show(fig=None)
Create a Marimo interactive view of the given Matplotlib figure (or the current figure if None).
Source code in mass2/core/misc.py
18 19 20 21 22 | |
sigma_mad(x)
Return the nomrlized median absolute deviation of the input, rescaled to give the standard deviation if distribution is Gaussian. This method is more robust to outliers than calculating the standard deviation directly.
Source code in mass2/core/misc.py
66 67 68 69 | |
smallest_positive_real(arr)
Return the smallest positive real number in the given array-like object.
Source code in mass2/core/misc.py
39 40 41 42 43 44 45 46 47 | |
unpickle_object(filename)
Unpickle an object from the given filename using dill.
Source code in mass2/core/misc.py
32 33 34 35 36 | |
Tools for fitting multiple spectral lines in a single pass.
FitSpec
dataclass
Specification of a single line fit within a MultiFit.
Source code in mass2/core/multifit.py
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 | |
fit_ch(ch, col)
Fit the given Channel's DataFrame column col after applying the Channel's good_expr and
this FitSpec's use_expr filters.
Source code in mass2/core/multifit.py
76 77 78 79 | |
fit_df(df, col, good_expr)
Fit the given DataFrame column col after applying good_expr and use_expr filters.
Source code in mass2/core/multifit.py
71 72 73 74 | |
fit_series_without_use_expr(series)
Fit the given Series without applying a use_expr filter.
Source code in mass2/core/multifit.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
params(bin_centers, counts)
Return a reasonable guess at the parameters given the spectrum to be fit.
Source code in mass2/core/multifit.py
47 48 49 50 51 52 53 | |
MultiFit
dataclass
Specification of multiple emission-line fits to be done in one pass.
Source code in mass2/core/multifit.py
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 | |
fit_ch(ch, col)
Fit all the FitSpecs in this MultiFit to the given Channel's DataFrame column col
after applying the Channel's good_expr filter.
Source code in mass2/core/multifit.py
159 160 161 162 | |
fit_df(df, col, good_expr)
Fit all the FitSpecs in this MultiFit to the given DataFrame column col after applying good_expr filter.
Source code in mass2/core/multifit.py
151 152 153 154 155 156 157 | |
fit_series_without_use_expr(series)
Fit all the FitSpecs in this MultiFit to the given Series without applying any use_expr filter.
Source code in mass2/core/multifit.py
146 147 148 149 | |
plot_results(n_extra_axes=0)
Plot all the fit results in subplots, with n_extra_axes empty subplots included at the end.
Source code in mass2/core/multifit.py
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 | |
plot_results_and_pfit(uncalibrated_name, previous_energy2ph, n_extra_axes=0)
Plot all the fit results in subplots, and also plot the gain curve on an extra axis.
Source code in mass2/core/multifit.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
results_params_as_df()
Return a DataFrame made from the fit parameters from the results.
Source code in mass2/core/multifit.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |
to_mass_cal(previous_energy2ph, curvetype=Curvetypes.GAIN, approximate=False)
Return a calibration object made from the fit results in this MultiFit.
Source code in mass2/core/multifit.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
to_pfit_gain(previous_energy2ph)
Return a best-fit 2nd degree polynomial for gain (ph/energy) vs uncalibrated ph, and the rms residual in energy after applying that gain correction.
Source code in mass2/core/multifit.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
with_fitspec(fitspec)
Return a copy of this MultiFit with a new FitSpec added.
Source code in mass2/core/multifit.py
114 115 116 117 118 | |
with_line(line, dlo=None, dhi=None, bin_size=None, use_expr=None, params_update=None)
Return a copy of this MultiFit with an additional FitSpec for the given line.
Source code in mass2/core/multifit.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
with_results(results)
Return a copy of this MultiFit with the given results added.
Source code in mass2/core/multifit.py
120 121 122 | |
MultiFitMassCalibrationStep
dataclass
Bases: RecipeStep
A RecipeStep to apply a mass-style calibration derived from a MultiFit.
Source code in mass2/core/multifit.py
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 | |
calc_from_df(df)
Calibrate energy and return a new DataFrame with results.
Source code in mass2/core/multifit.py
333 334 335 336 337 338 339 340 | |
dbg_plot(df_after, **kwargs)
Plot the fit results and gain curve for debugging purposes.
Source code in mass2/core/multifit.py
346 347 348 349 350 351 352 353 | |
drop_debug()
For slimmer object pickling, return a copy of self with the fat debugging info removed
Source code in mass2/core/multifit.py
342 343 344 | |
energy2ph(energy)
The inverse of the quadratic gain calibration curve: energy -> ph
Source code in mass2/core/multifit.py
360 361 362 363 | |
learn(ch, multifit_spec, previous_cal_step_index, calibrated_col, use_expr=pl.lit(True))
classmethod
multifit then make a mass calibration object with curve_type=Curvetypes.GAIN and approx=False TODO: support more options
Source code in mass2/core/multifit.py
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 | |
ph2energy(ph)
The quadratic gain calibration curve: ph -> energy
Source code in mass2/core/multifit.py
355 356 357 358 | |
MultiFitQuadraticGainStep
dataclass
Bases: RecipeStep
A RecipeStep to apply a quadratic gain curve, after fitting multiple emission lines.
Source code in mass2/core/multifit.py
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 | |
calc_from_df(df)
Calibrate energy and return a new DataFrame with results.
Source code in mass2/core/multifit.py
255 256 257 258 259 260 261 262 | |
dbg_plot(df_after, **kwargs)
Plot the fit results and gain curve for debugging purposes.
Source code in mass2/core/multifit.py
264 265 266 267 268 | |
drop_debug()
For slimmer object pickling, return a copy of self with the fat debugging info removed
Source code in mass2/core/multifit.py
270 271 272 | |
energy2ph(energy)
The inverse of the quadratic gain calibration curve: energy -> ph
Source code in mass2/core/multifit.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |
learn(ch, multifit_spec, previous_cal_step_index, calibrated_col, use_expr=pl.lit(True))
classmethod
Perform a multifit then make a quadratic gain calibration object.
Source code in mass2/core/multifit.py
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 | |
ph2energy(ph)
The quadratic gain calibration curve: ph -> energy
Source code in mass2/core/multifit.py
274 275 276 277 278 | |
handle_none(val, default)
If val is None, return a copy of default, else return val.
Source code in mass2/core/multifit.py
31 32 33 34 35 | |
Algorithms to analyze noise data.
NoiseResult
dataclass
A dataclass to hold the results of noise analysis, both power-spectral density and (optionally) autocorrelation.
Source code in mass2/core/noise_algorithms.py
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 | |
plot(axis=None, arb_to_unit_scale_and_label=(1, 'arb'), sqrt_psd=True, loglog=True, **plotkwarg)
Plot the power spectral density.
Source code in mass2/core/noise_algorithms.py
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 | |
plot_log_rebinned(bins_per_decade=10, axis=None, arb_to_unit_scale_and_label=(1, 'arb'), sqrt_psd=True, **plotkwarg)
Plot PSD rebinned into logarithmically spaced frequency bins.
Source code in mass2/core/noise_algorithms.py
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 | |
calc_autocorrelation_times(n, dt)
Compute the timesteps for an autocorrelation function
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in mass2/core/noise_algorithms.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
calc_continuous_autocorrelation(data, n_lags, max_excursion=1000)
Calculate the autocorrelation of the input data, assuming the entire array is continuous.
| Parameters: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
Source code in mass2/core/noise_algorithms.py
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 | |
calc_discontinuous_autocorrelation(data, max_excursion=1000)
Calculate the autocorrelation of the input data, assuming the rows of the array are NOT continuous in time.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in mass2/core/noise_algorithms.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
calc_noise_result(data, dt, continuous, window=None, skip_autocorr_if_length_over=100000)
Analyze the noise as Mass has always done.
- Compute autocorrelation with a lower noise at longer lags when data are known to be continuous
- Subtract the mean before computing the power spectrum
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in mass2/core/noise_algorithms.py
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 | |
noise_psd_periodogram(data, dt, window='boxcar', detrend=False)
Compute the noise power spectral density using scipy's periodogram function and the autocorrelation.
Source code in mass2/core/noise_algorithms.py
151 152 153 154 155 156 157 158 159 | |
Hold a class to represent a channel with noise data only, and to analyze its noise characteristics.
NoiseChannel
dataclass
A class to represent a channel with noise data only, and to analyze its noise characteristics.
Source code in mass2/core/noise_channel.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 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 | |
is_continuous
property
Whether this channel is continuous data (True) or triggered records with arbitrary gaps (False).
__eq__(other)
Equality based on object identity.
Source code in mass2/core/noise_channel.py
108 109 110 | |
__hash__()
A hash function based on the object's id.
Source code in mass2/core/noise_channel.py
101 102 103 104 105 106 | |
calc_max_excursion(trace_col_name='pulse', n_limit=10000, excursion_nsigma=5)
Compute the maximum excursion from the median for each noise record, and store in dataframe.
Source code in mass2/core/noise_channel.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
from_ljh(path)
classmethod
Create a NoiseChannel by loading data from the given LJH file path.
Source code in mass2/core/noise_channel.py
119 120 121 122 123 124 125 | |
get_records_2d(trace_col_name='pulse', n_limit=10000, excursion_nsigma=5, trunc_front=0, trunc_back=0)
Return a 2D NumPy array of cleaned noise traces from the specified column.
This method identifies noise traces with excursions below a threshold and optionally truncates the beginning and/or end of each trace.
Parameters:
trace_col_name : str, optional Name of the column containing trace data. Default is "pulse". n_limit : int, optional Maximum number of traces to analyze. Default is 10000. excursion_nsigma : float, optional Threshold for maximum excursion in units of noise sigma. Default is 5. trunc_front : int, optional Number of samples to truncate from the front of each trace. Default is 0. trunc_back : int, optional Number of samples to truncate from the back of each trace. Must be >= 0. Default is 0.
Returns:
np.ndarray A 2D array of cleaned and optionally truncated noise traces.
Shape: (n_pulses, len(pulse))
Source code in mass2/core/noise_channel.py
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 | |
spectrum(trace_col_name='pulse', n_limit=10000, excursion_nsigma=5, trunc_front=0, trunc_back=0, skip_autocorr_if_length_over=100000)
Compute and return the noise result from the noise traces.
Source code in mass2/core/noise_channel.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
Code copied from Mass version 1. Not up to date with latest style. Sorry.
Supported off versions: 0.1.0 has projectors and basis in json with base64 encoding 0.2.0 has projectors and basis after json as binary 0.3.0 adds pretrigDelta field
OffFile
Working with an OFF file: off = OffFile("filename") print off.dtype # show the fields available off[0] # get record 0 off[0]["coefs"] # get the model coefs for record 0 x,y = off.recordXY(0) plot(x,y) # plot record 0
Source code in mass2/core/offfiles.py
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 | |
__getitem__(*args, **kwargs)
Make indexing into the off the same as indexing into the memory mapped array
Source code in mass2/core/offfiles.py
143 144 145 146 | |
__len__()
Number of records in the OFF file
Source code in mass2/core/offfiles.py
148 149 150 151 | |
__repr__()
Return a string representation of the OffFile object.
Source code in mass2/core/offfiles.py
210 211 212 | |
__sizeof__()
Size of the memory mapped array in bytes
Source code in mass2/core/offfiles.py
153 154 155 156 | |
close()
Close the memory map and projectors and basis memmaps
Source code in mass2/core/offfiles.py
115 116 117 118 119 | |
modeledPulse(i)
return a vector of the modeled pulse samples, the best available value of the actual raw samples
Source code in mass2/core/offfiles.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
recordXY(i)
return (x,y) for record i, where x is time and y is modeled pulse
Source code in mass2/core/offfiles.py
236 237 238 | |
sampleTimes(i)
return a vector of sample times for record i, approriate for plotting
Source code in mass2/core/offfiles.py
214 215 216 217 218 | |
validateHeader()
Check that the header looks like we expect, with a valid version code
Source code in mass2/core/offfiles.py
121 122 123 124 125 126 127 128 | |
view(*args)
Return a view of the memmap with the given args
Source code in mass2/core/offfiles.py
246 247 248 249 | |
readJsonString(f)
look in file f for a line "}\n" and return all contents up to that point for an OFF file this can be parsed by json.dumps and all remaining data is records
Source code in mass2/core/offfiles.py
57 58 59 60 61 62 63 64 65 66 67 68 | |
recordDtype(offVersion, nBasis, descriptive_coefs_names=True)
return a np.dtype matching the record datatype for the given offVersion and nBasis
descriptive_coefs_names - determines how the modeled pulse coefficients are name, you usually want True
For True, the names will be derivLike, pulseLike, and if nBasis>3, also extraCoefs
For False, they will all have the single name coefs. False is to make implementing recordXY and other
methods that want access to all coefs simultaneously easier
Source code in mass2/core/offfiles.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
Classes to create time-domain and Fourier-domain optimal filters.
Filter
dataclass
Bases: ABC
A single optimal filter, possibly with optimal estimators of the Delta-t and of the DC level.
| Returns: |
|
|---|
Source code in mass2/core/optimal_filtering.py
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 | |
is_arrival_time_safe
abstractmethod
property
Is this an arrival-time-safe filter?
filter_records(x)
abstractmethod
Filter one microcalorimeter record or an array of records.
Source code in mass2/core/optimal_filtering.py
318 319 320 321 | |
plot(axis=None, **kwargs)
Make a plot of the filter
| Parameters: |
|
|---|
Source code in mass2/core/optimal_filtering.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
report(std_energy=5898.8)
Report on estimated V/dV for the filter.
| Parameters: |
|
|---|
Source code in mass2/core/optimal_filtering.py
304 305 306 307 308 309 310 311 312 313 314 315 316 | |
Filter1Lag
dataclass
Bases: Filter
Represent an optimal filter, specifically one intended for single-lag convolution with data
| Returns: |
|
|---|
Source code in mass2/core/optimal_filtering.py
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 | |
is_arrival_time_safe
property
Is this an arrival-time-safe filter?
__post_init__()
Post-init checks that this filter, indeed, is a 1-lag one
Source code in mass2/core/optimal_filtering.py
414 415 416 | |
filter_records(x)
Filter one microcalorimeter record or an array of records.
| Parameters: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
Source code in mass2/core/optimal_filtering.py
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 | |
Filter5Lag
dataclass
Bases: Filter
Represent an optimal filter, specifically one intended for 5-lag convolution with data
The traditional 5-lag filter used by default until 2015.
| Returns: |
|
|---|
Source code in mass2/core/optimal_filtering.py
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 | |
is_arrival_time_safe
property
Is this an arrival-time-safe filter?
__post_init__()
Post-init checks that this filter, indeed, is a 5-lag one
Source code in mass2/core/optimal_filtering.py
336 337 338 | |
filter_records(x)
Filter one microcalorimeter record or an array of records.
| Parameters: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
Source code in mass2/core/optimal_filtering.py
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | |
FilterATS
dataclass
Bases: Filter
Represent an optimal filter according to the arrival-time-safe, single-lag design of 2015.
| Returns: |
|
|---|
Source code in mass2/core/optimal_filtering.py
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 | |
is_arrival_time_safe
property
Is this an arrival-time-safe filter?
__post_init__()
Post-init checks that this filter aexpects one lag, and has a dt_values array
Source code in mass2/core/optimal_filtering.py
469 470 471 472 | |
filter_records(x)
Filter one microcalorimeter record or an array of records.
| Parameters: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
Source code in mass2/core/optimal_filtering.py
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 | |
FilterMaker
dataclass
An object capable of creating optimal filter based on a single signal and noise set.
| Parameters: |
|
|---|
Notes
-
If both
noise_autocorrandwhitenerare None, then methodscompute_5lagandcompute_atswill both fail, as they require a time-domain characterization of the noise. -
The units of
noise_autocorrare the square of the units used insignal_modeland/orpeak. The units ofwhitenerare the inverse of the signal units. Any rescaling of the noise autocorrelation or whitener does not affect any filter values, but only the predicted signal/noise ratios. -
The units of
noise_psdare square signal units, per Hertz.
| Returns: |
|
|---|
Source code in mass2/core/optimal_filtering.py
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 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 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 780 781 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 996 997 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 | |
compute_1lag(fmax=None, f_3db=None, cut_pre=0, cut_post=0)
Compute a single filter, with optional low-pass filtering, and with optional zero weights at the pre-trigger or post-trigger end of the filter. Can be used with 0-lag "convolution" only, so cannot estimate arrival time.
Either or both of fmax and f_3db are allowed.
| Parameters: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
Source code in mass2/core/optimal_filtering.py
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 | |
compute_5lag(fmax=None, f_3db=None, cut_pre=0, cut_post=0)
Compute a single filter, with optional low-pass filtering, and with optional zero weights at the pre-trigger or post-trigger end of the filter.
Either or both of fmax and f_3db are allowed.
| Parameters: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
Source code in mass2/core/optimal_filtering.py
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 | |
compute_5lag_noexp(exp_time_seconds, fmax=None, f_3db=None, cut_pre=0, cut_post=0)
Compute a single filter, with optional low-pass filtering, and with optional zero weights at the pre-trigger or post-trigger end of the filter.
Either or both of fmax and f_3db are allowed.
| Parameters: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
Source code in mass2/core/optimal_filtering.py
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 | |
compute_ats(fmax=None, f_3db=None, cut_pre=0, cut_post=0)
Compute a single "arrival-time-safe" filter, with optional low-pass filtering, and with optional zero weights at the pre-trigger or post-trigger end of the filter.
Either or both of fmax and f_3db are allowed.
| Parameters: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
Source code in mass2/core/optimal_filtering.py
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 996 997 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 | |
compute_constrained_1lag(constraints=None, fmax=None, f_3db=None, cut_pre=0, cut_post=0)
Compute a single constrained optimal filter, with optional low-pass filtering, and with optional zero weights at the pre-trigger or post-trigger end of the filter. Can be used with 0-lag "convolution" only, so cannot estimate arrival time.
Either or both of fmax and f_3db are allowed.
| Parameters: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
Source code in mass2/core/optimal_filtering.py
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 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 | |
compute_constrained_5lag(constraints=None, fmax=None, f_3db=None, cut_pre=0, cut_post=0)
Compute a single constrained optimal filter, with optional low-pass filtering, and with optional zero weights at the pre-trigger or post-trigger end of the filter.
Either or both of fmax and f_3db are allowed.
| Parameters: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
Source code in mass2/core/optimal_filtering.py
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 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 | |
compute_fourier(fmax=None, f_3db=None, cut_pre=0, cut_post=0)
Compute a single Fourier-domain filter, with optional low-pass filtering, and with optional zero weights at the pre-trigger or post-trigger end of the filter. Fourier domain calculation implicitly assumes periodic boundary conditions.
Either or both of fmax and f_3db are allowed.
| Parameters: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
Source code in mass2/core/optimal_filtering.py
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 | |
ToeplitzWhitener
dataclass
An object that can perform approximate noise whitening.
For an ARMA(p,q) noise model, mutliply by (or solve) the matrix W (or its transpose), where W is the Toeplitz approximation to the whitening matrix V. A whitening matrix V means that if R is the ARMA noise covariance matrix, then VRV' = I. While W only approximately satisfies this, it has some handy properties that make it a useful replacement. (In particular, it has the time-transpose property that if you zero-pad the beginning of vector v and shift the remaining elements, then the same is done to Wv.)
The callable function object returns Wv or WM if called with vector v or matrix M. Other methods:
tw.whiten(v)returns Wv; it is equivalent totw(v)tw.solveWT(v)returns inv(W')*vtw.applyWT(v)returns W'vtw.solveW(v)returns inv(W)*v
Arguments
theta : np.ndarray The moving-average (MA) process coefficients phi : np.ndarray The autoregressive (AR) process coefficients
| Returns: |
|
|---|
| Raises: |
|
|---|
Source code in mass2/core/optimal_filtering.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 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 | |
p
property
Return the autoregressive order
q
property
Return the moving-average order
W(N)
Return the full, approximate whitening matrix.
Normally the full W is large and slow to use. But it's here so you can easily test that W(len(v))*v == whiten(v), and similar.
Source code in mass2/core/optimal_filtering.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
__call__(v)
Return whitened vector (or matrix of column vectors) Wv
Source code in mass2/core/optimal_filtering.py
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 | |
applyWT(v)
Return vector (or matrix of column vectors) W'v
Source code in mass2/core/optimal_filtering.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
solveW(v)
Return unwhitened vector (or matrix of column vectors) inv(W)*v
Source code in mass2/core/optimal_filtering.py
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 | |
solveWT(v)
Return vector (or matrix of column vectors) inv(W')*v
Source code in mass2/core/optimal_filtering.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
whiten(v)
Return whitened vector (or matrix of column vectors) Wv
Source code in mass2/core/optimal_filtering.py
68 69 70 | |
band_limit(modelmatrix, sample_time_sec, fmax, f_3db)
Band-limit the column-vectors in a model matrix with a hard and/or
1-pole low-pass filter. Change the input modelmatrix in-place.
No effect if both fmax and f_3db are None.
| Parameters: |
|
|---|
Source code in mass2/core/optimal_filtering.py
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 | |
bracketR(q, noise)
Return the dot product (q^T R q) for vector and matrix R constructed from
the vector
Source code in mass2/core/optimal_filtering.py
1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 | |
Classes and functions to correct for arrival-time bias in optimal filtering.
PhaseCorrector
A class to correct for arrival-time bias in optimal filtering.
Source code in mass2/core/phase_correct.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 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 | |
__call__(phase_indicator, ph)
Equivalent to self.correct()
Source code in mass2/core/phase_correct.py
71 72 73 | |
__repr__()
String representation of this object.
Source code in mass2/core/phase_correct.py
93 94 95 96 97 98 99 100 101 | |
correct(phase, ph)
Apply the phase correction to the given data ph.
Source code in mass2/core/phase_correct.py
60 61 62 63 64 65 66 67 68 69 | |
fromHDF5(hdf5_group, name='phase_correction')
classmethod
Recover a PhaseCorrector object from the given HDF5 group.
Source code in mass2/core/phase_correct.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
toHDF5(hdf5_group, name='phase_correction', overwrite=False)
Write to the given HDF5 group for later recovery from disk (by fromHDF5 class method).
Source code in mass2/core/phase_correct.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
phase_correct(phase, pheight, ph_peaks=None, method2017=True, kernel_width=None, indicatorName='', uncorrectedName='')
Create a PhaseCorrector object to correct for arrival-time bias in optimal filtering.
Source code in mass2/core/phase_correct.py
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 | |
Phase correction step, Mass-style.
PhaseCorrectMassStep
dataclass
Bases: RecipeStep
Perform a Mass-style phase correction step.
Source code in mass2/core/phase_correct_steps.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
calc_from_df(df)
Calculate the phase-corrected pulse height and return a new DataFrame.
Source code in mass2/core/phase_correct_steps.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
dbg_plot(df_after, **kwargs)
Make a diagnostic plot of the phase correction.
Source code in mass2/core/phase_correct_steps.py
40 41 42 43 44 45 46 47 48 49 50 51 52 | |
phase_correct_mass_specific_lines(ch, indicator_col, uncorrected_col, corrected_col, previous_step_index, line_names, use_expr)
Perform a Mass-style phase correction step using specific lines.
Source code in mass2/core/phase_correct_steps.py
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 | |
Pulse summarizing algorithms.
fit_pulse_2exp_with_tail(data, npre, dt=1, guess_tau=None)
Fit a pulse shape to data using two exponentials plus an exponential tail.
Source code in mass2/core/pulse_algorithms.py
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 | |
pulse_2exp_with_tail(t, t0, a_tail, tau_tail, a, tau_rise, tau_fall_factor, baseline)
Create a pulse shape from two exponentials plus an exponential tail.
Source code in mass2/core/pulse_algorithms.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
summarize_data_numba(rawdata, timebase, peak_samplenumber, pretrigger_ignore_samples, nPresamples)
Summarize one segment of the data file, loading it into cache.
Source code in mass2/core/pulse_algorithms.py
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 | |
Pulse model object, to hold a low-dimensional linear basis able to express all normal pulses,
PulseModel
Object to hold a "pulse model", meaning a low-dimensional linear basis to express "all" pulses, along with a projector such that projector.dot(basis) is the identity matrix.
Also has the capacity to store to and restore from HDF5, and the ability to compute additional basis elements and corresponding projectors with method _additional_projectors_tsvd
Source code in mass2/core/pulse_model.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 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 | |
fromHDF5(hdf5_group)
classmethod
Restore a pulse model from an HDF5 group.
Source code in mass2/core/pulse_model.py
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 | |
labels()
Return a list of labels for the basis elements.
Source code in mass2/core/pulse_model.py
174 175 176 177 178 179 180 181 182 | |
plot(fig1=None, fig2=None)
Plot a pulse model
Source code in mass2/core/pulse_model.py
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 | |
toHDF5(hdf5_group, save_inverted)
Save the pulse model to an HDF5 group.
Source code in mass2/core/pulse_model.py
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 | |
Define RecipeStep and Recipe classes for processing pulse data in a sequence of steps.
CategorizeStep
dataclass
Bases: RecipeStep
A step to categorize pulses into discrete categories based on conditions given in a dictionary mapping category names to polars expressions. The first condition must be True, to be used as a fallback.
Source code in mass2/core/recipe.py
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 | |
__post_init__()
Verify that the first condition is always True.
Source code in mass2/core/recipe.py
220 221 222 223 224 | |
calc_from_df(df)
Calculate the category for each pulse and return a new DataFrame with a column for the category names.
Source code in mass2/core/recipe.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
ChangeTimeZoneStep
dataclass
Bases: RecipeStep
Replace all polars Datetime type series in the dataframe with ones using the given time zone.
Alternatively, replace only the columns named in inputs if not an empty collection.
Usage:
ctzstep = mass2.core.ChangeTimeZoneStep.new("America/Chicago") ch2 = ch.with_step(ctzstep)
Source code in mass2/core/recipe.py
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 | |
calc_from_df(df)
Change timezones for all Datetime-type series in df
Source code in mass2/core/recipe.py
131 132 133 134 135 136 137 138 139 140 141 | |
new(new_time_zone, inputs=[])
classmethod
Create a ChangeTimeZoneStep
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in mass2/core/recipe.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
ColumnAsNumpyMapStep
dataclass
Bases: RecipeStep
This step is meant for interactive exploration, it takes a column and applies a function to it, and makes a new column with the result. It makes it easy to test functions on a column without having to write a whole new step class, while maintaining the benefit of being able to use the step in a Recipe chain, like replaying steps on another channel.
example usage:
def my_function(x): ... return x * 2 step = ColumnAsNumpyMapStep(inputs=["my_column"], output=["my_new_column"], f=my_function) ch2 = ch.with_step(step)
Source code in mass2/core/recipe.py
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 | |
__post_init__()
Check that inputs and outputs are valid (single column each) and that f is a callable object.
Source code in mass2/core/recipe.py
186 187 188 189 190 191 | |
calc_from_df(df)
Calculate the new column by applying f to the input column, returning a new DataFrame.
Source code in mass2/core/recipe.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
PretrigMeanJumpFixStep
dataclass
Bases: RecipeStep
A step to fix jumps in the pretrigger mean by unwrapping the phase angle, a periodic quantity.
Source code in mass2/core/recipe.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
calc_from_df(df)
Calculate the jump-corrected pretrigger mean and return a new DataFrame.
Source code in mass2/core/recipe.py
65 66 67 68 69 70 | |
dbg_plot(df_after, **kwargs)
Make a diagnostic plot of the pretrigger mean before and after the jump fix.
Source code in mass2/core/recipe.py
72 73 74 75 76 77 78 79 80 81 | |
Recipe
dataclass
Bases: Sequence[RecipeStep]
A sequence of RecipeStep objects to be applied in order to a DataFrame.
Source code in mass2/core/recipe.py
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 | |
__getitem__(key)
__getitem__(key: int) -> RecipeStep
__getitem__(key: slice) -> Sequence[RecipeStep]
Return the step at the given index, or the steps at a slice of steps.
Source code in mass2/core/recipe.py
295 296 297 | |
__len__()
Return the number of steps in the recipe.
Source code in mass2/core/recipe.py
299 300 301 | |
calc_from_df(df)
return a dataframe with all the newly calculated info
Source code in mass2/core/recipe.py
274 275 276 277 278 | |
new_empty()
classmethod
Create a new empty Recipe.
Source code in mass2/core/recipe.py
280 281 282 283 | |
trim_dead_ends(required_fields, drop_debug=True)
Create a new Recipe object with all dead-end steps (and optionally also debug info) removed.
The purpose is to replace the fully useful interactive Recipe with a trimmed-down object that can
repeat the current steps as a "recipe" without having the extra information from which the recipe
was first created. In one test, this method reduced the pickle file's size from 3.4 MB per channel
to 30 kB per channel, or a 112x size reduction (with drop_debug=True).
Dead-end steps are defined as any step that can be omitted without affecting the ability to
compute any of the fields given in required_fields. The result of this method is to return
a Recipe where any step is remove if it does not contribute to computing any of the required_fields
(i.e., if it is a dead end).
Examples of a dead end are typically steps used to prepare a tentative, intermediate calibration function.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in mass2/core/recipe.py
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 | |
trim_debug_info()
Create a new Recipe object with all debug info removed from each step, but no steps removed.
The following are exactly equivalent:
recipe2 = recipe.trim_debug_info() recipe2 = recipe.trim_dead_ends(required_fields=None, drop_debug=True)
| Returns: |
|
|---|
Source code in mass2/core/recipe.py
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | |
with_step(step)
Create a new Recipe with the given step added to the end.
Source code in mass2/core/recipe.py
303 304 305 306 | |
RecipeStep
dataclass
Bases: ABC
Represent one step in a data processing recipe.
A step has inputs, outputs, and a calculation method. It also has a good_expr and use_expr that can be used to filter the data before processing.
This is an abstract base class, subclasses should implement calc_from_df and dbg_plot.
Source code in mass2/core/recipe.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
description
property
A short description of this step, including its inputs and outputs.
name
property
The name of this step, usually the class name.
calc_from_df(df)
abstractmethod
Calculate the outputs from the inputs in the given DataFrame, returning a new DataFrame.
Source code in mass2/core/recipe.py
40 41 42 43 44 45 | |
dbg_plot(df_after, **kwargs)
Generate a diagnostic plot of the results after this step.
Source code in mass2/core/recipe.py
47 48 49 50 51 52 | |
drop_debug()
Return self, or a copy of it with debug information removed
Source code in mass2/core/recipe.py
54 55 56 | |
SelectStep
dataclass
Bases: RecipeStep
This step is meant for interactive exploration, it's basically like the df.select() method, but it's saved as a step.
Source code in mass2/core/recipe.py
250 251 252 253 254 255 256 257 258 259 260 261 | |
calc_from_df(df)
Select the given columns and return a new DataFrame.
Source code in mass2/core/recipe.py
258 259 260 261 | |
SummarizeStep
dataclass
Bases: RecipeStep
Summarize raw pulse data into summary statistics using numba-accelerated code.
Source code in mass2/core/recipe.py
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 | |
calc_from_df(df)
Calculate the summary statistics and return a new DataFrame.
Source code in mass2/core/recipe.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
Tools for rough calibration of pulse heights to energies
BestAssignmentPfitGainResult
dataclass
Result of finding the best assignment of pulse heights to energies and fitting a polynomial gain curve.
Source code in mass2/core/rough_cal.py
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 | |
energy2ph(energy)
Invert the gain curve to convert energy to pulse height.
Source code in mass2/core/rough_cal.py
136 137 138 139 140 141 142 143 144 145 | |
ph2energy(ph)
Convert pulse height to energy using the fitted gain curve.
Source code in mass2/core/rough_cal.py
132 133 134 | |
ph_unassigned()
Which pulse heights were not assigned to any energy.
Source code in mass2/core/rough_cal.py
99 100 101 | |
phzerogain()
Find the pulse height where the gain goes to zero. Quadratic fits should have two roots, we want the positive one; if they are complex, choose the real part.
Source code in mass2/core/rough_cal.py
119 120 121 122 123 124 125 126 127 128 129 130 | |
plot(ax=None)
Make a diagnostic plot of the gain fit.
Source code in mass2/core/rough_cal.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
predicted_energies()
Convert the assigned pulse heights to energies using the fitted gain curve.
Source code in mass2/core/rough_cal.py
185 186 187 | |
RoughCalibrationStep
dataclass
Bases: RecipeStep
A step to perform a rough calibration of pulse heights to energies.
Source code in mass2/core/rough_cal.py
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 780 781 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 | |
calc_from_df(df)
Apply the rough calibration to a dataframe.
Source code in mass2/core/rough_cal.py
759 760 761 762 763 764 765 766 | |
dbg_plot(df_after, **kwargs)
Create diagnostic plots of the rough calibration step.
Source code in mass2/core/rough_cal.py
772 773 774 775 776 777 | |
dbg_plot_failure(df, **kwargs)
Create diagnostic plots of the rough calibration step, if it failed.
Source code in mass2/core/rough_cal.py
788 789 790 791 792 793 | |
dbg_plot_success(df, **kwargs)
Create diagnostic plots of the rough calibration step, if it succeeded.
Source code in mass2/core/rough_cal.py
779 780 781 782 783 784 785 786 | |
drop_debug()
Return a copy of this step with debug information removed.
Source code in mass2/core/rough_cal.py
768 769 770 | |
energy2ph(energy)
Convert energy to pulse height using the fitted gain curve.
Source code in mass2/core/rough_cal.py
795 796 797 798 799 | |
learn_3peak(ch, line_names, uncalibrated_col='filtValue', calibrated_col=None, use_expr=field(default_factory=alwaysTrue), max_fractional_energy_error_3rd_assignment=0.1, min_gain_fraction_at_ph_30k=0.25, fwhm_pulse_height_units=75, n_extra_peaks=10, acceptable_rms_residual_e=10)
classmethod
Train a rough calibration step by finding peaks in a smoothed histogram of pulse heights, and assigning 3 of them to known energies in a way that minimizes the RMS error in a local linearity test, and then evaluating that assignment by fitting a 2nd degree polynomial gain curve to all possible pulse heights and returning the RMS error in energy after applying that gain curve to all possible pulse heights. If no good assignment is found, the step will be marked as unsuccessful.
Source code in mass2/core/rough_cal.py
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 | |
learn_combinatoric(ch, line_names, uncalibrated_col, calibrated_col, ph_smoothing_fwhm, n_extra, use_expr=field(default_factory=alwaysTrue))
classmethod
Train a rough calibration step by finding peaks in a smoothed histogram of pulse heights, and assigning them to known energies in a way that minimizes the RMS error in a local linearity test.
Source code in mass2/core/rough_cal.py
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 | |
learn_combinatoric_height_info(ch, line_names, line_heights_allowed, uncalibrated_col, calibrated_col, ph_smoothing_fwhm, n_extra, use_expr=field(default_factory=alwaysTrue))
classmethod
Train a rough calibration step by finding peaks in a smoothed histogram of pulse heights, and assigning them to known energies in a way that minimizes the RMS error in a local linearity test, while respecting constraints on which pulse heights can be assigned to which energies.
Source code in mass2/core/rough_cal.py
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 | |
SmoothedLocalMaximaResult
dataclass
A set of local maxima found in a smoothed histogram of pulse heights.
Source code in mass2/core/rough_cal.py
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 | |
inds_sorted_by_peak_height()
Indices of local maxima sorted by peak height, highest first.
Source code in mass2/core/rough_cal.py
201 202 203 | |
inds_sorted_by_prominence()
Indices of local maxima sorted by prominence, most prominent first.
Source code in mass2/core/rough_cal.py
205 206 207 | |
peak_height()
Peak heights of local maxima.
Source code in mass2/core/rough_cal.py
217 218 219 | |
ph_sorted_by_peak_height()
Pulse heights of local maxima sorted by peak height, highest first.
Source code in mass2/core/rough_cal.py
213 214 215 | |
ph_sorted_by_prominence()
Pulse heights of local maxima sorted by prominence, most prominent first.
Source code in mass2/core/rough_cal.py
209 210 211 | |
plot(assignment_result=None, n_highlight=10, plot_counts=False, ax=None)
Make a diagnostic plot of the smoothed histogram and local maxima.
Source code in mass2/core/rough_cal.py
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 | |
prominence()
Prominence of local maxima, in aems order as local_maxima_inds.
Source code in mass2/core/rough_cal.py
221 222 223 224 225 226 227 228 229 230 231 232 233 | |
drift_correct_entropy(slope, indicator_zero_mean, uncorrected, bin_edges, fwhm_in_bin_number_units)
Calculate the entropy of a histogram of drift-corrected pulse heights.
Source code in mass2/core/rough_cal.py
637 638 639 640 641 642 643 644 645 646 647 648 | |
eval_3peak_assignment_pfit_gain(ph_assigned, e_assigned, possible_phs, line_energies, line_names)
Evaluate a proposed assignment of 3 pulse heights to 3 energies by fitting a 2nd degree polynomial gain curve, and returning the RMS residual in energy after applying that gain curve to all possible pulse heights. If the proposed assignment does not lead to a well formed gain curve, return infinity and a string describing the problem.
Source code in mass2/core/rough_cal.py
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 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 | |
find_best_residual_among_all_possible_assignments(ph, e)
Try all possible assignments of pulse heights to energies, and return the one with the lowest RMS residual in energy after fitting a 2nd degree polynomial gain curve.
Source code in mass2/core/rough_cal.py
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 | |
find_best_residual_among_all_possible_assignments2(ph, e, names)
Try all possible assignments of pulse heights to energies, and return the one with the lowest RMS residual in energy after fitting a 2nd degree polynomial gain curve. Return as a BestAssignmentPfitGainResult object.
Source code in mass2/core/rough_cal.py
581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 | |
find_local_maxima(pulse_heights, gaussian_fwhm)
Smears each pulse by a gaussian of gaussian_fhwm and finds local maxima, returns a list of their locations in pulse_height units (sorted by number of pulses in peak) AND their peak values as: (peak_locations, peak_intensities)
Args: pulse_heights (np.array(dtype=float)): a list of pulse heights (eg p_filt_value) gaussian_fwhm = fwhm of a gaussian that each pulse is smeared with, in same units as pulse heights
Source code in mass2/core/rough_cal.py
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 | |
find_optimal_assignment(ph, e)
Find the optimal assignment of pulse heights to energies by minimizing the RMS error in a local linearity test.
Source code in mass2/core/rough_cal.py
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 | |
find_optimal_assignment2(ph, e, line_names)
Find the optimal assignment of pulse heights to energies by minimizing the RMS error in a local linearity test, and fit a polynomial gain curve to the result.
Source code in mass2/core/rough_cal.py
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 | |
find_optimal_assignment2_height_info(ph, e, line_names, line_heights_allowed)
Find the optimal assignment of pulse heights to energies by minimizing the RMS error in a local linearity test, while respecting constraints on which pulse heights can be assigned to which energies, and fit a polynomial gain curve to the result.
Source code in mass2/core/rough_cal.py
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 | |
find_optimal_assignment_height_info(ph, e, line_heights_allowed)
Find the optimal assignment of pulse heights to energies by minimizing the RMS error in a local linearity test, while respecting constraints on which pulse heights can be assigned to which energies.
Source code in mass2/core/rough_cal.py
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 | |
find_pfit_gain_residual(ph, e)
Find a 2nd degree polynomial fit to the gain curve defined by ph/e, and return the residuals in energy when using that gain curve to convert ph to energy.
Source code in mass2/core/rough_cal.py
565 566 567 568 569 570 571 572 573 574 575 576 577 578 | |
hist_smoothed(pulse_heights, fwhm_pulse_height_units, bin_edges=None)
Compute a histogram of pulse heights and smooth it with a Gaussian of given FWHM.
Source code in mass2/core/rough_cal.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | |
local_maxima(y)
Find local maxima and minima, as 1D arrays.
Source code in mass2/core/rough_cal.py
342 343 344 345 346 347 348 349 350 351 352 353 354 355 | |
minimize_entropy_linear(indicator, uncorrected, bin_edges, fwhm_in_bin_number_units)
Minimize the entropy of a histogram of drift-corrected pulse heights by varying the slope of a linear correction based on the given indicator.
Source code in mass2/core/rough_cal.py
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 | |
peakfind_local_maxima_of_smoothed_hist(pulse_heights, fwhm_pulse_height_units, bin_edges=None)
Find local maxima in a smoothed histogram of pulse heights.
Source code in mass2/core/rough_cal.py
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 | |
rank_3peak_assignments(ph, e, line_names, max_fractional_energy_error_3rd_assignment=0.1, min_gain_fraction_at_ph_30k=0.25)
Explore and rank possible assignments of pulse heights to energies when there are 3 or more lines.
Source code in mass2/core/rough_cal.py
30 31 32 33 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 | |
rank_assignments(ph, e)
Rank possible assignments of pulse heights to energies by how locally linear their implied gain curves are.
Source code in mass2/core/rough_cal.py
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 | |
smooth_hist_with_gauassian_by_fft(hist, fwhm_in_bin_number_units)
Smooth a histogram by convolution with a Gaussian, using FFTs.
Source code in mass2/core/rough_cal.py
303 304 305 306 307 | |
smooth_hist_with_gauassian_by_fft_compute_kernel(nbins, fwhm_in_bin_number_units)
Compute the DFT of a Gaussian kernel for smoothing a histogram.
Source code in mass2/core/rough_cal.py
310 311 312 313 314 315 316 | |
Tools for working with continuous data, as taken by the True Bequerel project.
TriggerResult
dataclass
A trigger result from applying a triggering filter and threshold to a TrueBqBin data source.
Source code in mass2/core/truebq_bin.py
33 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 | |
get_noise(n_dead_samples_after_pulse_trigger, n_record_samples, max_noise_triggers=200)
Synthesize a NoiseChannel from the data source by finding time periods without pulse triggers.
Source code in mass2/core/truebq_bin.py
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 | |
plot(decimate=10, n_limit=100000, offset_raw=0, x_axis_time_s=False, ax=None)
Make a diagnostic plot of the trigger result.
Source code in mass2/core/truebq_bin.py
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 | |
to_channel_copy_to_memory(noise_n_dead_samples_after_pulse_trigger, npre, npost, invert=False)
Create a Channel object by copying pulse data into memory.
Source code in mass2/core/truebq_bin.py
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 | |
to_channel_mmap(noise_n_dead_samples_after_pulse_trigger, npre, npost, invert=False, verbose=True)
Create a Channel object by memory-mapping pulse data from disk.
Source code in mass2/core/truebq_bin.py
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 | |
TrueBqBin
dataclass
Represents a binary data file from the True Bequerel project.
Source code in mass2/core/truebq_bin.py
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 | |
load(bin_path)
classmethod
Create a TrueBqBin object by memory-mapping the given binary file.
Source code in mass2/core/truebq_bin.py
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 | |
trigger(filter_in, threshold, limit_hours=None, verbose=True)
Compute trigger indices by applying the given filter and threshold to the data.
Source code in mass2/core/truebq_bin.py
306 307 308 309 310 311 312 313 | |
fast_apply_filter(data, filter_in)
Apply a filter to the data, returning the filter output.
Source code in mass2/core/truebq_bin.py
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 | |
fasttrig_filter_trigger(data, filter_in, threshold, verbose)
Apply a filter to the data and return trigger indices where the filter output crosses the threshold.
Source code in mass2/core/truebq_bin.py
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 | |
filter_and_residual_rms(data, chosen_filter, avg_pulse, trig_inds, npre, nsamples, polarity)
Apply a filter to pulses extracted from data at the given trigger indices, returning filter values and residual RMS.
Source code in mass2/core/truebq_bin.py
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 | |
gather_pulses_from_inds_numpy_contiguous(data, npre, nsamples, inds)
Gather pulses from data at the given trigger indices, returning a contiguous numpy array.
Source code in mass2/core/truebq_bin.py
442 443 444 445 446 447 448 449 450 | |
gather_pulses_from_inds_numpy_contiguous_mmap(data, npre, nsamples, inds, filename='.mmapped_pulses.npy')
Gather pulses from data at the given trigger indices, returning a memory-mapped numpy array.
Source code in mass2/core/truebq_bin.py
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 | |
gather_pulses_from_inds_numpy_contiguous_mmap_with_cache(data, npre, nsamples, inds, bin_path, verbose=True)
Gather pulses from data at the given trigger indices, returning a memory-mapped numpy array, using a cache.
Source code in mass2/core/truebq_bin.py
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 622 623 624 625 | |
get_noise_trigger_inds(pulse_trigger_inds, n_dead_samples_after_previous_pulse, n_record_samples, max_noise_triggers)
Get trigger indices for noise periods, avoiding pulses.
Source code in mass2/core/truebq_bin.py
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 | |
write_truebq_bin_file(path, data, sample_rate_hz, *, voltage_scale=1.0, format_version=1, schema_version=1, data_reduction_factor=1, acquisition_flags=0, start_time=None, stop_time=None)
Write a binary file that can be opened by TrueBqBin.load().
This function writes data efficiently without copying by using memory mapping and direct file operations.
Args: path: Output file path data: Data array to write (will be converted to int16 if not already) sample_rate_hz: Sample rate in Hz voltage_scale: Voltage scaling factor format_version: File format version (default: 1) schema_version: Schema version (default: 1) data_reduction_factor: Data reduction factor (default: 1) acquisition_flags: Acquisition flags (default: 0) start_time: Start time as uint64 array of length 2 (optional) stop_time: Stop time as uint64 array of length 2 (optional)
Source code in mass2/core/truebq_bin.py
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 | |
Various utility functions and classes:
- MouseClickReader: a class to use as a callback for reading mouse click locations in matplotlib plots.
- InlineUpdater: a class that loops over a generator and prints a message to the terminal each time it yields.
InlineUpdater
A class to print progress updates to the terminal.
Source code in mass2/core/utilities.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 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 | |
elapsedTimeSec
property
Elapsed time in seconds since the creation of this object.
elapsedTimeStr
property
String version of elapsed time.
timeRemaining
property
Estimate of time remaining in seconds, or -1 if not enough information yet.
timeRemainingStr
property
String version of time-remaining estimate.
update(fracDone)
Update the progress to the given fraction done.
Source code in mass2/core/utilities.py
28 29 30 31 32 33 34 35 36 | |
NullUpdater
A do-nothing updater class with the same API as InlineUpdater.
Source code in mass2/core/utilities.py
71 72 73 74 75 76 | |
update(f)
Do nothing.
Source code in mass2/core/utilities.py
74 75 76 | |
show_progress(name)
A decorator to show progress updates for another function.
Source code in mass2/core/utilities.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
Other docstrings
See also Other docstrings for modules other than mass2.core.