pycbc.inject package¶
Submodules¶
pycbc.inject.inject module¶
This module provides utilities for injecting signals into data
-
class
pycbc.inject.inject.
CBCHDFInjectionSet
(sim_file, hdf_group=None, **kwds)[source]¶ Bases:
pycbc.inject.inject._HDFInjectionSet
Manages CBC injections.
-
apply
(strain, detector_name, f_lower=None, distance_scale=1, simulation_ids=None, inj_filter_rejector=None)[source]¶ Add injections (as seen by a particular detector) to a time series.
Parameters: - strain (TimeSeries) – Time series to inject signals into, of type float32 or float64.
- detector_name (string) – Name of the detector used for projecting injections.
- f_lower ({None, float}, optional) – Low-frequency cutoff for injected signals. If None, use value provided by each injection.
- distance_scale ({1, float}, optional) – Factor to scale the distance of an injection with. The default is no scaling.
- simulation_ids (iterable, optional) – If given, only inject signals with the given simulation IDs.
- inj_filter_rejector (InjFilterRejector instance; optional, default=None) – If given send each injected waveform to the InjFilterRejector instance so that it can store a reduced representation of that injection if necessary.
Returns: Return type: Raises: TypeError
– For invalid types of strain.
-
injtype
= 'cbc'¶
-
make_strain_from_inj_object
(inj, delta_t, detector_name, f_lower=None, distance_scale=1)[source]¶ Make a h(t) strain time-series from an injection object.
Parameters: - inj (injection object) – The injection object to turn into a strain h(t). Can be any
object which has waveform parameters as attributes, such as an
element in a
WaveformArray
. - delta_t (float) – Sample rate to make injection at.
- detector_name (string) – Name of the detector used for projecting injections.
- f_lower ({None, float}, optional) – Low-frequency cutoff for injected signals. If None, use value provided by each injection.
- distance_scale ({1, float}, optional) – Factor to scale the distance of an injection with. The default is no scaling.
Returns: signal – h(t) corresponding to the injection.
Return type: - inj (injection object) – The injection object to turn into a strain h(t). Can be any
object which has waveform parameters as attributes, such as an
element in a
-
-
class
pycbc.inject.inject.
InjectionSet
(sim_file, **kwds)[source]¶ Bases:
object
Manages sets of injections and injects them into time series.
Injections are read from either LIGOLW XML files or HDF files.
Parameters: - sim_file (string) – Path to an hdf file or a LIGOLW XML file that contains a SimInspiralTable.
- **kwds – The rest of the keyword arguments are passed to the waveform generation function when generating injections.
-
table
¶
-
static
from_cli
(opt)[source]¶ Return an instance of InjectionSet configured as specified on the command line.
-
static
write
(filename, samples, write_params=None, static_args=None, injtype=None, **metadata)[source]¶ Writes the injection samples to the given hdf file.
Parameters: - filename (str) – The name of the file to write to.
- samples (io.FieldArray) – FieldArray of parameters.
- write_params (list, optional) – Only write the given parameter names. All given names must be keys
in
samples
. Default is to write all parameters insamples
. - static_args (dict, optional) – Dictionary mapping static parameter names to values. These are
written to the
attrs
. - injtype (str, optional) – Specify which HDFInjectionSet class to use for writing. If not
provided, will try to determine it by looking for an approximant in
the
static_args
, followed by thesamples
. - **metadata – All other keyword arguments will be written to the file’s attrs.
-
class
pycbc.inject.inject.
LIGOLWContentHandler
(document, start_handlers={})[source]¶ Bases:
glue.ligolw.ligolw.LIGOLWContentHandler
-
startColumn
(parent, attrs)¶
-
startStream
(parent, attrs, __orig_startStream=<unbound method LIGOLWContentHandler.startStream>)¶
-
startTable
(parent, attrs, __orig_startTable=<unbound method LIGOLWContentHandler.startTable>)¶
-
-
class
pycbc.inject.inject.
RingdownHDFInjectionSet
(sim_file, hdf_group=None, **kwds)[source]¶ Bases:
pycbc.inject.inject._HDFInjectionSet
Manages a ringdown injection: reads injection from hdf file and injects it into time series.
-
apply
(strain, detector_name, distance_scale=1, simulation_ids=None, inj_filter_rejector=None)[source]¶ Add injection (as seen by a particular detector) to a time series.
Parameters: - strain (TimeSeries) – Time series to inject signals into, of type float32 or float64.
- detector_name (string) – Name of the detector used for projecting injections.
- distance_scale (float, optional) – Factor to scale the distance of an injection with. The default (=1) is no scaling.
- simulation_ids (iterable, optional) – If given, only inject signals with the given simulation IDs.
- inj_filter_rejector (InjFilterRejector instance, optional) – Not implemented. If not
None
, aNotImplementedError
will be raised.
Returns: Return type: Raises: NotImplementedError
– If aninj_filter_rejector
is provided.TypeError
– For invalid types of strain.
-
end_times
()[source]¶ Return the approximate end times of all injections.
Currently, this just assumes all ringdowns are 2 seconds long.
-
injtype
= 'ringdown'¶
-
make_strain_from_inj_object
(inj, delta_t, detector_name, distance_scale=1)[source]¶ Make a h(t) strain time-series from an injection object as read from an hdf file.
Parameters: - inj (injection object) – The injection object to turn into a strain h(t).
- delta_t (float) – Sample rate to make injection at.
- detector_name (string) – Name of the detector used for projecting injections.
- distance_scale (float, optional) – Factor to scale the distance of an injection with. The default (=1) is no scaling.
Returns: signal – h(t) corresponding to the injection.
Return type:
-
-
class
pycbc.inject.inject.
SGBurstInjectionSet
(sim_file, **kwds)[source]¶ Bases:
object
Manages sets of sine-Gaussian burst injections: reads injections from LIGOLW XML files and injects them into time series.
Parameters: sim_file (string) – Path to a LIGOLW XML file containing a SimBurstTable with injection definitions. -
indoc
¶
-
table
¶
-
apply
(strain, detector_name, f_lower=None, distance_scale=1)[source]¶ Add injections (as seen by a particular detector) to a time series.
Parameters: - strain (TimeSeries) – Time series to inject signals into, of type float32 or float64.
- detector_name (string) – Name of the detector used for projecting injections.
- f_lower ({None, float}, optional) – Low-frequency cutoff for injected signals. If None, use value provided by each injection.
- distance_scale ({1, foat}, optional) – Factor to scale the distance of an injection with. The default is no scaling.
Returns: Return type: Raises: TypeError
– For invalid types of strain.
-
-
pycbc.inject.inject.
get_hdf_injtype
(sim_file)[source]¶ Gets the HDFInjectionSet class to use with the given file.
This looks for the
injtype
in the given file’s top levelattrs
. If that attribute isn’t set, will default toCBCHDFInjectionSet
.Parameters: sim_file (str) – Name of the file. The file must already exist. Returns: The type of HDFInjectionSet to use. Return type: HDFInjectionSet
-
pycbc.inject.inject.
hdf_injtype_from_approximant
(approximant)[source]¶ Gets the HDFInjectionSet class to use with the given approximant.
Parameters: approximant (str) – Name of the approximant. Returns: The type of HDFInjectionSet to use. Return type: HDFInjectionSet
pycbc.inject.injfilterrejector module¶
This module contains functions to filter injections with only useful templates.
This module implements a set of checks to test for each segment and template combination whether injections contained within the segment are sufficiently “similar” to the template to require a matched-filter. There are a few ways of testing the “similarity” of templates and injections.
- A chirp time threshold rejects templates if chirp time difference is large
- A coarse match threshold rejects templates if a coarse overlap is small
-
class
pycbc.inject.injfilterrejector.
InjFilterRejector
(injection_file, chirp_time_window, match_threshold, f_lower, coarsematch_deltaf=1.0, coarsematch_fmax=256, seg_buffer=10)[source]¶ Bases:
object
Class for holding parameters for using injection/template pre-filtering.
This class is responsible for identifying where a matched-filter operation between templates and data is unncessary because the injections contained in the data will not match well with the given template.
-
classmethod
from_cli_multi_ifos
(opt, ifos)[source]¶ Create an InjFilterRejector instance from command-line options.
-
classmethod
from_cli_single_ifo
(opt, ifo)[source]¶ Create an InjFilterRejector instance from command-line options.
-
generate_short_inj_from_inj
(inj_waveform, simulation_id)[source]¶ Generate and a store a truncated representation of inj_waveform.
-
template_segment_checker
(bank, t_num, segment, start_time)[source]¶ Test if injections in segment are worth filtering with template.
Using the current template, current segment, and injections within that segment. Test if the injections and sufficiently “similar” to any of the injections to justify actually performing a matched-filter call. Ther are two parts to this test: First we check if the chirp time of the template is within a provided window of any of the injections. If not then stop here, it is not worth filtering this template, segment combination for this injection set. If this check passes we compute a match between a coarse representation of the template and a coarse representation of each of the injections. If that match is above a user-provided value for any of the injections then filtering can proceed. This is currently only available if using frequency-domain templates.
Parameters: FIXME – Returns: Return type: FIXME
-
classmethod