lyapower.fitter¶
Arinyo non-linear model fitting of the flux P3D with iminuit.
lyapower.fitter ¶
Fitting routines for the 3D Lyman-alpha forest flux power spectrum.
This module implements the flux power spectrum model of
Arinyo-i-Prats et al. (2015), including the non-linear correction terms
D0 and D1 (and a BAO-damped D1 variant), builds Pf_model from a
linear matter power spectrum (obtained via CLASS or cosmoprimo, or read
directly from Nyx/gimlet outputs), sets up iminuit-based cost
functions and Minuit fits, drives the end-to-end fitting pipeline
(prepare_data, fitter_k_mu), reads gimlet power-spectrum output
files, and produces diagnostic plots and LaTeX summaries of fit results.
Conventions: wavenumbers k are in h/Mpc, mu = k_par / k; b
and beta are the linear bias and RSD parameter; non_linear_model
selects between the "0" (D0), "1" (D1), "1_bao"/"1_BAO" (D1 + BAO
damping) and None (linear) flux power spectrum models.
read_pfkmu_hdf5 ¶
read_pfkmu_hdf5(filename, field_name, power_weighted=False, error_estimator=None, **kwargs)
Read a 3D flux power spectrum P(k, mu) from an HDF5 gimlet output file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the HDF5 file produced by gimlet. |
required |
field_name
|
str
|
Name of the HDF5 field/dataset to read. |
required |
power_weighted
|
bool
|
Whether the stored k/mu values are already power-weighted bin centers. Defaults to False. |
False
|
error_estimator
|
str or None
|
Name of the error estimator to use when building the error array. Defaults to None. |
None
|
**kwargs
|
Additional keyword arguments forwarded to
|
{}
|
Returns:
| Type | Description |
|---|---|
|
power_spectra.FluxPowerSpectrum: The loaded 3D flux power spectrum. |
Source code in lyapower/fitter.py
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 | |
read_pfkmu ¶
read_pfkmu(filename, power_weighted=False, error_estimator=None, **kwargs)
Read a 3D flux power spectrum P(k, mu) from a text gimlet output file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the text file produced by gimlet. |
required |
power_weighted
|
bool
|
Whether the stored k/mu values are already power-weighted bin centers. Defaults to False. |
False
|
error_estimator
|
str or None
|
Name of the error estimator to use when building the error array. Defaults to None. |
None
|
**kwargs
|
Additional keyword arguments forwarded to
|
{}
|
Returns:
| Type | Description |
|---|---|
|
power_spectra.FluxPowerSpectrum: The loaded 3D flux power spectrum, |
|
|
parametrized in (k, mu). |
Source code in lyapower/fitter.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 | |
read_pfkperpkpar ¶
read_pfkperpkpar(filename, power_weighted=False, error_estimator=None, **kwargs)
Read a 3D flux power spectrum P(k_perp, k_par) from a text gimlet file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the text file produced by gimlet. |
required |
power_weighted
|
bool
|
Whether the stored k values are already power-weighted bin centers. Defaults to False. |
False
|
error_estimator
|
str or None
|
Name of the error estimator to use when building the error array. Defaults to None. |
None
|
**kwargs
|
Additional keyword arguments forwarded to
|
{}
|
Returns:
| Type | Description |
|---|---|
|
power_spectra.FluxPowerSpectrum: The loaded 3D flux power spectrum, |
|
|
parametrized in (k_perp, k_par). |
Source code in lyapower/fitter.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 | |
read_p1d ¶
read_p1d(filename, power_weighted=False, error_estimator=None, **kwargs)
Read a 1D flux power spectrum P(k) from a gimlet output file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the file produced by gimlet. |
required |
power_weighted
|
bool
|
Whether the stored k values are already power-weighted bin centers. Defaults to False. |
False
|
error_estimator
|
str or None
|
Name of the error estimator to use when building the error array. Defaults to None. |
None
|
**kwargs
|
Additional keyword arguments forwarded to
|
{}
|
Returns:
| Type | Description |
|---|---|
|
power_spectra.FluxPowerSpectrum: The loaded 1D flux power spectrum. |
Source code in lyapower/fitter.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
read_pk ¶
read_pk(filename, power_weighted=False, error_estimator=None, **kwargs)
Read a matter power spectrum P(k) from a gimlet output file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the file produced by gimlet. |
required |
power_weighted
|
bool
|
Whether the stored k values are already power-weighted bin centers. Defaults to False. |
False
|
error_estimator
|
str or None
|
Name of the error estimator to use when building the error array. Defaults to None. |
None
|
**kwargs
|
Additional keyword arguments forwarded to
|
{}
|
Returns:
| Type | Description |
|---|---|
|
power_spectra.MatterPowerSpectrum: The loaded matter power spectrum. |
Source code in lyapower/fitter.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
rebin_matter_power ¶
rebin_matter_power(power_m, k_m, k_f)
Interpolate a matter power spectrum onto a new set of wavenumbers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
power_m
|
ndarray
|
Matter power spectrum values sampled at |
required |
k_m
|
ndarray
|
Wavenumbers at which |
required |
k_f
|
ndarray
|
Target wavenumbers (typically the flux power spectrum k-grid) to interpolate onto. |
required |
Returns:
| Type | Description |
|---|---|
|
numpy.ndarray: |
|
|
outside the range of |
Source code in lyapower/fitter.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
mask_data ¶
mask_data(indexes, *args)
Mask near-zero entries in-place across a set of arrays.
For each array indexed in indexes, flags array elements whose
absolute value is smaller than 1e-10 times the array's mean, then
sets those positions to NaN in every array in args (in-place).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indexes
|
iterable of int
|
Indices into |
required |
*args
|
ndarray
|
Arrays to be masked in-place; all must
share the same shape as |
()
|
Returns:
| Type | Description |
|---|---|
|
None |
Source code in lyapower/fitter.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
D0 ¶
D0(k, mu, k_nl, a_nl, k_p, a_p, k_v0, a_v0, k_v1, a_v1)
Arinyo-i-Prats et al. (2015) "D0" non-linear correction term.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
ndarray or float
|
Wavenumber, in h/Mpc. |
required |
mu
|
ndarray or float
|
Cosine of the angle to the line of sight. |
required |
k_nl
|
float
|
Non-linear growth scale. |
required |
a_nl
|
float
|
Non-linear growth exponent. |
required |
k_p
|
float
|
Pressure (smoothing) scale. |
required |
a_p
|
float
|
Pressure exponent. |
required |
k_v0
|
float
|
Velocity non-linear scale normalization. |
required |
a_v0
|
float
|
Velocity non-linear exponent. |
required |
k_v1
|
float
|
Velocity scale used in the k-dependence of |
required |
a_v1
|
float
|
Exponent of the k-dependence of |
required |
Returns:
| Type | Description |
|---|---|
|
numpy.ndarray or float: The multiplicative non-linear correction |
|
|
D0(k, mu). |
Source code in lyapower/fitter.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 | |
D1 ¶
D1(k, mu, q_1, q_2, k_v, a_v, b_v, k_p, linear_power_spectrum)
Arinyo-i-Prats et al. (2015) "D1" non-linear correction term.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
ndarray or float
|
Wavenumber, in h/Mpc. |
required |
mu
|
ndarray or float
|
Cosine of the angle to the line of sight. |
required |
q_1
|
float
|
Linear coefficient of the non-linear growth term. |
required |
q_2
|
float
|
Quadratic coefficient of the non-linear growth term. |
required |
k_v
|
float
|
Velocity non-linear scale. |
required |
a_v
|
float
|
Velocity non-linear exponent (k-dependence). |
required |
b_v
|
float
|
Velocity non-linear exponent (mu-dependence). |
required |
k_p
|
float
|
Pressure (smoothing) scale. |
required |
linear_power_spectrum
|
ndarray or float
|
Linear matter
power spectrum evaluated at |
required |
Returns:
| Type | Description |
|---|---|
|
numpy.ndarray or float: The multiplicative non-linear correction |
|
|
D1(k, mu). |
Source code in lyapower/fitter.py
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 | |
Pl_class ¶
Pl_class(k_array, settings, z, name='class')
Compute the linear matter power spectrum at redshift z using CLASS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k_array
|
ndarray
|
Wavenumbers (h/Mpc) spanning the desired range; only its min/max and length are used to set up the CLASS k-grid. |
required |
settings
|
dict
|
CLASS configuration/settings dictionary passed
to |
required |
z
|
float
|
Redshift at which to evaluate the power spectrum. |
required |
name
|
str
|
Output file base name used by |
'class'
|
Returns:
| Type | Description |
|---|---|
|
power_spectra.MatterPowerSpectrum: The linear matter power |
|
|
spectrum computed by CLASS, h-normalized. |
Source code in lyapower/fitter.py
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 | |
Pl_cosmoprimo ¶
Pl_cosmoprimo(k_array, settings, z)
Compute the (wiggle and no-wiggle) linear matter power spectra via cosmoprimo.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k_array
|
ndarray
|
Wavenumbers (h/Mpc) at which to evaluate the power spectra. |
required |
settings
|
dict
|
Cosmoprimo/CLASS configuration dictionary passed
to |
required |
z
|
float
|
Redshift at which to evaluate the power spectra. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
|
|
|
|
||
|
the full (BAO wiggles included) linear power spectrum and its |
||
|
no-wiggle counterpart, both evaluated on |
Source code in lyapower/fitter.py
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 | |
Pm_normalized ¶
Pm_normalized(pm_file, class_dict, z_simu, z_init, name='pmnorm')
Build a matter power spectrum from simulation output, rescaled by CLASS growth.
Reads a raw simulation matter power spectrum from pm_file and
rescales it by the ratio of CLASS linear power spectra at z_simu
and z_init (times an Omega_m/(Omega_m - Omega_b) coefficient), to
correct for baryon growth suppression / normalize onto a fiducial
linear growth.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pm_file
|
str
|
Path to the gimlet matter power spectrum file. |
required |
class_dict
|
dict
|
CLASS configuration dictionary. |
required |
z_simu
|
float
|
Simulation output redshift. |
required |
z_init
|
float
|
Simulation initial-conditions redshift. |
required |
name
|
str
|
Output file base name used by |
'pmnorm'
|
Returns:
| Type | Description |
|---|---|
|
power_spectra.MatterPowerSpectrum: The rescaled, h-normalized |
|
|
matter power spectrum, sampled on the same k-grid as |
Source code in lyapower/fitter.py
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 | |
Pm ¶
Pm(pm_file, name='pm')
Read a raw matter power spectrum from a gimlet file and set its name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pm_file
|
str
|
Path to the gimlet matter power spectrum file. |
required |
name
|
str
|
Name to assign to the returned power spectrum object. Defaults to "pm". |
'pm'
|
Returns:
| Type | Description |
|---|---|
|
power_spectra.MatterPowerSpectrum: The matter power spectrum read |
|
|
from |
Source code in lyapower/fitter.py
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 | |
Pf_model ¶
Pf_model(linear_power_spectrum, non_linear_model='0', linear_power_spectrum_no_bao=None, integrate_model=True, N_mu_integration=1000, mu_max=1.0)
Build the flux power spectrum model function P_f(k, mu).
Selects and returns a callable model of the flux power spectrum,
P_f = b^2 (1 + beta*mu^2)^2 * P_linear * D(k, mu), where D is either
the Arinyo-i-Prats "D0" or "D1" non-linear correction (optionally
with BAO damping via linear_power_spectrum_no_bao), or omitted
entirely for a linear model (non_linear_model=None). If
integrate_model is True, the returned model integrates the
analytic expression over each mu bin (using Simpson's rule) instead
of evaluating it at bin-center mu values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
linear_power_spectrum
|
ndarray
|
Linear matter power spectrum evaluated on the flux power spectrum k-grid. |
required |
non_linear_model
|
str or None
|
Which non-linear correction to use: "0" (D0), "1" (D1), "1_bao"/"1_BAO" (D1 + BAO damping), or None for a purely linear model. Defaults to "0". |
'0'
|
linear_power_spectrum_no_bao
|
ndarray or None
|
No-wiggle linear matter power spectrum, required for the BAO-damped variant. Defaults to None. |
None
|
integrate_model
|
bool
|
If True, integrate the model over each mu bin instead of evaluating at bin centers. Defaults to True. |
True
|
N_mu_integration
|
int
|
Number of mu sub-samples used per bin
when |
1000
|
mu_max
|
float
|
Maximum mu value used to compute mu bin widths. Defaults to 1.0. |
1.0
|
Returns:
| Name | Type | Description |
|---|---|---|
callable |
A model function |
|
|
|
||
|
non-linear model's nuisance parameters, returning the predicted |
||
|
flux power spectrum. |
Source code in lyapower/fitter.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 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 | |
custom_least_squares ¶
custom_least_squares(model, data_x, data_y, data_yerr, non_linear_model='0')
Build a plain least-squares iminuit cost function for a given model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
callable
|
Flux power spectrum model function, as
returned by |
required |
data_x
|
tuple
|
|
required |
data_y
|
ndarray
|
Observed flux power spectrum values. |
required |
data_yerr
|
ndarray
|
Uncertainties on |
required |
non_linear_model
|
str or None
|
Selects which cost function signature to return: "0" (D0), "1" (D1), "1_bao" (D1 + BAO), or None (linear). Defaults to "0". |
'0'
|
Returns:
| Name | Type | Description |
|---|---|---|
callable |
A cost function |
|
|
|
||
|
ignoring NaNs, with a signature matching the selected model. |
Source code in lyapower/fitter.py
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 | |
custom_least_squares_arinyo ¶
custom_least_squares_arinyo(model, data_x, data_y, data_yerr, non_linear_model='0')
Build an Arinyo-style least-squares iminuit cost function for a model.
Like custom_least_squares, but computes the residual as
((data_y**2 / ym) - ym) / data_yerr instead of
(data_y - ym) / data_yerr.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
callable
|
Flux power spectrum model function, as
returned by |
required |
data_x
|
tuple
|
|
required |
data_y
|
ndarray
|
Observed flux power spectrum values. |
required |
data_yerr
|
ndarray
|
Uncertainties on |
required |
non_linear_model
|
str or None
|
Selects which cost function signature to return: "0" (D0), "1" (D1), "1_bao" (D1 + BAO), or None (linear). Defaults to "0". |
'0'
|
Returns:
| Name | Type | Description |
|---|---|---|
callable |
A cost function |
|
|
|
||
|
|
Source code in lyapower/fitter.py
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 | |
cost_function ¶
cost_function(model, data_x, data_y, data_yerr, cost_name, non_linear_model='0')
Dispatch to the requested iminuit cost function builder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
callable
|
Flux power spectrum model function. |
required |
data_x
|
tuple
|
|
required |
data_y
|
ndarray
|
Observed flux power spectrum values. |
required |
data_yerr
|
ndarray
|
Uncertainties on |
required |
cost_name
|
str
|
Which cost function family to build: "least"
( |
required |
non_linear_model
|
str or None
|
Non-linear model selector forwarded to the chosen cost-function builder. Defaults to "0". |
'0'
|
Returns:
| Type | Description |
|---|---|
|
callable or None: The selected cost function, or None if |
|
|
|
Source code in lyapower/fitter.py
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 | |
run_minuit ¶
run_minuit(data_x, data_y, data_yerr, minuit_parameters, minuit_limits, power_l_rebin, non_linear_model='0', cost_name='least', ncall=100, fix_args=None, launch_minos=False, sigma_minos=None, var_minos=None, integrate_model=True, N_mu_integration=1000, mu_max=1.0, power_l_no_bao_rebin=None)
Build the flux power spectrum model and cost function, and run a Minuit fit.
Constructs the model via Pf_model, builds the corresponding cost
function via cost_function, initializes an iminuit.Minuit
instance, applies parameter limits and fixed parameters, then runs
MIGRAD (and optionally HESSE and MINOS).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_x
|
tuple
|
|
required |
data_y
|
ndarray
|
Observed flux power spectrum values. |
required |
data_yerr
|
ndarray
|
Uncertainties on |
required |
minuit_parameters
|
dict
|
Initial parameter values/settings
passed to |
required |
minuit_limits
|
list or None
|
Sequence of |
required |
power_l_rebin
|
ndarray
|
Linear power spectrum rebinned
onto the flux power spectrum k-grid, passed to |
required |
non_linear_model
|
str or None
|
Non-linear model selector ("0", "1", "1_bao", or None). Defaults to "0". |
'0'
|
cost_name
|
str
|
Cost function family ("least" or "least_arinyo"). Defaults to "least". |
'least'
|
ncall
|
int
|
Maximum number of function calls for MIGRAD (and MINOS). Defaults to 100. |
100
|
fix_args
|
list or None
|
Parameter names to fix (hold constant). Defaults to None. |
None
|
launch_minos
|
bool
|
Whether to run MINOS after HESSE. Defaults to False. |
False
|
sigma_minos
|
float or None
|
Sigma level passed to |
None
|
var_minos
|
str or list or None
|
Parameter(s) to run MINOS on. Defaults to None. |
None
|
integrate_model
|
bool
|
Whether |
True
|
N_mu_integration
|
int
|
Number of mu sub-samples per bin when integrating. Defaults to 1000. |
1000
|
mu_max
|
float
|
Maximum mu used for bin-width computation. Defaults to 1.0. |
1.0
|
power_l_no_bao_rebin
|
ndarray or None
|
No-wiggle linear power spectrum rebinned onto the flux power spectrum k-grid, required for the BAO-damped model. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
|
iminuit.Minuit: The fitted Minuit instance after MIGRAD (and |
|
|
optionally HESSE/MINOS). |
Source code in lyapower/fitter.py
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 | |
run_migrad ¶
run_migrad(minuit, ncall=1000)
Run the iminuit MIGRAD minimizer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
minuit
|
Minuit
|
The Minuit instance to minimize. |
required |
ncall
|
int
|
Maximum number of function calls. Defaults to 1000. |
1000
|
Returns:
| Type | Description |
|---|---|
|
iminuit.Minuit: The Minuit instance after MIGRAD, as returned by |
|
|
|
Source code in lyapower/fitter.py
1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 | |
run_minos ¶
run_minos(minuit, sigma, ncall=1000, var_minos=None)
Run the iminuit MINOS error analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
minuit
|
Minuit
|
The Minuit instance to analyze. |
required |
sigma
|
float
|
Confidence-level sigma passed to |
required |
ncall
|
int
|
Maximum number of function calls. Defaults to 1000. |
1000
|
var_minos
|
str or list or None
|
Parameter(s) to run MINOS on; None runs it on all free parameters. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
|
iminuit.Minuit: The Minuit instance after MINOS, as returned by |
|
|
|
Source code in lyapower/fitter.py
1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 | |
run_hesse ¶
run_hesse(minuit)
Run the iminuit HESSE error analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
minuit
|
Minuit
|
The Minuit instance to analyze. |
required |
Returns:
| Type | Description |
|---|---|
|
iminuit.Minuit: The Minuit instance after HESSE, as returned by |
|
|
|
Source code in lyapower/fitter.py
1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 | |
prepare_data ¶
prepare_data(pf_file, pk_file, power_weighted=False, class_dict=None, z_simu=None, z_init=None, kmax=None, kmin=None, name_pm_file=None, error_estimator=None, use_wavenumber_centers=True, use_mu_centers=False, **kwargs)
Load, center, cut, and rebin the flux and linear power spectra for fitting.
Reads the 3D flux power spectrum from pf_file, optionally
recenters its wavenumber/mu bin values, trims it to
[kmin, kmax], optionally rebins it, then builds the linear
matter power spectrum (from CLASS, a normalized/raw simulation
power spectrum, cosmoprimo, or a gimlet file depending on
pk_file) and rebins it onto the flux power spectrum k-grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pf_file
|
str
|
Path to the gimlet 3D flux power spectrum file. |
required |
pk_file
|
str
|
Source of the linear matter power spectrum: "class", "pmnorm", "pm", "cosmoprimo", or a path to a gimlet matter power spectrum file. |
required |
power_weighted
|
bool
|
Whether the flux power spectrum bins are already power-weighted. Defaults to False. |
False
|
class_dict
|
dict or None
|
CLASS/cosmoprimo settings
dictionary, required when |
None
|
z_simu
|
float or None
|
Simulation redshift, required when
|
None
|
z_init
|
float or None
|
Initial-conditions redshift, required
when |
None
|
kmax
|
float or None
|
Maximum wavenumber kept. Defaults to None. |
None
|
kmin
|
float or None
|
Minimum wavenumber kept. Defaults to None. |
None
|
name_pm_file
|
str or None
|
Path to the raw simulation matter
power spectrum file, required when |
None
|
error_estimator
|
str or None
|
Error estimator forwarded to
|
None
|
use_wavenumber_centers
|
bool
|
Whether to recenter wavenumber
bins via |
True
|
use_mu_centers
|
bool
|
Whether to recenter mu bins via
|
False
|
**kwargs
|
Additional keyword arguments; may include a "rebin"
dict with keys "nb_bin", "loglin", "k_loglin" controlling
|
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
`(power_f, power_l, power_l_rebin, data_x, data_y, |
|
|
data_yerr, power_l_no_bao, power_l_no_bao_rebin)` — the flux |
||
|
power spectrum object, the linear matter power spectrum |
||
|
object, the linear power spectrum rebinned onto the flux |
||
|
k-grid, the fit x/y/yerr data arrays, and (when applicable) the |
||
|
no-wiggle linear power spectrum object and its rebinned |
||
|
counterpart (both None otherwise). |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
Source code in lyapower/fitter.py
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 | |
fitter_k_mu ¶
fitter_k_mu(pf_file, pk_file, minuit_parameters, minuit_limits, power_weighted=False, class_dict=None, z_simu=None, z_init=None, non_linear_model='0', cost_name='least', ncall=100, kmax=None, kmin=None, launch_minos=None, var_minos=None, sigma_minos=None, name_pm_file=None, error_estimator=None, fix_args=None, integrate_model=True, N_mu_integration=1000, mu_max=1.0, use_wavenumber_centers=True, use_mu_centers=False, **kwargs)
End-to-end flux power spectrum fit in (k, mu): load data and run Minuit.
Validates the combination of power_weighted,
use_wavenumber_centers, use_mu_centers and integrate_model
options (printing warnings for inconsistent/untested combinations),
calls prepare_data to load and rebin the flux and linear power
spectra, then calls run_minuit to perform the fit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pf_file
|
str
|
Path to the gimlet 3D flux power spectrum file. |
required |
pk_file
|
str
|
Source of the linear matter power spectrum (see
|
required |
minuit_parameters
|
dict
|
Initial Minuit parameter values/settings. |
required |
minuit_limits
|
list or None
|
Sequence of |
required |
power_weighted
|
bool
|
Whether the flux power spectrum bins are already power-weighted. Defaults to False. |
False
|
class_dict
|
dict or None
|
CLASS/cosmoprimo settings dictionary. Defaults to None. |
None
|
z_simu
|
float or None
|
Simulation redshift. Defaults to None. |
None
|
z_init
|
float or None
|
Initial-conditions redshift. Defaults to None. |
None
|
non_linear_model
|
str or None
|
Non-linear model selector ("0", "1", "1_bao", or None). Defaults to "0". |
'0'
|
cost_name
|
str
|
Cost function family ("least" or "least_arinyo"). Defaults to "least". |
'least'
|
ncall
|
int
|
Maximum number of MIGRAD/MINOS function calls. Defaults to 100. |
100
|
kmax
|
float or None
|
Maximum wavenumber kept. Defaults to None. |
None
|
kmin
|
float or None
|
Minimum wavenumber kept. Defaults to None. |
None
|
launch_minos
|
bool or None
|
Whether to run MINOS after HESSE. Defaults to None. |
None
|
var_minos
|
str or list or None
|
Parameter(s) to run MINOS on. Defaults to None. |
None
|
sigma_minos
|
float or None
|
Sigma level passed to MINOS. Defaults to None. |
None
|
name_pm_file
|
str or None
|
Path to the raw simulation matter power spectrum file. Defaults to None. |
None
|
error_estimator
|
str or None
|
Error estimator forwarded to
|
None
|
fix_args
|
list or None
|
Parameter names to fix in Minuit. Defaults to None. |
None
|
integrate_model
|
bool
|
Whether |
True
|
N_mu_integration
|
int
|
Number of mu sub-samples per bin when integrating. Defaults to 1000. |
1000
|
mu_max
|
float
|
Maximum mu used for bin-width computation. Defaults to 1.0. |
1.0
|
use_wavenumber_centers
|
bool
|
Whether to recenter wavenumber bins. Defaults to True. |
True
|
use_mu_centers
|
bool
|
Whether to recenter mu bins. Defaults to False. |
False
|
**kwargs
|
Additional keyword arguments forwarded to
|
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
`(minuit, power_f, power_l, power_l_rebin, |
|
|
non_linear_model, power_l_no_bao, power_l_no_bao_rebin)` — the |
||
|
fitted Minuit instance, the flux and linear power spectrum |
||
|
objects, the rebinned linear power spectrum, the non-linear |
||
|
model name, and (when applicable) the no-wiggle linear power |
||
|
spectrum and its rebinned counterpart. |
Source code in lyapower/fitter.py
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 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 | |
compute_kna ¶
compute_kna(minuit, power_l, eps, nloopmax=1000)
Iteratively solve for the non-linear wavenumber k_na from a fit.
Solves the fixed-point equation
k_na = ((2*pi)^2 * k_v^a_v * ln(1+beta) / (q_1 * P_lin(k_na)))^(1/(3+a_v))
by simple fixed-point iteration starting from k_na = 3.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
minuit
|
Minuit
|
Fitted Minuit instance holding values for "a_v", "k_v", "beta", and "q_1". |
required |
power_l
|
MatterPowerSpectrum
|
Linear matter power spectrum used to evaluate P_lin(k_na) via interpolation. |
required |
eps
|
float
|
Convergence tolerance on successive iterates of k_na. |
required |
nloopmax
|
int
|
Maximum number of iterations. Defaults to 1000. |
1000
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
The converged value of k_na. |
Raises:
| Type | Description |
|---|---|
Warning
|
If the iteration does not converge within |
Source code in lyapower/fitter.py
1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 | |
plot_pl ¶
plot_pl(power_l)
Open a new plot and draw the 1D linear matter power spectrum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
power_l
|
MatterPowerSpectrum
|
Linear matter power spectrum to plot. |
required |
Returns:
| Type | Description |
|---|---|
|
None |
Source code in lyapower/fitter.py
1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 | |
plot_pf ¶
plot_pf(power_f, mu_bin, legend)
Open a new plot and draw the 2D flux power spectrum for given mu bins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
power_f
|
FluxPowerSpectrum
|
Flux power spectrum to plot. |
required |
mu_bin
|
list
|
Mu bin indices/values to plot. |
required |
legend
|
bool or list
|
Legend labels/flag forwarded to
|
required |
Returns:
| Type | Description |
|---|---|
|
None |
Source code in lyapower/fitter.py
1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 | |
plot_pf_pm ¶
plot_pf_pm(power_f, power_m, mu_bin, legend)
Plot the flux-to-matter power spectrum ratio for given mu bins.
Rebins power_m onto the flux power spectrum k-grid, divides
power_f's power and error arrays by the rebinned matter power
spectrum (in-place), and plots the resulting ratio.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
power_f
|
FluxPowerSpectrum
|
Flux power spectrum;
its |
required |
power_m
|
MatterPowerSpectrum
|
Matter power spectrum used as the denominator. |
required |
mu_bin
|
list
|
Mu bin indices/values to plot. |
required |
legend
|
bool or list
|
Legend labels/flag forwarded to
|
required |
Returns:
| Type | Description |
|---|---|
|
None |
Source code in lyapower/fitter.py
1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 | |
plot_fit ¶
plot_fit(minuit, power_f, power_l_rebin, non_linear_model, mu_bin, legend, name_out='fit_results', integrate_model=True, N_mu_integration=1000, power_l_no_bao_rebin=None, plot_no_bao_ratio=False, mu_max=1.0, **kwargs)
Plot fitted flux/matter power spectrum ratio against the data and save results.
Rebuilds the model via Pf_model using the best-fit Minuit
parameters, computes the data-to-linear and model-to-linear power
spectrum ratios, plots both (data as points, model as lines) per mu
bin, saves the figure as PDF and PNG, and writes the fit parameters
to a text file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
minuit
|
Minuit
|
Fitted Minuit instance providing best-fit parameter values. |
required |
power_f
|
FluxPowerSpectrum
|
Flux power spectrum data. |
required |
power_l_rebin
|
ndarray
|
Linear power spectrum rebinned onto the flux power spectrum k-grid. |
required |
non_linear_model
|
str or None
|
Non-linear model selector used
to rebuild the model via |
required |
mu_bin
|
list
|
Mu bin indices/values to plot. |
required |
legend
|
bool or list
|
Legend labels/flag forwarded to
|
required |
name_out
|
str
|
Base filename (without extension) for the saved plot and parameter files. Defaults to "fit_results". |
'fit_results'
|
integrate_model
|
bool
|
Whether |
True
|
N_mu_integration
|
int
|
Number of mu sub-samples per bin when integrating. Defaults to 1000. |
1000
|
power_l_no_bao_rebin
|
ndarray or None
|
No-wiggle linear
power spectrum rebinned onto the flux k-grid, used for the
BAO-damped model and/or as the ratio denominator when
|
None
|
plot_no_bao_ratio
|
bool
|
If True, use |
False
|
mu_max
|
float
|
Maximum mu used for bin-width computation. Defaults to 1.0. |
1.0
|
**kwargs
|
Additional keyword arguments forwarded to the
plotting calls ( |
{}
|
Returns:
| Type | Description |
|---|---|
|
None |
Source code in lyapower/fitter.py
1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 | |
minuit_to_latex ¶
minuit_to_latex(minuit, name='')
obsolete
Source code in lyapower/fitter.py
1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 | |