Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/572/dataops redshift #596

Merged
merged 38 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
ef88d5a
rename z_source->z_src
m-aguena May 23, 2023
f2522d9
rm internal computation of sigma_c from compute_tangential_and_cross_…
m-aguena May 23, 2023
d7ee778
rm unnecessary use_pdz args in GalaxyCluster
m-aguena May 24, 2023
7c65958
update examples/demo_compute_deltasigma_weights.ipynb
m-aguena May 24, 2023
78a9498
create _validate_data_z_src func
m-aguena May 25, 2023
e363e2e
fix merge conflicts
m-aguena May 25, 2023
5ac9cba
update compute_background_probability
m-aguena May 25, 2023
4ca0399
update docstring of compute_background_probability
m-aguena May 25, 2023
d65d30a
fix minor bug
m-aguena May 25, 2023
3834e6b
update GalaxyCluster.compute_galaxy_weights
m-aguena May 25, 2023
c9fd36a
fix import in clmm/redshift/tools.py
m-aguena May 25, 2023
f0af206
update z_src in .json files
m-aguena May 25, 2023
86673e5
update tests for new api
m-aguena May 25, 2023
4e35820
rm unused funcs
m-aguena May 25, 2023
24f21a2
update tests
m-aguena May 25, 2023
6f72adb
fix fmts
m-aguena May 25, 2023
c976981
rm commented part
m-aguena May 25, 2023
02c768e
make sigma_c=None for gamma components
m-aguena May 25, 2023
cc12a79
Merge branch 'issue/572/dataops_redshift' of github.com:LSSTDESC/CLMM…
m-aguena May 26, 2023
75ca052
rm is_deltasigma from docstring
m-aguena May 26, 2023
75675c0
update docstring
m-aguena May 26, 2023
13368e0
update docstrings
m-aguena May 26, 2023
61cf24a
fix merge conflicts
m-aguena May 26, 2023
0122f9f
force recomputation of sigma_c in GalaxyCluster when use_pdz flag is …
m-aguena May 26, 2023
bd4d6b6
separate sigma_c and sigma_c_eff in galcat
m-aguena May 26, 2023
200a6aa
update examples/demo_compute_deltasigma_weights.ipynb
m-aguena May 26, 2023
2ee9fc4
fix for type(sigma_c)=list
m-aguena May 26, 2023
87da6be
pylint clmm/dataops/__init__.py
m-aguena May 26, 2023
ff8c474
fix docstring
m-aguena Jul 12, 2023
426b799
add is_deltasigma back to dataops.compute_tangential_and_cross_compon…
m-aguena Jul 13, 2023
5b71380
update tests
m-aguena Jul 13, 2023
36d2858
update fmt
m-aguena Jul 13, 2023
37df96e
change args of _validate_is_deltasigma_sigma_c
m-aguena Jul 13, 2023
33a7f94
fix arg order
m-aguena Jul 13, 2023
d631f4e
fix err msg
m-aguena Aug 29, 2023
22d90d2
fix notebook
m-aguena Aug 29, 2023
0abab12
Merge branch 'main' into issue/572/dataops_redshift
m-aguena Oct 16, 2023
783efe9
Update version to 1.10.0
m-aguena Oct 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
223 changes: 62 additions & 161 deletions clmm/dataops/__init__.py

Large diffs are not rendered by default.

70 changes: 37 additions & 33 deletions clmm/galaxycluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def _repr_html_(self):
f"<br>{self.galcat._html_table()}"
)

def add_critical_surface_density(self, cosmo, use_pdz=False):
def add_critical_surface_density(self, cosmo, use_pdz=False, force=False):
r"""Computes the critical surface density for each galaxy in `galcat`.
It only runs if input cosmo != galcat cosmo or if `sigma_c` not in `galcat`.

Expand All @@ -128,14 +128,21 @@ def add_critical_surface_density(self, cosmo, use_pdz=False):
`sigma_c` is computed as 1/<1/Sigma_crit>, where the average is performed using
the individual galaxy redshift pdf. In that case, the `galcat` table should have
pzbins` and `pzpdf` columns.
force : bool
Force recomputation of sigma_c.

Returns
-------
None
"""
if cosmo is None:
raise TypeError("To compute Sigma_crit, please provide a cosmology")
if cosmo.get_desc() != self.galcat.meta["cosmo"] or "sigma_c" not in self.galcat.columns:
sigmac_colname = "sigma_c_eff" if use_pdz else "sigma_c"
if (
cosmo.get_desc() != self.galcat.meta["cosmo"]
or sigmac_colname not in self.galcat.columns
or force
):
if self.z is None:
raise TypeError("Cluster's redshift is None. Cannot compute Sigma_crit")
if not use_pdz and "z" not in self.galcat.columns:
Expand All @@ -149,19 +156,18 @@ def add_critical_surface_density(self, cosmo, use_pdz=False):
)

self.galcat.update_cosmo(cosmo, overwrite=True)
if use_pdz is False:
self.galcat["sigma_c"] = cosmo.eval_sigma_crit(self.z, self.galcat["z"])
self.galcat.meta["sigmac_type"] = "standard"
if not use_pdz:
self.galcat[sigmac_colname] = cosmo.eval_sigma_crit(self.z, self.galcat["z"])
else:
zdata = self._get_input_galdata({"pzpdf": "pzpdf", "pzbins": "pzbins"})
self.galcat["sigma_c"] = compute_critical_surface_density_eff(
self.galcat[sigmac_colname] = compute_critical_surface_density_eff(
cosmo=cosmo,
z_cluster=self.z,
pzbins=zdata["pzbins"],
pzpdf=zdata["pzpdf"],
validate_input=self.validate_input,
)
self.galcat.meta["sigmac_type"] = "effective"
return sigmac_colname

def _get_input_galdata(self, col_dict):
"""
Expand Down Expand Up @@ -211,15 +217,14 @@ def compute_tangential_and_cross_components(
r"""Adds a tangential- and cross- components for shear or ellipticity to self

Calls `clmm.dataops.compute_tangential_and_cross_components` with the following arguments:
ra_lens: cluster Ra
dec_lens: cluster Dec
ra_lens: `cluster` Ra
dec_lens: `cluster` Dec
ra_source: `galcat` Ra
dec_source: `galcat` Dec
shear1: `galcat` shape_component1
shear2: `galcat` shape_component2
geometry: `input` geometry
is_deltasigma: `input` is_deltasigma
sigma_c: `galcat` sigma_c | None

Parameters
----------
Expand Down Expand Up @@ -258,33 +263,34 @@ def compute_tangential_and_cross_components(
Cross shear (or assimilated quantity) for each source galaxy
"""
# Check is all the required data is available
cols = self._get_input_galdata(
{
"ra_source": "ra",
"dec_source": "dec",
"shear1": shape_component1,
"shear2": shape_component2,
}
)

col_dict = {
"ra_source": "ra",
"dec_source": "dec",
"shear1": shape_component1,
"shear2": shape_component2,
}
if is_deltasigma:
self.add_critical_surface_density(cosmo, use_pdz=use_pdz)
cols["sigma_c"] = self.galcat["sigma_c"]
sigmac_colname = self.add_critical_surface_density(cosmo, use_pdz=use_pdz)
col_dict.update({"sigma_c": sigmac_colname})
cols = self._get_input_galdata(col_dict)

# compute shears
angsep, tangential_comp, cross_comp = compute_tangential_and_cross_components(
is_deltasigma=is_deltasigma,
ra_lens=self.ra,
dec_lens=self.dec,
geometry=geometry,
is_deltasigma=is_deltasigma,
m-aguena marked this conversation as resolved.
Show resolved Hide resolved
use_pdz=use_pdz,
validate_input=self.validate_input,
**cols,
)
if add:
self.galcat["theta"] = angsep
self.galcat[tan_component] = tangential_comp
self.galcat[cross_component] = cross_comp
if is_deltasigma:
sigmac_type = "effective" if use_pdz else "standard"
self.galcat.meta[f"{tan_component}_sigmac_type"] = sigmac_type
self.galcat.meta[f"{cross_component}_sigmac_type"] = sigmac_type
return angsep, tangential_comp, cross_comp

def compute_background_probability(
Expand All @@ -308,7 +314,7 @@ def compute_background_probability(
Probability for being a background galaxy
"""
cols = self._get_input_galdata(
{"pzpdf": "pzpdf", "pzbins": "pzbins"} if use_pdz else {"z_source": "z"}
{"pzpdf": "pzpdf", "pzbins": "pzbins"} if use_pdz else {"z_src": "z"}
)
p_background = compute_background_probability(
self.z, use_pdz=use_pdz, validate_input=self.validate_input, **cols
Expand Down Expand Up @@ -369,12 +375,9 @@ def compute_galaxy_weights(
"""
# input cols
col_dict = {}
if use_pdz:
col_dict.update({"pzpdf": "pzpdf", "pzbins": "pzbins"})
if is_deltasigma:
if "sigma_c" not in self.galcat.columns:
self.add_critical_surface_density(cosmo, use_pdz=use_pdz)
col_dict.update({"z_source": "z", "sigma_c": "sigma_c"})
sigmac_colname = self.add_critical_surface_density(cosmo, use_pdz=use_pdz)
col_dict.update({"sigma_c": sigmac_colname})
if use_shape_noise:
col_dict.update(
{
Expand All @@ -393,17 +396,18 @@ def compute_galaxy_weights(

# computes weights
w_ls = compute_galaxy_weights(
self.z,
cosmo,
use_pdz=use_pdz,
is_deltasigma=is_deltasigma,
use_shape_noise=use_shape_noise,
use_shape_error=use_shape_error,
is_deltasigma=is_deltasigma,
validate_input=self.validate_input,
**cols,
)
if add:
self.galcat[weight_name] = w_ls
if is_deltasigma:
self.galcat.meta[f"{weight_name}_sigmac_type"] = (
"effective" if use_pdz else "standard"
)
return w_ls

def draw_gal_z_from_pdz(self, zcol_out="z", overwrite=False, nobj=1, xmin=None, xmax=None):
Expand Down
4 changes: 2 additions & 2 deletions clmm/support/mock_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def _generate_galaxy_catalog(
mdelta=cluster_m,
cdelta=cluster_c,
z_cluster=cluster_z,
z_source=galaxy_catalog["ztrue"],
z_src=galaxy_catalog["ztrue"],
cosmo=cosmo,
delta_mdef=delta_so,
halo_profile_model=halo_profile_model,
Expand All @@ -407,7 +407,7 @@ def _generate_galaxy_catalog(
mdelta=cluster_m,
cdelta=cluster_c,
z_cluster=cluster_z,
z_source=galaxy_catalog["ztrue"],
z_src=galaxy_catalog["ztrue"],
cosmo=cosmo,
delta_mdef=delta_so,
halo_profile_model=halo_profile_model,
Expand Down
Loading