Skip to content

Commit c2fff9b

Browse files
arahlinannegambrelAnne E. Gambrel
authored
Code cleanup (#14)
General reorganization and clean up of code to further generalize away from SPIDER-only applicability. Many options have changed so submit scripts must change. * Rename xfaster_tools to the more specific spec_tools. Now contains only functions for generating and manipulating model power spectra. Also move expand_qb function to parse_tools since that's where all the matrix handling code lives. * simplify config file option handling * simplify attribute storage * construct and store expanded transfer function in get_transfer * simplify planck HM map file selection using dicts * simplify residual cross terms as a single cls_res attribute * simplify template noise terms as a single cls_template_noise attribute * remove sims_attr dictionaries and just use local variables * move the meat of parse_data to load_and_parse * increment data version and maintain backward compatibility for reading v1 data from disk * rename template noise and planck subtraction options cleanup planck subtraction * cleanup get_files function and associated attributes also load data sim ("fake data") files with all the others in preparation for merging all data construction functions into one * bug fix in data sim file parsing * bug fixes found when running the tutorial notebook * Replace xfaster_tools with spec_tools in docs * documentation * bug fix * move all data construction functionality into get_masked_data * merge get_masked_fake_data int get_masked_data with a common set of options * include ensemble_mean and ensemble_median handling in get_masked_data * store data and bandpower output files with a consistent file naming scheme * Fixing bugs up through masks * fix bug-- directly compare lists * Don't check for equal number of sim files per half for fake data sims * bug fixes in computing transfer function and loading data * consistent organization of xfaster_run options * sort keyword arguments to xfaster_run() by section * rearrange common and bin_def options more logically * parse xfaster_run docstring to set CLI help menu * use generic references to uncorrelated templates and reference signals, rather than planck halfmission datasets * Fixing bugs in template noise spectrum computation * Fixing tranfser function bugs; nulls work now * handle lists of bin widths in xfaster_run * rename qb_file options for clarity, and to avoid confusion with original behavior * Add sim_data_components to list arguments that get parsed right if using xfaster_submit * Add EB/TB fields to qb_transfer so it doesn't force recompute every time * don't save data xcorr files by default * Fix bugs with using qb_file-- now null sims also have now bugs * Fix bugs in template subtraction * Don't break setting up residuals if not using noise in sims * Updating gcorr options to work with new code * Fix gcorr config files to not have comments on same line as variable * Hopefully fixing CI * parse lists of bin widths properly, undo whitespace change * update notebook with changes to get_masked_data * fix error message * docs tweaks * more general handling of tag list parameters more docstring cleanup * Have alpha prior default to None ie, only fit r by default Co-authored-by: Anne Gambrel <anne.gambrel@gmail.com> Co-authored-by: Anne E. Gambrel <agambrel@princeton.edu>
1 parent 2db2320 commit c2fff9b

File tree

15 files changed

+2299
-2919
lines changed

15 files changed

+2299
-2919
lines changed

.github/workflows/documentation_pr.yaml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ jobs:
1313
steps:
1414
- name: Checkout github repo
1515
uses: actions/checkout@v2
16-
- name: Upgrade pip
17-
run: |
18-
pip install --upgrade pip
1916
- name: Cache pip
2017
uses: actions/cache@v2
2118
with:
@@ -25,13 +22,10 @@ jobs:
2522
restore-keys: |
2623
${{ runner.os }}-pip-
2724
${{ runner.os }}-
28-
- name: Install package
29-
run: |
30-
pip install -e .
3125
# Standard drop-in approach that should work for most people.
3226
- uses: ammaraskar/sphinx-action@master
3327
with:
34-
pre-build-command: "apt-get update -y && apt-get install -y g++ && apt-get install -y gfortran && apt-get install -y pandoc"
28+
pre-build-command: "apt-get --allow-releaseinfo-change update -y && apt-get install -y g++ && apt-get install -y gfortran && apt-get install -y pandoc"
3529
docs-folder: "docs/"
3630
# Create an artifact of the html output.
3731
- uses: actions/upload-artifact@v2

docs/api.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ xfaster_exec
3434
The module containing the master function that performs all the algorithm steps in order, and optionally
3535
submits the job to a grid system
3636

37-
xfaster_tools
37+
spec_tools
3838
-------------
39-
.. automodule:: xfaster.xfaster_tools
39+
.. automodule:: xfaster.spec_tools
4040
:members:
4141
:undoc-members:
4242

docs/notebooks/XFaster_Tutorial.ipynb

Lines changed: 63 additions & 56 deletions
Large diffs are not rendered by default.

docs/quickstart.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,11 @@ The code requires a certain directory structure for your input maps:
7575
[[optional:]]
7676
├── foreground_<foreground_type> (same filenames as signal_<signal_type>
7777
├── templates_<template_type>
78-
│ ├── halfmission-1 (same filenames as data_<data_type>)
79-
│ ├── halfmission-2 (same filenames as data_<data_type>)
80-
└── reobs_planck (same filenames as templates_<template_type>, used if sub_planck=True for null tests)
78+
│ ├── template1 (same filenames as data_<data_type>)
79+
│ ├── template2 (same filenames as data_<data_type>)
80+
└── reobs_reference (used if subtract_reference_signal=True for null tests)
81+
├── reference1 (same filenames as data_<data_type>)
82+
└── reference2 (same filenames as data_<data_type>)
8183
8284
The required types of maps are data, signal simulations, noise simulations, and masks.
8385
Each map should have a tag, which is used consistently across these different map types.
@@ -179,13 +181,12 @@ This script is also in the repo: `xfaster/example/plot_outputs.py <https://githu
179181
import numpy as np
180182
import matplotlib.pyplot as plt
181183
import xfaster as xf
182-
from xfaster import xfaster_tools as xft
183184
184185
# First, load up inputs to our sims so we can check how well they're recovered
185186
# (bearing in mind, this is a single sim, so noise fluctuations and sample
186187
# variance will cause scatter.
187188
r_in = 1.0
188-
Dls_in = xft.get_camb_cl(r=r_in, lmax=500, lfac=True)
189+
Dls_in = xf.get_camb_cl(r=r_in, lmax=500, lfac=True)
189190
Fl_in = np.loadtxt("maps_example/transfer_example.txt")
190191
191192
# load up bandpowers file, where most of the useful stuff is stored

example/make_example_maps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
import numpy as np
33
import healpy as hp
4-
from xfaster import xfaster_tools as xft
4+
import xfaster as xf
55

66
"""
77
This scipt will generate the ensemble of maps needed to run the
@@ -42,7 +42,7 @@
4242
dls = np.loadtxt(spec_file, unpack=True)[1:]
4343
cls = np.hstack([np.zeros((len(dls), 2)), dls / lfac[2:]])
4444
else:
45-
cls = xft.get_camb_cl(r=1.0, lmax=2000, lfac=False)
45+
cls = xf.get_camb_cl(r=1.0, lmax=2000, lfac=False)
4646
# write to disk for transfer function
4747
dls = np.vstack([ell[2:], (lfac * cls)[:, 2:]])
4848
np.savetxt(spec_file, dls.T)

example/plot_outputs.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import numpy as np
22
import matplotlib.pyplot as plt
33
import xfaster as xf
4-
from xfaster import xfaster_tools as xft
54

65
# First, load up inputs to our sims so we can check how well they're recovered
76
# (bearing in mind, this is a single sim, so noise fluctuations and sample
87
# variance will cause scatter.
98
r_in = 1.0
10-
Dls_in = xft.get_camb_cl(r=r_in, lmax=500, lfac=True)
9+
Dls_in = xf.get_camb_cl(r=r_in, lmax=500, lfac=True)
1110
Fl_in = np.loadtxt("maps_example/transfer_example.txt")
1211

1312
# load up bandpowers file, where most of the useful stuff is stored

example/xfaster_example.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
"bin_width_res": 100,
4343
# spectrum
4444
"ensemble_mean": False,
45-
"sim_index": None,
4645
"tbeb": True,
4746
"converge_criteria": 0.005,
4847
"iter_max": 200,
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
# Options specific to gcorr calculation
22
[gcorr_opts]
33
null = true
4-
map_tags = 90, 150a
4+
map_tags = 95,150
55
data_subset = full
66
output_root = ../../example/null/gcorr_run
77
nsim = 100
88

99
# Options we can directly pass to XFaster
1010
[xfaster_opts]
1111
config = ../../example/config_example.ini
12-
#Make null map set using the same set as for the signal run.
12+
# Make null map set using the same set as for the signal run.
1313
data_root = ../../example/maps_example_half1
14-
data_root2 = ../../example/maps_example_half2 #necessary for a null run
14+
# Need second data root for null run
15+
data_root2 = ../../example/maps_example_half2
1516
signal_type = synfast
16-
noise_type = gaussian #necessary for null gcorr
17+
# Noise type needed for nulls
18+
noise_type = gaussian
1719
mask_type = rectangle
1820
verbose = debug

scripts/gcorr/gcorr_config_signal.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ config = ../../example/config_example.ini
1313
data_root = ../../example/maps_example
1414
# data_root2 = # change for nulls
1515
signal_type = synfast
16-
noise_type = gaussian # ignored for signal gcorr
16+
# noise type ignored for signal gcorr
17+
noise_type = gaussian
1718
mask_type = rectangle
1819
verbose = debug

scripts/gcorr/run_xfaster.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@
6767
# null tests should use noise sims. signal shouldn't.
6868
if null:
6969
opts["noise_type"] = g_cfg["xfaster_opts"]["noise_type"]
70+
opts["sim_data_components"] = ["signal", "noise"]
7071
else:
7172
opts["noise_type"] = None
73+
opts["sim_data_components"] = ["signal"]
7274

7375
opts["output_root"] = os.path.join(g_cfg["gcorr_opts"]["output_root"], args.output)
7476

@@ -80,6 +82,7 @@
8082
seeds = list(range(args.first, args.first + args.num))
8183

8284
for tag in tags:
85+
opts["sim_data"] = True
8386
opts["output_tag"] = tag
8487
opts["gcorr_file"] = os.path.abspath(
8588
os.path.join(
@@ -99,7 +102,7 @@
99102
opts.update(**submit_opts)
100103

101104
for s in seeds:
102-
opts["sim_index"] = s
105+
opts["sim_index_default"] = s
103106
if args.submit:
104107
xf.xfaster_submit(**opts)
105108
else:

0 commit comments

Comments
 (0)