Skip to content
This repository was archived by the owner on Dec 7, 2018. It is now read-only.

Commit 1bab04b

Browse files
docs: first cut at working documentation
- see /docs/README.md for details on some non-standard stuff - added `gwin.utils` sub-package with `gwin.utils.sphinx` module
1 parent 1c331ff commit 1bab04b

File tree

17 files changed

+640
-108
lines changed

17 files changed

+640
-108
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ pip-delete-this-directory.txt
3232
# Sphinx documentation
3333
/docs/_build
3434
/docs/_generated
35+
/docs/api/
36+
/docs/_includes/*.rst
3537

3638
# OS/editor files
3739
*.swp

docs/Makefile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line.
5+
SPHINXOPTS =
6+
SPHINXBUILD = sphinx-build
7+
SPHINXPROJ = GWIn
8+
SOURCEDIR = .
9+
BUILDDIR = _build
10+
11+
INCLUDES := $(shell ls _includes/*.py)
12+
13+
# Put it first so that "make" without argument is like "make help".
14+
help:
15+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
16+
17+
.PHONY: help Makefile
18+
19+
# Catch-all target: route all unknown targets to Sphinx using the new
20+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
21+
html: Makefile $(INCLUDES:.py=.rst)
22+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
23+
24+
clean: Makefile
25+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
26+
@$(RM) api/*.rst
27+
@for EXRST in $(INCLUDES:.py=.rst); do \
28+
$(RM) -f $$EXRST ; \
29+
done
30+
31+
# -- build includes from python files -----------------------------------------
32+
33+
_includes/%.rst: _includes/%.py
34+
python _includes/$*.py >> $@

docs/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Documentation stucture
2+
3+
This document describes the structure of the documentation for GWIn
4+
5+
## How-to generate documentation
6+
7+
```
8+
make html -j2
9+
```
10+
11+
## ``/_includes``
12+
13+
The `/docs/_includes` directory is automatically parsed during `make html`,
14+
allowing for on-the-fly generation of RST documentation.
15+
16+
Any Python files in there will be executed and the output dumped to an RST
17+
file with the same base name, e.g. output from `_includes/foo.py` will be
18+
written to `_includes/foo.rst`.
19+
20+
The output RST files can then be embedded into other RST files (in the
21+
regular documentation) via RST `..include::` directives, e.g.:
22+
23+
```rst
24+
.. include:: /_includes/foo.rst
25+
```

docs/_includes/distributions-table.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env python
2+
3+
"""Print an RST table of available distributions from
4+
"""
5+
6+
from pycbc.distributions import distribs
7+
from gwin.utils.sphinx import rst_dict_table
8+
9+
10+
def val_format(class_):
11+
return ':py:class:`{0}.{1}`'.format(class_.__module__, class_.__name__)
12+
13+
print(rst_dict_table(distribs, key_format='``\'{0}\'``'.format,
14+
val_format=val_format))

docs/_includes/waveform-parameters.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python
2+
3+
"""Print the usable waveform parameters
4+
"""
5+
6+
# NOTE: the manual call to OrdereDict can be removed in favour of
7+
# `ParameterList.description_dict` when gwastro/pycbc#2125 is merged
8+
# and released
9+
10+
from collections import OrderedDict
11+
12+
from pycbc import waveform
13+
from gwin.utils.sphinx import rst_dict_table
14+
15+
allparams = (waveform.fd_waveform_params +
16+
waveform.location_params +
17+
waveform.calibration_params)
18+
paramdict = OrderedDict(allparams.descriptions)
19+
20+
print(rst_dict_table(
21+
paramdict,
22+
key_format='``\'{0}\'``'.format,
23+
header=('Parameter', 'Description'),
24+
))

docs/_templates/autosummary/class.rst

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{% if referencefile %}
2+
.. include:: {{ referencefile }}
3+
{% endif %}
4+
5+
TEST
6+
7+
{{ fullname | escape | underline}}
8+
9+
.. currentmodule:: {{ module }}
10+
11+
.. autoclass:: {{ objname }}
12+
:no-inherited-members:
13+
14+
{% if '__init__' in methods %}
15+
{{ methods.remove('__init__') }}
16+
{% endif %}
17+
18+
{% block attributes_summary %}
19+
{% if attributes %}
20+
21+
.. rubric:: Attributes Summary
22+
23+
.. autosummary::
24+
{% for item in attributes %}
25+
~{{ name }}.{{ item }}
26+
{%- endfor %}
27+
28+
{% endif %}
29+
{% endblock %}
30+
31+
{% block methods_summary %}
32+
{% if methods %}
33+
34+
.. rubric:: Methods Summary
35+
36+
.. autosummary::
37+
{% for item in methods %}
38+
~{{ name }}.{{ item }}
39+
{%- endfor %}
40+
41+
{% endif %}
42+
{% endblock %}
43+
44+
{% block attributes_documentation %}
45+
{% if attributes %}
46+
47+
.. rubric:: Attributes Documentation
48+
49+
{% for item in attributes %}
50+
.. autoattribute:: {{ item }}
51+
{%- endfor %}
52+
53+
{% endif %}
54+
{% endblock %}
55+
56+
{% block methods_documentation %}
57+
{% if methods %}
58+
59+
.. rubric:: Methods Documentation
60+
61+
{% for item in methods %}
62+
.. automethod:: {{ item }}
63+
{%- endfor %}
64+
65+
{% endif %}
66+
{% endblock %}

docs/gwin.rst renamed to docs/command-line/gwin.rst

Lines changed: 24 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
###################################################################
2-
PyCBC inference documentation (``gwin``)
3-
###################################################################
1+
###################################
2+
GWin on the command line (``gwin``)
3+
###################################
44

55
===================
66
Introduction
77
===================
88

99
This page gives details on how to use the various parameter estimation
10-
executables and modules available in PyCBC. The ``gwin`` subpackage
10+
executables and modules available in GWin. The ``gwin`` subpackage
1111
contains classes and functions for evaluating probability distributions,
1212
likelihoods, and running Bayesian samplers.
1313

1414
==================================================
15-
Sampling the parameter space (``pycbc_inference``)
15+
Sampling the parameter space (``gwin``)
1616
==================================================
1717

1818
--------
1919
Overview
2020
--------
2121

22-
The executable ``pycbc_inference`` is designed to sample the parameter space
22+
The executable ``gwin`` is designed to sample the parameter space
2323
and save the samples in an HDF file. A high-level description of the
24-
``pycbc_inference`` algorithm is
24+
``gwin`` algorithm is
2525

2626
#. Estimate a PSD from a model or data.
2727

@@ -37,11 +37,11 @@ and save the samples in an HDF file. A high-level description of the
3737
Options for samplers, likelihood models, and priors
3838
---------------------------------------------------
3939

40-
For a full listing of all options run ``pycbc_inference --help``. In this subsection we reference documentation for Python classes that contain more information about choices for samplers, likelihood models, and priors.
40+
For a full listing of all options run ``gwin --help``. In this subsection we reference documentation for Python classes that contain more information about choices for samplers, likelihood models, and priors.
4141

4242
The user specifies the sampler on the command line with the ``--sampler`` option.
43-
A complete list of samplers is given in ``pycbc_inference --help``.
44-
These samplers are described in :py:class:`gwin.sampler_kombine.KombineSampler`, :py:class:`gwin.sampler_emcee.EmceeEnsembleSampler`, and :py:class:`gwin.sampler_emcee.EmceePTSampler`.
43+
A complete list of samplers is given in ``gwin --help``.
44+
These samplers are described in :py:class:`gwin.sampler.KombineSampler`, :py:class:`gwin.sampler.EmceeEnsembleSampler`, and :py:class:`gwin.sampler.EmceePTSampler`.
4545
In addition to ``--sampler`` the user will need to specify the number of walkers to use ``--nwalkers``, and for parallel-tempered samplers the number of temperatures ``--ntemps``. You also need to either specify the number of iterations to run for using ``--niterations`` **or** the number of independent samples to collect using ``--n-independent-samples``. For the latter, a burn-in function must be specified using ``--burn-in-function``. In this case, the program will run until the sampler has burned in, at which point the number of independent samples equals the number of walkers. If the number of independent samples desired is greater than the number of walkers, the program will continue to run until it has collected the specified number of independent samples (to do this, an autocorrelation length is computed at each checkpoint to determine how many iterations need to be skipped to obtain independent samples).
4646

4747
The user specifies the likelihood model on the command line with the ``--likelihood-evaluator`` option. Any choice that starts with ``test_`` is an analytic test distribution that requires no data or waveform generation; see the section below on running on an analytic distribution for more details. For running on data, use ``--likelihood-evaluator gaussian``; this uses :py:class:`gwin.likelihood.GaussianLikelihood` for evaluating posteriors. Examples of using this on a BBH injection and on GW150914 are given below.
@@ -62,10 +62,8 @@ To create a subsection use the ``-`` char, e.g. for one of the mass parameters d
6262

6363
Each prior subsection must have a ``name`` option that identifies what prior to use.
6464
These distributions are described in :py:mod:`pycbc.distributions`.
65-
A list of all distributions that can be used is found with
6665

67-
.. literalinclude:: ../examples/distributions/list_distributions.py
68-
.. command-output:: python ../examples/distributions/list_distributions.py
66+
.. include:: /_includes/distributions-table.rst
6967

7068
One or more of the ``variable_args`` may be transformed to a different parameter space for purposes of sampling. This is done by specifying a ``[sampling_parameters]`` section. This section specifies which ``variable_args`` to replace with which parameters for sampling. This must be followed by one or more ``[sampling_transforms-{sampling_params}]`` sections that provide the transform class to use. For example, the following would cause the sampler to sample in chirp mass (``mchirp``) and mass ratio (``q``) instead of ``mass1`` and ``mass2``::
7169

@@ -100,10 +98,9 @@ Any class in the transforms module may be used. A useful transform for these pur
10098
inputs = lambda1
10199
dquad_mon1 = dquadmon_from_lambda(lambda1)
102100

103-
A list of all parameters that are understood by the CBC waveform generator can be found with:
101+
The following table lists all parameters understood by the CBC waveform generator:
104102

105-
.. literalinclude:: ../examples/inference/list_parameters.py
106-
.. command-output:: python ../examples/inference/list_parameters.py
103+
.. include:: /_includes/waveform-parameters.rst
107104

108105
Some common transforms are pre-defined in the code. These are: the mass parameters ``mass1`` and ``mass2`` can be substituted with ``mchirp`` and ``eta`` or ``mchirp`` and ``q``.
109106
The component spin parameters ``spin1x``, ``spin1y``, and ``spin1z`` can be substituted for polar coordinates ``spin1_a``, ``spin1_azimuthal``, and ``spin1_polar`` (ditto for ``spin2``).
@@ -136,7 +133,7 @@ This example demonstrates how to sample a 2D normal distribution with the ``emce
136133

137134
Then run::
138135

139-
pycbc_inference --verbose \
136+
gwin --verbose \
140137
--config-files normal2d.ini \
141138
--output-file normal2d.hdf \
142139
--sampler emcee \
@@ -148,7 +145,7 @@ This will run the ``emcee`` sampler on the 2D analytic normal distribution with
148145

149146
To plot the posterior distribution after the last iteration, run::
150147

151-
pycbc_inference_plot_posterior --verbose \
148+
gwin_plot_posterior --verbose \
152149
--input-file normal2d.hdf \
153150
--output-file posterior-normal2d.png \
154151
--plot-scatter \
@@ -157,11 +154,11 @@ To plot the posterior distribution after the last iteration, run::
157154
--z-arg loglr \
158155
--iteration -1
159156

160-
This will plot each walker's position as a single point colored by the log likelihood ratio at that point, with the 50th and 90th percentile contours drawn. See below for more information about using ``pycbc_inference_plot_posterior``.
157+
This will plot each walker's position as a single point colored by the log likelihood ratio at that point, with the 50th and 90th percentile contours drawn. See below for more information about using ``gwin_plot_posterior``.
161158

162159
To make a movie showing how the walkers evolved, run::
163160

164-
pycbc_inference_plot_movie --verbose \
161+
gwin_plot_movie --verbose \
165162
--input-file normal2d.hdf \
166163
--output-prefix frames-normal2d \
167164
--movie-file normal2d_mcmc_evolution.mp4 \
@@ -172,11 +169,11 @@ To make a movie showing how the walkers evolved, run::
172169
--z-arg loglr \
173170
--frame-step 1
174171

175-
**Note:** you need ``ffmpeg`` installed for the mp4 to be created. See below for more information on using ``pycbc_inference_plot_movie``.
172+
**Note:** you need ``ffmpeg`` installed for the mp4 to be created. See below for more information on using ``gwin_plot_movie``.
176173

177174
The number of dimensions of the distribution is set by the number of ``variable_args`` in the configuration file. The names of the ``variable_args`` do not matter, just that the prior sections use the same names (in this example ``x`` and ``y`` were used, but ``foo`` and ``bar`` would be equally valid). A higher (or lower) dimensional distribution can be tested by simply adding more (or less) ``variable_args``.
178175

179-
Which analytic distribution is used is set by the ``--likelihood-evaluator`` option. By setting to ``test_normal`` we used :py:class:`gwin.likelihood.TestNormal`. To see the list of available likelihood classes run ``pycbc_inference --help``; any choice for ``--likelihood-evaluator`` that starts with ``test_`` is analytic. The other analytic distributions available are: :py:class:`gwin.likelihood.TestEggbox`, :py:class:`gwin.likelihood.TestRosenbrock`, and :py:class:`gwin.likelihood.TestVolcano`. As with ``test_normal``, the dimensionality of these test distributions is set by the number of ``variable_args`` in the configuration file. The ``test_volcano`` distribution must be two dimensional, but all of the other distributions can have any number of dimensions. The configuration file syntax for the other test distributions is the same as in this example. Indeed, with this configuration file one only needs to change the ``--likelihood-evaluator`` argument to try (2D versions of) the other distributions.
176+
Which analytic distribution is used is set by the ``--likelihood-evaluator`` option. By setting to ``test_normal`` we used :py:class:`gwin.likelihood.TestNormal`. To see the list of available likelihood classes run ``gwin --help``; any choice for ``--likelihood-evaluator`` that starts with ``test_`` is analytic. The other analytic distributions available are: :py:class:`gwin.likelihood.TestEggbox`, :py:class:`gwin.likelihood.TestRosenbrock`, and :py:class:`gwin.likelihood.TestVolcano`. As with ``test_normal``, the dimensionality of these test distributions is set by the number of ``variable_args`` in the configuration file. The ``test_volcano`` distribution must be two dimensional, but all of the other distributions can have any number of dimensions. The configuration file syntax for the other test distributions is the same as in this example. Indeed, with this configuration file one only needs to change the ``--likelihood-evaluator`` argument to try (2D versions of) the other distributions.
180177

181178
------------------------------
182179
BBH software injection example
@@ -335,7 +332,7 @@ An example of generating an injection::
335332
--taper-injection ${TAPER} \
336333
--disable-spin
337334

338-
An example of running ``pycbc_inference`` to analyze the injection in fake data::
335+
An example of running ``gwin`` to analyze the injection in fake data::
339336

340337
# injection parameters
341338
TRIGGER_TIME=1126259462.0
@@ -371,9 +368,9 @@ An example of running ``pycbc_inference`` to analyze the injection in fake data:
371368
# specifies the number of threads for OpenMP
372369
# Running with OMP_NUM_THREADS=1 stops lalsimulation
373370
# to spawn multiple jobs that would otherwise be used
374-
# by pycbc_inference and cause a reduced runtime.
371+
# by gwin and cause a reduced runtime.
375372
OMP_NUM_THREADS=1 \
376-
pycbc_inference --verbose \
373+
gwin --verbose \
377374
--seed 12 \
378375
--instruments ${IFOS} \
379376
--gps-start-time ${GPS_START_TIME} \
@@ -490,9 +487,9 @@ Now run::
490487
# specifies the number of threads for OpenMP
491488
# Running with OMP_NUM_THREADS=1 stops lalsimulation
492489
# to spawn multiple jobs that would otherwise be used
493-
# by pycbc_inference and cause a reduced runtime.
490+
# by gwin and cause a reduced runtime.
494491
OMP_NUM_THREADS=1 \
495-
pycbc_inference --verbose \
492+
gwin --verbose \
496493
--seed 12 \
497494
--instruments ${IFOS} \
498495
--gps-start-time ${GPS_START_TIME} \
@@ -524,54 +521,3 @@ Now run::
524521
--save-psd \
525522
--save-stilde \
526523
--force
527-
528-
----------------------------------------------------
529-
HDF output file handler (``pycbc.io.InferenceFile``)
530-
----------------------------------------------------
531-
532-
The executable ``pycbc_inference`` will write a HDF file with all the samples from each walker along with the PSDs and some meta-data about the sampler.
533-
There is a handler class ``pycbc.io.InferenceFile`` that extends ``h5py.File``.
534-
To read the output file you can do::
535-
536-
from pycbc.io import InferenceFile
537-
fp = InferenceFile("cbc_example-n1e4.hdf", "r")
538-
539-
To get all samples for ``distance`` from the first walker you can do::
540-
541-
samples = fp.read_samples("distance", walkers=0)
542-
print samples.distance
543-
544-
The function ``InferenceFile.read_samples`` includes the options to thin the samples.
545-
By default the function will return samples beginning at the end of the burn-in to the last written sample, and will use the autocorrelation length (ACL) calculated by ``pycbc_inference`` to select the indepdedent samples.
546-
You can supply ``thin_start``, ``thin_end``, and ``thin_interval`` to override this. To read all samples you would do::
547-
548-
samples = fp.read_samples("distance", walkers=0, thin_start=0, thin_end=-1, thin_interval=1)
549-
print samples.distance
550-
551-
Some standard parameters that are derived from the variable arguments (listed via ``fp.variable_args``) can also be retrieved. For example, if ``fp.variable_args`` includes ``mass1`` and ``mass2``, then you can retrieve the chirp mass with::
552-
553-
samples = fp.read_samples("mchirp")
554-
print samples.mchirp
555-
556-
In this case, ``fp.read_samples`` will retrieve ``mass1`` and ``mass2`` (since they are needed to compute chirp mass); ``samples.mchirp`` then returns an array of the chirp mass computed from ``mass1`` and ``mass2``.
557-
558-
For more information, including the list of predefined derived parameters, see :py:class:`pycbc.io.InferenceFile`.
559-
560-
===============================================
561-
Visualizing the Posteriors
562-
===============================================
563-
564-
.. toctree::
565-
:maxdepth: 1
566-
567-
inference/viz.rst
568-
569-
===============================================
570-
Workflows
571-
===============================================
572-
573-
.. toctree::
574-
:maxdepth: 1
575-
576-
workflow/pycbc_make_inference_workflow
577-
workflow/pycbc_make_inference_inj_workflow

0 commit comments

Comments
 (0)