pybinny 2.2.0__tar.gz → 2.3.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.2.0/src/pybinny.egg-info → pybinny-2.3.0}/PKG-INFO +1 -1
  2. {pybinny-2.2.0 → pybinny-2.3.0}/pyproject.toml +2 -2
  3. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/binning/__init__.py +4 -0
  4. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/binning/photoz.py +88 -1
  5. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/binning/specz.py +82 -1
  6. {pybinny-2.2.0 → pybinny-2.3.0/src/pybinny.egg-info}/PKG-INFO +1 -1
  7. pybinny-2.3.0/tests/test_binning_photoz.py +456 -0
  8. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_binning_specz.py +188 -10
  9. pybinny-2.2.0/tests/test_binning_photoz.py +0 -217
  10. {pybinny-2.2.0 → pybinny-2.3.0}/LICENSE +0 -0
  11. {pybinny-2.2.0 → pybinny-2.3.0}/README.md +0 -0
  12. {pybinny-2.2.0 → pybinny-2.3.0}/setup.cfg +0 -0
  13. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/__init__.py +0 -0
  14. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/analysis/__init__.py +0 -0
  15. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/analysis/combinations.py +0 -0
  16. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/analysis/comparison.py +0 -0
  17. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/analysis/composition.py +0 -0
  18. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/analysis/stats.py +0 -0
  19. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/axes/__init__.py +0 -0
  20. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/axes/bin_edges.py +0 -0
  21. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/axes/grids.py +0 -0
  22. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/axes/mixed_edges.py +0 -0
  23. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/binning/assignments.py +0 -0
  24. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/binning/core.py +0 -0
  25. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/binning/edges.py +0 -0
  26. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/binning/scheme_registry.py +0 -0
  27. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/binning/specs.py +0 -0
  28. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/calibration/__init__.py +0 -0
  29. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/calibration/depth.py +0 -0
  30. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/calibration/photoz_fitting.py +0 -0
  31. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/calibration/psf_selection.py +0 -0
  32. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/correlations/__init__.py +0 -0
  33. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/correlations/bin_combo_filter.py +0 -0
  34. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/correlations/filters.py +0 -0
  35. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/correlations/metrics.py +0 -0
  36. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/correlations/scores.py +0 -0
  37. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/correlations/topology.py +0 -0
  38. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/cosmology/__init__.py +0 -0
  39. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/cosmology/ccl_wrappers.py +0 -0
  40. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/nz/__init__.py +0 -0
  41. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/nz/luminosity_function_distribution.py +0 -0
  42. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/nz/models.py +0 -0
  43. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/nz/registry.py +0 -0
  44. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/nz/sampling.py +0 -0
  45. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/style/__init__.py +0 -0
  46. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/style/colors.py +0 -0
  47. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/surveys/__init__.py +0 -0
  48. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/surveys/config_utils.py +0 -0
  49. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/surveys/configs/__init__.py +0 -0
  50. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/surveys/configs/des_survey_specs.yaml +0 -0
  51. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/surveys/configs/desi_survey_specs.yaml +0 -0
  52. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/surveys/configs/euclid_survey_specs.yaml +0 -0
  53. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/surveys/configs/example_full_photoz.yaml +0 -0
  54. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/surveys/configs/example_full_specz.yaml +0 -0
  55. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/surveys/configs/example_generalized_photoz.yaml +0 -0
  56. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/surveys/configs/example_minimal_photoz.yaml +0 -0
  57. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/surveys/configs/example_minimal_specz.yaml +0 -0
  58. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/surveys/configs/example_tabulated.yaml +0 -0
  59. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/surveys/configs/lsst_survey_specs.yaml +0 -0
  60. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/surveys/configs/mock_predefined_config.yaml +0 -0
  61. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/surveys/configs/roman_survey_specs.yaml +0 -0
  62. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/surveys/data/__init__.py +0 -0
  63. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/surveys/data/desi_bgs_sgc_nz.txt +0 -0
  64. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/surveys/data/desi_elg_nz.txt +0 -0
  65. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/surveys/data/desi_lrg_nz.txt +0 -0
  66. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/surveys/data/desi_lrg_sgc_nz.txt +0 -0
  67. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/surveys/data/example_tabulated_nz.txt +0 -0
  68. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/surveys/data/lsst_dp2_nz_degraded_r24p5_masked.txt +0 -0
  69. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/surveys/data/mock_predefined_bins.txt +0 -0
  70. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/surveys/data/roman_n_eff20.nz +0 -0
  71. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/surveys/data/roman_n_eff30.nz +0 -0
  72. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/surveys/data/roman_n_eff40.nz +0 -0
  73. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/surveys/data/roman_n_eff50.nz +0 -0
  74. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/surveys/scripts/fit_roman_smail.py +0 -0
  75. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/surveys/sky.py +0 -0
  76. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/surveys/survey_presets.py +0 -0
  77. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/tomography/__init__.py +0 -0
  78. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/tomography/builders.py +0 -0
  79. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/tomography/core.py +0 -0
  80. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/tomography/predefined.py +0 -0
  81. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/tomography/specs.py +0 -0
  82. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/utils/__init__.py +0 -0
  83. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/utils/broadcasting.py +0 -0
  84. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/utils/io.py +0 -0
  85. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/utils/metadata.py +0 -0
  86. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/utils/normalization.py +0 -0
  87. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/utils/pairwise_metrics.py +0 -0
  88. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/utils/relations.py +0 -0
  89. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/utils/types.py +0 -0
  90. {pybinny-2.2.0 → pybinny-2.3.0}/src/binny/utils/validators.py +0 -0
  91. {pybinny-2.2.0 → pybinny-2.3.0}/src/pybinny.egg-info/SOURCES.txt +0 -0
  92. {pybinny-2.2.0 → pybinny-2.3.0}/src/pybinny.egg-info/dependency_links.txt +0 -0
  93. {pybinny-2.2.0 → pybinny-2.3.0}/src/pybinny.egg-info/requires.txt +0 -0
  94. {pybinny-2.2.0 → pybinny-2.3.0}/src/pybinny.egg-info/top_level.txt +0 -0
  95. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_analysis_combinations.py +0 -0
  96. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_analysis_comparison.py +0 -0
  97. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_analysis_comparison_helpers.py +0 -0
  98. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_analysis_comparison_similarity.py +0 -0
  99. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_analysis_composition.py +0 -0
  100. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_analysis_stats.py +0 -0
  101. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_analysis_stats_center_invariance_fast.py +0 -0
  102. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_analysis_stats_center_invariance_slow.py +0 -0
  103. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_analysis_stats_invariances.py +0 -0
  104. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_axes_bin_edges.py +0 -0
  105. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_axes_grids.py +0 -0
  106. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_axes_mixed_edges.py +0 -0
  107. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_axes_mixed_edges_invariances_fast.py +0 -0
  108. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_axes_mixed_edges_invariances_slow.py +0 -0
  109. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_binning_core.py +0 -0
  110. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_binning_edges.py +0 -0
  111. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_binning_kernels.py +0 -0
  112. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_binning_photoz_builder.py +0 -0
  113. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_binning_scheme_registry.py +0 -0
  114. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_binning_specz_builder.py +0 -0
  115. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_calibration_depth.py +0 -0
  116. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_calibration_photoz_fitting.py +0 -0
  117. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_calibration_psf_selection.py +0 -0
  118. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_correlations_bin_combo_filter.py +0 -0
  119. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_correlations_filters.py +0 -0
  120. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_correlations_metrics.py +0 -0
  121. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_correlations_scores.py +0 -0
  122. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_correlations_topology.py +0 -0
  123. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_functional_binning_consistency.py +0 -0
  124. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_nz_luminosity_function_distribution.py +0 -0
  125. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_nz_models.py +0 -0
  126. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_nz_registry.py +0 -0
  127. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_nz_sampling.py +0 -0
  128. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_predefined_api_consistency.py +0 -0
  129. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_public_api.py +0 -0
  130. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_style_colors.py +0 -0
  131. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_surveys_config_utils.py +0 -0
  132. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_surveys_population_stats.py +0 -0
  133. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_surveys_sky.py +0 -0
  134. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_surveys_survey_presets.py +0 -0
  135. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_surveys_tomography.py +0 -0
  136. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_tomography_builder.py +0 -0
  137. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_tomography_core.py +0 -0
  138. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_tomography_metadata_normalization.py +0 -0
  139. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_tomography_predefined.py +0 -0
  140. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_tomography_specs.py +0 -0
  141. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_utils_broadcasting.py +0 -0
  142. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_utils_io.py +0 -0
  143. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_utils_metadata.py +0 -0
  144. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_utils_metadata_arrays.py +0 -0
  145. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_utils_metadata_extended.py +0 -0
  146. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_utils_normalization.py +0 -0
  147. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_utils_pairwise_metrics.py +0 -0
  148. {pybinny-2.2.0 → pybinny-2.3.0}/tests/test_utils_relations.py +0 -0
  149. {pybinny-2.2.0 → pybinny-2.3.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.2.0
3
+ Version: 2.3.0
4
4
  Summary: Flexible tomographic binning algorithms for cosmology.
5
5
  Author-email: Nikolina Sarcevic <nikolina.sarcevic@gmail.com>
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pybinny"
3
- version = "2.2.0"
3
+ version = "2.3.0"
4
4
  description = "Flexible tomographic binning algorithms for cosmology."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
@@ -94,7 +94,7 @@ where = ["src"]
94
94
  ]
95
95
 
96
96
  [tool.bumpversion]
97
- current_version = "2.2.0"
97
+ current_version = "2.3.0"
98
98
  commit = true
99
99
  tag = true
100
100
 
@@ -27,6 +27,7 @@ from binny.binning.edges import (
27
27
  from binny.binning.photoz import (
28
28
  photoz_assignment,
29
29
  photoz_assignment_probability,
30
+ photoz_probability_density,
30
31
  true_redshift_distribution,
31
32
  )
32
33
  from binny.binning.scheme_registry import (
@@ -39,6 +40,7 @@ from binny.binning.specz import (
39
40
  build_specz_response_matrix,
40
41
  specz_assignment,
41
42
  specz_gaussian_response_matrix,
43
+ specz_probability_density,
42
44
  )
43
45
  from binny.utils.io import load_binning_recipe
44
46
 
@@ -62,6 +64,7 @@ __all__ = [
62
64
  "mixed_edges_from_segments",
63
65
  "photoz_assignment",
64
66
  "photoz_assignment_probability",
67
+ "photoz_probability_density",
65
68
  "power_edges",
66
69
  "register_binning_scheme",
67
70
  "resolve_bin_edges",
@@ -69,6 +72,7 @@ __all__ = [
69
72
  "sinh_edges",
70
73
  "specz_assignment",
71
74
  "specz_gaussian_response_matrix",
75
+ "specz_probability_density",
72
76
  "specz_selection_in_bin",
73
77
  "true_redshift_distribution",
74
78
  "validate_bin_edges",
@@ -1,4 +1,4 @@
1
- """Photometric-redshift tomographic assignment probabilities."""
1
+ """Photometric-redshift probability densities and assignment probabilities."""
2
2
 
3
3
  from __future__ import annotations
4
4
 
@@ -14,6 +14,7 @@ __all__ = [
14
14
  "true_redshift_distribution",
15
15
  "photoz_assignment",
16
16
  "photoz_assignment_probability",
17
+ "photoz_probability_density",
17
18
  ]
18
19
 
19
20
 
@@ -75,6 +76,92 @@ def _broadcast_photoz_params(
75
76
  ]
76
77
 
77
78
 
79
+ def photoz_probability_density(
80
+ z: FloatArray,
81
+ z_ph: FloatArray,
82
+ scatter_scale: float,
83
+ mean_offset: float,
84
+ *,
85
+ mean_scale: float = 1.0,
86
+ outlier_frac: float = 0.0,
87
+ outlier_scatter_scale: float | None = None,
88
+ outlier_mean_offset: float = 0.0,
89
+ outlier_mean_scale: float = 1.0,
90
+ ) -> FloatArray:
91
+ """Evaluate the conditional photometric-redshift probability density.
92
+
93
+ The density is modeled as a Gaussian core with an optional Gaussian
94
+ outlier component. True and photometric redshifts follow NumPy
95
+ broadcasting rules.
96
+
97
+ Args:
98
+ z: True-redshift values.
99
+ z_ph: Photometric-redshift values.
100
+ scatter_scale: Core Gaussian scatter scale.
101
+ mean_offset: Core Gaussian mean offset.
102
+ mean_scale: Core Gaussian mean scale.
103
+ outlier_frac: Outlier mixture fraction.
104
+ outlier_scatter_scale: Outlier Gaussian scatter scale.
105
+ outlier_mean_offset: Outlier Gaussian mean offset.
106
+ outlier_mean_scale: Outlier Gaussian mean scale.
107
+
108
+ Returns:
109
+ Conditional probability density with the broadcast shape of
110
+ the true and photometric redshift inputs.
111
+
112
+ Raises:
113
+ ValueError: If the photo-z parameters are invalid or an active
114
+ Gaussian component has zero scatter.
115
+ """
116
+ z_arr = np.asarray(z, dtype=float)
117
+ z_ph_arr = np.asarray(z_ph, dtype=float)
118
+
119
+ if not (0.0 <= outlier_frac <= 1.0):
120
+ raise ValueError("outlier_frac must lie in [0, 1].")
121
+
122
+ if mean_scale <= 0.0:
123
+ raise ValueError("mean_scale must be > 0.")
124
+
125
+ if scatter_scale < 0.0:
126
+ raise ValueError("scatter_scale must be >= 0.")
127
+
128
+ if outlier_frac < 1.0 and scatter_scale == 0.0:
129
+ raise ValueError(
130
+ "scatter_scale must be > 0 for an active core density. "
131
+ "Zero scatter corresponds to a Dirac delta."
132
+ )
133
+
134
+ if outlier_frac > 0.0:
135
+ if outlier_mean_scale <= 0.0:
136
+ raise ValueError("outlier_mean_scale must be > 0.")
137
+
138
+ if outlier_scatter_scale is None:
139
+ raise ValueError("outlier_scatter_scale must be set when outlier_frac > 0.")
140
+
141
+ if outlier_scatter_scale <= 0.0:
142
+ raise ValueError(
143
+ "outlier_scatter_scale must be > 0 for an active outlier "
144
+ "density. Zero scatter corresponds to a Dirac delta."
145
+ )
146
+
147
+ density = np.zeros(np.broadcast_shapes(z_arr.shape, z_ph_arr.shape))
148
+ sqrt2pi = np.sqrt(2.0 * np.pi)
149
+
150
+ if outlier_frac < 1.0:
151
+ mu = mean_scale * z_arr - mean_offset
152
+ sigma = np.maximum(scatter_scale * (1.0 + z_arr), 1e-10)
153
+ residual = (z_ph_arr - mu) / sigma
154
+ density += (1.0 - outlier_frac) * np.exp(-0.5 * residual**2) / (sqrt2pi * sigma)
155
+
156
+ if outlier_frac > 0.0:
157
+ mu = outlier_mean_scale * z_arr - outlier_mean_offset
158
+ sigma = np.maximum(outlier_scatter_scale * (1.0 + z_arr), 1e-10)
159
+ residual = (z_ph_arr - mu) / sigma
160
+ density += outlier_frac * np.exp(-0.5 * residual**2) / (sqrt2pi * sigma)
161
+
162
+ return density
163
+
164
+
78
165
  def photoz_assignment_probability(
79
166
  z: FloatArray,
80
167
  bin_min: float,
@@ -15,7 +15,7 @@ from binny.binning.assignments import (
15
15
  )
16
16
  from binny.binning.edges import validate_bin_edges
17
17
  from binny.utils.broadcasting import as_per_bin
18
- from binny.utils.types import FloatArray1D, FloatArray2D
18
+ from binny.utils.types import FloatArray, FloatArray1D, FloatArray2D
19
19
  from binny.utils.validators import (
20
20
  validate_n_bins,
21
21
  validate_response_matrix,
@@ -26,6 +26,7 @@ __all__ = [
26
26
  "apply_response_matrix",
27
27
  "specz_assignment",
28
28
  "specz_gaussian_response_matrix",
29
+ "specz_probability_density",
29
30
  ]
30
31
 
31
32
 
@@ -235,6 +236,86 @@ def _gaussian_bin_probability(
235
236
  return float(ndtr(upper) - ndtr(lower))
236
237
 
237
238
 
239
+ def specz_probability_density(
240
+ z: FloatArray,
241
+ z_sp: FloatArray,
242
+ *,
243
+ specz_scatter: float | None = None,
244
+ model: Literal["sigma0_plus_sigma1_1pz"] = "sigma0_plus_sigma1_1pz",
245
+ sigma0: float = 0.0,
246
+ sigma1: float = 0.0,
247
+ ) -> FloatArray:
248
+ """Evaluate the conditional spectroscopic-redshift probability density.
249
+
250
+ The measurement model is an unbiased Gaussian with constant or
251
+ redshift-dependent scatter. True and spectroscopic redshifts follow
252
+ NumPy broadcasting rules.
253
+
254
+ The density describes measurement scatter only, independently of
255
+ completeness and catastrophic bin reassignment.
256
+
257
+ Args:
258
+ z: True-redshift values.
259
+ z_sp: Spectroscopic-redshift values.
260
+ specz_scatter: Constant measurement scatter.
261
+ model: Scatter parameterization used when specz_scatter is None.
262
+ sigma0: Additive scatter component.
263
+ sigma1: Redshift-dependent scatter component.
264
+
265
+ Returns:
266
+ Conditional probability density with the broadcast shape of
267
+ the true and spectroscopic redshift inputs.
268
+
269
+ Raises:
270
+ ValueError: If scatter settings are invalid or the measurement
271
+ scatter is zero at any supplied true redshift.
272
+ """
273
+ z_arr = np.asarray(z, dtype=float)
274
+ z_sp_arr = np.asarray(z_sp, dtype=float)
275
+
276
+ if specz_scatter is not None and (sigma0 != 0.0 or sigma1 != 0.0):
277
+ raise ValueError("Provide either specz_scatter OR sigma0/sigma1, not both.")
278
+
279
+ if not np.all(np.isfinite([sigma0, sigma1])):
280
+ raise ValueError("sigma0 and sigma1 must be finite.")
281
+
282
+ if sigma0 < 0.0 or sigma1 < 0.0:
283
+ raise ValueError("sigma0 and sigma1 must be >= 0.")
284
+
285
+ if specz_scatter is not None:
286
+ if not np.isfinite(specz_scatter):
287
+ raise ValueError("specz_scatter must be finite.")
288
+
289
+ if specz_scatter < 0.0:
290
+ raise ValueError("specz_scatter must be >= 0.")
291
+
292
+ sigma = specz_scatter
293
+ else:
294
+ if model != "sigma0_plus_sigma1_1pz":
295
+ raise ValueError("model must be 'sigma0_plus_sigma1_1pz'.")
296
+
297
+ sigma = sigma0 + sigma1 * (1.0 + z_arr)
298
+
299
+ if not np.all(np.isfinite(sigma)):
300
+ raise ValueError("Measurement scatter must be finite.")
301
+
302
+ if np.any(np.asarray(sigma) < 0.0):
303
+ raise ValueError("Measurement scatter must be non-negative.")
304
+
305
+ if np.any(np.asarray(sigma) == 0.0):
306
+ raise ValueError(
307
+ "Measurement scatter must be > 0 for a probability density. "
308
+ "Zero scatter corresponds to a Dirac delta."
309
+ )
310
+
311
+ residual = (z_sp_arr - z_arr) / sigma
312
+
313
+ return np.asarray(
314
+ np.exp(-0.5 * residual**2) / (np.sqrt(2.0 * np.pi) * sigma),
315
+ dtype=float,
316
+ )
317
+
318
+
238
319
  def specz_gaussian_response_matrix(
239
320
  *,
240
321
  z_arr: FloatArray1D,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pybinny
3
- Version: 2.2.0
3
+ Version: 2.3.0
4
4
  Summary: Flexible tomographic binning algorithms for cosmology.
5
5
  Author-email: Nikolina Sarcevic <nikolina.sarcevic@gmail.com>
6
6
  License: MIT