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

Commit

Permalink
Add calibration uncertainty model (#54)
Browse files Browse the repository at this point in the history
* add base Recalibrate class and CubicSpline

* Adding calibration preamble

* fix extraction of frequencies from strain object

* add call to super.__init__

* add parameter prefix as argument

* add documentation

* add reading from config

* fix bug in prefix removal

* Typos

* remove model name from options

* make loading from config more generic

* update loading of calibration

* force inputs to have the correct type

* force inputs to have the correct type

* Adding warning for too few spline points

* make recalibration objects know the ifo name

* add base Recalibrate class and CubicSpline

* Adding calibration preamble

* fix extraction of frequencies from strain object

* add call to super.__init__

* add parameter prefix as argument

* add documentation

* add reading from config

* fix bug in prefix removal

* Typos

* remove model name from options

* make loading from config more generic

* update loading of calibration

* force inputs to have the correct type

* force inputs to have the correct type

* Adding warning for too few spline points

* make recalibration objects know the ifo name

* add calibration ini file for cubic spline

* add calibration ini to docs

* Commenting config file

* make lines < 80 characters

* use var not stdev

* allow multiple config files in workflow

* typo fix

* standardise ini file name, allow for multiple ini files

* update workflow docs for using multiple calibration files

* add tests for calibration

* remove unused import

* style fix

* fix style

* make cubic spline raise error if too few points are provided

* add test of too few spline points

* placate codeclimate

* use correct frequency array

* address comments to pull request

* remove useless statement
  • Loading branch information
Colm Talbot authored and Collin Capano committed Jul 20, 2018
1 parent 5be86c7 commit 91214d7
Show file tree
Hide file tree
Showing 7 changed files with 411 additions and 16 deletions.
7 changes: 4 additions & 3 deletions bin/gwin
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import gwin
from gwin import (__version__, burn_in, option_utils)
from gwin.io.hdf import InferenceFile
from gwin.option_utils import validate_checkpoint_files
from gwin.calibration import Recalibrate

# command line usage
parser = argparse.ArgumentParser(usage=__file__ + " [--options]",
Expand Down Expand Up @@ -198,9 +199,9 @@ with ctx:
# get ifo-specific instances of calibration model
if cp.has_section('calibration'):
logging.info("Initializing calibration model")
recalib = {ifo : strain.read_model_from_config(cp, ifo) for
ifo in opts.instruments}
model_args['recalib'] = recalib
recalibration = {ifo: Recalibrate.from_config(cp, ifo, section='calibration') for
ifo in opts.instruments}
model_args['recalibration'] = recalibration

# get gates for templates
gates = strain.gates_from_cli(opts)
Expand Down
16 changes: 7 additions & 9 deletions bin/gwin_make_workflow
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ parser.add_argument("--gps-end-time", type=float, nargs="+", default=None,
"this option is ignored.")

# input configuration file options
parser.add_argument("--inference-config-file", type=str, required=True,
parser.add_argument("--inference-config-file", type=str, nargs='+', required=True,
help="workflow.WorkflowConfigParser parsable file with "
"proir information.")
"prior information.")
parser.add_argument("--prior-section", type=str, default="prior",
help="Name of the section in inference configuration file "
"that contains priors.")
Expand Down Expand Up @@ -154,9 +154,6 @@ workflow_options = opts.bank_file != None \
if not workflow_options and not (opts.gps_end_time != None):
raise ValueError("Must use either workflow options or --gps-end-time")

# typecast str from command line to File instances
config_file = to_file(opts.inference_config_file)

# sections for output HTML pages
rdir = layout.SectionNumber("results",
["detector_sensitivity", "priors", "posteriors",
Expand Down Expand Up @@ -194,9 +191,6 @@ workflow_options = opts.bank_file != None \
if not workflow_options and not (opts.gps_end_time != None):
raise ValueError("Must use either workflow options or --gps-end-time")

# typecast str from command line to File instances
config_file = to_file(opts.inference_config_file)

# if using workflow files to find analysis times
if workflow_options:

Expand Down Expand Up @@ -239,7 +233,11 @@ inference_exe = wf.Executable(workflow.cp, "inference", ifos=workflow.ifos,
out_dir=opts.output_dir)

# read inference configuration file
cp = WorkflowConfigParser([opts.inference_config_file])
# typecast str from command line to File instances
cp = WorkflowConfigParser(opts.inference_config_file)
with open('inference.ini', 'w') as ff:
cp.write(ff)
config_file = to_file('inference.ini')

# get channel names
channel_names = {}
Expand Down
12 changes: 10 additions & 2 deletions docs/command-line/gwin_make_workflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,19 @@ A simple configuration file for parameter estimation on the ringdown is::

If you want to use another variable parameter in the inference sampler then add its name to ``[variable_params]`` and add a prior section like shown above.

When working on real data, it is necessary to marginalise over calibration uncertainty.
The model and parameters describing the calibration uncertainty can be passed in another ini file, e.g.:

.. literalinclude:: ../../examples/workflow/GW150914_example/calibration.ini
:language: ini

=====================
Generate the workflow
=====================

To generate a workflow you will need your configuration files. We set the following enviroment variables for this example::
To generate a workflow you will need your configuration files.
The workflow creates a single config file ``inference.ini`` from all the files specified in ``INFERENCE_CONFIG_PATH``.
We set the following enviroment variables for this example::

# name of the workflow
WORKFLOW_NAME="r1"
Expand All @@ -92,7 +100,7 @@ To generate a workflow you will need your configuration files. We set the follow

# input configuration files
CONFIG_PATH=workflow.ini
INFERENCE_CONFIG_PATH=gwin.ini
INFERENCE_CONFIG_PATH="gwin.ini calibration.ini"

Specify a directory to save the HTML pages::

Expand Down
132 changes: 132 additions & 0 deletions examples/workflow/GW150914_example/calibration.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# Details of set up as given in the O1 Binary Black Hole Paper https://arxiv.org/abs/1606.04856
[calibration]
h1_model = cubic_spline
h1_minimum_frequency = 10
h1_maximum_frequency = 1024
h1_n_points = 5
l1_model = cubic_spline
l1_minimum_frequency = 10
l1_maximum_frequency = 1024
l1_n_points = 5

[variable_params]
recalib_amplitude_h1_0 =
recalib_amplitude_h1_1 =
recalib_amplitude_h1_2 =
recalib_amplitude_h1_3 =
recalib_amplitude_h1_4 =
recalib_phase_h1_0 =
recalib_phase_h1_1 =
recalib_phase_h1_2 =
recalib_phase_h1_3 =
recalib_phase_h1_4 =
recalib_amplitude_l1_0 =
recalib_amplitude_l1_1 =
recalib_amplitude_l1_2 =
recalib_amplitude_l1_3 =
recalib_amplitude_l1_4 =
recalib_phase_l1_0 =
recalib_phase_l1_1 =
recalib_phase_l1_2 =
recalib_phase_l1_3 =
recalib_phase_l1_4 =

[prior-recalib_amplitude_h1_0]
name = gaussian
recalib_amplitude_h1_0_mean = 0
recalib_amplitude_h1_0_var = 0.0023

[prior-recalib_amplitude_h1_1]
name = gaussian
recalib_amplitude_h1_1_mean = 0
recalib_amplitude_h1_1_var = 0.0023

[prior-recalib_amplitude_h1_2]
name = gaussian
recalib_amplitude_h1_2_mean = 0
recalib_amplitude_h1_2_var = 0.0023

[prior-recalib_amplitude_h1_3]
name = gaussian
recalib_amplitude_h1_3_mean = 0
recalib_amplitude_h1_3_var = 0.0023

[prior-recalib_amplitude_h1_4]
name = gaussian
recalib_amplitude_h1_4_mean = 0
recalib_amplitude_h1_4_var = 0.0023

[prior-recalib_amplitude_l1_0]
name = gaussian
recalib_amplitude_l1_0_mean = 0
recalib_amplitude_l1_0_var = 0.0068

[prior-recalib_amplitude_l1_1]
name = gaussian
recalib_amplitude_l1_1_mean = 0
recalib_amplitude_l1_1_var = 0.0068

[prior-recalib_amplitude_l1_2]
name = gaussian
recalib_amplitude_l1_2_mean = 0
recalib_amplitude_l1_2_var = 0.0068

[prior-recalib_amplitude_l1_3]
name = gaussian
recalib_amplitude_l1_3_mean = 0
recalib_amplitude_l1_3_var = 0.0068

[prior-recalib_amplitude_l1_4]
name = gaussian
recalib_amplitude_l1_4_mean = 0
recalib_amplitude_l1_4_var = 0.0068

[prior-recalib_phase_h1_0]
name = gaussian
recalib_phase_h1_0_mean = 0
recalib_phase_h1_0_var = 0.0030

[prior-recalib_phase_h1_1]
name = gaussian
recalib_phase_h1_1_mean = 0
recalib_phase_h1_1_var = 0.0030

[prior-recalib_phase_h1_2]
name = gaussian
recalib_phase_h1_2_mean = 0
recalib_phase_h1_2_var = 0.0030

[prior-recalib_phase_h1_3]
name = gaussian
recalib_phase_h1_3_mean = 0
recalib_phase_h1_3_var = 0.0030

[prior-recalib_phase_h1_4]
name = gaussian
recalib_phase_h1_4_mean = 0
recalib_phase_h1_4_var = 0.0030

[prior-recalib_phase_l1_0]
name = gaussian
recalib_phase_l1_0_mean = 0
recalib_phase_l1_0_var = 0.0054

[prior-recalib_phase_l1_1]
name = gaussian
recalib_phase_l1_1_mean = 0
recalib_phase_l1_1_var = 0.0054

[prior-recalib_phase_l1_2]
name = gaussian
recalib_phase_l1_2_mean = 0
recalib_phase_l1_2_var = 0.0054

[prior-recalib_phase_l1_3]
name = gaussian
recalib_phase_l1_3_mean = 0
recalib_phase_l1_3_var = 0.0054

[prior-recalib_phase_l1_4]
name = gaussian
recalib_phase_l1_4_mean = 0
recalib_phase_l1_4_var = 0.0054
Loading

0 comments on commit 91214d7

Please sign in to comment.