Skip to content

Commit

Permalink
deploy: 489b904
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurmloureiro committed Aug 7, 2024
0 parents commit 5960de2
Show file tree
Hide file tree
Showing 59 changed files with 6,631 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .buildinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 2991d903a9f78a6f81f1153a39917b8e
tags: 645f666f9bcd5a90fca523b33c5a78b7
Binary file added .doctrees/environment.pickle
Binary file not shown.
Binary file added .doctrees/index.doctree
Binary file not shown.
Binary file added .doctrees/installation.doctree
Binary file not shown.
Binary file added .doctrees/reference.doctree
Binary file not shown.
Binary file added .doctrees/usage.doctree
Binary file not shown.
Empty file added .nojekyll
Empty file.
Binary file added _images/Smokescreen_Banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions _sources/index.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
.. Smokescreen documentation master file, created by
sphinx-quickstart on Thu Aug 1 17:44:01 2024.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
********************************************************************
**Smokescreen** -- DESC Library for concealing cosmological results
********************************************************************

.. image:: _static/Smokescreen_Banner.png
:align: center

`Smokescreen <https://github.com/LSSTDESC/Smokescreen>`_ (currently under development) contains the modules for data concealment (blinding) at the following levels of the analysis:

* Data-vector measurements

* Posterior distribution [not yet developed]

* (TBC) Catalogues

.. attention::
The term "blinding" is used in the context of data concealment for scientific analysis. We understand this is an outdated term and we are working to update it to a more appropriate term. If you have any suggestions, please let us know.

Smokescreen's data-vector blinding methodis based on the `Muir et al. (2021) <https://arxiv.org/abs/1911.05929>`_ and was developed to be used as part of DESC measurements and inference pipelines such as `TXPipe <https://github.com/LSSTDESC/TXPipe>`_ .

.. toctree::
:maxdepth: 2
:caption: Contents

installation
usage
reference


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
57 changes: 57 additions & 0 deletions _sources/installation.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Installation
============

.. note::
If you have both `Firecrown <https://github.com/LSSTDESC/firecrown>`_ and `pyccl <https://github.com/LSSTDESC/CCL>`_ installed in your environment, you can skip the installation of the dependencies in the ``environment.yml`` file and simply install ``Smokescreen`` using ``pip``:

.. code-block:: bash
python -m pip install smokescreen
If you do not have *Firecrown* and *pyccl* installed, you can install the dependencies using the instructions below.

Creating a new environment:
---------------------------

You can create a new conda environment with the required packages using the `environment.yml` file:

.. code-block:: bash
conda env create -f environment.yml
This will create a new environment called `desc_smokescreen` with the required packages. You can activate the environment with:

.. code-block:: bash
conda activate desc_smokescreen
Using an existing environment
-----------------------------

If you want to install the `Smokescreen` package in an existing environment, you can install it using:

.. code-block:: bash
conda activate myenv
conda env update --name myenv --file environment.yml --prune
After installing the dependencies from `environment.yml`, you can install the `Smokescreen` package using:

Normal Usage Installation
--------------------------
After installing the dependencies from ``environment.yml``, you can install the ``Smokescreen`` package using:

.. code-block:: bash
python -m pip install [-e] .
The `-e` flag is optional and installs the package in editable mode (useful for development).

Testing the installation
------------------------

You can test the installation by running the tests:

.. code-block:: bash
pytest .
6 changes: 6 additions & 0 deletions _sources/reference.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
API References
===============

.. automodule:: smokescreen.datavector
.. automodule:: smokescreen.param_shifts
.. automodule:: smokescreen.utils
139 changes: 139 additions & 0 deletions _sources/usage.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
Usage
======

Currently, only data vector concealment is implemented in Smokescreen. Posterior-level concealment is under development.

Data Vector Concealment (blinding)
-----------------------------------

The `Smokescreen` library provides a method for blinding data vectors. This method is based on the `Muir et al. (2021) <https://arxiv.org/abs/1911.05929>`_ data-vector blinding method.

To conceal a data-vector you need the following elements:

* A CCL cosmology object

* A dictionary of the nuisance parameters used in the likelihood (soon to be deprecated)

* A Firecrown Likelihood, which takes a SACC data-vector (see more below). It can be either a path to the python file containing the likelihood or the module itself.

* A dictionary of cosmological parameters to be shifted in the format:

.. code-block:: python
# for a random uniform parameter shift:
{'PARAM_Y': (Y_MIN, Y_MAX), 'PARAM_Z': (Z_MIN, Z_MAX)}
# or for a determinist shift (used for debugging):
{'PARAM_Y': Y_VALUE, 'PARAM_Z': Z_VALUE}
* A SACC data-vector

* A random seed as int or string

.. attention::
**Likelihood Requirements**

The blinding module requires the Firecrown likelihood to be built with certain requirements. First, we must be able to build the likelihood by providing a `sacc <https://github.com/LSSTDESC/sacc/tree/master>`_ object with the measurements for the data-vector:

.. code-block:: python
def build_likelihood(build_parameters):
"""
This is a generic likelihood theory model
for a generic data vector.
"""
sacc_data = build_parameters['sacc_data']
This is simular to what is currently done in `TXPipe <https://github.com/LSSTDESC/TXPipe/blob/df0dcc8c1e974576dd1942624ab5ff7bd0fbbaa0/txpipe/utils/theory_model.py#L19>`_.

The likelihood module also must have a method ``.compute_theory_vector(ModellingTools)`` which calls for the calculation of the theory vector inside the likelihood object.

.. danger::
**Likelihoods with hardcoded sacc files:**

If you provide a Firecrown likelihood with a hardcoded path to a sacc file as the data-vector, **Smokescreen will conceal the hardcoded sacc file and not the one you provided**. This is because the likelihood is built with the hardcoded path. Firecrown currently has not checks to avoid a hardcoded sacc file in the ``build_likelihood(...)`` function. To avoid this, please build the likelihood as described above.

The likelihood can be provided either as a path to the python file containing the ``build_likelihood`` function or as a python module. In the latter case, the module must be imported.

TL;DR: Check the `Smokescreen notebooks folder <https://github.com/LSSTDESC/Smokescreen/tree/main/notebooks>`_ for a couple of examples.

From the command line
~~~~~~~~~~~~~~~~~~~~~~
The blinding module can be used to blind the data-vector measurements. The module can be used as follows:

.. code-block:: bash
python -m smokescreen --config configuration_file.yaml
You can find an example of a configuration file here:

.. code-block:: yaml
path_to_sacc: "./cosmicshear_sacc.fits"
likelihood_path: "./cosmicshear_likelihood.py"
systematics:
trc1_delta_z: 0.1
trc0_delta_z: 0.1
shifts_dict:
Omega_c: [0.20, 0.42]
sigma8: [0.67, 0.92]
seed: 2112
# only needed if you want a different reference cosmology
# than ccl.VanillaLCDM
reference_cosmology:
sigma8: 0.85
Or you can use the following command to create a template configuration file:

.. code-block:: bash
python -m smokescreen --print_config > template_config.yaml
Note that the `reference_cosmology` is optional. If not provided, the CCL `VanillaLCDM` reference cosmology will be the one used to compute the data vector.

From a notebook/your code
~~~~~~~~~~~~~~~~~~~~~~~~~

The smokescreen module can be used to blind the data-vector measurements. The module can be used as follows:

.. code-block:: python
# import the module
import pyccl as ccl
from smokescreen import ConcealDataVector
# import the likelihood that contains the model and data vector
[...]
import my_likelihood
# create the cosmology ccl object
cosmo = ccl.Cosmology(Omega_c=0.27,
Omega_b=0.045,
h=0.67,
sigma8=0.8,
n_s=0.96,
transfer_function='bbks')
# load a sacc object with the data vector [FIXME: this is a placeholder, the sacc object should be loaded from the likelihood]
sacc_data = sacc.Sacc.load_fits('path/to/data_vector.sacc')
# create a dictionary of the necessary firecrown nuisance parameters
syst_dict = {
"ia_a_1": 1.0,
"ia_a_2": 0.5,
"ia_a_d": 0.5,
"lens0_bias": 2.0,
"lens0_b_2": 1.0,
"lens0_b_s": 1.0,
"lens0_mag_bias": 1.0,
"src0_delta_z": 0.000,
"lens0_delta_z": 0.000,}
# create the smokescreen object
smoke = ConcealDataVector(cosmo, syst_dict, sacc_data, my_likelihood,
{'Omega_c': (0.22, 0.32), 'sigma8': (0.7, 0.9)})
# conceals (blinds) the data vector
smoke.calculate_concealing_factor()
concealed_dv = smoke.apply_concealing_to_likelihood_datavec()
Posterior Concealment (blinding)
---------------------------------

.. warning::

**UNDER DEVELOPMENT**
Binary file added _static/Smokescreen_Banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
123 changes: 123 additions & 0 deletions _static/_sphinx_javascript_frameworks_compat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/* Compatability shim for jQuery and underscores.js.
*
* Copyright Sphinx contributors
* Released under the two clause BSD licence
*/

/**
* small helper function to urldecode strings
*
* See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent#Decoding_query_parameters_from_a_URL
*/
jQuery.urldecode = function(x) {
if (!x) {
return x
}
return decodeURIComponent(x.replace(/\+/g, ' '));
};

/**
* small helper function to urlencode strings
*/
jQuery.urlencode = encodeURIComponent;

/**
* This function returns the parsed url parameters of the
* current request. Multiple values per key are supported,
* it will always return arrays of strings for the value parts.
*/
jQuery.getQueryParameters = function(s) {
if (typeof s === 'undefined')
s = document.location.search;
var parts = s.substr(s.indexOf('?') + 1).split('&');
var result = {};
for (var i = 0; i < parts.length; i++) {
var tmp = parts[i].split('=', 2);
var key = jQuery.urldecode(tmp[0]);
var value = jQuery.urldecode(tmp[1]);
if (key in result)
result[key].push(value);
else
result[key] = [value];
}
return result;
};

/**
* highlight a given string on a jquery object by wrapping it in
* span elements with the given class name.
*/
jQuery.fn.highlightText = function(text, className) {
function highlight(node, addItems) {
if (node.nodeType === 3) {
var val = node.nodeValue;
var pos = val.toLowerCase().indexOf(text);
if (pos >= 0 &&
!jQuery(node.parentNode).hasClass(className) &&
!jQuery(node.parentNode).hasClass("nohighlight")) {
var span;
var isInSVG = jQuery(node).closest("body, svg, foreignObject").is("svg");
if (isInSVG) {
span = document.createElementNS("http://www.w3.org/2000/svg", "tspan");
} else {
span = document.createElement("span");
span.className = className;
}
span.appendChild(document.createTextNode(val.substr(pos, text.length)));
node.parentNode.insertBefore(span, node.parentNode.insertBefore(
document.createTextNode(val.substr(pos + text.length)),
node.nextSibling));
node.nodeValue = val.substr(0, pos);
if (isInSVG) {
var rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
var bbox = node.parentElement.getBBox();
rect.x.baseVal.value = bbox.x;
rect.y.baseVal.value = bbox.y;
rect.width.baseVal.value = bbox.width;
rect.height.baseVal.value = bbox.height;
rect.setAttribute('class', className);
addItems.push({
"parent": node.parentNode,
"target": rect});
}
}
}
else if (!jQuery(node).is("button, select, textarea")) {
jQuery.each(node.childNodes, function() {
highlight(this, addItems);
});
}
}
var addItems = [];
var result = this.each(function() {
highlight(this, addItems);
});
for (var i = 0; i < addItems.length; ++i) {
jQuery(addItems[i].parent).before(addItems[i].target);
}
return result;
};

/*
* backward compatibility for jQuery.browser
* This will be supported until firefox bug is fixed.
*/
if (!jQuery.browser) {
jQuery.uaMatch = function(ua) {
ua = ua.toLowerCase();

var match = /(chrome)[ \/]([\w.]+)/.exec(ua) ||
/(webkit)[ \/]([\w.]+)/.exec(ua) ||
/(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) ||
/(msie) ([\w.]+)/.exec(ua) ||
ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) ||
[];

return {
browser: match[ 1 ] || "",
version: match[ 2 ] || "0"
};
};
jQuery.browser = {};
jQuery.browser[jQuery.uaMatch(navigator.userAgent).browser] = true;
}
Loading

0 comments on commit 5960de2

Please sign in to comment.