pybinny 2.0.0__tar.gz → 2.2.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 (149) hide show
  1. {pybinny-2.0.0/src/pybinny.egg-info → pybinny-2.2.0}/PKG-INFO +2 -8
  2. {pybinny-2.0.0 → pybinny-2.2.0}/pyproject.toml +3 -11
  3. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/analysis/__init__.py +4 -4
  4. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/analysis/stats.py +196 -131
  5. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/nz/luminosity_function_distribution.py +21 -39
  6. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/surveys/__init__.py +2 -0
  7. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/surveys/configs/desi_survey_specs.yaml +4 -0
  8. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/surveys/configs/euclid_survey_specs.yaml +2 -1
  9. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/surveys/configs/lsst_survey_specs.yaml +1 -0
  10. pybinny-2.2.0/src/binny/surveys/survey_presets.py +387 -0
  11. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/utils/metadata.py +5 -23
  12. {pybinny-2.0.0 → pybinny-2.2.0/src/pybinny.egg-info}/PKG-INFO +2 -8
  13. {pybinny-2.0.0 → pybinny-2.2.0}/src/pybinny.egg-info/SOURCES.txt +1 -0
  14. {pybinny-2.0.0 → pybinny-2.2.0}/src/pybinny.egg-info/requires.txt +1 -9
  15. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_analysis_stats.py +573 -85
  16. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_analysis_stats_invariances.py +38 -33
  17. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_nz_luminosity_function_distribution.py +89 -135
  18. pybinny-2.2.0/tests/test_surveys_population_stats.py +348 -0
  19. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_surveys_tomography.py +17 -0
  20. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_utils_metadata.py +0 -4
  21. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_utils_metadata_extended.py +0 -6
  22. pybinny-2.0.0/src/binny/surveys/survey_presets.py +0 -177
  23. {pybinny-2.0.0 → pybinny-2.2.0}/LICENSE +0 -0
  24. {pybinny-2.0.0 → pybinny-2.2.0}/README.md +0 -0
  25. {pybinny-2.0.0 → pybinny-2.2.0}/setup.cfg +0 -0
  26. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/__init__.py +0 -0
  27. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/analysis/combinations.py +0 -0
  28. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/analysis/comparison.py +0 -0
  29. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/analysis/composition.py +0 -0
  30. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/axes/__init__.py +0 -0
  31. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/axes/bin_edges.py +0 -0
  32. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/axes/grids.py +0 -0
  33. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/axes/mixed_edges.py +0 -0
  34. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/binning/__init__.py +0 -0
  35. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/binning/assignments.py +0 -0
  36. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/binning/core.py +0 -0
  37. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/binning/edges.py +0 -0
  38. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/binning/photoz.py +0 -0
  39. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/binning/scheme_registry.py +0 -0
  40. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/binning/specs.py +0 -0
  41. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/binning/specz.py +0 -0
  42. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/calibration/__init__.py +0 -0
  43. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/calibration/depth.py +0 -0
  44. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/calibration/photoz_fitting.py +0 -0
  45. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/calibration/psf_selection.py +0 -0
  46. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/correlations/__init__.py +0 -0
  47. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/correlations/bin_combo_filter.py +0 -0
  48. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/correlations/filters.py +0 -0
  49. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/correlations/metrics.py +0 -0
  50. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/correlations/scores.py +0 -0
  51. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/correlations/topology.py +0 -0
  52. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/cosmology/__init__.py +0 -0
  53. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/cosmology/ccl_wrappers.py +0 -0
  54. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/nz/__init__.py +0 -0
  55. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/nz/models.py +0 -0
  56. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/nz/registry.py +0 -0
  57. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/nz/sampling.py +0 -0
  58. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/style/__init__.py +0 -0
  59. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/style/colors.py +0 -0
  60. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/surveys/config_utils.py +0 -0
  61. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/surveys/configs/__init__.py +0 -0
  62. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/surveys/configs/des_survey_specs.yaml +0 -0
  63. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/surveys/configs/example_full_photoz.yaml +0 -0
  64. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/surveys/configs/example_full_specz.yaml +0 -0
  65. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/surveys/configs/example_generalized_photoz.yaml +0 -0
  66. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/surveys/configs/example_minimal_photoz.yaml +0 -0
  67. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/surveys/configs/example_minimal_specz.yaml +0 -0
  68. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/surveys/configs/example_tabulated.yaml +0 -0
  69. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/surveys/configs/mock_predefined_config.yaml +0 -0
  70. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/surveys/configs/roman_survey_specs.yaml +0 -0
  71. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/surveys/data/__init__.py +0 -0
  72. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/surveys/data/desi_bgs_sgc_nz.txt +0 -0
  73. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/surveys/data/desi_elg_nz.txt +0 -0
  74. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/surveys/data/desi_lrg_nz.txt +0 -0
  75. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/surveys/data/desi_lrg_sgc_nz.txt +0 -0
  76. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/surveys/data/example_tabulated_nz.txt +0 -0
  77. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/surveys/data/lsst_dp2_nz_degraded_r24p5_masked.txt +0 -0
  78. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/surveys/data/mock_predefined_bins.txt +0 -0
  79. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/surveys/data/roman_n_eff20.nz +0 -0
  80. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/surveys/data/roman_n_eff30.nz +0 -0
  81. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/surveys/data/roman_n_eff40.nz +0 -0
  82. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/surveys/data/roman_n_eff50.nz +0 -0
  83. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/surveys/scripts/fit_roman_smail.py +0 -0
  84. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/surveys/sky.py +0 -0
  85. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/tomography/__init__.py +0 -0
  86. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/tomography/builders.py +0 -0
  87. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/tomography/core.py +0 -0
  88. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/tomography/predefined.py +0 -0
  89. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/tomography/specs.py +0 -0
  90. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/utils/__init__.py +0 -0
  91. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/utils/broadcasting.py +0 -0
  92. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/utils/io.py +0 -0
  93. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/utils/normalization.py +0 -0
  94. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/utils/pairwise_metrics.py +0 -0
  95. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/utils/relations.py +0 -0
  96. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/utils/types.py +0 -0
  97. {pybinny-2.0.0 → pybinny-2.2.0}/src/binny/utils/validators.py +0 -0
  98. {pybinny-2.0.0 → pybinny-2.2.0}/src/pybinny.egg-info/dependency_links.txt +0 -0
  99. {pybinny-2.0.0 → pybinny-2.2.0}/src/pybinny.egg-info/top_level.txt +0 -0
  100. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_analysis_combinations.py +0 -0
  101. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_analysis_comparison.py +0 -0
  102. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_analysis_comparison_helpers.py +0 -0
  103. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_analysis_comparison_similarity.py +0 -0
  104. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_analysis_composition.py +0 -0
  105. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_analysis_stats_center_invariance_fast.py +0 -0
  106. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_analysis_stats_center_invariance_slow.py +0 -0
  107. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_axes_bin_edges.py +0 -0
  108. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_axes_grids.py +0 -0
  109. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_axes_mixed_edges.py +0 -0
  110. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_axes_mixed_edges_invariances_fast.py +0 -0
  111. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_axes_mixed_edges_invariances_slow.py +0 -0
  112. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_binning_core.py +0 -0
  113. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_binning_edges.py +0 -0
  114. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_binning_kernels.py +0 -0
  115. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_binning_photoz.py +0 -0
  116. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_binning_photoz_builder.py +0 -0
  117. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_binning_scheme_registry.py +0 -0
  118. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_binning_specz.py +0 -0
  119. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_binning_specz_builder.py +0 -0
  120. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_calibration_depth.py +0 -0
  121. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_calibration_photoz_fitting.py +0 -0
  122. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_calibration_psf_selection.py +0 -0
  123. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_correlations_bin_combo_filter.py +0 -0
  124. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_correlations_filters.py +0 -0
  125. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_correlations_metrics.py +0 -0
  126. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_correlations_scores.py +0 -0
  127. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_correlations_topology.py +0 -0
  128. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_functional_binning_consistency.py +0 -0
  129. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_nz_models.py +0 -0
  130. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_nz_registry.py +0 -0
  131. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_nz_sampling.py +0 -0
  132. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_predefined_api_consistency.py +0 -0
  133. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_public_api.py +0 -0
  134. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_style_colors.py +0 -0
  135. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_surveys_config_utils.py +0 -0
  136. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_surveys_sky.py +0 -0
  137. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_surveys_survey_presets.py +0 -0
  138. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_tomography_builder.py +0 -0
  139. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_tomography_core.py +0 -0
  140. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_tomography_metadata_normalization.py +0 -0
  141. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_tomography_predefined.py +0 -0
  142. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_tomography_specs.py +0 -0
  143. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_utils_broadcasting.py +0 -0
  144. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_utils_io.py +0 -0
  145. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_utils_metadata_arrays.py +0 -0
  146. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_utils_normalization.py +0 -0
  147. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_utils_pairwise_metrics.py +0 -0
  148. {pybinny-2.0.0 → pybinny-2.2.0}/tests/test_utils_relations.py +0 -0
  149. {pybinny-2.0.0 → pybinny-2.2.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.2.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.2.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.2.0"
106
98
  commit = true
107
99
  tag = true
108
100
 
@@ -21,12 +21,12 @@ from binny.analysis.composition import (
21
21
  sample_combinations,
22
22
  )
23
23
  from binny.analysis.stats import (
24
+ angular_count_per_bin,
25
+ angular_density_per_bin,
24
26
  bin_centers,
25
27
  bin_moments,
26
28
  bin_quantiles,
27
29
  comoving_density_per_bin,
28
- galaxy_count_per_bin,
29
- galaxy_density_per_bin,
30
30
  galaxy_fraction_per_bin,
31
31
  in_range_fraction,
32
32
  in_range_fraction_per_bin,
@@ -85,8 +85,8 @@ __all__ = [
85
85
  "filter_by_score_relation",
86
86
  "filter_by_score_separation",
87
87
  "filter_by_width_ratio",
88
- "galaxy_count_per_bin",
89
- "galaxy_density_per_bin",
88
+ "angular_count_per_bin",
89
+ "angular_density_per_bin",
90
90
  "galaxy_fraction_per_bin",
91
91
  "in_range_fraction",
92
92
  "in_range_fraction_per_bin",
@@ -31,8 +31,8 @@ __all__ = [
31
31
  "bin_centers",
32
32
  "comoving_density_per_bin",
33
33
  "galaxy_fraction_per_bin",
34
- "galaxy_count_per_bin",
35
- "galaxy_density_per_bin",
34
+ "angular_count_per_bin",
35
+ "angular_density_per_bin",
36
36
  "in_range_fraction",
37
37
  "in_range_fraction_per_bin",
38
38
  "peak_flags",
@@ -411,8 +411,27 @@ def peak_flags_per_bin(
411
411
  }
412
412
 
413
413
 
414
- def galaxy_fraction_per_bin(meta: Mapping[str, Any]) -> dict[int, float]:
415
- """Extract and normalize per-bin population fractions from tomo metadata."""
414
+ def galaxy_fraction_per_bin(
415
+ meta: Mapping[str, Any],
416
+ *,
417
+ fraction_mode: str = "parent",
418
+ ) -> dict[int, float]:
419
+ """Extract population fractions from tomography metadata.
420
+
421
+ Args:
422
+ meta: Tomography metadata containing per-bin population fractions.
423
+ fraction_mode: Parent fractions or normalized selected-bin contributions.
424
+ Supported values are "parent" and "selected".
425
+
426
+ Returns:
427
+ Mapping from bin index to population fraction.
428
+
429
+ Raises:
430
+ ValueError: If fractions or the fraction mode are invalid.
431
+ """
432
+ if fraction_mode not in {"parent", "selected"}:
433
+ raise ValueError("fraction_mode must be 'parent' or 'selected'.")
434
+
416
435
  bins_meta = meta.get("bins")
417
436
 
418
437
  if not isinstance(bins_meta, Mapping):
@@ -423,71 +442,89 @@ def galaxy_fraction_per_bin(meta: Mapping[str, Any]) -> dict[int, float]:
423
442
  if not isinstance(frac, Mapping):
424
443
  raise ValueError("metadata must contain a mapping 'bins.frac_per_bin'.")
425
444
 
426
- out: dict[int, float] = {int(k): float(v) for k, v in frac.items()}
427
- s = float(sum(out.values()))
445
+ if not frac:
446
+ raise ValueError("Population fractions must not be empty.")
428
447
 
429
- if s <= 0.0:
430
- raise ValueError("Sum of metadata frac_per_bin must be positive.")
448
+ out = {int(k): float(v) for k, v in frac.items()}
431
449
 
432
- return {i: f / s for i, f in out.items()}
450
+ if len(out) != len(frac):
451
+ raise ValueError("Population fractions contain duplicate bin indices.")
433
452
 
453
+ if any(not np.isfinite(f) or f < 0.0 for f in out.values()):
454
+ raise ValueError("Population fractions must be finite and non-negative.")
434
455
 
435
- def galaxy_count_per_bin(
436
- density_per_bin: Mapping[int, float],
437
- survey_area: float,
438
- ) -> dict[int, float]:
439
- """Convert per-bin surface densities to effective counts using a survey area.
456
+ if fraction_mode == "parent":
457
+ return out
458
+
459
+ total = float(sum(out.values()))
440
460
 
441
- Conventions:
442
- - ``density_per_bin`` values are in galaxies per square arcminute.
443
- - ``survey_area`` is in square arcminutes.
444
- - returned counts are dimensionless effective counts.
461
+ if not np.isfinite(total) or total <= 0.0:
462
+ raise ValueError("Sum of metadata frac_per_bin must be positive and finite.")
463
+
464
+ return {i: f / total for i, f in out.items()}
465
+
466
+
467
+ def angular_count_per_bin(
468
+ angular_density_per_bin: Mapping[int, float],
469
+ survey_area_arcmin2: float,
470
+ ) -> dict[int, float]:
471
+ """Convert angular number densities to effective population counts.
445
472
 
446
473
  Args:
447
- density_per_bin: Mapping from bin index to surface density (gal/arcmin^2).
448
- survey_area: Survey area (arcmin^2).
474
+ angular_density_per_bin: Per-bin densities in galaxies per square arcminute.
475
+ survey_area_arcmin2: Survey area in square arcminutes.
449
476
 
450
477
  Returns:
451
- Mapping from bin index to effective counts.
478
+ Effective population counts per bin.
452
479
 
453
480
  Raises:
454
- ValueError: If survey_area is not positive.
455
- ValueError: If any density is negative.
481
+ ValueError: If densities or survey area are invalid.
456
482
  """
457
- if survey_area <= 0.0:
458
- raise ValueError("survey_area must be positive.")
483
+ if not np.isfinite(survey_area_arcmin2) or survey_area_arcmin2 <= 0.0:
484
+ raise ValueError("survey_area_arcmin2 must be positive and finite.")
459
485
 
460
486
  out: dict[int, float] = {}
461
- for idx, dens in density_per_bin.items():
462
- d = float(dens)
463
- if d < 0.0:
464
- raise ValueError(f"density_per_bin[{idx}] must be non-negative.")
465
- out[int(idx)] = d * float(survey_area)
487
+
488
+ for idx, density in angular_density_per_bin.items():
489
+ density = float(density)
490
+
491
+ if not np.isfinite(density) or density < 0.0:
492
+ raise ValueError(f"angular_density_per_bin[{idx}] must be non-negative and finite.")
493
+
494
+ out[int(idx)] = density * float(survey_area_arcmin2)
495
+
466
496
  return out
467
497
 
468
498
 
469
- def galaxy_density_per_bin(
499
+ def angular_density_per_bin(
470
500
  metadata: Mapping[str, Any],
471
- density_total: float,
501
+ angular_density_total: float,
502
+ *,
503
+ fraction_mode: str,
472
504
  ) -> dict[int, float]:
473
- """Computes per-bin surface densities from tomo metadata and total
474
- effective density..
505
+ """Allocate total angular number density across tomographic bins.
475
506
 
476
507
  Args:
477
- metadata: Tomography metadata containing ``metadata["bins"]["frac_per_bin"]``.
478
- density_total: Total effective surface density (gal/arcmin^2).
508
+ metadata: Tomography metadata containing population fractions.
509
+ angular_density_total: Total density in galaxies per square arcminute.
510
+ fraction_mode: Population convention of the supplied total density.
511
+ Supported values are "parent" and "selected".
479
512
 
480
513
  Returns:
481
- Mapping {bin_idx: gal/arcmin^2}.
514
+ Per-bin angular densities in galaxies per square arcminute.
482
515
 
483
516
  Raises:
484
- ValueError: If density_total is negative.
485
- ValueError: If metadata does not contain valid fractions.
517
+ ValueError: If the density or population fractions are invalid.
486
518
  """
487
- if density_total < 0.0:
488
- raise ValueError("density_total must be non-negative.")
489
- frac = galaxy_fraction_per_bin(metadata)
490
- return {i: float(density_total) * float(f) for i, f in frac.items()}
519
+ if not np.isfinite(angular_density_total) or angular_density_total < 0.0:
520
+ raise ValueError("angular_density_total must be non-negative and finite.")
521
+
522
+ fractions = galaxy_fraction_per_bin(
523
+ metadata,
524
+ fraction_mode=fraction_mode,
525
+ )
526
+
527
+ return {i: float(angular_density_total) * fraction for i, fraction in fractions.items()}
491
528
 
492
529
 
493
530
  def shape_stats(
@@ -603,15 +640,34 @@ def comoving_density_per_bin(
603
640
  total_count_per_bin: Mapping[int, float],
604
641
  volume_per_bin: Mapping[int, float],
605
642
  ) -> dict[int, float]:
606
- """Compute per-bin comoving number densities from counts and volumes."""
643
+ """Compute per-bin comoving number densities from counts and volumes.
644
+
645
+ Args:
646
+ total_count_per_bin: Galaxy counts in each bin.
647
+ volume_per_bin: Comoving volumes in (Mpc/h)^3.
648
+
649
+ Returns:
650
+ Per-bin comoving number densities in h^3/Mpc^3.
651
+
652
+ Raises:
653
+ ValueError: If bin indices differ or counts or volumes are invalid.
654
+ """
655
+ if set(total_count_per_bin) != set(volume_per_bin):
656
+ raise ValueError("Counts and volumes must have matching bin indices.")
657
+
607
658
  out: dict[int, float] = {}
608
659
 
609
660
  for idx, count in total_count_per_bin.items():
610
- volume = float(volume_per_bin[int(idx)])
611
- if volume <= 0.0:
612
- raise ValueError(f"volume_per_bin[{idx}] must be positive.")
661
+ count = float(count)
662
+ volume = float(volume_per_bin[idx])
663
+
664
+ if not np.isfinite(count) or count < 0.0:
665
+ raise ValueError(f"total_count_per_bin[{idx}] must be non-negative and finite.")
666
+
667
+ if not np.isfinite(volume) or volume <= 0.0:
668
+ raise ValueError(f"volume_per_bin[{idx}] must be positive and finite.")
613
669
 
614
- out[int(idx)] = float(count) / volume
670
+ out[int(idx)] = count / volume
615
671
 
616
672
  return out
617
673
 
@@ -620,120 +676,129 @@ def population_stats(
620
676
  bins: Mapping[int, Any],
621
677
  metadata: Mapping[str, Any],
622
678
  *,
623
- density_total: float | None = None,
624
- survey_area: float | None = None,
625
- normalize_frac: bool = True,
626
- rtol: float = 1e-2,
627
- atol: float = 1e-3,
679
+ fraction_mode: str | None = None,
680
+ angular_density_total: float | None = None,
681
+ survey_area_arcmin2: float | None = None,
628
682
  total_count_per_bin: Mapping[int, float] | None = None,
629
683
  volume_per_bin: Mapping[int, float] | None = None,
630
- decimal_places: int | None = 2,
684
+ comoving_density: float | Mapping[int, float] | None = None,
685
+ decimal_places: int | None = None,
631
686
  ) -> dict[str, Any]:
632
- """Compute population / normalization statistics for tomographic bins.
633
-
634
- This function computes quantities that depend on relative bin populations,
635
- using metadata produced by Binny's tomo builders.
636
-
637
- The primary input is ``metadata["bins"]["frac_per_bin"]`` (mapping bin index to
638
- fraction). Fractions are checked against the bin indices present in
639
- ``bins``.
640
-
641
- Optional allocations:
687
+ """Compute population statistics for tomographic bins.
642
688
 
643
- - If ``density_total`` is provided, return per-bin allocated surface
644
- densities in galaxies per square arcminute.
645
- - If ``survey_area`` is also provided, return effective counts using the
646
- surface density and survey area in square arcminutes.
647
- - If ``total_count_per_bin`` and ``volume_per_bin`` are provided, return
648
- per-bin comoving densities computed as count divided by volume.
689
+ Population fractions are obtained from tomography metadata rather than
690
+ individually normalized bin curves. Selecting a subset of bins does not
691
+ renormalize their population fractions.
649
692
 
650
693
  Args:
651
- bins: Mapping from bin index to bin curves.
652
- metadata: Tomography metadata containing ``metadata["bins"]["frac_per_bin"]``.
653
- density_total: Optional total effective surface density in
654
- galaxies per square arcminute.
655
- survey_area: Optional survey area in square arcminutes. Requires
656
- ``density_total``.
657
- normalize_frac: If True, renormalize metadata fractions to sum to 1.
658
- If False, require they sum to 1 within ``rtol`` and ``atol``.
659
- rtol: Relative tolerance for sum-to-one checks when
660
- ``normalize_frac=False``.
661
- atol: Absolute tolerance for sum-to-one checks when
662
- ``normalize_frac=False``.
663
- total_count_per_bin: Optional mapping from bin index to total galaxy
664
- count in that bin.
665
- volume_per_bin: Optional mapping from bin index to comoving volume in
666
- that bin.
667
- decimal_places: Rounding precision for returned values.
694
+ bins: Mapping from bin index to bin curve.
695
+ metadata: Tomography metadata containing population fractions.
696
+ fraction_mode: Population convention, either "parent" or "selected".
697
+ Defaults to parent fractions when no angular density is supplied.
698
+ Must be explicit when angular_density_total is supplied.
699
+ angular_density_total: Total angular density in galaxies per arcmin^2.
700
+ survey_area_arcmin2: Survey area in square arcminutes.
701
+ total_count_per_bin: Galaxy counts per bin.
702
+ volume_per_bin: Comoving volumes per bin in (Mpc/h)^3.
703
+ comoving_density: Scalar or per-bin comoving density in h^3/Mpc^3.
704
+ Mutually exclusive with counts and volumes.
705
+ decimal_places: Optional rounding precision. None preserves precision.
668
706
 
669
707
  Returns:
670
- Mapping with key ``"fractions"`` and, when requested, surface-density
671
- fields, count fields, or comoving-density fields. Comoving densities are
672
- returned under ``"density_per_bin"`` with ``"density_unit"`` set to
673
- ``"h^3 Mpc^-3"``.
708
+ Population fractions and available angular densities, effective counts,
709
+ comoving densities, galaxy counts, and comoving volumes.
674
710
 
675
711
  Raises:
676
- ValueError: If bins is empty.
677
- ValueError: If metadata does not contain valid per-bin population fractions.
678
- ValueError: If metadata fractions are missing any bin index.
679
- ValueError: If ``survey_area`` is provided without ``density_total``.
680
- ValueError: If only one of ``total_count_per_bin`` and
681
- ``volume_per_bin`` is provided.
682
- ValueError: If any requested comoving volume is non-positive.
683
- ValueError: If fractions cannot be normalized or validated.
712
+ ValueError: If population metadata or physical quantities are invalid,
713
+ or incompatible population inputs are supplied.
684
714
  """
685
- indices = sorted(int(i) for i in bins.keys())
686
- if len(indices) == 0:
715
+ indices = sorted(int(i) for i in bins)
716
+
717
+ if not indices:
687
718
  raise ValueError("bins must not be empty.")
688
719
 
689
- if survey_area is not None and density_total is None:
690
- raise ValueError("survey_area requires density_total to compute counts.")
720
+ if angular_density_total is not None and fraction_mode is None:
721
+ raise ValueError("angular_density_total requires an explicit fraction_mode.")
691
722
 
692
- frac_meta = galaxy_fraction_per_bin(metadata)
723
+ if survey_area_arcmin2 is not None and angular_density_total is None:
724
+ raise ValueError("survey_area_arcmin2 requires angular_density_total.")
693
725
 
694
- frac: dict[int, float] = {}
695
- for i in indices:
696
- if i not in frac_meta:
697
- raise ValueError(f"metadata frac_per_bin missing bin index {i}.")
698
- frac[i] = float(frac_meta[i])
726
+ if fraction_mode is None:
727
+ fraction_mode = "parent"
699
728
 
700
- s = float(sum(frac.values()))
701
- if s <= 0.0:
702
- raise ValueError("Sum of per-bin fractions must be positive.")
729
+ fractions = galaxy_fraction_per_bin(
730
+ metadata,
731
+ fraction_mode=fraction_mode,
732
+ )
703
733
 
704
- if not normalize_frac:
705
- if not np.isclose(s, 1.0, rtol=rtol, atol=atol):
706
- raise ValueError(f"normalize_frac=False requires fractions to sum to 1 (got {s}).")
707
- else:
708
- frac = {i: f / s for i, f in frac.items()}
734
+ missing = set(indices) - set(fractions)
709
735
 
710
- out: dict[str, Any] = {"fractions": frac}
736
+ if missing:
737
+ raise ValueError(f"metadata frac_per_bin missing bin indices: {sorted(missing)}.")
738
+
739
+ out: dict[str, Any] = {
740
+ "fraction_mode": fraction_mode,
741
+ "fractions": {i: fractions[i] for i in indices},
742
+ }
743
+
744
+ if comoving_density is not None:
745
+ if total_count_per_bin is not None or volume_per_bin is not None:
746
+ raise ValueError("comoving_density cannot be combined with counts and volumes.")
747
+
748
+ if isinstance(comoving_density, Mapping):
749
+ missing = set(indices) - set(comoving_density)
750
+
751
+ if missing:
752
+ raise ValueError(f"comoving_density missing bin indices: {sorted(missing)}.")
753
+
754
+ densities = {i: float(comoving_density[i]) for i in indices}
755
+ else:
756
+ densities = {i: float(comoving_density) for i in indices}
757
+
758
+ if any(not np.isfinite(value) or value < 0.0 for value in densities.values()):
759
+ raise ValueError("Comoving densities must be non-negative and finite.")
760
+
761
+ out["comoving_density_per_bin"] = densities
711
762
 
712
763
  if total_count_per_bin is not None or volume_per_bin is not None:
713
764
  if total_count_per_bin is None or volume_per_bin is None:
714
765
  raise ValueError("total_count_per_bin and volume_per_bin must be provided together.")
715
766
 
716
- counts = {int(i): float(total_count_per_bin[i]) for i in indices}
717
- volumes = {int(i): float(volume_per_bin[i]) for i in indices}
767
+ missing = set(indices) - set(total_count_per_bin)
768
+
769
+ if missing:
770
+ raise ValueError(f"total_count_per_bin missing bin indices: {sorted(missing)}.")
771
+
772
+ missing = set(indices) - set(volume_per_bin)
773
+
774
+ if missing:
775
+ raise ValueError(f"volume_per_bin missing bin indices: {sorted(missing)}.")
776
+
777
+ counts = {i: float(total_count_per_bin[i]) for i in indices}
778
+ volumes = {i: float(volume_per_bin[i]) for i in indices}
718
779
 
719
780
  out["total_count_per_bin"] = counts
720
781
  out["volume_per_bin"] = volumes
721
- out["density_per_bin"] = comoving_density_per_bin(counts, volumes)
722
- out["density_unit"] = "h^3 Mpc^-3"
782
+ out["comoving_density_per_bin"] = comoving_density_per_bin(counts, volumes)
723
783
 
724
- if density_total is not None:
725
- density_per_bin_all = galaxy_density_per_bin(
784
+ if angular_density_total is not None:
785
+ densities = angular_density_per_bin(
726
786
  metadata,
727
- density_total=float(density_total),
787
+ angular_density_total,
788
+ fraction_mode=fraction_mode,
728
789
  )
729
- density_per_bin = {i: density_per_bin_all[i] for i in indices}
730
790
 
731
- out["density_total"] = float(density_total)
732
- out["density_per_bin"] = density_per_bin
791
+ densities = {i: densities[i] for i in indices}
792
+
793
+ out["angular_density_total"] = float(angular_density_total)
794
+ out["angular_density_per_bin"] = densities
733
795
 
734
- if survey_area is not None:
735
- out["survey_area"] = float(survey_area)
736
- out["count_per_bin"] = galaxy_count_per_bin(density_per_bin, float(survey_area))
796
+ if survey_area_arcmin2 is not None:
797
+ out["survey_area_arcmin2"] = float(survey_area_arcmin2)
798
+ out["angular_count_per_bin"] = angular_count_per_bin(
799
+ densities,
800
+ survey_area_arcmin2,
801
+ )
737
802
 
738
803
  return round_floats(out, decimal_places)
739
804
 
@@ -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).")
@@ -21,6 +21,7 @@ from binny.surveys.survey_presets import (
21
21
  list_survey_configs,
22
22
  load_survey_config,
23
23
  show_survey_config,
24
+ survey_population_stats,
24
25
  )
25
26
 
26
27
  __all__ = [
@@ -42,4 +43,5 @@ __all__ = [
42
43
  "list_survey_configs",
43
44
  "load_survey_config",
44
45
  "show_survey_config",
46
+ "survey_population_stats",
45
47
  ]