Implementation of corrections for projection effects [version:1.0.11]#88
Implementation of corrections for projection effects [version:1.0.11]#88eduardojsbarroso wants to merge 19 commits into
Conversation
Add Costanzi19 projection model and binned_grid skeleton
…py. Add function comments. Clean the code by isort and black
Implement Costanzi binned and unbinned projection-effect probability calculations for Gaussian richness-mass relations. Add recipe support for projection-effect grid construction and cache handling. Update tests for binned probabilities, unbinned PDFs, mass-redshift meshing, and projection recipe grid construction.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #88 +/- ##
==========================================
- Coverage 98.41% 97.99% -0.42%
==========================================
Files 28 32 +4
Lines 1826 2341 +515
Branches 60 89 +29
==========================================
+ Hits 1797 2294 +497
- Misses 29 47 +18 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
… models
This update responds to review feedback by removing the combined
projection+mass-richness classes (CostanziBinned and CostanziUnBinned) from the PR.
The projection model is now kept as a standalone richness-bias kernel, while the full integration over rich_tru, mass, redshift, purity, and observed-richness bins is left for a future recipe-level PR.
Main changes relative to LSSTDESC/crow main:
- Add crow.cluster_modules.projection_effects.
- Add richness_bias.py with CostanziRichnessBias:
- P(rich_obs | rich_tru)
- observed-richness-bin integral at fixed rich_tru (this is useful for calculating the number counts over a observed richness bin?)
- default Costanzi projection parameters (this can be removed in the future)
- Add lensing_bias.py with CostanziLensingBias / bsel:
- multiplicative post-stacking DeltaSigma correction
- explicit radius handling: comoving Mpc/h or physical Mpc converted using z_ref and h
- Wire optional lensing_profile_correction into binned recipes:
- applied after stacked lensing integration
- restricted to DeltaSigma
- raises for reduced shear
- Add projection tutorial notebook.
- Add tests for:
- Costanzi richness-bias probability shape, positivity, finiteness
- observed-richness-bin integration at fixed rich_tru
- parameter validation
- lensing-bias radius conversion and shape validation
- exact/grid recipe DeltaSigma correction behavior
- reduced-shear rejection
- Remove the earlier CostanziBinned / CostanziUnBinned classes.
- Remove the temporary grid projection-cache integration from this PR.
| arrayLike = int | float | npt.ArrayLike | ||
|
|
||
|
|
||
| def _as_1d_array(name: str, value: arrayLike) -> npt.NDArray[np.floating]: |
There was a problem hiding this comment.
I think we don't need this function. All that it is doing is calling np.atleast_1d with dtype=float.
It would be easier if all the functions just take numpy array as inputs, like the other codes.
Check: https://github.com/LSSTDESC/crow/blob/main/crow/cluster_modules/mass_proxy/murata.py
So ideally, change every function here that takes arrayLike to take npt.NDArray[np.float64]
| return array | ||
|
|
||
|
|
||
| def _selection_parameter_arrays( |
There was a problem hiding this comment.
If you changed all the inputs to numpy array, we dont need this function anymore as well. It is just calling the as_1d_array and checking if they have the same length, which we can do later
| return parameters | ||
|
|
||
|
|
||
| def bsel( |
There was a problem hiding this comment.
Is there an specific reason for this function to be outside the class?
There was a problem hiding this comment.
Have moved this inside the module.
| if np.any(Rcmv <= 0.0): | ||
| raise ValueError("Rcmv must contain only positive radii.") | ||
|
|
||
| A_sel, alpha_sel, beta_sel, gamma_sel, R0_sel = _selection_parameter_arrays( |
There was a problem hiding this comment.
Here can just be now a test to see if the parameters have the same length
|
|
||
|
|
||
| def bsel( | ||
| Rcmv: arrayLike, |
There was a problem hiding this comment.
If this function is in the class, and you will check my comment about parameters, it would only take Rcmv as input to run
| ) * 2.0 # (n_obs, n_tru,) | ||
| term1 = ( | ||
| (1.0 - fmsk) * fprj * tau + fmsk * fprj / rich_tru | ||
| ) * CostanziRichnessBias._exp_times_erfc(log_exptau, erfc_arg1) |
There was a problem hiding this comment.
self._exp_times_erfc
There was a problem hiding this comment.
I think we can still use staticmethod for this function? Because we make the probability and its integral (over rich_obs) instance methods already?
| fmsk | ||
| * fprj | ||
| / rich_tru | ||
| * CostanziRichnessBias._exp_times_erfc( |
There was a problem hiding this comment.
self._exp_times_erfc
|
|
||
| @staticmethod | ||
| def prob_richobs_at_richtru( | ||
| rich_obs: arrayLike, |
There was a problem hiding this comment.
Make the input ndarray
There was a problem hiding this comment.
No wrappers for arrayLike now.
|
|
||
| @staticmethod | ||
| def Sprob_at_richtru( | ||
| rich_obs_eds: arrayLike, |
There was a problem hiding this comment.
NDArray and not static method anymore
| rich_obs_digit = np.digitize(rich_obs_bins, bins=rich_obs_eds) | ||
|
|
||
| # calc | ||
| prob_obs = CostanziRichnessBias.prob_richobs_at_richtru( |
There was a problem hiding this comment.
self.prob_richobs_at_richtru
…tion directly to bsel. Use default Parameters to store and unpack parametrs. Corresponding tests are changed to reflect the changes. Only modify for the lensing bias module for now.
…as instance methods. Users are required to provide projection effect parameters when creating an object. Otherwise, it will use the default costanzi parameters (which can be changed later). Use PArameters to store and unpack parameters. Tests are changed to reflect the modifications. Use the variable name fractional_sig_pure instead of sig_pure.
- CostanziRichnessBias keeps its calibration parameters inside the object via Parameters. - Array conversion wrappers and the arrayLike alias are removed. Use direct npt.ArrayLike. - Lensing bias uses explicit radial_units with clear behavior for Mpc/h or Mpc - Restore all recipes. - Tests were cleaned.
- Removed the combined binned Costanzi implementation and kept the projection model as P(lambda_obs | lambda_true). - Updated projection-effect inputs to use npt.NDArray[np.float64]. - Added RICHNESS_BIAS_DEFAULT_PARAMETERS and LENSING_BIAS_DEFAULT_PARAMETERS. - Updated both classes to initialize self.parameters from defaults, with optional constructor overrides. - Moved lensing-bias evaluation into CostanziLensingBias.bsel(). - Replaced the radius boolean with explicit radial_units. - Updated projection tests; tests/test_proj.py passes.
This PR adds support for projection effects in CROW, including a Costanzi-style projected richness model and an optional projection-induced lensing profile correction for stacked DeltaSigma predictions.
Main Changes:
crow.cluster_modules.projection_effectsmodule.CostanziBaseModel,CostanziBinned, andCostanziUnBinnedfor projected observed-richness probabilities.CostanziLensingBias/bselfor multiplicative selection-bias corrections to stacked DeltaSigma profiles.GridBinnedClusterRecipe.notebooks/run_projection.ipynb.Implementation Notes:
h.