pybinny 2.0.0__tar.gz → 2.1.0__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 (147) hide show
  1. {pybinny-2.0.0/src/pybinny.egg-info → pybinny-2.1.0}/PKG-INFO +2 -8
  2. {pybinny-2.0.0 → pybinny-2.1.0}/pyproject.toml +3 -11
  3. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/nz/luminosity_function_distribution.py +21 -39
  4. {pybinny-2.0.0 → pybinny-2.1.0/src/pybinny.egg-info}/PKG-INFO +2 -8
  5. {pybinny-2.0.0 → pybinny-2.1.0}/src/pybinny.egg-info/requires.txt +1 -9
  6. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_nz_luminosity_function_distribution.py +89 -135
  7. {pybinny-2.0.0 → pybinny-2.1.0}/LICENSE +0 -0
  8. {pybinny-2.0.0 → pybinny-2.1.0}/README.md +0 -0
  9. {pybinny-2.0.0 → pybinny-2.1.0}/setup.cfg +0 -0
  10. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/__init__.py +0 -0
  11. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/analysis/__init__.py +0 -0
  12. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/analysis/combinations.py +0 -0
  13. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/analysis/comparison.py +0 -0
  14. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/analysis/composition.py +0 -0
  15. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/analysis/stats.py +0 -0
  16. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/axes/__init__.py +0 -0
  17. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/axes/bin_edges.py +0 -0
  18. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/axes/grids.py +0 -0
  19. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/axes/mixed_edges.py +0 -0
  20. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/binning/__init__.py +0 -0
  21. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/binning/assignments.py +0 -0
  22. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/binning/core.py +0 -0
  23. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/binning/edges.py +0 -0
  24. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/binning/photoz.py +0 -0
  25. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/binning/scheme_registry.py +0 -0
  26. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/binning/specs.py +0 -0
  27. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/binning/specz.py +0 -0
  28. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/calibration/__init__.py +0 -0
  29. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/calibration/depth.py +0 -0
  30. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/calibration/photoz_fitting.py +0 -0
  31. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/calibration/psf_selection.py +0 -0
  32. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/correlations/__init__.py +0 -0
  33. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/correlations/bin_combo_filter.py +0 -0
  34. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/correlations/filters.py +0 -0
  35. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/correlations/metrics.py +0 -0
  36. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/correlations/scores.py +0 -0
  37. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/correlations/topology.py +0 -0
  38. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/cosmology/__init__.py +0 -0
  39. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/cosmology/ccl_wrappers.py +0 -0
  40. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/nz/__init__.py +0 -0
  41. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/nz/models.py +0 -0
  42. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/nz/registry.py +0 -0
  43. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/nz/sampling.py +0 -0
  44. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/style/__init__.py +0 -0
  45. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/style/colors.py +0 -0
  46. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/surveys/__init__.py +0 -0
  47. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/surveys/config_utils.py +0 -0
  48. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/surveys/configs/__init__.py +0 -0
  49. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/surveys/configs/des_survey_specs.yaml +0 -0
  50. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/surveys/configs/desi_survey_specs.yaml +0 -0
  51. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/surveys/configs/euclid_survey_specs.yaml +0 -0
  52. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/surveys/configs/example_full_photoz.yaml +0 -0
  53. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/surveys/configs/example_full_specz.yaml +0 -0
  54. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/surveys/configs/example_generalized_photoz.yaml +0 -0
  55. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/surveys/configs/example_minimal_photoz.yaml +0 -0
  56. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/surveys/configs/example_minimal_specz.yaml +0 -0
  57. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/surveys/configs/example_tabulated.yaml +0 -0
  58. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/surveys/configs/lsst_survey_specs.yaml +0 -0
  59. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/surveys/configs/mock_predefined_config.yaml +0 -0
  60. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/surveys/configs/roman_survey_specs.yaml +0 -0
  61. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/surveys/data/__init__.py +0 -0
  62. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/surveys/data/desi_bgs_sgc_nz.txt +0 -0
  63. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/surveys/data/desi_elg_nz.txt +0 -0
  64. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/surveys/data/desi_lrg_nz.txt +0 -0
  65. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/surveys/data/desi_lrg_sgc_nz.txt +0 -0
  66. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/surveys/data/example_tabulated_nz.txt +0 -0
  67. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/surveys/data/lsst_dp2_nz_degraded_r24p5_masked.txt +0 -0
  68. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/surveys/data/mock_predefined_bins.txt +0 -0
  69. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/surveys/data/roman_n_eff20.nz +0 -0
  70. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/surveys/data/roman_n_eff30.nz +0 -0
  71. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/surveys/data/roman_n_eff40.nz +0 -0
  72. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/surveys/data/roman_n_eff50.nz +0 -0
  73. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/surveys/scripts/fit_roman_smail.py +0 -0
  74. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/surveys/sky.py +0 -0
  75. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/surveys/survey_presets.py +0 -0
  76. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/tomography/__init__.py +0 -0
  77. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/tomography/builders.py +0 -0
  78. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/tomography/core.py +0 -0
  79. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/tomography/predefined.py +0 -0
  80. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/tomography/specs.py +0 -0
  81. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/utils/__init__.py +0 -0
  82. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/utils/broadcasting.py +0 -0
  83. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/utils/io.py +0 -0
  84. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/utils/metadata.py +0 -0
  85. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/utils/normalization.py +0 -0
  86. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/utils/pairwise_metrics.py +0 -0
  87. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/utils/relations.py +0 -0
  88. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/utils/types.py +0 -0
  89. {pybinny-2.0.0 → pybinny-2.1.0}/src/binny/utils/validators.py +0 -0
  90. {pybinny-2.0.0 → pybinny-2.1.0}/src/pybinny.egg-info/SOURCES.txt +0 -0
  91. {pybinny-2.0.0 → pybinny-2.1.0}/src/pybinny.egg-info/dependency_links.txt +0 -0
  92. {pybinny-2.0.0 → pybinny-2.1.0}/src/pybinny.egg-info/top_level.txt +0 -0
  93. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_analysis_combinations.py +0 -0
  94. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_analysis_comparison.py +0 -0
  95. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_analysis_comparison_helpers.py +0 -0
  96. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_analysis_comparison_similarity.py +0 -0
  97. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_analysis_composition.py +0 -0
  98. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_analysis_stats.py +0 -0
  99. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_analysis_stats_center_invariance_fast.py +0 -0
  100. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_analysis_stats_center_invariance_slow.py +0 -0
  101. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_analysis_stats_invariances.py +0 -0
  102. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_axes_bin_edges.py +0 -0
  103. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_axes_grids.py +0 -0
  104. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_axes_mixed_edges.py +0 -0
  105. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_axes_mixed_edges_invariances_fast.py +0 -0
  106. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_axes_mixed_edges_invariances_slow.py +0 -0
  107. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_binning_core.py +0 -0
  108. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_binning_edges.py +0 -0
  109. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_binning_kernels.py +0 -0
  110. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_binning_photoz.py +0 -0
  111. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_binning_photoz_builder.py +0 -0
  112. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_binning_scheme_registry.py +0 -0
  113. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_binning_specz.py +0 -0
  114. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_binning_specz_builder.py +0 -0
  115. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_calibration_depth.py +0 -0
  116. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_calibration_photoz_fitting.py +0 -0
  117. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_calibration_psf_selection.py +0 -0
  118. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_correlations_bin_combo_filter.py +0 -0
  119. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_correlations_filters.py +0 -0
  120. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_correlations_metrics.py +0 -0
  121. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_correlations_scores.py +0 -0
  122. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_correlations_topology.py +0 -0
  123. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_functional_binning_consistency.py +0 -0
  124. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_nz_models.py +0 -0
  125. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_nz_registry.py +0 -0
  126. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_nz_sampling.py +0 -0
  127. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_predefined_api_consistency.py +0 -0
  128. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_public_api.py +0 -0
  129. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_style_colors.py +0 -0
  130. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_surveys_config_utils.py +0 -0
  131. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_surveys_sky.py +0 -0
  132. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_surveys_survey_presets.py +0 -0
  133. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_surveys_tomography.py +0 -0
  134. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_tomography_builder.py +0 -0
  135. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_tomography_core.py +0 -0
  136. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_tomography_metadata_normalization.py +0 -0
  137. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_tomography_predefined.py +0 -0
  138. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_tomography_specs.py +0 -0
  139. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_utils_broadcasting.py +0 -0
  140. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_utils_io.py +0 -0
  141. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_utils_metadata.py +0 -0
  142. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_utils_metadata_arrays.py +0 -0
  143. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_utils_metadata_extended.py +0 -0
  144. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_utils_normalization.py +0 -0
  145. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_utils_pairwise_metrics.py +0 -0
  146. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_utils_relations.py +0 -0
  147. {pybinny-2.0.0 → pybinny-2.1.0}/tests/test_utils_validators.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pybinny
3
- Version: 2.0.0
3
+ Version: 2.1.0
4
4
  Summary: Flexible tomographic binning algorithms for cosmology.
5
5
  Author-email: Nikolina Sarcevic <nikolina.sarcevic@gmail.com>
6
6
  License: MIT
@@ -12,20 +12,15 @@ Requires-Dist: pyyaml
12
12
  Requires-Dist: scipy
13
13
  Requires-Dist: matplotlib
14
14
  Requires-Dist: derivkit
15
- Provides-Extra: lf
16
- Requires-Dist: py-lfkit>=0.1.4; extra == "lf"
15
+ Requires-Dist: py-lfkit>=1.1.0
17
16
  Provides-Extra: cosmo
18
17
  Requires-Dist: pyccl>=3; extra == "cosmo"
19
- Provides-Extra: lf-cosmo
20
- Requires-Dist: py-lfkit>=0.1.4; extra == "lf-cosmo"
21
- Requires-Dist: pyccl>=3; extra == "lf-cosmo"
22
18
  Provides-Extra: dev
23
19
  Requires-Dist: bump-my-version>=0.26; extra == "dev"
24
20
  Requires-Dist: pytest>=8; extra == "dev"
25
21
  Requires-Dist: pytest-cov>=5; extra == "dev"
26
22
  Requires-Dist: ruff>=0.6; extra == "dev"
27
23
  Requires-Dist: tox>=4.22; extra == "dev"
28
- Requires-Dist: py-lfkit>=0.1.4; extra == "dev"
29
24
  Requires-Dist: pyccl>=3; extra == "dev"
30
25
  Provides-Extra: docs
31
26
  Requires-Dist: cmasher; extra == "docs"
@@ -35,7 +30,6 @@ Requires-Dist: sphinx-design; extra == "docs"
35
30
  Requires-Dist: sphinx-multiversion; extra == "docs"
36
31
  Requires-Dist: sphinxawesome-theme; extra == "docs"
37
32
  Requires-Dist: furo; extra == "docs"
38
- Requires-Dist: py-lfkit>=0.1.4; extra == "docs"
39
33
  Requires-Dist: pyccl>=3; extra == "docs"
40
34
  Dynamic: license-file
41
35
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pybinny"
3
- version = "2.0.0"
3
+ version = "2.1.0"
4
4
  description = "Flexible tomographic binning algorithms for cosmology."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
@@ -13,26 +13,19 @@ dependencies = [
13
13
  "scipy",
14
14
  "matplotlib",
15
15
  "derivkit",
16
+ "py-lfkit>=1.1.0",
16
17
  ]
17
18
 
18
19
  [project.optional-dependencies]
19
- lf = [
20
- "py-lfkit>=0.1.4",
21
- ]
22
20
  cosmo = [
23
21
  "pyccl>=3",
24
22
  ]
25
- lf-cosmo = [
26
- "py-lfkit>=0.1.4",
27
- "pyccl>=3",
28
- ]
29
23
  dev = [
30
24
  "bump-my-version>=0.26",
31
25
  "pytest>=8",
32
26
  "pytest-cov>=5",
33
27
  "ruff>=0.6",
34
28
  "tox>=4.22",
35
- "py-lfkit>=0.1.4",
36
29
  "pyccl>=3",
37
30
  ]
38
31
  docs = [
@@ -43,7 +36,6 @@ docs = [
43
36
  "sphinx-multiversion",
44
37
  "sphinxawesome-theme",
45
38
  "furo",
46
- "py-lfkit>=0.1.4",
47
39
  "pyccl>=3",
48
40
  ]
49
41
 
@@ -102,7 +94,7 @@ where = ["src"]
102
94
  ]
103
95
 
104
96
  [tool.bumpversion]
105
- current_version = "2.0.0"
97
+ current_version = "2.1.0"
106
98
  commit = true
107
99
  tag = true
108
100
 
@@ -8,11 +8,12 @@ weights the result by a redshift-dependent volume factor.
8
8
  The model is intentionally backend-agnostic: distances, volume weights,
9
9
  K-corrections, and luminosity functions are supplied as callables. This keeps
10
10
  the interface compatible with different cosmology backends and LF
11
- implementations, including LFKit ``LuminosityFunction`` objects.
11
+ implementations, including LFKit luminosity-function models.
12
12
  """
13
13
 
14
14
  from __future__ import annotations
15
15
 
16
+ import inspect
16
17
  from collections.abc import Callable
17
18
  from typing import Any
18
19
 
@@ -97,34 +98,6 @@ def _absolute_magnitude_grid(
97
98
  return m_arr[None, :] - distance_modulus[:, None] - k_correction[:, None]
98
99
 
99
100
 
100
- def _as_lf_callable(
101
- lf: Any,
102
- ) -> tuple[Callable[..., FloatArray], bool]:
103
- """Return an LF callable and whether it expects two-dimensional redshift input.
104
-
105
- LFKit ``LuminosityFunction`` objects expose ``_as_callable`` and/or
106
- ``phi``. Those interfaces broadcast naturally when redshift is supplied as
107
- ``z[:, None]`` against the two-dimensional absolute-magnitude grid.
108
-
109
- Plain callables are left unchanged so existing Binny callables continue to
110
- receive the original one-dimensional redshift grid.
111
-
112
- Args:
113
- lf: Luminosity-function callable or LFKit-style object.
114
-
115
- Returns:
116
- A callable luminosity function and a flag indicating whether redshift
117
- should be passed as ``z[:, None]``.
118
- """
119
- if hasattr(lf, "_as_callable"):
120
- return lf._as_callable(), True
121
-
122
- if hasattr(lf, "phi"):
123
- return lambda absolute_mag, z: lf.phi(absolute_mag, z), True
124
-
125
- return lf, False
126
-
127
-
128
101
  def luminosity_function_distribution(
129
102
  z: FloatArray,
130
103
  lf: Callable[..., FloatArray],
@@ -156,9 +129,11 @@ def luminosity_function_distribution(
156
129
  z:
157
130
  One-dimensional redshift grid.
158
131
  lf:
159
- Luminosity-function callable or LFKit ``LuminosityFunction`` object.
160
- Plain callables must accept ``lf(M, z, **kwargs)``. LFKit objects
161
- are evaluated through their ``_as_callable`` or ``phi`` interface.
132
+ Static or redshift-dependent luminosity-function callable.
133
+ Static models accept ``lf(M, **kwargs)`` and evolving models
134
+ accept ``lf(M, z, **kwargs)``. LFKit models receive a broadcastable
135
+ redshift column, while other callables receive a one-dimensional
136
+ redshift grid.
162
137
  cosmo:
163
138
  Optional PyCCL cosmology object. If supplied, Binny uses its
164
139
  CCL-backed luminosity-distance and comoving-volume helpers whenever
@@ -182,7 +157,7 @@ def luminosity_function_distribution(
182
157
  normalize:
183
158
  If ``True``, normalize the output over the redshift grid.
184
159
  **lf_kwargs:
185
- Extra keyword arguments passed directly to plain LF callables.
160
+ Extra keyword arguments passed directly to the luminosity function.
186
161
 
187
162
  Returns:
188
163
  Parent redshift distribution evaluated on ``z``.
@@ -241,13 +216,20 @@ def luminosity_function_distribution(
241
216
  k_correction_fn=k_correction_fn,
242
217
  )
243
218
 
244
- lf_callable, wants_2d_z = _as_lf_callable(lf)
245
- z_for_lf = z_positive[:, None] if wants_2d_z else z_positive
219
+ is_lfkit = getattr(lf, "__module__", "").startswith("lfkit.")
220
+ z_for_lf = z_positive[:, None] if is_lfkit else z_positive
246
221
 
247
- phi = np.asarray(
248
- lf_callable(absolute_magnitude, z_for_lf, **lf_kwargs),
249
- dtype=np.float64,
250
- )
222
+ signature = inspect.signature(lf)
223
+
224
+ try:
225
+ signature.bind(absolute_magnitude, z_for_lf, **lf_kwargs)
226
+ except TypeError:
227
+ signature.bind(absolute_magnitude, **lf_kwargs)
228
+ phi = lf(absolute_magnitude, **lf_kwargs)
229
+ else:
230
+ phi = lf(absolute_magnitude, z_for_lf, **lf_kwargs)
231
+
232
+ phi = np.asarray(phi, dtype=np.float64)
251
233
 
252
234
  if phi.shape != absolute_magnitude.shape:
253
235
  raise ValueError("lf(M, z, ...) must return an array of shape (len(z), n_m).")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pybinny
3
- Version: 2.0.0
3
+ Version: 2.1.0
4
4
  Summary: Flexible tomographic binning algorithms for cosmology.
5
5
  Author-email: Nikolina Sarcevic <nikolina.sarcevic@gmail.com>
6
6
  License: MIT
@@ -12,20 +12,15 @@ Requires-Dist: pyyaml
12
12
  Requires-Dist: scipy
13
13
  Requires-Dist: matplotlib
14
14
  Requires-Dist: derivkit
15
- Provides-Extra: lf
16
- Requires-Dist: py-lfkit>=0.1.4; extra == "lf"
15
+ Requires-Dist: py-lfkit>=1.1.0
17
16
  Provides-Extra: cosmo
18
17
  Requires-Dist: pyccl>=3; extra == "cosmo"
19
- Provides-Extra: lf-cosmo
20
- Requires-Dist: py-lfkit>=0.1.4; extra == "lf-cosmo"
21
- Requires-Dist: pyccl>=3; extra == "lf-cosmo"
22
18
  Provides-Extra: dev
23
19
  Requires-Dist: bump-my-version>=0.26; extra == "dev"
24
20
  Requires-Dist: pytest>=8; extra == "dev"
25
21
  Requires-Dist: pytest-cov>=5; extra == "dev"
26
22
  Requires-Dist: ruff>=0.6; extra == "dev"
27
23
  Requires-Dist: tox>=4.22; extra == "dev"
28
- Requires-Dist: py-lfkit>=0.1.4; extra == "dev"
29
24
  Requires-Dist: pyccl>=3; extra == "dev"
30
25
  Provides-Extra: docs
31
26
  Requires-Dist: cmasher; extra == "docs"
@@ -35,7 +30,6 @@ Requires-Dist: sphinx-design; extra == "docs"
35
30
  Requires-Dist: sphinx-multiversion; extra == "docs"
36
31
  Requires-Dist: sphinxawesome-theme; extra == "docs"
37
32
  Requires-Dist: furo; extra == "docs"
38
- Requires-Dist: py-lfkit>=0.1.4; extra == "docs"
39
33
  Requires-Dist: pyccl>=3; extra == "docs"
40
34
  Dynamic: license-file
41
35
 
@@ -3,6 +3,7 @@ pyyaml
3
3
  scipy
4
4
  matplotlib
5
5
  derivkit
6
+ py-lfkit>=1.1.0
6
7
 
7
8
  [cosmo]
8
9
  pyccl>=3
@@ -13,7 +14,6 @@ pytest>=8
13
14
  pytest-cov>=5
14
15
  ruff>=0.6
15
16
  tox>=4.22
16
- py-lfkit>=0.1.4
17
17
  pyccl>=3
18
18
 
19
19
  [docs]
@@ -24,12 +24,4 @@ sphinx-design
24
24
  sphinx-multiversion
25
25
  sphinxawesome-theme
26
26
  furo
27
- py-lfkit>=0.1.4
28
- pyccl>=3
29
-
30
- [lf]
31
- py-lfkit>=0.1.4
32
-
33
- [lf-cosmo]
34
- py-lfkit>=0.1.4
35
27
  pyccl>=3
@@ -2,8 +2,6 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from typing import Any
6
-
7
5
  import numpy as np
8
6
  import pytest
9
7
 
@@ -26,41 +24,6 @@ def constant_lf(m_abs: np.ndarray, z: np.ndarray) -> np.ndarray:
26
24
  return np.ones_like(m_abs)
27
25
 
28
26
 
29
- class FakeLFKitWithAsCallable:
30
- """Mock an LFKit object exposing ``_as_callable``."""
31
-
32
- def __init__(self) -> None:
33
- """Store captured LF inputs."""
34
- self.captured_m_abs: np.ndarray | None = None
35
- self.captured_z: np.ndarray | None = None
36
-
37
- def _as_callable(self) -> Any:
38
- """Return an LF callable."""
39
-
40
- def lf_callable(m_abs: np.ndarray, z: np.ndarray) -> np.ndarray:
41
- """Return a constant LF and capture inputs."""
42
- self.captured_m_abs = m_abs.copy()
43
- self.captured_z = z.copy()
44
- return np.ones_like(m_abs)
45
-
46
- return lf_callable
47
-
48
-
49
- class FakeLFKitWithPhi:
50
- """Mock an LFKit object exposing ``phi``."""
51
-
52
- def __init__(self) -> None:
53
- """Store captured LF inputs."""
54
- self.captured_m_abs: np.ndarray | None = None
55
- self.captured_z: np.ndarray | None = None
56
-
57
- def phi(self, absolute_mag: np.ndarray, z: np.ndarray) -> np.ndarray:
58
- """Return a constant LF and capture inputs."""
59
- self.captured_m_abs = absolute_mag.copy()
60
- self.captured_z = z.copy()
61
- return np.ones_like(absolute_mag)
62
-
63
-
64
27
  def test_constant_lf_and_constant_volume_gives_constant_nz() -> None:
65
28
  """Test that constant LF and constant volume give flat n(z)."""
66
29
  z = np.linspace(0.1, 1.0, 20)
@@ -226,58 +189,6 @@ def test_lf_can_use_extra_keyword_arguments() -> None:
226
189
  np.testing.assert_allclose(nz, expected)
227
190
 
228
191
 
229
- def test_lfkit_like_object_with_as_callable_gets_2d_redshift_grid() -> None:
230
- """Test that ``_as_callable`` objects receive broadcastable redshift."""
231
- z = np.linspace(0.1, 1.0, 20)
232
- lf = FakeLFKitWithAsCallable()
233
-
234
- nz = luminosity_function_distribution(
235
- z,
236
- lf,
237
- m_bright=14.0,
238
- m_lim=22.0,
239
- n_m=64,
240
- luminosity_distance_mpc_fn=luminosity_distance_mpc,
241
- volume_weight_fn=lambda z_arr: np.ones_like(z_arr),
242
- normalize=False,
243
- )
244
-
245
- expected = np.full_like(z, 22.0 - 14.0)
246
-
247
- np.testing.assert_allclose(nz, expected)
248
- assert lf.captured_m_abs is not None
249
- assert lf.captured_z is not None
250
- assert lf.captured_m_abs.shape == (z.size, 64)
251
- assert lf.captured_z.shape == (z.size, 1)
252
- np.testing.assert_allclose(lf.captured_z[:, 0], z)
253
-
254
-
255
- def test_lfkit_like_object_with_phi_gets_2d_redshift_grid() -> None:
256
- """Test that ``phi`` objects receive broadcastable redshift."""
257
- z = np.linspace(0.1, 1.0, 20)
258
- lf = FakeLFKitWithPhi()
259
-
260
- nz = luminosity_function_distribution(
261
- z,
262
- lf,
263
- m_bright=14.0,
264
- m_lim=22.0,
265
- n_m=64,
266
- luminosity_distance_mpc_fn=luminosity_distance_mpc,
267
- volume_weight_fn=lambda z_arr: np.ones_like(z_arr),
268
- normalize=False,
269
- )
270
-
271
- expected = np.full_like(z, 22.0 - 14.0)
272
-
273
- np.testing.assert_allclose(nz, expected)
274
- assert lf.captured_m_abs is not None
275
- assert lf.captured_z is not None
276
- assert lf.captured_m_abs.shape == (z.size, 64)
277
- assert lf.captured_z.shape == (z.size, 1)
278
- np.testing.assert_allclose(lf.captured_z[:, 0], z)
279
-
280
-
281
192
  def test_plain_callable_still_gets_1d_redshift_grid() -> None:
282
193
  """Test that plain LF callables still receive one-dimensional redshift."""
283
194
  z = np.linspace(0.1, 1.0, 20)
@@ -305,52 +216,6 @@ def test_plain_callable_still_gets_1d_redshift_grid() -> None:
305
216
  np.testing.assert_allclose(captured["z"], z)
306
217
 
307
218
 
308
- def test_as_callable_takes_precedence_over_phi() -> None:
309
- """Test that ``_as_callable`` is preferred when both hooks exist."""
310
-
311
- class FakeLFKitWithBoth:
312
- """Mock an LFKit object exposing both hooks."""
313
-
314
- def __init__(self) -> None:
315
- """Store which hook was used."""
316
- self.used_as_callable = False
317
- self.used_phi = False
318
-
319
- def _as_callable(self) -> Any:
320
- """Return an LF callable."""
321
-
322
- def lf_callable(m_abs: np.ndarray, z: np.ndarray) -> np.ndarray:
323
- """Mark ``_as_callable`` as used."""
324
- _ = z
325
- self.used_as_callable = True
326
- return np.ones_like(m_abs)
327
-
328
- return lf_callable
329
-
330
- def phi(self, absolute_mag: np.ndarray, z: np.ndarray) -> np.ndarray:
331
- """Mark ``phi`` as used."""
332
- _ = z
333
- self.used_phi = True
334
- return np.ones_like(absolute_mag)
335
-
336
- z = np.linspace(0.1, 1.0, 20)
337
- lf = FakeLFKitWithBoth()
338
-
339
- luminosity_function_distribution(
340
- z,
341
- lf,
342
- m_bright=14.0,
343
- m_lim=22.0,
344
- n_m=64,
345
- luminosity_distance_mpc_fn=luminosity_distance_mpc,
346
- volume_weight_fn=lambda z_arr: np.ones_like(z_arr),
347
- normalize=False,
348
- )
349
-
350
- assert lf.used_as_callable
351
- assert not lf.used_phi
352
-
353
-
354
219
  @pytest.mark.parametrize(
355
220
  ("z", "message"),
356
221
  [
@@ -554,3 +419,92 @@ def test_negative_volume_weight_raises() -> None:
554
419
  luminosity_distance_mpc_fn=luminosity_distance_mpc,
555
420
  volume_weight_fn=bad_volume_weight,
556
421
  )
422
+
423
+
424
+ def test_lfkit_static_schechter() -> None:
425
+ """Tests that Binny integrates a static LFKit Schechter model correctly."""
426
+ from lfkit.models import schechter
427
+
428
+ z = np.linspace(0.1, 1.0, 50)
429
+ m = np.linspace(14.0, 22.0, 512)
430
+
431
+ lf_kwargs = {
432
+ "phi_star": 3.0e-3,
433
+ "m_star": -21.0,
434
+ "alpha": -1.25,
435
+ }
436
+
437
+ nz = luminosity_function_distribution(
438
+ z,
439
+ schechter,
440
+ m_bright=14.0,
441
+ m_lim=22.0,
442
+ n_m=512,
443
+ luminosity_distance_mpc_fn=luminosity_distance_mpc,
444
+ volume_weight_fn=np.ones_like,
445
+ normalize=False,
446
+ **lf_kwargs,
447
+ )
448
+
449
+ distance_modulus = 5.0 * np.log10(luminosity_distance_mpc(z) * 1.0e5)
450
+ absolute_mag = m[None, :] - distance_modulus[:, None]
451
+
452
+ expected = np.trapezoid(
453
+ schechter(absolute_mag, **lf_kwargs),
454
+ x=m,
455
+ axis=1,
456
+ )
457
+
458
+ np.testing.assert_allclose(nz, expected, rtol=1e-12, atol=0.0)
459
+
460
+
461
+ def test_lfkit_evolving_schechter() -> None:
462
+ """Tests that Binny integrates an evolving LFKit Schechter model correctly."""
463
+ from lfkit.models import evolving_schechter, schechter
464
+
465
+ z = np.linspace(0.1, 0.8, 50)
466
+ m = np.linspace(14.0, 19.8, 512)
467
+
468
+ lf_kwargs = {
469
+ "phi_model": "linear_p",
470
+ "phi_kwargs": {"phi_0_star": 0.0038, "p": 2.9},
471
+ "m_star_model": "linear_q",
472
+ "m_star_kwargs": {
473
+ "m_0_star": -20.45,
474
+ "q": 0.8,
475
+ "z_ref": 0.1,
476
+ },
477
+ "alpha_model": "constant",
478
+ "alpha_kwargs": {"alpha": -1.49},
479
+ }
480
+
481
+ nz = luminosity_function_distribution(
482
+ z,
483
+ evolving_schechter,
484
+ m_bright=14.0,
485
+ m_lim=19.8,
486
+ n_m=512,
487
+ luminosity_distance_mpc_fn=luminosity_distance_mpc,
488
+ volume_weight_fn=np.ones_like,
489
+ normalize=False,
490
+ **lf_kwargs,
491
+ )
492
+
493
+ distance_modulus = 5.0 * np.log10(luminosity_distance_mpc(z) * 1.0e5)
494
+ absolute_mag = m[None, :] - distance_modulus[:, None]
495
+
496
+ phi_star = 0.0038 * 10.0 ** (0.4 * 2.9 * z)
497
+ m_star = -20.45 - 0.8 * (z - 0.1)
498
+
499
+ expected = np.trapezoid(
500
+ schechter(
501
+ absolute_mag,
502
+ phi_star=phi_star[:, None],
503
+ m_star=m_star[:, None],
504
+ alpha=-1.49,
505
+ ),
506
+ x=m,
507
+ axis=1,
508
+ )
509
+
510
+ np.testing.assert_allclose(nz, expected, rtol=1e-12, atol=0.0)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes