Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
49 changes: 46 additions & 3 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The data-vector, `cosmicshear_sacc.fits`, was computed using the `generate_cosmi

You can run this example from `cosmic_shear/` directory using the following command:
```bash
python -m blinding blind_cosmic_shear_example.yaml
smokescreen datavector --config blind_cosmic_shear_example.yaml
```

You can find a notebook example on how to run this from the command line at `notebooks/test_cosmicshear_example.ipynb`.
Expand All @@ -29,6 +29,49 @@ The datavector was also computed from the firecrown example.

You can run this example from the `supernovae/` directory using the following command:
```bash
python -m blinding blind_sn_example.yaml
smokescreen datavector --config blind_sn_example.yaml
```
You can find a notebook example on how to run this from the command line at `notebooks/test_supernova_example.ipynb`.
You can find a notebook example on how to run this from the command line at `notebooks/test_supernova_example.ipynb`.

## LSST Y1 3x2pt Example
> __:warning: Important: this folder contains the example used in the Smokescreen JOSS paper__
>
> :pushpin: The 3x2pt LSST Y1 SACC file here (`sacc_forecasting_y1_3x2pt.sacc`) was produced by Pedro H. Ribeiro ( @Arara09 ) as a part of DESC Project 314, if you intend to use this for another project, please give credit to him.

This folder contains the deterministic concealment on $(A_s, w)$-space of a LSST Y1 3x2pt sacc forecasted data vector. The shifts are determinist as this folder is a proof of concept used in the Smokescreen JOSS Paper.

The fiducial cosmology used to generate this sacc is:
```yaml
Omega_c = 0.2906682
Omega_b = 0.04575
A_s_1e9 = 1.9019
n_s = 0.9493
h0 = 0.6714
w = -3.0 -1.0 0.0
wa = 0.0
mnu = 0.1
nnu = 3.044
TCMB = 2.7255
Omega_k = 0.0
num_massive_neutrinos = 3
tau = 0.0544
```

There are two concealment smokescreen files here:
* **Blind A**: Shifts $A_s \rightarrow 2.00\times 10^{-09}$ and $w\rightarrow -1.1$
* **Blind B**: Shifts $A_s \rightarrow 1.80\times 10^{-09}$ and $w\rightarrow -0.9$

You can run these examples with:
```bash
smokescreen datavector --config conceal_lsst_y1_3x2pt_blind_[A/B].yaml
```

### Cosmosis files
The folder `lsst_3x2pt/cosmosis_ini_files` also contains the cosmosis files to reproduce the posteriors shown in the Smokescreen JOSS paper. Cosmosis will vary only these three cosmological paramters $(A_s, \Omega_{\rm cdm}, w)$ for the example.

The `.ini` files are:
* `cosmosis_lsst_3x2pt.ini`: the run without concealment.
* `cosmosis_lsst_3x2pt_blind_A.ini`: the blind A case.
* `cosmosis_lsst_3x2pt_blind_B.ini`: the blind B case.

**Please note: you may need to change the `project_dir` variable in the `.ini` files to the folder where your copy of smokescreen is located.**
95 changes: 95 additions & 0 deletions examples/lsst_3x2pt/3x2pt_likelihood.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import pathlib
from firecrown.data_functions import (
extract_all_harmonic_data,
check_two_point_consistence_harmonic,
)
from firecrown.likelihood.factories import load_sacc_data
from firecrown.likelihood import TwoPoint, TwoPointFactory
from firecrown.modeling_tools import ModelingTools, CCLCreationMode, CCLPureModeTransferFunction
from firecrown.modeling_tools import CCLFactory, PoweSpecAmplitudeParameter
from pyccl.neutrinos import NeutrinoMassSplits
from firecrown.metadata_types import TwoPointCorrelationSpace

import firecrown.likelihood.weak_lensing as wl
import firecrown.likelihood.number_counts as nc
from firecrown.likelihood.weak_lensing import PhotoZShiftFactory

from firecrown.likelihood import (
ConstGaussian,
Likelihood,
NamedParameters,
)


def build_likelihood(
build_parameters: NamedParameters,
) -> tuple[Likelihood, ModelingTools]:
"""
Docstring for build_likelihood

:param build_parameters: you should pass the following
build_parameters:
- sacc_data: path to a sacc file
- factory_yaml: a yaml file with the firecrown systematics.
"""

# load sacc data from build parameters
try:
sacc_data = build_parameters['sacc_data']
except TypeError:
sacc_data = build_parameters.data['sacc_data']

# This is a trick TXPipe uses to pass a sacc file or object
# to the likelihood. We need to check if the input is a string
if isinstance(sacc_data, (str, pathlib.Path)):
sacc_data = load_sacc_data(sacc_data)
else:
sacc_data = sacc_data.copy()

# extract the relevant metadata and check things:
two_point_cls = extract_all_harmonic_data(sacc_data)
check_two_point_consistence_harmonic(two_point_cls)

# WeakLensing systematics
ia_systematic = wl.LinearAlignmentSystematicFactory()
wl_photoz = PhotoZShiftFactory()
wl_mult_bias = wl.MultiplicativeShearBiasFactory()

wlf = wl.WeakLensingFactory(
per_bin_systematics=[wl_mult_bias, wl_photoz],
global_systematics=[ia_systematic],
)

# NumberCounts systematics
nc_photoz = PhotoZShiftFactory()
ncf = nc.NumberCountsFactory(
per_bin_systematics=[nc_photoz],
global_systematics=[],
)

all_two_point_functions = TwoPoint.from_measurement(
two_point_cls,
tp_factory=TwoPointFactory(
correlation_space=TwoPointCorrelationSpace.HARMONIC,
weak_lensing_factories=[wlf],
number_counts_factories=[ncf],
),
)

likelihood_ready = ConstGaussian.create_ready(all_two_point_functions,
sacc_data.covariance.dense)

tools = ModelingTools(ccl_factory=CCLFactory(
require_nonlinear_pk=True,
amplitude_parameter=PoweSpecAmplitudeParameter.AS,
num_neutrino_masses=None,
mass_split=NeutrinoMassSplits.EQUAL,
creation_mode=CCLCreationMode.DEFAULT,
pure_ccl_transfer_function=CCLPureModeTransferFunction.BOLTZMANN_CAMB,
use_camb_hm_sampling=False,
allow_multiple_camb_instances=False,
camb_extra_params=None,
)
)

return likelihood_ready, tools
38 changes: 38 additions & 0 deletions examples/lsst_3x2pt/conceal_lsst_y1_3x2pt_blind_A.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
path_to_sacc: "./sacc_forecasting_y1_3x2pt.sacc"
likelihood_path: "./3x2pt_likelihood.py"
output_suffix: "blind_A"
shifts_dict:
A_s: 2.00e-09
w0: -1.1
seed: 2112
shift_distribution: "flat"
systematics:
lens0_delta_z: 0.0
lens1_delta_z: 0.0
lens2_delta_z: 0.0
lens3_delta_z: 0.0
lens4_delta_z: 0.0
src0_delta_z: 0.0
src1_delta_z: 0.0
src2_delta_z: 0.0
src3_delta_z: 0.0
src4_delta_z: 0.0
src0_mult_bias: 0.0
src1_mult_bias: 0.0
src2_mult_bias: 0.0
src3_mult_bias: 0.0
src4_mult_bias: 0.0
lens0_bias: 1.2497
lens1_bias: 1.3809
lens2_bias: 1.5231
lens3_bias: 1.6716
lens4_bias: 1.8245
ia_bias: 1.0
alphaz: 0.0
z_piv: 0.62
reference_cosmology:
A_s: 1.9019e-09
Omega_c: 0.2906
# only needed if you want a different reference cosmology
# than ccl.VanillaLCDM
keep_original_sacc: true
36 changes: 36 additions & 0 deletions examples/lsst_3x2pt/conceal_lsst_y1_3x2pt_blind_B.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
path_to_sacc: "./sacc_forecasting_y1_3x2pt.sacc"
likelihood_path: "./3x2pt_likelihood.py"
output_suffix: "blind_B"
shifts_dict:
A_s: 1.80e-09
w0: -0.9
seed: 4224
shift_distribution: "flat"
systematics:
lens0_delta_z: 0.0
lens1_delta_z: 0.0
lens2_delta_z: 0.0
lens3_delta_z: 0.0
lens4_delta_z: 0.0
src0_delta_z: 0.0
src1_delta_z: 0.0
src2_delta_z: 0.0
src3_delta_z: 0.0
src4_delta_z: 0.0
src0_mult_bias: 0.0
src1_mult_bias: 0.0
src2_mult_bias: 0.0
src3_mult_bias: 0.0
src4_mult_bias: 0.0
lens0_bias: 1.2497
lens1_bias: 1.3809
lens2_bias: 1.5231
lens3_bias: 1.6716
lens4_bias: 1.8245
ia_bias: 1.0
alphaz: 0.0
z_piv: 0.62
reference_cosmology:
A_s: 1.9019e-09
Omega_c: 0.2906
keep_original_sacc: true
60 changes: 60 additions & 0 deletions examples/lsst_3x2pt/cosmosis_ini_files/cosmosis_lsst_3x2pt.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
[runtime]
verbosity = standard
root = ${PWD}
sampler = nautilus

[DEFAULT]
# You may need to change this your full path
project_dir = ${PWD}/../../

[output]
format = text
verbosity = 1
filename = output/lsst_y1_3x2pt.txt

[test]
save_dir=output/lsst_y1_3x2pt
fatal_errors=T

[nautilus]
n_live = 150
n_networks = 6
n_batch = 75
verbose = True
f_live = 0.02
n_eff = 1000
discard_exploration = True
resume = True

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

[pipeline]
modules = consistency camb firecrown_likelihood
likelihoods = firecrown
timing = F
debug = F
values = cosmosis_values.ini
priors = cosmosis_priors.ini
extra_output=cosmological_parameters/omega_m cosmological_parameters/S8 cosmological_parameters/sigma_8

[camb]
file = ${COSMOSIS_STD_LIB_DIR}/boltzmann/camb/camb_interface.py
mode = all
accurate_massive_neutrino_transfers = True
use_ppf_w = True
nonlinear = 'pk'
halofit_version = mead2020_feedback
zmin = 0.0
zmax = 3.5
nz = 256
kmax = 5.0
nk = 300
neutrino_hierarchy = degenerate

[firecrown_likelihood]
file = ${FIRECROWN_DIR}/firecrown/connector/cosmosis/likelihood.py
require_nonlinear_pk = True
sampling_parameters_sections = firecrown_two_point
likelihood_source = %(project_dir)s/examples/lsst_y1_3x2pt/3x2pt_likelihood.py
sacc_data = %(project_dir)s/examples/lsst_y1_3x2pt/sacc_forecasting_y1_3x2pt.sacc
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[runtime]
verbosity = standard
root = ${PWD}
sampler = nautilus

[DEFAULT]
project_dir = ${PWD}/../../

[output]
format = text
verbosity = 1
filename = output_blind_A/lsst_y1_3x2pt.txt

[test]
save_dir=output_blindA/lsst_y1_3x2pt
fatal_errors=T

[nautilus]
n_live = 150
n_networks = 6
n_batch = 75
verbose = True
f_live = 0.02
n_eff = 1000
discard_exploration = True
resume = True

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

[pipeline]
modules = consistency camb firecrown_likelihood
likelihoods = firecrown
timing = F
debug = F
values = cosmosis_values.ini
priors = cosmosis_priors.ini
extra_output=cosmological_parameters/omega_m cosmological_parameters/S8 cosmological_parameters/sigma_8

[camb]
file = ${COSMOSIS_STD_LIB_DIR}/boltzmann/camb/camb_interface.py
mode = all
accurate_massive_neutrino_transfers = True
use_ppf_w = True
nonlinear = 'pk'
halofit_version = mead2020_feedback
zmin = 0.0
zmax = 3.5
nz = 256
kmax = 5.0
nk = 300
neutrino_hierarchy = degenerate

[firecrown_likelihood]
file = ${FIRECROWN_DIR}/firecrown/connector/cosmosis/likelihood.py
require_nonlinear_pk = True
sampling_parameters_sections = firecrown_two_point
likelihood_source = %(project_dir)s/examples/lsst_y1_3x2pt/3x2pt_likelihood.py
sacc_data = %(project_dir)s/examples/lsst_y1_3x2pt/sacc_forecasting_y1_3x2pt_blind_A.fits
Loading
Loading