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/438/cluster wl simple #461

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
b33bf4a
modify script to also generate mock shear profile sacc file
combet Jul 17, 2024
4f242c1
add scripts to generate deltatheta sacc data
m-aguena Jul 18, 2024
2c0dbed
Started to implement shear profile models and tests
eduardojsbarroso Sep 10, 2024
4d154d9
Add one more test for DeltaSigma object
eduardojsbarroso Sep 10, 2024
12b5413
add change
m-aguena Sep 13, 2024
b6f413f
fix conflict
m-aguena Sep 13, 2024
6d4fc3c
add draft for shear
m-aguena Sep 13, 2024
8ef9624
Added DeltaSigmaStatics for shear analysis and created examples
eduardojsbarroso Sep 23, 2024
e228fb0
Revert "add draft for shear"
eduardojsbarroso Sep 23, 2024
10fd49b
Merge branch 'issue/438/cluster_wl_simple' of https://github.com/LSST…
eduardojsbarroso Sep 23, 2024
f5f8beb
Revert "add draft for shear"
eduardojsbarroso Sep 23, 2024
bcb7808
Implemented concentration as parameter or function call
eduardojsbarroso Oct 9, 2024
3fcbb00
Merge branch 'master' into issue/438/cluster_wl_simple
eduardojsbarroso Oct 9, 2024
703b179
Added comment to ini file to be used if needed
eduardojsbarroso Oct 9, 2024
1372e3f
Added CosmoDC2 SACC file to examples
eduardojsbarroso Oct 9, 2024
162fff2
Fix typo
eduardojsbarroso Oct 9, 2024
833ba3a
Cleaned code and changed abstract method of cluste recipe
eduardojsbarroso Oct 11, 2024
41a6a0e
Running black
eduardojsbarroso Oct 11, 2024
d69a23e
More cleaning on the code
eduardojsbarroso Oct 15, 2024
51b9789
Runned black
eduardojsbarroso Oct 16, 2024
7e62c53
Running flake8
eduardojsbarroso Oct 16, 2024
c25ca5e
Ignoring dulicate code and commented old test
eduardojsbarroso Oct 16, 2024
c792d1d
Disable unable to import
eduardojsbarroso Oct 16, 2024
358c0b5
Refactored objects to avoid duplicated code
eduardojsbarroso Oct 17, 2024
80b435b
Changed abstract method variable definition
eduardojsbarroso Oct 17, 2024
46f91e0
Changed number of initiation variables for ClusterAbundance
eduardojsbarroso Oct 17, 2024
de49909
Fix function input
eduardojsbarroso Oct 17, 2024
db0edbc
Minor change
eduardojsbarroso Nov 25, 2024
8f474bf
Merge branch 'master' into issue/438/cluster_wl_simple
eduardojsbarroso Nov 25, 2024
9706a7c
Changed for new Data and Theory vectors
eduardojsbarroso Nov 25, 2024
d9736f8
Adding CLMM to requisites.
vitenti Nov 26, 2024
ea0de99
Merge branch 'master' into issue/438/cluster_wl_simple
vitenti Nov 26, 2024
9824ff7
Minor fixes
eduardojsbarroso Dec 19, 2024
49dcb86
Merge branch 'master' into issue/438/cluster_wl_simple
eduardojsbarroso Dec 19, 2024
ed705ec
Changed test
eduardojsbarroso Dec 19, 2024
7fe5229
Added CLMM to docs/environment.yml
eduardojsbarroso Dec 19, 2024
0977f6c
Improving tests
eduardojsbarroso Dec 19, 2024
60be60e
More testing
eduardojsbarroso Dec 20, 2024
e67fbd0
Run black
eduardojsbarroso Dec 20, 2024
bc93dba
Removed unecessary condition
eduardojsbarroso Dec 20, 2024
e04795d
Fix data object
eduardojsbarroso Dec 20, 2024
b6d65f8
Running black
eduardojsbarroso Dec 20, 2024
1ba148e
Black
eduardojsbarroso Dec 20, 2024
ad34b39
More testing
eduardojsbarroso Dec 20, 2024
8ba36c7
Merge branch 'master' into issue/438/cluster_wl_simple
vitenti Jan 7, 2025
55e5dd9
Merge branch 'master' into issue/438/cluster_wl_simple
eduardojsbarroso Jan 27, 2025
c9abc4b
Resolved datatype inconsistency in tests
eduardojsbarroso Jan 27, 2025
31c12e1
Run black
eduardojsbarroso Jan 27, 2025
625263b
Merge branch 'master' into issue/438/cluster_wl_simple
vitenti Feb 4, 2025
7e6e77b
Merge branch 'master' into issue/438/cluster_wl_simple
vitenti Feb 5, 2025
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
[runtime]
sampler = test
resume = T
root = ${PWD}

[default]
fatal_errors = T

[output]
filename = output_rps_2/number_counts_samples.txt
format = text
verbosity = 0

[pipeline]
modules = consistency camb firecrown_likelihood
values = ${FIRECROWN_DIR}/examples/cluster_number_counts/cluster_richness_values_deltasigma.ini
likelihoods = firecrown
quiet = T
debug = T
timing = T

[consistency]
file = ${CSL_DIR}/utility/consistency/consistency_interface.py

[camb]
file = ${CSL_DIR}/boltzmann/camb/camb_interface.py

mode = all
lmax = 2500
feedback = 0
zmin = 0.0
zmax = 1.0
nz = 100
kmin = 1e-4
kmax = 50.0
nk = 1000

[firecrown_likelihood]
;; Fix this to use an environment variable to find the files.
;; Set FIRECROWN_DIR to the base of the firecrown installation (or build, if you haven't
;; installed it)
file = ${FIRECROWN_DIR}/firecrown/connector/cosmosis/likelihood.py
likelihood_source = ${FIRECROWN_DIR}/examples/cluster_number_counts/cluster_redshift_richness_deltasigma.py
sampling_parameters_sections = firecrown_number_counts
use_cluster_counts = True
use_mean_log_mass = True
use_mean_deltasigma = True

[test]
fatal_errors = T
save_dir = output_counts_mean_mass

[metropolis]
samples = 1000
nsteps = 1

[emcee]
walkers = 20
samples = 4000
nsteps = 3
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
"""Likelihood factory function for cluster number counts."""

import os

import pyccl as ccl
import sacc

from firecrown.likelihood.gaussian import ConstGaussian
from firecrown.likelihood.binned_cluster_number_counts_deltasigma import (
BinnedClusterDeltaSigma,
)
from firecrown.likelihood.binned_cluster_number_counts import (
BinnedClusterNumberCounts,
)

from firecrown.likelihood.likelihood import Likelihood, NamedParameters
from firecrown.modeling_tools import ModelingTools
from firecrown.models.cluster.abundance import ClusterAbundance
from firecrown.models.cluster.deltasigma import ClusterDeltaSigma
from firecrown.models.cluster.properties import ClusterProperty
from firecrown.models.cluster.recipes.murata_binned_spec_z_deltasigma import (
MurataBinnedSpecZDeltaSigmaRecipe,
)
from firecrown.models.cluster.recipes.murata_binned_spec_z import (
MurataBinnedSpecZRecipe,
)


def get_cluster_abundance() -> ClusterAbundance:
"""Creates and returns a ClusterAbundance object."""
hmf = ccl.halos.MassFuncTinker08()
min_mass, max_mass = 13.0, 16.0
min_z, max_z = 0.2, 0.8
cluster_abundance = ClusterAbundance(min_mass, max_mass, min_z, max_z, hmf)

return cluster_abundance


def get_cluster_deltasigma() -> ClusterDeltaSigma:
"""Creates and returns a ClusterAbundance object."""
hmf = ccl.halos.MassFuncTinker08()
min_mass, max_mass = 13.0, 16.0
min_z, max_z = 0.2, 0.8
cluster_deltasigma = ClusterDeltaSigma(min_mass, max_mass, min_z, max_z, hmf)

return cluster_deltasigma


def build_likelihood(
build_parameters: NamedParameters,
) -> tuple[Likelihood, ModelingTools]:
"""Builds the likelihood for Firecrown."""
# Pull params for the likelihood from build_parameters
average_on = ClusterProperty.NONE
if build_parameters.get_bool("use_cluster_counts", True):
average_on |= ClusterProperty.COUNTS
if build_parameters.get_bool("use_mean_log_mass", True):
average_on |= ClusterProperty.MASS
if build_parameters.get_bool("use_mean_deltasigma", True):
average_on |= ClusterProperty.DELTASIGMA

survey_name = "numcosmo_simulated_redshift_richness_deltasigma"
likelihood = ConstGaussian(
[
BinnedClusterNumberCounts(
average_on, survey_name, MurataBinnedSpecZRecipe()
),
BinnedClusterDeltaSigma(
average_on, survey_name, MurataBinnedSpecZDeltaSigmaRecipe()
),
]
)

# Read in sacc data
sacc_file_nm = "cluster_redshift_richness_deltasigma_sacc_data.fits"
sacc_path = os.path.expanduser(
os.path.expandvars("${FIRECROWN_DIR}/examples/cluster_number_counts/")
)
sacc_data = sacc.Sacc.load_fits(os.path.join(sacc_path, sacc_file_nm))
likelihood.read(sacc_data)
cluster_abundance = get_cluster_abundance()
cluster_deltasigma = get_cluster_deltasigma()
modeling_tools = ModelingTools(
cluster_abundance=cluster_abundance, cluster_deltasigma=cluster_deltasigma
)

return likelihood, modeling_tools
2 changes: 1 addition & 1 deletion examples/cluster_number_counts/cluster_richness_values.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[cosmological_parameters]

; These are the only cosmological parameters being varied.
omega_c = 0.1552 0.2052 0.3552
omega_c = 0.1552 0.22 0.3552
# We are choosing to use a flat prior in sigma_8.
# To choose a float prior in A_s, remove the specification
# of a prior for sigma_8 and replace it with the
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
; Parameters and data in CosmoSIS are organized into sections
; so we can easily see what they mean.
; There is only one section in this case, called cosmological_parameters
[cosmological_parameters]

; These are the only cosmological parameters being varied.
omega_c = 0.1552 0.22 0.3552
# We are choosing to use a flat prior in sigma_8.
# To choose a float prior in A_s, remove the specification
# of a prior for sigma_8 and replace it with the
# desired range for A_s
sigma_8 = 0.7 0.800 0.9
; The following parameters are set, but not varied.
;
omega_k = 0.0
omega_b = 0.0448
tau = 0.08
n_s = 0.963
h0 = 0.71
w = -1.0
wa = 0.0

[firecrown_number_counts]
; These are the firecrown likelihood parameters.
; These parameters are used to set the richness-mass
; proxy relation using the data from cluster number counts.
;
; The following parameters can be fixed in the same way as the above
; cosmological parameters if needed.
mu_p0 = 3.19
mu_p1 = 0.8685889638
mu_p2 = -0.304
sigma_p0 = 0.33
sigma_p1 = -0.034
sigma_p2 = 0
#cluster_conc = 4.

Binary file not shown.
96 changes: 96 additions & 0 deletions examples/cluster_number_counts/gen_sacc_aux.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file declares a main, but it doesn't seem to be an actual program that does something when invoked.
Is there something missing, or should the main be removed?
If it is removed, then the shebang line can also be removed.
The documentation also says this is a notebook -- it appears some of the documentation is stale and in need of review.

Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/usr/bin/env python

"""Defines a function to generate a SACC file for cluster number counts."""

# # Cluster count-only SACC file creation
#
# This notebook examplifies the creation of a SACC file for cluster count, using
# NumCosmo facilities to simulate cluster data.

import itertools

from numcosmo_py import Nc
from numcosmo_py import Ncm

from typing import Any
import sacc


def convert_binned_profile_to_sacc(
cluster_counts,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add type hints for the function arguments, so that mypy can verify the use of this function.

mean_DeltaSigma,
covariance,
z_edges,
richness_edges,
radius_edges,
radius_centers,
area,
survey_name="numcosmo_simulated_redshift_richness",
) -> sacc.Sacc:
N_z = len(z_edges) - 1
N_richness = len(richness_edges) - 1
N_radius = len(radius_edges) - 1

# Prepare the SACC file
s_count = sacc.Sacc()
bin_z_labels = []
bin_richness_labels = []
bin_radius_labels = []

s_count.add_tracer("survey", survey_name, area)

for i, z_bin in enumerate(zip(z_edges[:-1], z_edges[1:])):
lower, upper = z_bin
bin_z_label = f"bin_z_{i}"
s_count.add_tracer("bin_z", bin_z_label, lower, upper)
bin_z_labels.append(bin_z_label)

for i, richness_bin in enumerate(zip(richness_edges[:-1], richness_edges[1:])):
lower, upper = richness_bin
bin_richness_label = f"rich_{i}"
s_count.add_tracer("bin_richness", bin_richness_label, lower, upper)
bin_richness_labels.append(bin_richness_label)

for i, (radius_lower, radius_upper, radius_center) in enumerate(
zip(radius_edges[:-1], radius_edges[1:], radius_centers)
):
bin_radius_label = f"bin_radius_{i}"
s_count.add_tracer(
"bin_radius", bin_radius_label, radius_lower, radius_upper, radius_center
)
bin_radius_labels.append(bin_radius_label)

# pylint: disable-next=no-member
type_cluster_counts = sacc.standard_types.cluster_counts
# pylint: disable-next=no-member
type_cluster_DeltaSigma = sacc.standard_types.cluster_shear

for counts, (bin_z_label, bin_richness_label) in zip(
cluster_counts.flatten(), itertools.product(bin_z_labels, bin_richness_labels)
):
s_count.add_data_point(
type_cluster_counts,
(survey_name, bin_z_label, bin_richness_label),
int(counts),
)

for profile, (bin_z_label, bin_richness_label) in zip(
mean_DeltaSigma.reshape(N_richness * N_z, N_radius),
itertools.product(bin_z_labels, bin_richness_labels),
):
for profile_value, bin_radius_label in zip(profile, bin_radius_labels):
s_count.add_data_point(
type_cluster_DeltaSigma,
(survey_name, bin_z_label, bin_richness_label, bin_radius_label),
profile_value,
)

# ### Then the add the covariance and save the file

s_count.add_covariance(covariance)
s_count.to_canonical_order()
return s_count


if __name__ == "__main__":
Ncm.cfg_init()
Loading
Loading