CosmoWAP 0.5.2__tar.gz → 0.6.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. {cosmowap-0.5.2 → cosmowap-0.6.1}/PKG-INFO +15 -13
  2. {cosmowap-0.5.2 → cosmowap-0.6.1}/README.md +13 -11
  3. {cosmowap-0.5.2 → cosmowap-0.6.1}/pyproject.toml +5 -2
  4. cosmowap-0.6.1/src/cosmo_wap/__init__.py +9 -0
  5. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/bk/GR0.py +3 -1
  6. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/bk/GR1.py +2 -0
  7. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/bk/GR2.py +2 -0
  8. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/bk/PNG.py +6 -4
  9. cosmowap-0.6.1/src/cosmo_wap/bk/bk_int.py +393 -0
  10. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/bk/combined.py +8 -3
  11. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/bk/cov.py +2 -2
  12. cosmowap-0.6.1/src/cosmo_wap/bk_mt/GR0.py +38 -0
  13. cosmowap-0.6.1/src/cosmo_wap/bk_mt/GR1.py +28 -0
  14. cosmowap-0.6.1/src/cosmo_wap/bk_mt/GR2.py +28 -0
  15. cosmowap-0.6.1/src/cosmo_wap/bk_mt/PNG.py +115 -0
  16. cosmowap-0.6.1/src/cosmo_wap/bk_mt/__init__.py +20 -0
  17. cosmowap-0.6.1/src/cosmo_wap/forecast/__init__.py +6 -0
  18. cosmowap-0.6.1/src/cosmo_wap/forecast/base_posterior.py +309 -0
  19. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/forecast/core.py +137 -85
  20. cosmowap-0.6.1/src/cosmo_wap/forecast/covariances.py +487 -0
  21. cosmowap-0.6.1/src/cosmo_wap/forecast/fisher.py +249 -0
  22. cosmowap-0.6.1/src/cosmo_wap/forecast/fisher_list.py +104 -0
  23. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/forecast/forecast.py +169 -64
  24. cosmowap-0.6.1/src/cosmo_wap/forecast/sampler.py +467 -0
  25. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/integrated.py +6 -6
  26. cosmowap-0.6.1/src/cosmo_wap/lib/betas.py +82 -0
  27. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/lib/bk_plots.py +1 -1
  28. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/lib/integrate.py +7 -7
  29. cosmowap-0.6.1/src/cosmo_wap/lib/kernels.py +145 -0
  30. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/lib/luminosity_funcs.py +35 -32
  31. cosmowap-0.6.1/src/cosmo_wap/lib/unpack.py +173 -0
  32. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/lib/utils.py +42 -13
  33. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/main.py +122 -210
  34. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/peak_background_bias.py +4 -401
  35. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/pk/IxS_components.py +58 -41
  36. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/pk/PNG.py +3 -3
  37. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/pk/Pk_0.py +10 -10
  38. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/pk/Pk_WS.py +10 -10
  39. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/pk/Pk_WSGR.py +4 -4
  40. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/pk/combined.py +59 -0
  41. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/pk/cov.py +9 -9
  42. cosmowap-0.6.1/src/cosmo_wap/pk/covRR.py +55 -0
  43. cosmowap-0.6.1/src/cosmo_wap/pk/covWS.py +43 -0
  44. cosmowap-0.6.1/src/cosmo_wap/pk/covWSGR.py +55 -0
  45. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/pk/int.py +27 -27
  46. cosmowap-0.6.1/src/cosmo_wap/pk/int_components.py +1124 -0
  47. cosmowap-0.6.1/src/cosmo_wap/pk/pk_int.py +396 -0
  48. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/survey_params.py +41 -69
  49. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmowap.egg-info/PKG-INFO +15 -13
  50. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmowap.egg-info/SOURCES.txt +21 -2
  51. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmowap.egg-info/requires.txt +1 -1
  52. cosmowap-0.6.1/tests/test_bk_multipoles.py +151 -0
  53. cosmowap-0.6.1/tests/test_fisher.py +119 -0
  54. cosmowap-0.6.1/tests/test_forecast.py +154 -0
  55. cosmowap-0.6.1/tests/test_luminosity_funcs.py +102 -0
  56. cosmowap-0.6.1/tests/test_pk_multipoles.py +183 -0
  57. cosmowap-0.6.1/tests/test_survey_params.py +98 -0
  58. cosmowap-0.6.1/tests/test_utils.py +129 -0
  59. cosmowap-0.5.2/src/cosmo_wap/__init__.py +0 -4
  60. cosmowap-0.5.2/src/cosmo_wap/forecast/__init__.py +0 -4
  61. cosmowap-0.5.2/src/cosmo_wap/forecast/covariances.py +0 -235
  62. cosmowap-0.5.2/src/cosmo_wap/forecast/posterior.py +0 -910
  63. cosmowap-0.5.2/src/cosmo_wap/lib/betas.py +0 -158
  64. cosmowap-0.5.2/src/cosmo_wap/pk/covWS.py +0 -68
  65. cosmowap-0.5.2/src/cosmo_wap/pk/covWSGR.py +0 -67
  66. cosmowap-0.5.2/src/cosmo_wap/pk/int_components.py +0 -1124
  67. cosmowap-0.5.2/tests/test-cosmowap.py +0 -952
  68. {cosmowap-0.5.2 → cosmowap-0.6.1}/LICENSE.txt +0 -0
  69. {cosmowap-0.5.2 → cosmowap-0.6.1}/setup.cfg +0 -0
  70. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/bk/GR_0.py +0 -0
  71. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/bk/GR_1.py +0 -0
  72. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/bk/GR_2.py +0 -0
  73. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/bk/PNG_.py +0 -0
  74. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/bk/RR1.py +0 -0
  75. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/bk/RR2.py +0 -0
  76. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/bk/RR_1.py +0 -0
  77. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/bk/WA1.py +0 -0
  78. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/bk/WA2.py +0 -0
  79. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/bk/WARR.py +0 -0
  80. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/bk/WA_1.py +0 -0
  81. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/bk/WA_2.py +0 -0
  82. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/bk/WSGR.py +0 -0
  83. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/bk/__init__.py +0 -0
  84. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/data_library/SKAO1Data.txt +0 -0
  85. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/data_library/SKAO2Data.txt +0 -0
  86. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/data_library/k_modes.txt +0 -0
  87. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/data_library/snr_surveyparams.txt +0 -0
  88. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/forecast/mpi_mcmc.py +0 -0
  89. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/lib/__init__.py +0 -0
  90. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmo_wap/pk/__init__.py +0 -0
  91. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmowap.egg-info/dependency_links.txt +0 -0
  92. {cosmowap-0.5.2 → cosmowap-0.6.1}/src/cosmowap.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cosmowap
3
- Version: 0.5.2
3
+ Version: 0.6.1
4
4
  Summary: package for computing power spectra and bispectra
5
5
  Author-email: Chris Addis <c.l.j.addis@qmul.ac.uk>
6
6
  License: MIT
@@ -12,7 +12,7 @@ Requires-Python: >=3.10
12
12
  Description-Content-Type: text/markdown
13
13
  License-File: LICENSE.txt
14
14
  Requires-Dist: numpy
15
- Requires-Dist: scipy
15
+ Requires-Dist: scipy>=1.15.0
16
16
  Requires-Dist: matplotlib
17
17
  Requires-Dist: tqdm
18
18
  Requires-Dist: cython
@@ -36,13 +36,14 @@ Dynamic: license-file
36
36
  [![Docs](https://img.shields.io/readthedocs/cosmowap/latest?logo=ReadtheDocs)](https://readthedocs.org/projects/cosmowap/builds/)
37
37
  [![Codacy Badge](https://app.codacy.com/project/badge/Grade/fcc0f69852984e01b101fc56d67c43f4)](https://app.codacy.com/gh/craddis1/CosmoWAP/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
38
38
  [![PyPI version](https://img.shields.io/badge/ascl-2507.020-blue.svg?colorB=262255)](https://ascl.net/2507.020)
39
+ [![PyPI Downloads](https://static.pepy.tech/personalized-badge/cosmowap?period=total&units=INTERNATIONAL_SYSTEM&left_color=BLACK&right_color=MAGENTA&left_text=downloads)](https://pepy.tech/projects/cosmowap)
39
40
 
40
- **Cosmo**logy with **W**ide-separation, rel**A**tivistic and **P**rimordial non-Gaussian contibutions.
41
+ **Cosmo**logy with **W**ide-separation, rel**A**tivistic and **P**rimordial non-Gaussian contributions.
41
42
 
42
- CosmoWAP is an effort to provide a (hopefully) self consistent framework to compute contribtuions within standard peturbation theory to the fourier power spectrum and bispectrum including wide-separation and relatvisitic effects as well as Primordial non-Gaussianity (PNG).
43
- These expression can be very cumbersome and it can be tricky to check for consistency in the community and so hopefully this code should be useful in that regard.
43
+ CosmoWAP is an effort to provide a (hopefully) self consistent framework to compute contributions within standard perturbation theory to the Fourier power spectrum and bispectrum including wide-separation and relativistic effects as well as Primordial non-Gaussianity (PNG).
44
+ These expressions can be very cumbersome and it can be tricky to check for consistency in the community and so hopefully this code should be useful in that regard.
44
45
 
45
- CosmoWAP is a *Python* package to analyse the power spectra and bispectra but the analytical expressions themselves are computed analytically in Mathematica using routines which are publicly avalable at [*MathWAP*](https://github.com/craddis1/MathWAP) and then exported as .py files. therefore the main functionality of CosmoWAP is to take these expressions and implement them for a given cosmology (from CLASS) and set of survey parameters.
46
+ CosmoWAP is a *Python* package to analyse the power spectra and bispectra but the analytical expressions themselves are computed analytically in Mathematica using routines which are publicly available at [*MathWAP*](https://github.com/craddis1/MathWAP) and then exported as .py files. Therefore the main functionality of CosmoWAP is to take these expressions and implement them for a given cosmology (from CLASS) and set of survey parameters.
46
47
 
47
48
  ## [*Documentation*](https://cosmowap.readthedocs.io/en/latest/)
48
49
 
@@ -52,7 +53,7 @@ Full documentation is available at [*ReadtheDocs*](https://cosmowap.readthedocs.
52
53
 
53
54
  > [!NOTE]
54
55
  > Note this is still in progress as this is an evolving repo!
55
- > Occassionaly parts will be outdated and will contain deprecated methods.
56
+ > Occasionally parts will be outdated and will contain deprecated methods.
56
57
 
57
58
  ## Installation
58
59
 
@@ -81,28 +82,29 @@ See requirements.txt for full list of dependencies (most are common python libra
81
82
 
82
83
  ## Features
83
84
 
84
- CosmoWAPs aim is to provide self-consistent modelling for the linear bispectrum and power spectrum. It contains redshift space expressions for the 3D Fourier (multipoles and full LOS dependent expressions) *power spectrum* (with multi-tracer capabilites) as well as the *bispectrum* (with Sccoccimarro spherical harmonic multipoles), including terms from:
85
+ CosmoWAPs aim is to provide self-consistent modelling for the linear bispectrum and power spectrum. It contains redshift space expressions for the 3D Fourier (multipoles and full LOS dependent expressions) *power spectrum* (with multi-tracer capabilities) as well as the *bispectrum* (with Sccoccimarro spherical harmonic multipoles), including terms from:
85
86
 
86
87
  - Wide separation (WS) effects (i.e. wide angle and radial redshift contributions) up to second order in the WS expansion
87
88
  - Local Relativistic (GR) effects (including projection and dynamical effects) up to $\left(\frac{\mathcal{H}}{k}\right)^2$
88
- - Integrated Effects (IntInt, IntNPP), (e.g. lensing + ISW...) (power spectrum only currently)
89
- - Primordial non-Gaussian (PNG) contribution for local, equilateral and orthogonal types
89
+ - Integrated Effects, (e.g. lensing + ISW...) (power spectrum only currently)
90
+ - Primordial non-Gaussian (PNG) contribution for local, equilateral and orthogonal types
90
91
 
91
92
  It also has a fully integrated forecasting and plotting library that allows these expressions to be explored.
92
93
 
93
94
  ### additional features
94
95
 
95
96
  - Bias modelling through Luminosity functions and HOD/HMF
96
- - Gaussian multipole covariances (Multi-tracer power spectrum)
97
+ - Multi-tracer multipole covariances (assuming gaussianity)
97
98
  - Finger-of-God damping and non-linear corrections
98
99
  - TriPOSH bispectrum expansion terms (Coming soon)
99
100
 
100
101
  ## Usage
101
102
  Base code based on work in [arXiv:2407.00168](https://arxiv.org/abs/2407.00168)
102
103
 
103
- For PNG and Forecasting routines related please also refer too: arXiv:25xx.xxxx
104
+ For Integrated effects see: [arXiv:2511.09466](https://arxiv.org/abs/2511.09466)
105
+
106
+ For PNG and Forecasting routines related please also refer to: arXiv:25xx.xxxx
104
107
 
105
- For Integrated effects see: arXiv:25xx.xxxx
106
108
 
107
109
 
108
110
  ## Contact
@@ -13,13 +13,14 @@
13
13
  [![Docs](https://img.shields.io/readthedocs/cosmowap/latest?logo=ReadtheDocs)](https://readthedocs.org/projects/cosmowap/builds/)
14
14
  [![Codacy Badge](https://app.codacy.com/project/badge/Grade/fcc0f69852984e01b101fc56d67c43f4)](https://app.codacy.com/gh/craddis1/CosmoWAP/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
15
15
  [![PyPI version](https://img.shields.io/badge/ascl-2507.020-blue.svg?colorB=262255)](https://ascl.net/2507.020)
16
+ [![PyPI Downloads](https://static.pepy.tech/personalized-badge/cosmowap?period=total&units=INTERNATIONAL_SYSTEM&left_color=BLACK&right_color=MAGENTA&left_text=downloads)](https://pepy.tech/projects/cosmowap)
16
17
 
17
- **Cosmo**logy with **W**ide-separation, rel**A**tivistic and **P**rimordial non-Gaussian contibutions.
18
+ **Cosmo**logy with **W**ide-separation, rel**A**tivistic and **P**rimordial non-Gaussian contributions.
18
19
 
19
- CosmoWAP is an effort to provide a (hopefully) self consistent framework to compute contribtuions within standard peturbation theory to the fourier power spectrum and bispectrum including wide-separation and relatvisitic effects as well as Primordial non-Gaussianity (PNG).
20
- These expression can be very cumbersome and it can be tricky to check for consistency in the community and so hopefully this code should be useful in that regard.
20
+ CosmoWAP is an effort to provide a (hopefully) self consistent framework to compute contributions within standard perturbation theory to the Fourier power spectrum and bispectrum including wide-separation and relativistic effects as well as Primordial non-Gaussianity (PNG).
21
+ These expressions can be very cumbersome and it can be tricky to check for consistency in the community and so hopefully this code should be useful in that regard.
21
22
 
22
- CosmoWAP is a *Python* package to analyse the power spectra and bispectra but the analytical expressions themselves are computed analytically in Mathematica using routines which are publicly avalable at [*MathWAP*](https://github.com/craddis1/MathWAP) and then exported as .py files. therefore the main functionality of CosmoWAP is to take these expressions and implement them for a given cosmology (from CLASS) and set of survey parameters.
23
+ CosmoWAP is a *Python* package to analyse the power spectra and bispectra but the analytical expressions themselves are computed analytically in Mathematica using routines which are publicly available at [*MathWAP*](https://github.com/craddis1/MathWAP) and then exported as .py files. Therefore the main functionality of CosmoWAP is to take these expressions and implement them for a given cosmology (from CLASS) and set of survey parameters.
23
24
 
24
25
  ## [*Documentation*](https://cosmowap.readthedocs.io/en/latest/)
25
26
 
@@ -29,7 +30,7 @@ Full documentation is available at [*ReadtheDocs*](https://cosmowap.readthedocs.
29
30
 
30
31
  > [!NOTE]
31
32
  > Note this is still in progress as this is an evolving repo!
32
- > Occassionaly parts will be outdated and will contain deprecated methods.
33
+ > Occasionally parts will be outdated and will contain deprecated methods.
33
34
 
34
35
  ## Installation
35
36
 
@@ -58,28 +59,29 @@ See requirements.txt for full list of dependencies (most are common python libra
58
59
 
59
60
  ## Features
60
61
 
61
- CosmoWAPs aim is to provide self-consistent modelling for the linear bispectrum and power spectrum. It contains redshift space expressions for the 3D Fourier (multipoles and full LOS dependent expressions) *power spectrum* (with multi-tracer capabilites) as well as the *bispectrum* (with Sccoccimarro spherical harmonic multipoles), including terms from:
62
+ CosmoWAPs aim is to provide self-consistent modelling for the linear bispectrum and power spectrum. It contains redshift space expressions for the 3D Fourier (multipoles and full LOS dependent expressions) *power spectrum* (with multi-tracer capabilities) as well as the *bispectrum* (with Sccoccimarro spherical harmonic multipoles), including terms from:
62
63
 
63
64
  - Wide separation (WS) effects (i.e. wide angle and radial redshift contributions) up to second order in the WS expansion
64
65
  - Local Relativistic (GR) effects (including projection and dynamical effects) up to $\left(\frac{\mathcal{H}}{k}\right)^2$
65
- - Integrated Effects (IntInt, IntNPP), (e.g. lensing + ISW...) (power spectrum only currently)
66
- - Primordial non-Gaussian (PNG) contribution for local, equilateral and orthogonal types
66
+ - Integrated Effects, (e.g. lensing + ISW...) (power spectrum only currently)
67
+ - Primordial non-Gaussian (PNG) contribution for local, equilateral and orthogonal types
67
68
 
68
69
  It also has a fully integrated forecasting and plotting library that allows these expressions to be explored.
69
70
 
70
71
  ### additional features
71
72
 
72
73
  - Bias modelling through Luminosity functions and HOD/HMF
73
- - Gaussian multipole covariances (Multi-tracer power spectrum)
74
+ - Multi-tracer multipole covariances (assuming gaussianity)
74
75
  - Finger-of-God damping and non-linear corrections
75
76
  - TriPOSH bispectrum expansion terms (Coming soon)
76
77
 
77
78
  ## Usage
78
79
  Base code based on work in [arXiv:2407.00168](https://arxiv.org/abs/2407.00168)
79
80
 
80
- For PNG and Forecasting routines related please also refer too: arXiv:25xx.xxxx
81
+ For Integrated effects see: [arXiv:2511.09466](https://arxiv.org/abs/2511.09466)
82
+
83
+ For PNG and Forecasting routines related please also refer to: arXiv:25xx.xxxx
81
84
 
82
- For Integrated effects see: arXiv:25xx.xxxx
83
85
 
84
86
 
85
87
  ## Contact
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "cosmowap"
7
- version = "0.5.2"
7
+ version = "0.6.1"
8
8
  authors = [
9
9
  { name="Chris Addis", email="c.l.j.addis@qmul.ac.uk" },
10
10
  ]
@@ -20,7 +20,7 @@ classifiers = [
20
20
  # List of dependencies required for the project to run
21
21
  dependencies = [
22
22
  "numpy",
23
- "scipy",
23
+ "scipy >= 1.15.0",
24
24
  "matplotlib",
25
25
  "tqdm",
26
26
  "cython",
@@ -41,3 +41,6 @@ include-package-data = true
41
41
 
42
42
  [tool.setuptools.packages.find]
43
43
  where = ["src"]
44
+
45
+ [tool.pytest.ini_options]
46
+ testpaths = ["tests"]
@@ -0,0 +1,9 @@
1
+ from importlib.metadata import version
2
+
3
+ from .main import ClassWAP
4
+ from .peak_background_bias import PBBias
5
+ from .survey_params import SurveyParams, SetSurveyFunctions
6
+ from . import forecast, lib, integrated
7
+
8
+ __version__ = version("cosmowap")
9
+ __all__ = ['ClassWAP', 'PBBias', 'SurveyParams', 'SetSurveyFunctions', 'forecast', 'lib', 'integrated']
@@ -2,8 +2,10 @@ import numpy as np
2
2
  from numpy import cos
3
3
  import cosmo_wap.bk as bk
4
4
  import cosmo_wap
5
+ from cosmo_wap.lib.utils import add_empty_methods_bk
5
6
 
6
7
  #Netwonian, plane parallel constant redshift limit
8
+ @add_empty_methods_bk('l1','l3')
7
9
  class NPP:
8
10
  @staticmethod
9
11
  def ylm(l,m,cosmo_funcs,k1,k2,k3=None,theta=None,zz=0,r=0,s=0,sigma=None):
@@ -11,7 +13,7 @@ class NPP:
11
13
 
12
14
  @staticmethod
13
15
  def l0(cosmo_funcs,k1,k2,k3=None,theta=None,zz=0,r=0,s=0):
14
-
16
+
15
17
  #get generic cosmology parameters
16
18
  k1,k2,k3,theta,Pk1,Pk2,Pk3,_,_,_,_,_,_,_,K,C,f,D1,b1,b2,g2 = cosmo_funcs.get_params(k1,k2,k3,theta,zz)
17
19
 
@@ -2,7 +2,9 @@ import numpy as np
2
2
  import cosmo_wap.bk as bk
3
3
  from cosmo_wap.lib.integrate import ylm
4
4
  from numpy import cos, sin
5
+ from cosmo_wap.lib.utils import add_empty_methods_bk
5
6
 
7
+ @add_empty_methods_bk('l0','l2','l4')
6
8
  class GR1:
7
9
  # for mu phi expression
8
10
  def ylm(l,m,cosmo_funcs,k1,k2,k3=None,theta=None,zz=0,r=0,s=0,sigma=None):
@@ -2,7 +2,9 @@ import numpy as np
2
2
  import cosmo_wap.bk as bk
3
3
  from cosmo_wap.lib.integrate import ylm
4
4
  from numpy import cos, sin
5
+ from cosmo_wap.lib.utils import add_empty_methods_bk
5
6
 
7
+ @add_empty_methods_bk('l1','l3')
6
8
  class GR2:
7
9
  # for mu phi expression
8
10
  def ylm(l,m,cosmo_funcs,k1,k2,k3=None,theta=None,zz=0,r=0,s=0,sigma=None):
@@ -1,7 +1,9 @@
1
1
  import numpy as np
2
2
  import cosmo_wap.bk as bk
3
3
  from cosmo_wap.lib.integrate import ylm
4
+ from cosmo_wap.lib.utils import add_empty_methods_bk
4
5
 
6
+ @add_empty_methods_bk('l1','l3')
5
7
  class Loc:
6
8
  def ylm(l,m,cosmo_funcs,k1,k2,k3=None,theta=None,zz=0,r=0,s=0,sigma=None):
7
9
  return ylm(bk.Loc_,l,m,cosmo_funcs,k1,k2,k3=k3,theta=theta,zz=zz,r=r,s=s,sigma=sigma)
@@ -38,7 +40,7 @@ class Loc:
38
40
 
39
41
  return tmp_expr
40
42
 
41
-
43
+ @add_empty_methods_bk('l1','l3')
42
44
  class Eq:
43
45
  def ylm(l,m,cosmo_funcs,k1,k2,k3=None,theta=None,zz=0,r=0,s=0,sigma=None):
44
46
  return ylm(bk.Eq_,l,m,cosmo_funcs,k1,k2,k3=k3,theta=theta,zz=zz,r=r,s=s,sigma=sigma)
@@ -66,7 +68,7 @@ class Eq:
66
68
  #get generic cosmology parameters
67
69
  k1,k2,k3,theta,Pk1,Pk2,Pk3,_,_,_,_,_,_,_,K,C,f,D1,b1,b2,g2 = cosmo_funcs.get_params(k1,k2,k3,theta,zz)
68
70
 
69
- b01,b11,Mk1,Mk2,Mk3 = cosmo_funcs.get_PNGparams(zz,k1,k2,k3, shape='Loc')
71
+ b01,b11,Mk1,Mk2,Mk3 = cosmo_funcs.get_PNGparams(zz,k1,k2,k3, shape='Eq')
70
72
 
71
73
  st = np.sin(theta)
72
74
  ct = np.cos(theta)
@@ -75,7 +77,7 @@ class Eq:
75
77
 
76
78
  return tmp_expr
77
79
 
78
-
80
+ @add_empty_methods_bk('l1','l3')
79
81
  class Orth:
80
82
  def ylm(l,m,cosmo_funcs,k1,k2,k3=None,theta=None,zz=0,r=0,s=0,sigma=None):
81
83
  return ylm(bk.Orth_,l,m,cosmo_funcs,k1,k2,k3=k3,theta=theta,zz=zz,r=r,s=s,sigma=sigma)
@@ -103,7 +105,7 @@ class Orth:
103
105
  #get generic cosmology parameters
104
106
  k1,k2,k3,theta,Pk1,Pk2,Pk3,_,_,_,_,_,_,_,K,C,f,D1,b1,b2,g2 = cosmo_funcs.get_params(k1,k2,k3,theta,zz)
105
107
 
106
- b01,b11,Mk1,Mk2,Mk3 = cosmo_funcs.get_PNGparams(zz,k1,k2,k3, shape='Loc')
108
+ b01,b11,Mk1,Mk2,Mk3 = cosmo_funcs.get_PNGparams(zz,k1,k2,k3, shape='Orth')
107
109
 
108
110
  st = np.sin(theta)
109
111
  ct = np.cos(theta)
@@ -0,0 +1,393 @@
1
+ import numpy as np
2
+ from cosmo_wap.integrated import BaseInt
3
+ from cosmo_wap.lib import utils
4
+
5
+ from cosmo_wap.lib.kernels import K1
6
+ from scipy.interpolate import CubicSpline
7
+ import scipy
8
+ from scipy.special import factorial
9
+
10
+ def compute_robust_integral(d, p_arr, r_data, z_data,deg=5):
11
+ """
12
+ Computes the integral I(p) = d * ∫₀¹ exp(i*p*d*u) * Z(u) du robustly
13
+ for complex Z(r), large d values, and wide ranges of p.
14
+
15
+ Uses normalized domain u = r/d and automatically switches between
16
+ Taylor series (small |p*d|) and analytic recurrence (large |p*d|) methods.
17
+
18
+ Args:
19
+ d: Characteristic length scale
20
+ p_arr: Array of p values to evaluate (can include negative values)
21
+ r_data: Radial coordinate data
22
+ z_data_complex: Complex function values Z(r)
23
+
24
+ Returns:
25
+ I_total: Complex array of integral values
26
+ coeffs_u: Complex polynomial coefficients of Z(u)
27
+ """
28
+ # Normalize radial coordinate to prevent numerical overflow
29
+ # Map r → u where u ∈ [0, 1], avoiding large powers like (3000)^5
30
+ u_data = r_data / d
31
+
32
+ # Fit Z(u) as a complex polynomial: Z(u) = Σ c_j * u^j
33
+ # NumPy handles complex coefficients automatically
34
+ coeffs_u = np.polyfit(u_data, z_data, deg=deg)
35
+ n = len(coeffs_u) - 1
36
+
37
+ # Define dimensionless parameter φ = p * d
38
+ # This controls which integration method to use
39
+ phi = p_arr * d
40
+
41
+ # Initialize result array
42
+ I_total = np.zeros_like(p_arr, dtype=complex)
43
+
44
+ # Choose method based on |φ| magnitude:
45
+ # Small |φ|: Taylor series converges rapidly and avoids division by zero
46
+ # Large |φ|: Recurrence relation is stable
47
+ mask_taylor = np.abs(phi) < 0.5
48
+ mask_recurrence = ~mask_taylor
49
+
50
+ # TAYLOR SERIES METHOD (for |φ| < 0.5)
51
+ # Expand exp(i*φ*u) = Σ (i*φ)^k / k! * u^k
52
+ if np.any(mask_taylor):
53
+ phi_small = phi[mask_taylor]
54
+ res_taylor = np.zeros_like(phi_small, dtype=complex)
55
+
56
+ n_taylor = 15 # Terms needed for machine precision
57
+
58
+ for k in range(n_taylor):
59
+ # Exponential expansion coefficient
60
+ exp_term = (1j * phi_small)**k / factorial(k)
61
+
62
+ # Integrate polynomial term-by-term
63
+ # For each coefficient c_j with power (n-j), compute:
64
+ # ∫₀¹ c_j * u^(n-j+k) du = c_j / (n-j+k+1)
65
+ poly_int_val = 0j # Initialize as complex
66
+ for j, c_val in enumerate(coeffs_u):
67
+ pow_u = n - j
68
+ poly_int_val += c_val / (pow_u + k + 1)
69
+
70
+ res_taylor += exp_term * poly_int_val
71
+
72
+ I_total[mask_taylor] = res_taylor * d
73
+
74
+ # ANALYTIC RECURRENCE METHOD (for |φ| ≥ 0.5)
75
+ # Use recurrence: F_k = exp(i*φ)/φ - k*F_{k-1}/φ
76
+ if np.any(mask_recurrence):
77
+ phi_large = phi[mask_recurrence]
78
+
79
+ # Base case: F_0 = ∫₀¹ exp(i*φ*u) du
80
+ ip = 1j * phi_large
81
+ exp_ip = np.exp(ip)
82
+ F_current = (exp_ip - 1.0) / ip
83
+
84
+ # Start accumulation with constant term (coeffs_u[-1] is c_0)
85
+ recurrence_res = coeffs_u[-1] * F_current
86
+
87
+ # Apply recurrence for powers k = 1 to n
88
+ for k in range(1, n + 1):
89
+ # Compute F_k = ∫₀¹ u^k * exp(i*φ*u) du
90
+ F_next = exp_ip / ip - (k / ip) * F_current
91
+
92
+ # Add contribution from coefficient c_k
93
+ c_k = coeffs_u[-(k + 1)]
94
+ recurrence_res += c_k * F_next
95
+ F_current = F_next
96
+
97
+ I_total[mask_recurrence] = recurrence_res * d
98
+
99
+ return I_total, coeffs_u
100
+
101
+ def filon_integrate(u, kk, mu, integrand, d):
102
+ """
103
+ Computes int f(u, k, mu) * e^{i * d * k * mu * u} du
104
+ Result has shape (N_k, N_mu)
105
+ """
106
+
107
+ # 2. Compute Frequency Omega (w)
108
+ # w = d * k * mu
109
+ # Shape becomes (N_k, N_mu, 1)
110
+ # Let's calculate w directly from the phase term logic.
111
+ w = d * kk * mu
112
+
113
+ w[w == 0] = 1e-15
114
+
115
+ # 3. Compute Intervals (du) along the last axis
116
+ # du shape: (N_u - 1)
117
+ du = np.diff(u, axis=-1)
118
+
119
+ # Left and Right u-points
120
+ ul = u[:-1]
121
+ ur = u[1:]
122
+
123
+ # 4. Compute Exact Exponentials
124
+ # Shape: (N_k, N_mu, N_u - 1)
125
+ inv_iw = 1.0 / (1j * w)
126
+ E_left = np.exp(1j * w * ul)
127
+ E_right = np.exp(1j * w * ur)
128
+
129
+ # Filon Weights (Standard formulas, just propagated in 3D)
130
+ v0 = (E_right - E_left) * inv_iw
131
+ v1 = (du * E_right * inv_iw) - (v0 * inv_iw)
132
+
133
+ W_right = v1 / du
134
+ W_left = v0 - W_right
135
+
136
+ # 6. Apply Weights to Integrand
137
+ # integrand shape must be (N_k, N_mu, N_u)
138
+ f_left = integrand[:, :, :-1]
139
+ f_right = integrand[:, :, 1:]
140
+
141
+ segments = (W_left * f_left) + (W_right * f_right)
142
+
143
+ # 7. Sum over the last axis (u)
144
+ # Result shape: (N_k, N_mu)
145
+ return np.sum(segments, axis=-1)
146
+
147
+ def get_int_r3(kernel,cosmo_funcs,zz,deg=8,n_p=5000):
148
+ """Get values - dont interpolate as very oscillatory - so just call as is very quick"""
149
+ p_arr = np.concatenate((-np.logspace(-6,4,n_p)[::-1],np.logspace(-6,4,n_p)))
150
+ d = cosmo_funcs.comoving_dist(zz)
151
+ r1 = np.linspace(1e-3,d,1000)
152
+
153
+ arr_dict = {}
154
+ for kern in kernel:
155
+ func = getattr(K1,kern)
156
+
157
+ tmp_dict = func(r1,cosmo_funcs,zz=zz,tracer=2)
158
+
159
+ # loop over dict to merge them
160
+ for i in tmp_dict.keys():
161
+ if i in arr_dict:
162
+ for j in tmp_dict[i].keys():
163
+ if j in arr_dict[i]:
164
+ arr_dict[i][j] = arr_dict[i][j] + tmp_dict[i][j] # Element-wise addition
165
+ else:
166
+ arr_dict[i][j] = tmp_dict[i][j]
167
+ else:
168
+ arr_dict[i] = tmp_dict[i].copy()
169
+
170
+ # now get interpolated function in p for all kernels
171
+ for i in arr_dict.keys():
172
+ for j in arr_dict[i].keys():
173
+ I_arr, _ = compute_robust_integral(d, -p_arr, r1, arr_dict[i][j],deg=deg)
174
+ arr_dict[i][j] = [CubicSpline(p_arr,I_arr.real),CubicSpline(p_arr,I_arr.imag)]
175
+
176
+ return arr_dict
177
+
178
+ def get_int_K2(kernel,r2,cosmo_funcs,zz,mu,kk):
179
+ """Get kernel 2 array"""
180
+ d = cosmo_funcs.comoving_dist(zz)
181
+ mu, kk = utils.enable_broadcasting(mu,kk,n=1)
182
+
183
+ G = r2/d
184
+ qq = kk/G
185
+ k2_arr = np.zeros((kk.shape[0],mu.shape[0],r2.shape[0]),dtype=np.complex128)
186
+
187
+ for kern in kernel:
188
+ func = getattr(K1,kern)
189
+ k2_arr += func(r2,cosmo_funcs,zz,-mu,qq,tracer=1)
190
+
191
+ return k2_arr
192
+
193
+ def I1_sum(arr_dict,r2_arr,mu,kk,cosmo_funcs,zz,n=128,I2=False):
194
+
195
+ baseint = BaseInt(cosmo_funcs)
196
+ d = cosmo_funcs.comoving_dist(zz)
197
+ if I2: # II
198
+ nodes, weights = np.polynomial.legendre.leggauss(n)#legendre gauss - get nodes and weights for given
199
+ r2 = (d)*(nodes+1)/2.0 # sample r range [0,d]
200
+ mu, kk = utils.enable_broadcasting(mu,kk,n=1)
201
+ G = r2/d
202
+ qq = kk/G
203
+ else:
204
+ #only IS
205
+ qq=kk
206
+
207
+ #arr_dict = get_int_r1(qq*mu,int_k1,cosmo_funcs,zz,deg=8)
208
+
209
+ tot_arr = np.zeros((len(kk),len(mu)),dtype=np.complex128) # shape (mu,kk)
210
+ for i in arr_dict.keys():
211
+ for j in arr_dict[i].keys():
212
+ coef = qq**j * mu**i # this is the mu from first order field
213
+
214
+ r1_arr = arr_dict[i][j][0](qq*mu) + 1j*arr_dict[i][j][1](qq*mu) # get complex array
215
+
216
+ tmp_arr = np.exp(-1j *kk*mu*d)*coef*r2_arr*r1_arr
217
+ if I2:
218
+ tot_arr += ((d) / 2.0) *np.sum(G**(-3)* baseint.pk(qq,zz)*weights *tmp_arr,axis=-1)
219
+ else:
220
+ tot_arr += baseint.pk(qq,zz)*tmp_arr
221
+
222
+ return tot_arr
223
+
224
+ def s1_sum(s_k1,r2_arr,mu,kk,cosmo_funcs,zz,n=128,I2=False):
225
+ """Now for case where S if first field"""
226
+ baseint = BaseInt(cosmo_funcs)
227
+ if I2: # SI
228
+ #so this integral can be a little oscillatory near the source - we use filon integration
229
+ d = cosmo_funcs.comoving_dist(zz)
230
+
231
+ nodes, _ = np.polynomial.legendre.leggauss(n)#legendre gauss - get nodes and weights for given
232
+ r2 = (d)*(nodes+1)/2.0 # sample r range [0,d]
233
+
234
+ # u = d / r = 1 / G
235
+ u = d / r2 # Note: u_grid now goes from 1.0 to (d/r_min)
236
+
237
+ # Jacobian from Eq 31 transformation: J = d * u
238
+ # (Recall: dr = -d/u^2 du, and G^-3 = u^3, so net is d*u)
239
+ Jac = d * u
240
+
241
+ #r2_arr = get_int_K2(int_k2,r2,cosmo_funcs,zz,mu,kk)
242
+ mu, kk = utils.enable_broadcasting(mu,kk,n=1)
243
+ qq = kk * u
244
+
245
+ # Full Integrand
246
+ s1_arr = get_K(s_k1,cosmo_funcs,zz,mu,qq,tracer=0)
247
+ integrand = Jac * baseint.pk(qq,zz)* r2_arr * s1_arr
248
+
249
+ # u_grid is now strictly increasing, so Filon works perfectly.
250
+ tot_arr = np.exp(-1j *kk[...,0]*mu[...,0]*d)*filon_integrate(u[::-1], kk, mu, integrand[...,::-1], d)
251
+
252
+ else:
253
+ #only SS
254
+ s1_arr = get_K(s_k1,cosmo_funcs,zz,mu,kk,tracer=0)
255
+ tot_arr = baseint.pk(kk,zz)*r2_arr*s1_arr
256
+
257
+ return tot_arr
258
+
259
+ def split_kernels(kernels):
260
+ """Seperate integrated and normal kernels"""
261
+ int_kernels = set(['I','L','TD','ISW','L1']) # these are the integrated kernels - will need updating if add more
262
+ if not isinstance(kernels, list):
263
+ kernels = [kernels]
264
+ return [s for s in kernels if s in int_kernels],[s for s in kernels if s not in int_kernels]
265
+
266
+ def get_K(kernels,cosmo_funcs,zz,mu,kk,tracer=0):
267
+ tot_arr = np.zeros((kk*mu).shape,dtype=np.complex128)
268
+ for kern in kernels:
269
+ func = getattr(K1,kern)
270
+ print(func(cosmo_funcs,zz,mu,kk,tracer=tracer).shape)
271
+ tot_arr += func(cosmo_funcs,zz,mu,kk,tracer=tracer)
272
+ return tot_arr
273
+
274
+ def sss_perm(Ks1,Ks2,Ks3,pks):
275
+ tot_arr = np.zeros((Ks1*Ks2*Ks3).shape,dtype=np.complex128)
276
+ for i in range(3):
277
+ tot_arr += Ks1[0]*Ks2[1]*Ks3[2]*pks[0]*pks[1]
278
+ return tot_arr
279
+
280
+ def get_K2(cosmo_funcs,kern_list,k1,k2,mu,mu2,mu3,tracer=0):
281
+ tot_arr = np.zeros((k1*k2*k3).shape,dtype=np.complex128)
282
+ for kern in kern_list:
283
+ func = getattr(K1,kern)
284
+ tot_arr += func(cosmo_funcs,zz,mu,phi,k1,k2,k3,tracer=tracer)
285
+
286
+ return 1
287
+
288
+ def get_full(mu,phi,kernels1,kernels2,kernels3,cosmo_funcs,k1,k2,k3=None,theta=None,zz=0,n=16,deg=8):
289
+ """Collect full mu, phi dependent bispectrum, d=x_3
290
+ So kernels1 and kernels 2 refer to linear first order ones
291
+ and kernels3 refers to second order kernels"""
292
+
293
+ #d = cosmo_funcs.comoving_dist(zz)
294
+ #nodes, _ = np.polynomial.legendre.leggauss(n)#legendre gauss - get nodes and weights for given
295
+ #rr = (d)*(nodes+1)/2.0 # sample r range [0,d]
296
+
297
+ # lets define some bispectrum stuff
298
+ theta = utils.get_theta(k1,k2,k3)
299
+ mu2 = mu*np.cos(theta)-np.sqrt(1-mu**2)*np.sin(theta)*np.cos(phi)
300
+ mu3 = -(k1/k3)*mu-(k2/k3)*mu2
301
+
302
+ mus = [mu,mu2,mu3]
303
+ ks = [k1,k2,k3]
304
+ # lets split kernels into integrated and not!
305
+ int_k1,s_k1 = split_kernels(kernels1)
306
+ int_k2,s_k2 = split_kernels(kernels2)
307
+ int_k3,s_k3 = split_kernels(kernels3)
308
+
309
+ # so get linear kernels
310
+ Ks1 = []
311
+ for i in range(3):
312
+ Ks1.append(get_K(s_k1,cosmo_funcs,zz,mus[i],ks[i],tracer=0))
313
+
314
+ Ks2 = []
315
+ for i in range(3):
316
+ Ks2.append(get_K(s_k2,cosmo_funcs,zz,mus[i],ks[i],tracer=0))
317
+
318
+ pks = []
319
+ for i in range(3):
320
+ pks.append(cosmo_funcs.pk(ks[i]))
321
+
322
+ # precompute ------------------------------------------------------------------------
323
+ if int_k3:
324
+ arr_dict = get_int_r3(int_k3,cosmo_funcs,zz,deg=deg) # is dict
325
+ if int_k2:
326
+ arr_dict2 = 1
327
+
328
+ if s_k2:
329
+ s2_arr = get_K(s_k2,cosmo_funcs,zz,-mu,kk,tracer=1)
330
+
331
+ if s_k2:
332
+ s2_arr = get_K(s_k2,cosmo_funcs,zz,-mu,kk,tracer=1)
333
+ if int_k1:
334
+ arr_dict = get_int_K1(int_k1,cosmo_funcs,zz,deg=deg) # is dict
335
+ if int_k2:
336
+ r2_arr = get_int_K2(int_k2,r2,cosmo_funcs,zz,mu,kk) # is array
337
+
338
+ tot_arr = np.zeros(((k1*k2*k3).shape,mu.shape[0],phi.shape[0]),dtype=np.complex128) # shape (mu,phi,k1,k2,k3)
339
+
340
+ """
341
+ if int_k3:
342
+ if int_k1:
343
+ if int_k2:
344
+ tot_arr +=
345
+
346
+ """
347
+
348
+
349
+
350
+
351
+ # sum stuff --------------------------------------------------------------------------
352
+ tot_arr = np.zeros((kk.shape[0],mu.shape[0]),dtype=np.complex128) # shape (mu,kk)
353
+ if int_k1:
354
+ if int_k2: #II
355
+ tot_arr += I1_sum(arr_dict,r2_arr,mu,kk,cosmo_funcs,zz,n=n,I2=True)
356
+ if s_k2: #IS
357
+ tot_arr += I1_sum(arr_dict,s2_arr,mu,kk,cosmo_funcs,zz,I2=False)
358
+
359
+ if s_k1:
360
+ if int_k2: #SI
361
+ tot_arr += s1_sum(s_k1,r2_arr,mu,kk,cosmo_funcs,zz,n=n,I2=True)
362
+ if s_k2: # SS
363
+ tot_arr += s1_sum(s_k1,s2_arr,mu,kk,cosmo_funcs,zz,I2=False)
364
+
365
+ return tot_arr
366
+
367
+ def get_multipole(kernel1,kernel2,l,cosmo_funcs,kk,zz,sigma=None,n=32,n_mu=256,deg=8,delta=0.1,GL=False):
368
+ if GL:
369
+ mu, weights = np.polynomial.legendre.leggauss(n_mu)#legendre gauss - get nodes and weights for given n
370
+ else:
371
+ N_fine = n_mu//2 # High density for the central region
372
+ N_coarse = n_mu//4 # Low density for the wings
373
+
374
+ # 1. Generate Non-Uniform Grid (Vectorized)
375
+ mu = np.unique(np.concatenate([
376
+ np.linspace(-1, -delta, N_coarse),
377
+ np.linspace(-delta, delta, N_fine),
378
+ np.linspace(delta, 1, N_coarse)
379
+ ]))
380
+
381
+ arr = get_mu(mu,kernel1,kernel2,cosmo_funcs,kk,zz,n=n,deg=deg)
382
+
383
+ # get legendre
384
+ leg = scipy.special.eval_legendre(l,mu)
385
+
386
+ if sigma is None: #no FOG
387
+ dfog_val = 1
388
+ else:
389
+ dfog_val = np.exp(-(1/2)*((kk*mu)**2)*sigma**2) # exponential damping
390
+
391
+ if GL:
392
+ return ((2*l+1)/2)*np.sum(weights*leg*dfog_val*arr,axis=-1)
393
+ return ((2*l+1)/2)*utils.trapezoid(leg*dfog_val*arr,x=mu,axis=-1)