pybinny 2.1.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.
- {pybinny-2.1.0/src/pybinny.egg-info → pybinny-2.3.0}/PKG-INFO +1 -1
- {pybinny-2.1.0 → pybinny-2.3.0}/pyproject.toml +2 -2
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/analysis/__init__.py +4 -4
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/analysis/stats.py +196 -131
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/binning/__init__.py +4 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/binning/photoz.py +88 -1
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/binning/specz.py +82 -1
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/surveys/__init__.py +2 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/surveys/configs/desi_survey_specs.yaml +4 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/surveys/configs/euclid_survey_specs.yaml +2 -1
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/surveys/configs/lsst_survey_specs.yaml +1 -0
- pybinny-2.3.0/src/binny/surveys/survey_presets.py +387 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/utils/metadata.py +5 -23
- {pybinny-2.1.0 → pybinny-2.3.0/src/pybinny.egg-info}/PKG-INFO +1 -1
- {pybinny-2.1.0 → pybinny-2.3.0}/src/pybinny.egg-info/SOURCES.txt +1 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_analysis_stats.py +573 -85
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_analysis_stats_invariances.py +38 -33
- pybinny-2.3.0/tests/test_binning_photoz.py +456 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_binning_specz.py +188 -10
- pybinny-2.3.0/tests/test_surveys_population_stats.py +348 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_surveys_tomography.py +17 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_utils_metadata.py +0 -4
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_utils_metadata_extended.py +0 -6
- pybinny-2.1.0/src/binny/surveys/survey_presets.py +0 -177
- pybinny-2.1.0/tests/test_binning_photoz.py +0 -217
- {pybinny-2.1.0 → pybinny-2.3.0}/LICENSE +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/README.md +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/setup.cfg +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/__init__.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/analysis/combinations.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/analysis/comparison.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/analysis/composition.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/axes/__init__.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/axes/bin_edges.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/axes/grids.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/axes/mixed_edges.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/binning/assignments.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/binning/core.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/binning/edges.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/binning/scheme_registry.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/binning/specs.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/calibration/__init__.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/calibration/depth.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/calibration/photoz_fitting.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/calibration/psf_selection.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/correlations/__init__.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/correlations/bin_combo_filter.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/correlations/filters.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/correlations/metrics.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/correlations/scores.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/correlations/topology.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/cosmology/__init__.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/cosmology/ccl_wrappers.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/nz/__init__.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/nz/luminosity_function_distribution.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/nz/models.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/nz/registry.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/nz/sampling.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/style/__init__.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/style/colors.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/surveys/config_utils.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/surveys/configs/__init__.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/surveys/configs/des_survey_specs.yaml +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/surveys/configs/example_full_photoz.yaml +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/surveys/configs/example_full_specz.yaml +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/surveys/configs/example_generalized_photoz.yaml +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/surveys/configs/example_minimal_photoz.yaml +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/surveys/configs/example_minimal_specz.yaml +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/surveys/configs/example_tabulated.yaml +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/surveys/configs/mock_predefined_config.yaml +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/surveys/configs/roman_survey_specs.yaml +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/surveys/data/__init__.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/surveys/data/desi_bgs_sgc_nz.txt +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/surveys/data/desi_elg_nz.txt +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/surveys/data/desi_lrg_nz.txt +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/surveys/data/desi_lrg_sgc_nz.txt +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/surveys/data/example_tabulated_nz.txt +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/surveys/data/lsst_dp2_nz_degraded_r24p5_masked.txt +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/surveys/data/mock_predefined_bins.txt +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/surveys/data/roman_n_eff20.nz +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/surveys/data/roman_n_eff30.nz +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/surveys/data/roman_n_eff40.nz +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/surveys/data/roman_n_eff50.nz +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/surveys/scripts/fit_roman_smail.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/surveys/sky.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/tomography/__init__.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/tomography/builders.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/tomography/core.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/tomography/predefined.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/tomography/specs.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/utils/__init__.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/utils/broadcasting.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/utils/io.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/utils/normalization.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/utils/pairwise_metrics.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/utils/relations.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/utils/types.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/binny/utils/validators.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/pybinny.egg-info/dependency_links.txt +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/pybinny.egg-info/requires.txt +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/src/pybinny.egg-info/top_level.txt +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_analysis_combinations.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_analysis_comparison.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_analysis_comparison_helpers.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_analysis_comparison_similarity.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_analysis_composition.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_analysis_stats_center_invariance_fast.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_analysis_stats_center_invariance_slow.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_axes_bin_edges.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_axes_grids.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_axes_mixed_edges.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_axes_mixed_edges_invariances_fast.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_axes_mixed_edges_invariances_slow.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_binning_core.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_binning_edges.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_binning_kernels.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_binning_photoz_builder.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_binning_scheme_registry.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_binning_specz_builder.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_calibration_depth.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_calibration_photoz_fitting.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_calibration_psf_selection.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_correlations_bin_combo_filter.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_correlations_filters.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_correlations_metrics.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_correlations_scores.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_correlations_topology.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_functional_binning_consistency.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_nz_luminosity_function_distribution.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_nz_models.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_nz_registry.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_nz_sampling.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_predefined_api_consistency.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_public_api.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_style_colors.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_surveys_config_utils.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_surveys_sky.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_surveys_survey_presets.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_tomography_builder.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_tomography_core.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_tomography_metadata_normalization.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_tomography_predefined.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_tomography_specs.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_utils_broadcasting.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_utils_io.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_utils_metadata_arrays.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_utils_normalization.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_utils_pairwise_metrics.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_utils_relations.py +0 -0
- {pybinny-2.1.0 → pybinny-2.3.0}/tests/test_utils_validators.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "pybinny"
|
|
3
|
-
version = "2.
|
|
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.
|
|
97
|
+
current_version = "2.3.0"
|
|
98
98
|
commit = true
|
|
99
99
|
tag = true
|
|
100
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
|
-
"
|
|
89
|
-
"
|
|
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
|
-
"
|
|
35
|
-
"
|
|
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(
|
|
415
|
-
|
|
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
|
-
|
|
427
|
-
|
|
445
|
+
if not frac:
|
|
446
|
+
raise ValueError("Population fractions must not be empty.")
|
|
428
447
|
|
|
429
|
-
|
|
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
|
-
|
|
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
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
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
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
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
|
-
|
|
448
|
-
|
|
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
|
-
|
|
478
|
+
Effective population counts per bin.
|
|
452
479
|
|
|
453
480
|
Raises:
|
|
454
|
-
ValueError: If
|
|
455
|
-
ValueError: If any density is negative.
|
|
481
|
+
ValueError: If densities or survey area are invalid.
|
|
456
482
|
"""
|
|
457
|
-
if
|
|
458
|
-
raise ValueError("
|
|
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
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
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
|
|
499
|
+
def angular_density_per_bin(
|
|
470
500
|
metadata: Mapping[str, Any],
|
|
471
|
-
|
|
501
|
+
angular_density_total: float,
|
|
502
|
+
*,
|
|
503
|
+
fraction_mode: str,
|
|
472
504
|
) -> dict[int, float]:
|
|
473
|
-
"""
|
|
474
|
-
effective density..
|
|
505
|
+
"""Allocate total angular number density across tomographic bins.
|
|
475
506
|
|
|
476
507
|
Args:
|
|
477
|
-
metadata: Tomography metadata containing
|
|
478
|
-
|
|
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
|
-
|
|
514
|
+
Per-bin angular densities in galaxies per square arcminute.
|
|
482
515
|
|
|
483
516
|
Raises:
|
|
484
|
-
ValueError: If
|
|
485
|
-
ValueError: If metadata does not contain valid fractions.
|
|
517
|
+
ValueError: If the density or population fractions are invalid.
|
|
486
518
|
"""
|
|
487
|
-
if
|
|
488
|
-
raise ValueError("
|
|
489
|
-
|
|
490
|
-
|
|
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
|
-
|
|
611
|
-
|
|
612
|
-
|
|
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)] =
|
|
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
|
-
|
|
624
|
-
|
|
625
|
-
|
|
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
|
-
|
|
684
|
+
comoving_density: float | Mapping[int, float] | None = None,
|
|
685
|
+
decimal_places: int | None = None,
|
|
631
686
|
) -> dict[str, Any]:
|
|
632
|
-
"""Compute population
|
|
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
|
-
|
|
644
|
-
|
|
645
|
-
|
|
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
|
|
652
|
-
metadata: Tomography metadata containing
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
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
|
-
|
|
671
|
-
|
|
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
|
|
677
|
-
|
|
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
|
|
686
|
-
|
|
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
|
|
690
|
-
raise ValueError("
|
|
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
|
-
|
|
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
|
-
|
|
695
|
-
|
|
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
|
-
|
|
701
|
-
|
|
702
|
-
|
|
729
|
+
fractions = galaxy_fraction_per_bin(
|
|
730
|
+
metadata,
|
|
731
|
+
fraction_mode=fraction_mode,
|
|
732
|
+
)
|
|
703
733
|
|
|
704
|
-
|
|
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
|
-
|
|
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
|
-
|
|
717
|
-
|
|
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["
|
|
722
|
-
out["density_unit"] = "h^3 Mpc^-3"
|
|
782
|
+
out["comoving_density_per_bin"] = comoving_density_per_bin(counts, volumes)
|
|
723
783
|
|
|
724
|
-
if
|
|
725
|
-
|
|
784
|
+
if angular_density_total is not None:
|
|
785
|
+
densities = angular_density_per_bin(
|
|
726
786
|
metadata,
|
|
727
|
-
|
|
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
|
-
|
|
732
|
-
|
|
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
|
|
735
|
-
out["
|
|
736
|
-
out["
|
|
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
|
|
|
@@ -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
|
|
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,
|