sgnl.psd
¶
A module for reading, writing, and measuring PSDs.
HorizonDistance
¶
Bases: object
Source code in sgnl/psd.py
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 |
|
__call__(psd, snr=8.0)
¶
Compute the horizon distance for the configured waveform model given the PSD and the SNR at which the horizon is defined (default = 8). Equivalently, from a PSD and an observed SNR compute and return the amplitude of the configured waveform's spectrum required to achieve that SNR.
The return value is a two-element tuple. The first element is the horizon distance in Mpc. The second element is, itself, a two-element tuple containing two vectors giving the frequencies and amplitudes of the waveform model's spectrum scaled so as to have the given SNR. The vectors are clipped to the range of frequencies that were used for the SNR integral.
The parameters of the PSD, for example its Nyquist and frequency resolution, need not match the parameters of the configured waveform model. In the event of a mismatch, the waveform model is resampled to the frequencies at which the PSD has been measured.
The inspiral spectrum returned has the same units as the PSD and is normalized so that the SNR is
SNR^2 = int (inspiral_spectrum / psd) df
That is, the ratio of the inspiral spectrum to the PSD gives the spectral density of SNR^2.
Source code in sgnl/psd.py
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 |
|
__init__(f_min, f_max, delta_f, m1, m2, spin1=(0.0, 0.0, 0.0), spin2=(0.0, 0.0, 0.0), eccentricity=0.0, inclination=0.0, approximant='IMRPhenomD')
¶
Configures the horizon distance calculation for a specific waveform model. The waveform is pre-computed and stored, so this initialization step can be time-consuming but computing horizon distances from measured PSDs will be fast.
The waveform model's spectrum parameters, for example its Nyquist and frequency resolution, need not match the parameters for the PSDs that will ultimately be supplied but there are some advantages to be had in getting them to match. For example, computing the waveform with a smaller delta_f than will be needed will require additional storage and consume additional CPU time for the initialization, while computing it with too low an f_max or too large a delta_f might lead to inaccurate horizon distance estimates.
f_min (Hertz) sets the frequency at which the waveform model is to begin.
f_max (Hertz) sets the frequency upto which the waveform's model is desired.
delta_f (Hertz) sets the frequency resolution of the desired waveform model.
m1, m2 (solar masses) set the component masses of the system to model.
spin1, spin2 (3-component vectors, geometric units) set the spins of the component masses.
eccentricity [0, 1) sets the eccentricity of the system.
inclination (radians) sets the orbital inclination of the system.
Example:
configure for non-spinning, circular, 1.4+1.4 BNS¶
horizon_distance = HorizonDistance(10., 1024., 1./32., 1.4, 1.4)
populate a PSD for testing¶
import lal, lalsimulation psd = lal.CreateREAL8FrequencySeries("psd", lal.LIGOTimeGPS(0), 0., 1./32., ... lal.Unit("strain^2 s"), horizon_distance.model.data.length) lalsimulation.SimNoisePSDaLIGODesignSensitivityP1200087(psd, 0.) 0
compute horizon distance¶
D, (f, model) = horizon_distance(psd) print("%.4g Mpc" % D) 434.7 Mpc
compute distance and spectrum for SNR = 25¶
D, (f, model) = horizon_distance(psd, 25.) "%.4g Mpc" % D '139.1 Mpc' f array([ 10. , 10.03125, 10.0625 , ..., 1023.9375 , 1023.96875, 1024. ]) model array([ 8.05622865e-45, 7.99763234e-45, 7.93964216e-45, ..., 1.11824864e-49, 1.11815656e-49, 1.11806450e-49])
NOTE:
- Currently the SEOBNRv4_ROM waveform model is used, so its limitations with respect to masses, spins, etc., apply. The choice of waveform model is subject to change.
Source code in sgnl/psd.py
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 |
|
condition_psd(psd, newdeltaF, minfs=(35.0, 40.0), maxfs=(1800.0, 2048.0), smoothing_frequency=4.0, fir_whiten=False)
¶
Condition a PSD suitable for whitening waveforms.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
psd
|
REAL8FrequencySeries
|
lal.REAL8FrequencySeries, the PSD to taper |
required |
newdeltaF
|
Hz
|
int, the target delta F to interpolate to |
required |
minfs
|
Hz
|
Tuple[float, float], optional, the frequency boundaries over which to taper the spectrum to infinity. i.e., frequencies below the first item in the tuple will have an infinite spectrum, the second item in the tuple will not be changed. A taper from 0 to infinity is applied in between. |
(35.0, 40.0)
|
maxfs
|
Hz
|
Tuple[float, float], optional, the frequency boundaries over which to taper the spectrum to infinity. i.e., frequencies above the second item in the tuple will have an infinite spectrum, the first item in the tuple will not be changed. A taper from 0 to infinity is applied in between. |
(1800.0, 2048.0)
|
smoothing_frequency
|
Hz
|
float, default = 4 Hz, the target frequency resolution after smoothing. Lines with bandwidths << smoothing_frequency are removed via a median calculation. Remaining features will be blurred out to this resolution. |
4.0
|
fir_whiten
|
Optional[bool]
|
bool, default False, whether to enable causal whitening with a time-domain whitening kernel vs. traditional acausal whitening |
False
|
Returns:
Type | Description |
---|---|
REAL8FrequencySeries
|
lal.REAL8FrequencySeries, the conditioned PSD |
Source code in sgnl/psd.py
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 |
|
effective_distance_factor(inclination, fp, fc)
¶
Returns the ratio of effective distance to physical distance for compact binary mergers. Inclination is the orbital inclination of the system in radians, fp and fc are the F+ and Fx antenna factors. See lal.ComputeDetAMResponse() for a function to compute antenna factors. The effective distance is given by
Deff = effective_distance_factor * D
See Equation (4.3) of arXiv:0705.1514.
Source code in sgnl/psd.py
908 909 910 911 912 913 914 915 916 917 918 919 920 921 |
|
harmonic_mean(psddict)
¶
Take the harmonic mean of a dictionary of PSDs.
Source code in sgnl/psd.py
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 |
|
interpolate_psd(psd, deltaF)
¶
Interpolates a PSD to a target frequency resolution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
psd
|
REAL8FrequencySeries
|
lal.REAL8FrequencySeries, the PSD to interpolate |
required |
deltaF
|
int
|
int, the target frequency resolution to interpolate to |
required |
Returns:
Type | Description |
---|---|
REAL8FrequencySeries
|
lal.REAL8FrequencySeries, the interpolated PSD |
Source code in sgnl/psd.py
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 |
|
movingaverage(psd, window_size)
¶
Smoothen a PSD with a moving average.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
psd
|
ndarray
|
numpy.ndarray, the PSD to smoothen |
required |
window_size
|
int
|
int, the size of the window used for the moving median |
required |
Returns:
Type | Description |
---|---|
ndarray
|
the smoothened PSD |
Source code in sgnl/psd.py
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 |
|
movingmedian(psd, window_size)
¶
Smoothen a PSD with a moving median.
Assumes that the underlying PSD doesn't have variance, i.e., that there is no median / mean correction factor required.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
psd
|
Union[ndarray, REAL8FrequencySeries]
|
Union[numpy.ndarray, lal.REAL8FrequencySeries], the PSD to smoothen |
required |
window_size
|
int
|
int, the size of the window used for the moving median |
required |
Returns:
Type | Description |
---|---|
Union[ndarray, REAL8FrequencySeries]
|
a smoothened PSD of same type as input PSD |
Source code in sgnl/psd.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 |
|
polyfit(psd, f_low, f_high, order, verbose=False)
¶
Fit a PSD to a polynomial.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
psd
|
REAL8FrequencySeries
|
lal.REAL8FrequencySeries, the PSD to fit |
required |
f_low
|
Hz
|
float, the low frequency to begin fitting with |
required |
f_high
|
Hz
|
float, the high frequency to stop fitting with |
required |
order
|
int
|
int, the order of the fitting polynomial |
required |
verbose
|
Optional[bool]
|
bool, default false, whether to display the fit |
False
|
Returns:
Type | Description |
---|---|
REAL8FrequencySeries
|
lal.REAL8FrequencySeries, the PSD fitted to a polynomial |
Source code in sgnl/psd.py
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 |
|
read_asd_txt(filename, df=0.25, zero_pad=False, read_as_psd=False)
¶
Reads in a text-formatted ASD as a PSD.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str
|
str, the file to read ASD(s) from |
required |
df
|
Hz
|
float, default 0.25, the frequency resolution to interpolate to |
0.25
|
zero_pad
|
bool
|
bool, default False, whether to zero-pad PSD to 0 Hz if needed. |
False
|
read_as_psd
|
bool
|
bool, default False, whether to treat input as PSD rather than ASD |
False
|
Returns:
Type | Description |
---|---|
REAL8FrequencySeries
|
lal.REAL8FrequencySeries, the PSD |
Source code in sgnl/psd.py
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 |
|
read_psd(filename, verbose=False)
¶
Reads in an XML-formatted PSD.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str
|
str, the file to read PSD(s) from |
required |
verbose
|
Optional[bool]
|
bool, default False, whether to display logging messages |
False
|
Returns:
Type | Description |
---|---|
Dict[str, REAL8FrequencySeries]
|
a dictionary of lal FrequencySeries keyed by instrument |
Source code in sgnl/psd.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|
taperzero_fseries(fseries, minfs=(35.0, 40.0), maxfs=(1800.0, 2048.0))
¶
Taper the PSD to infinity for given min/max frequencies.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
psd
|
lal.REAL8FrequencySeries, the PSD to taper |
required | |
minfs
|
Hz
|
Tuple[float, float], optional, the frequency boundaries over which to taper the spectrum to infinity. i.e., frequencies below the first item in the tuple will have an infinite spectrum, the second item in the tuple will not be changed. A taper from 0 to infinity is applied in between. |
(35.0, 40.0)
|
maxfs
|
Hz
|
Tuple[float, float], optional, the frequency boundaries over which to taper the spectrum to infinity. i.e., frequencies above the second item in the tuple will have an infinite spectrum, the first item in the tuple will not be changed. A taper from 0 to infinity is applied in between. |
(1800.0, 2048.0)
|
Returns:
Type | Description |
---|---|
REAL8FrequencySeries
|
lal.REAL8FrequencySeries, the tapered PSD |
Source code in sgnl/psd.py
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 |
|
write_asd_txt(filename, psd, verbose=False)
¶
Writes an text-formatted ASD to disk.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str
|
str, the file to write ASD to |
required |
psd
|
REAL8FrequencySeries
|
lal.REAL8FrequencySeries, the PSD |
required |
verbose
|
Optional[bool]
|
bool, default False, whether to display logging messages |
False
|
Source code in sgnl/psd.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
|
write_psd(filename, psddict, trap_signals=None, verbose=False)
¶
Writes an XML-formatted PSD to disk.
Wrapper around make_psd_xmldoc() to write the XML document directly to a named file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str
|
str, the file to write PSD(s) to |
required |
psds
|
Dict[str, lal.REAL8FrequencySeries], the PSD(s) |
required | |
trap_signals
|
Optional[Iterable[Signals]]
|
Iterable[signal.Signal], optional, whether to attach extra signal handlers on write |
None
|
verbose
|
Optional[bool]
|
bool, default False, whether to display logging messages |
False
|
Source code in sgnl/psd.py
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 |
|