Skip to content

Commit 0daf1c6

Browse files
authored
Migrate gcorr iteration script to library entry point (#33)
1 parent 98385f3 commit 0daf1c6

File tree

11 files changed

+336
-261
lines changed

11 files changed

+336
-261
lines changed

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
recursive-include docs example scripts
1+
recursive-include docs example

docs/api.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,17 @@ xfaster_exec
3535
submits the job to a grid system
3636

3737
spec_tools
38-
-------------
38+
----------
3939
.. automodule:: xfaster.spec_tools
4040
:members:
4141
:undoc-members:
4242

43-
More generic functions used by methods in xfaster_class
43+
More generic functions used by methods in :py:mod:`~xfaster.xfaster_class`
44+
45+
gcorr_tools
46+
-----------
47+
.. automodule:: xfaster.gcorr_tools
48+
:members:
49+
:undoc-members:
50+
51+
Tools for iteratively computing corrections to the ``g_ell`` factor

docs/gcorr.rst

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
G-Correction Calculation
2+
========================
3+
4+
Code package for calculating correction factors to g_ell using pre-generated
5+
simulation maps for each single mask. This procedure assumes you are running
6+
this code on a cluster-- it is extremely slow to do otherwise.
7+
8+
There is one main command-line utility that calls two functions from the
9+
:py:mod:`~xfaster.gcorr_tools` library:
10+
11+
1. :py:func:`~xfaster.gcorr_tools.xfaster_gcorr_once` -- This function calls
12+
XFaster to run or submit jobs for gcorr runs.
13+
2. :py:func:`~xfaster.gcorr_tools.process_gcorr` -- A function that computes the
14+
gcorr correction from the ensemble of bandpowers, updates the running total,
15+
and backs up the necessary files from each iteration.
16+
3. ``xfaster gcorr`` -- An xfaster command-line utility, that calls function 1
17+
and 2 to get a new gcorr.npz file each time. This is the main code you'll
18+
run.
19+
20+
There is also a config file with options specific to computing gcorr.
21+
22+
Procedure
23+
---------
24+
25+
1. Edit the gcorr config file to suit your purposes. Examples are given for
26+
signal and null runs in the examples directory. Required fields are:
27+
28+
* ``null`` -- must be true for null tests and false for signal runs
29+
* ``map_tags`` -- comma-separated list of map tags
30+
* ``data_subset`` -- the globabble data_subset argument to xfaster_run, but
31+
without map tags. So, "full", "chunk*", etc.
32+
* ``output_root`` -- the parent directory where your gcorr XFaster runs will
33+
be written
34+
* ``nsim`` -- the number of simulations to use to compute gcorr
35+
* ``[xfaster_opts]`` -- this is where you'll put any options that will be
36+
directly input to :py:func:`~xfaster.xfaster_exec.xfaster_run`
37+
* ``[submit_opts]`` -- this is where you'll put any options that will be
38+
directly input to :py:func:`~xfaster.xfaster_exec.xfaster_submit`, in
39+
addition to those in ``[xfaster_opts]``
40+
41+
2. Run ``xfaster gcorr`` once to get the full set of XFaster output files in the
42+
output directory. Since we haven't computed gcorr yet, this will set
43+
``apply_gcorr=False``. Make sure to use as many OMP threads as possible since
44+
this is the step where the sims_xcorr file, which benefits the most from
45+
extra threads, is computed. Your command should look like this::
46+
47+
xfaster gcorr path-to-my-gcorr-config.ini
48+
49+
3. Run ``xfaster gcorr`` until convergence is reached. In practice, you will run
50+
the command above and wait for it to finish. If you include the
51+
``--max-iters`` option with a non-zero value, the code will try to determine
52+
whether convergence or max_iters has been reached and stop on its own.
53+
Otherwise, you can look at the correction-to-the-correction that it both
54+
prints and plots (it should converge to 1s for TT, EE, BB), and rerun the
55+
same command if it hasn't converged. In much more detail, here's what the
56+
code does:
57+
58+
1. Call :py:func:`~xfaster.gcorr_tools.xfaster_gcorr_once` for the 0th sim
59+
seed while also reloading gcorr (if this is not the first iteration).
60+
This does a couple things-- saves the new gcorr in the ``masks_xcorr``
61+
file, so later seeds will use the right thing. And recompute the transfer
62+
function, which doesn't depend on the ``sim_index``, so is only necessary
63+
to do once.
64+
2. After the transfer functions are all on disk, submit individual jobs for
65+
all the other seeds, just doing the bandpowers step for those.
66+
3. Once they're all done, run :py:func:`~xfaster.gcorr_tools.compute_gcal`,
67+
and save a correction-to-gcorr as ``gcorr_corr_<tag>_iter<iter>.npz`` in the
68+
rundir.
69+
4. If not the first iteration, load up the correction-to-gcorr computed for
70+
this iteration. Multiply it by the total gcorr, and save that to the
71+
output directory as ``gcorr_total_<tag>_iter<iter>.npz``.
72+
5. Plot gcorr total and the correction to gcorr total. Save in rundir/plots.
73+
6. Clear out rundir bandpowers/transfer functions/logs.
74+
7. Exit.
75+
76+
4. After convergence is reached, copy the gcorr_total file for the last
77+
iteration from the rundir to the mask directory, labeling it
78+
``mask_map_<tag>_gcorr.npz`` for signal or ``mask_map_<tag>_gcorr_null.npz``
79+
for null.

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ More details of the math can be found in :ref:`Algorithm<Algorithm>`, and a deta
2020
quickstart
2121
algorithm
2222
notebooks/XFaster_Tutorial
23+
gcorr
2324
api
2425

2526
Indices and tables

docs/notebooks/XFaster_Tutorial.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@
420420
"source": [
421421
"We have now finished all the set-up. Now it's time to start calculating things. First, we compute the cross spectra of our masks--which will be needed for computing the $K_{\\ell \\ell^{\\prime}}$ mode-coupling matrix--and the $g_\\ell$ mode-counting factor. This is done with [get_mask_weights()](../api.rst#xfaster.xfaster_class.XFaster.get_mask_weights).\n",
422422
"\n",
423-
"For the example, we will not apply an empirical correction to $g_\\ell$, the calibration of which is discussed in Section 2.3.2 of the [XFaster paper](https://arxiv.org/abs/2104.01172). Otherwise, we would set `apply_gcorr=True`, and the code would look in the masks directory for this correction file for each map. The `reload_gcorr` option is only useful when doing the empirical calibration; it reloads the file, while by-passing the checkpoint tree that is usually performed after `get_mask_weights`."
423+
"For the example, we will not apply an empirical correction to $g_\\ell$, the calibration of which is discussed in Section 2.3.2 of the [XFaster paper](https://arxiv.org/abs/2104.01172). Otherwise, we would set `apply_gcorr=True`, and the code would look in the masks directory for this correction file for each map. The `reload_gcorr` option is only useful when doing the empirical calibration; it reloads the file, while by-passing the checkpoint tree that is usually performed after `get_mask_weights`. Instructions are [provided](../gcorr.rst) for constructing this calibration using the example dataset."
424424
]
425425
},
426426
{
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
null = true
44
map_tags = 95,150
55
data_subset = full
6-
output_root = ../../example/null/gcorr_run
6+
output_root = null/gcorr_run
77
nsim = 100
88

99
# Options we can directly pass to XFaster
1010
[xfaster_opts]
11-
config = ../../example/config_example.ini
11+
config = config_example.ini
1212
# Make null map set using the same set as for the signal run.
13-
data_root = ../../example/maps_example_half1
13+
data_root = maps_example_half1
1414
# Need second data root for null run
15-
data_root2 = ../../example/maps_example_half2
15+
data_root2 = maps_example_half2
1616
signal_type = synfast
1717
# Noise type needed for nulls
1818
noise_type = gaussian
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
null = false
44
map_tags = 95,150
55
data_subset = full
6-
output_root = ../../example/gcorr_run
6+
output_root = gcorr_run
77
nsim = 100
88

99
# Options we can directly pass to XFaster
1010
[xfaster_opts]
11-
config = ../../example/config_example.ini
12-
data_root = ../../example/maps_example
11+
config = config_example.ini
12+
data_root = maps_example
1313
# data_root2 = # change for nulls
1414
signal_type = synfast
1515
# noise type ignored for signal gcorr

scripts/gcorr/README

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)