示例#1
0
"""Unit test for coincident ranking statistic implementations."""

import unittest
import numpy as np
from utils import parse_args_cpu_only, simple_exit
from pycbc.events.stat import statistic_dict

# this test only needs to happen on the CPU
parse_args_cpu_only('coinc stats')


class CoincStatTest(unittest.TestCase):
    def setUp(self):
        # one could loop over all single rankings
        # and detector combinations for a complete test
        self.single_rank = 'snr'
        self.detectors = ['H1', 'L1']

        # simulate some single-detector triggers from Gaussian noise
        self.num_trigs = n = 100
        self.single_trigs = {}
        for d in self.detectors:
            self.single_trigs[d] = {
                'snr': np.random.chisquare(2, size=n)**0.5,
                'coa_phase': np.random.uniform(0, 2 * np.pi, size=n),
                'end_time':
                1295441120 + np.random.uniform(-0.01, 0.01, size=n),
                'sigmasq': np.random.uniform(1, 10, size=n)
            }

        self.time_slide_shift = 0.1
示例#2
0
from pycbc.types import TimeSeries, FrequencySeries
from pycbc.io.live import SingleCoincForGraceDB
from glue.ligolw import ligolw
from glue.ligolw import lsctables
from glue.ligolw import table
from glue.ligolw import utils as ligolw_utils
from lal import series as lalseries

# if we have the GraceDb module then we can do deeper tests,
# otherwise just fall back to quicker ones
try:
    from ligo.gracedb.rest import GraceDb
except ImportError:
    GraceDb = None

parse_args_cpu_only("io.live")


class ContentHandler(ligolw.LIGOLWContentHandler):
    pass


lsctables.use_in(ContentHandler)


class TestIOLive(unittest.TestCase):
    def setUp(self):
        self.template = {
            'template_id': 0,
            'mass1': 10,
            'mass2': 11,
示例#3
0
    "spin1_azimuthal" : (0.0, 2 * numpy.pi),
    "spin2_a" : (0.0, 1.0),
    "spin2_polar" : (0, numpy.pi),
    "spin2_azimuthal" : (0.0, 2 * numpy.pi),
    "chi_eff" : (-1.0, 1.0),
    "chi_a" : (0.0, 1.0),
    "chi_p" : (0.0, 1.0),
    "phi_s" : (0.0, 2 * numpy.pi),
    "phi_a" : (0.0, 2 * numpy.pi),
    "xi1" : (0.0, 1.0),
    "xi2" : (0.0, 1.0),
    "chirp_distance" : (2.0, 10.0),
}

# tests only need to happen on the CPU
parse_args_cpu_only("Transforms")

class TestTransforms(unittest.TestCase):

    def setUp(self):

        # set random seed
        numpy.random.seed(1024)

    def test_inverse(self):

        # set threshold how similar values must be
        threshold = 0.001

        # loop over forward CBC transforms
        for trans in transforms.common_cbc_forward_transforms:
示例#4
0
import tempfile
import lal
import pycbc
from pycbc.types import TimeSeries
from pycbc.detector import Detector
from pycbc.inject import InjectionSet
import unittest
import numpy
import itertools
from glue.ligolw import ligolw
from glue.ligolw import lsctables
from glue.ligolw import utils
from utils import parse_args_cpu_only, simple_exit

# Injection tests only need to happen on the CPU
parse_args_cpu_only("Injections")

class MyInjection(object):
    def fill_sim_inspiral_row(self, row):
        # using dummy values for many fields, should work for our purposes
        row.waveform = 'TaylorT4'
        row.distance = self.distance
        total_mass = self.mass1 + self.mass2
        row.mass1 = self.mass1
        row.mass2 = self.mass2
        row.eta = self.mass1 * self.mass2 / total_mass ** 2
        row.mchirp = total_mass * row.eta ** (3. / 5.)
        row.latitude = self.latitude
        row.longitude = self.longitude
        row.inclination = self.inclination
        row.polarization = self.polarization
示例#5
0
import pycbc.psd
import pycbc.pnutils
from pycbc import pnutils
from pycbc.types import Array
import difflib
import sys
import matplotlib
matplotlib.use('Agg')
import pylab

import unittest
from utils import parse_args_cpu_only, simple_exit

# This will return whatever is appropriate, depending on whether this
# particular instance of the unittest was called for CPU, CUDA, or OpenCL
parse_args_cpu_only("Template bank module")

import argparse
parser = argparse.ArgumentParser()

def update_mass_parameters(tmpltbank_class):
    """
    Choose various sets of mass parameters for testing.
    """
    num_comp_masses = 3
    min_mass1 = [1,2,6]
    max_mass1 = [5,8,12]
    min_mass2 = [1,1,1]
    max_mass2 = [5,5,5]
    num_tot_masses = 3
    # These *must* be provided
示例#6
0
import pycbc.psd
import pycbc.pnutils
from pycbc import pnutils
from pycbc.types import Array
import difflib
import sys
import matplotlib
matplotlib.use('Agg')
import pylab

import unittest
from utils import parse_args_cpu_only, simple_exit

# This will return whatever is appropriate, depending on whether this
# particular instance of the unittest was called for CPU, CUDA, or OpenCL
parse_args_cpu_only("Template bank module")

import argparse
parser = argparse.ArgumentParser()


def update_mass_parameters(tmpltbank_class):
    """
    Choose various sets of mass parameters for testing.
    """
    num_comp_masses = 3
    min_mass1 = [1, 2, 6]
    max_mass1 = [5, 8, 12]
    min_mass2 = [1, 1, 1]
    max_mass2 = [5, 5, 5]
    num_tot_masses = 3
    "spin1_azimuthal": (0.0, 2 * numpy.pi),
    "spin2_a": (0.0, 1.0),
    "spin2_polar": (0, numpy.pi),
    "spin2_azimuthal": (0.0, 2 * numpy.pi),
    "chi_eff": (-1.0, 1.0),
    "chi_a": (0.0, 1.0),
    "chi_p": (0.0, 1.0),
    "phi_s": (0.0, 2 * numpy.pi),
    "phi_a": (0.0, 2 * numpy.pi),
    "xi1": (0.0, 1.0),
    "xi2": (0.0, 1.0),
    "chirp_distance": (2.0, 10.0),
}

# tests only need to happen on the CPU
parse_args_cpu_only("Transforms")


class TestTransforms(unittest.TestCase):
    def setUp(self):

        # set random seed
        numpy.random.seed(1024)

    def test_inverse(self):

        # set threshold how similar values must be
        threshold = 0.001

        # loop over forward CBC transforms
        for trans in transforms.common_cbc_forward_transforms:
示例#8
0
import unittest
from pycbc import distributions
from pycbc.inference import entropy
from utils import parse_args_cpu_only
from utils import simple_exit
from pycbc.workflow import WorkflowConfigParser

# distributions to exclude from one-dimensional distribution unit tests
# some of these distributons have their own specific unit test
EXCLUDE_DIST_NAMES = [
    "fromfile", "arbitrary", "external", "uniform_solidangle", "uniform_sky",
    "independent_chip_chieff", "uniform_f0_tau"
]

# tests only need to happen on the CPU
parse_args_cpu_only("Distributions")


def cartesian(arrays):
    """ Returns a cartesian product from a list of iterables.
    """
    return numpy.array(
        [numpy.array(element) for element in itertools.product(*arrays)])


class TestDistributions(unittest.TestCase):
    def setUp(self):

        # set random seed
        numpy.random.seed(1024)
示例#9
0
#
"""
These are the unittests for the pycbc.inference subpackage
"""
import sys
import pycbc
import unittest
import numpy
from pycbc import distributions
from pycbc import inference
from pycbc import waveform
from pycbc import psd as pypsd
from utils import parse_args_cpu_only, simple_exit

# tests only need to happen on the CPU
parse_args_cpu_only("Inference")

class TestInference(unittest.TestCase):
    def setUp(self, *args):
        numpy.random.seed(1024)

    def test_likelihood_evaluator_init(self):

        # data args
        seglen = 4
        sample_rate = 2048
        N = seglen * sample_rate/2 + 1
        fmin = 30.

        # setup waveform generator and signal parameters
        m1, m2, s1z, s2z, tsig = 38.6, 29.3, 0., 0., 3.1
#
# =============================================================================
#
"""
These are the unit-tests for the pycbc.fft subpackage, testing only unthreaded
backends for the various schemes.
"""

import pycbc.fft
from pycbc.scheme import CPUScheme
import unittest
from sys import exit as _exit
from utils import parse_args_cpu_only, simple_exit
from fft_base import _BaseTestFFTClass

parse_args_cpu_only("FFTW openmp backend")

# See if we can get set the FFTW backend to 'openmp'; if not, say so and exit.

if 'fftw' in pycbc.fft.get_backend_names():
    import pycbc.fft.fftw
    try:
        pycbc.fft.fftw.set_threads_backend('openmp')
    except:
        print(
            "Unable to import openmp threads backend to FFTW; skipping openmp thread tests"
        )
        _exit(0)
else:
    print(
        "FFTW does not seem to be an available CPU backend; skipping openmp thread tests"
示例#11
0
#
'''
These are the unittests for the pycbc frame/cache reading functions
'''


import pycbc
import unittest
import pycbc.frame
import numpy
import lal
from pycbc.types import TimeSeries
from utils import parse_args_cpu_only, simple_exit

# Frame tests only need to happen on the CPU
parse_args_cpu_only("Frame I/O")

class FrameTestBase(unittest.TestCase):
    def setUp(self):
        numpy.random.seed(1023)
        self.size = pow(2,12)

        self.data1 = numpy.array(numpy.random.rand(self.size), dtype=self.dtype)
        self.data2 = numpy.array(numpy.random.rand(self.size), dtype=self.dtype)

        # If the dtype is complex, we should throw in some complex values as well
        if self.dtype == numpy.complex64 or self.dtype == numpy.complex128:
            self.data1 += numpy.random.rand(self.size) * 1j
            self.data2 += numpy.random.rand(self.size) * 1j

        self.delta_t = .5
示例#12
0
#                                   Preamble
#
# =============================================================================
#
"""
These are the unittests for the pycbc.filter.matchedfilter module
"""
import sys
import unittest
import numpy
from pycbc.pnutils import *
from pycbc.scheme import *
from utils import parse_args_cpu_only, simple_exit

# We only need CPU tests
parse_args_cpu_only("PN Utilities")

class TestUtils(unittest.TestCase):
    def test_mass1_mass2_to_tau0_tau3(self):
        result = mass1_mass2_to_tau0_tau3(3.0,5.0,15.0)
        answer = (63.039052988077955, 2.353532999897545)
        self.assertAlmostEqual(result[0]/answer[0],1,places=6)
        self.assertAlmostEqual(result[1]/answer[1],1,places=6)

    def test_tau0_tau3_to_mtotal_eta(self):
        result = tau0_tau3_to_mtotal_eta(93.84928959285253,2.9198487498891126,20.0)
        answer = [5., 4.*1./5./5.]
        self.assertAlmostEqual(result[0]/answer[0],1,places=6)
        self.assertAlmostEqual(result[1]/answer[1],1,places=6)

    def test_tau0_tau3_to_mass1_mass2(self):
示例#13
0
'''
These are the unittests for the pycbc frame/cache reading functions
'''

import pycbc
import unittest
from pycbc.types import *
from pycbc.scheme import *
import pycbc.frame
import numpy
import lal
#from pylal import Fr
from utils import parse_args_cpu_only, simple_exit

# Frame tests only need to happen on the CPU
parse_args_cpu_only("Frame I/O")


class FrameTestBase(unittest.TestCase):
    def setUp(self):
        numpy.random.seed(1023)
        self.size = pow(2, 12)

        self.data1 = numpy.array(numpy.random.rand(self.size),
                                 dtype=self.dtype)
        self.data2 = numpy.array(numpy.random.rand(self.size),
                                 dtype=self.dtype)

        # If the dtype is complex, we should throw in some complex values as well
        if self.dtype == numpy.complex64 or self.dtype == numpy.complex128:
            self.data1 += numpy.random.rand(self.size) * 1j
示例#14
0
These are the unittests for samplers in the pycbc.inference subpackage.
"""
import sys
import pycbc
import unittest
import numpy
from pycbc import distributions
from pycbc.inference import likelihood
from pycbc.inference import sampler
from pycbc.psd import analytical
from pycbc.waveform import generator
from utils import parse_args_cpu_only
from utils import simple_exit

# tests only need to happen on the CPU
parse_args_cpu_only("Samplers")

class TestSamplers(unittest.TestCase):

    def setUp(self, *args):

        # set random seed
        numpy.random.seed(1024)

        # set data parameters
        self.ifos = ["H1", "L1", "V1"]
        self.data_length = 4 # in seconds
        self.sample_rate = 2048 # in Hertz
        self.fdomain_samples = self.data_length * self.sample_rate / 2 + 1
        self.delta_f = 1.0 / self.data_length
        self.fmin = {ifo : 30.0 for ifo in self.ifos}
示例#15
0
from pycbc.types import TimeSeries, FrequencySeries
from pycbc.io.live import SingleCoincForGraceDB
from glue.ligolw import ligolw
from glue.ligolw import lsctables
from glue.ligolw import table
from glue.ligolw import utils as ligolw_utils

# if we have the GraceDb module then we can do deeper tests,
# otherwise just fall back to quicker ones
try:
    from ligo.gracedb.rest import GraceDb
except ImportError:
    GraceDb = None


parse_args_cpu_only("io.live")

class ContentHandler(ligolw.LIGOLWContentHandler):
    pass
lsctables.use_in(ContentHandler)

class TestIOLive(unittest.TestCase):
    def setUp(self):
        self.template = {'template_id': 0,
                         'mass1': 10,
                         'mass2': 11,
                         'spin1x': 0,
                         'spin1y': 0,
                         'spin1z': 0,
                         'spin2x': 0,
                         'spin2y': 0,
示例#16
0
import tempfile
import lal
import pycbc
from pycbc.types import TimeSeries
from pycbc.detector import Detector, get_available_detectors
from pycbc.inject import InjectionSet
import unittest
import numpy
import itertools
from glue.ligolw import ligolw
from glue.ligolw import lsctables
from glue.ligolw import utils as ligolw_utils
from utils import parse_args_cpu_only, simple_exit

# Injection tests only need to happen on the CPU
parse_args_cpu_only("Injections")


class MyInjection(object):
    def fill_sim_inspiral_row(self, row):
        # using dummy values for many fields, should work for our purposes
        row.waveform = 'TaylorT4threePointFivePN'
        row.distance = self.distance
        total_mass = self.mass1 + self.mass2
        row.mass1 = self.mass1
        row.mass2 = self.mass2
        row.eta = self.mass1 * self.mass2 / total_mass**2
        row.mchirp = total_mass * row.eta**(3. / 5.)
        row.latitude = self.latitude
        row.longitude = self.longitude
        row.inclination = self.inclination
示例#17
0
#
# =============================================================================
#
"""
These are the unit-tests for the pycbc.fft subpackage, testing only unthreaded
backends for the various schemes.
"""

import pycbc.fft
from pycbc.scheme import CPUScheme
import unittest
from sys import exit as _exit
from utils import parse_args_cpu_only, simple_exit
from fft_base import _BaseTestFFTClass

parse_args_cpu_only("FFTW openmp backend")

# See if we can get set the FFTW backend to 'openmp'; if not, say so and exit.

if 'fftw' in pycbc.fft.get_backend_names():
    import pycbc.fft.fftw
    try:
        pycbc.fft.fftw.set_threads_backend('openmp')
    except:
        print "Unable to import openmp threads backend to FFTW; skipping openmp thread tests"
        _exit(0)
else:
    print "FFTW does not seem to be an available CPU backend; skipping openmp thread tests"
    _exit(0)

# Now set the number of threads to something nontrivial
示例#18
0
# =============================================================================
#
"""
These are the unit-tests for the pycbc.fft subpackage, testing only unthreaded
backends for the various schemes.
"""
import platform
import unittest

import pycbc.fft
from pycbc.scheme import CPUScheme
from sys import exit as _exit
from utils import parse_args_cpu_only, simple_exit
from fft_base import _BaseTestFFTClass

parse_args_cpu_only("MKL threaded backend")

# See if we can get set the FFTW backend to 'openmp'; if not, say so and exit.
if 'arm64' in platform.machine():
    print("MKL not supported on arm64, skipping")
    pass
elif not 'mkl' in pycbc.fft.get_backend_names():
    print("MKL does not seem to be available; why isn't it installed?")
    _exit(0)
else:
    # Now set the number of threads to something nontrivial

    # Most of the work is now done in fft_base.

    FFTTestClasses = []
    for num_threads in [2, 4, 6, 8]:
示例#19
0
#
# =============================================================================
#
"""
These are the unit-tests for the pycbc.fft.fftw subpackage, testing only the pthreads
threading backend.
"""

import pycbc.fft
from pycbc.scheme import CPUScheme
import unittest
from sys import exit as _exit
from utils import parse_args_cpu_only, simple_exit
from fft_base import _BaseTestFFTClass

parse_args_cpu_only("FFTW pthreads backend")

# See if we can get set the FFTW backend to 'pthreads'; if not, say so and exit.

if 'fftw' in pycbc.fft._all_backends_list:
    import pycbc.fft.fftw
    try:
        pycbc.fft.fftw.set_threads_backend('pthreads')
    except:
        print "Unable to import pthreads threads backend to FFTW; skipping pthreads thread tests"
        _exit(0)
else:
    print "FFTW does not seem to be an available CPU backend; skipping pthreads thread tests"
    _exit(0)

# Most of the work is now done in fft_base.
示例#20
0
#
#                                   Preamble
#
# =============================================================================
#
"""
These are the unittests for the pycbc.filter.matchedfilter module
"""
import unittest
import numpy
from pycbc.pnutils import *
from pycbc.scheme import *
from utils import parse_args_cpu_only, simple_exit

# We only need CPU tests
parse_args_cpu_only("PN Utilities")


class TestUtils(unittest.TestCase):
    def test_mass1_mass2_to_tau0_tau3(self):
        result = mass1_mass2_to_tau0_tau3(3.0, 5.0, 15.0)
        answer = (63.039052988077955, 2.353532999897545)
        self.assertAlmostEqual(result[0] / answer[0], 1, places=6)
        self.assertAlmostEqual(result[1] / answer[1], 1, places=6)

    def test_tau0_tau3_to_mtotal_eta(self):
        result = tau0_tau3_to_mtotal_eta(93.84928959285253, 2.9198487498891126,
                                         20.0)
        answer = [5., 4. * 1. / 5. / 5.]
        self.assertAlmostEqual(result[0] / answer[0], 1, places=6)
        self.assertAlmostEqual(result[1] / answer[1], 1, places=6)
示例#21
0
#
# =============================================================================
#
"""
These are the unittests for the pycbc.inference subpackage
"""
import sys
import pycbc
import unittest
import numpy
from pycbc import inference, waveform
from pycbc import psd as pypsd
from utils import parse_args_cpu_only, simple_exit

# tests only need to happen on the CPU
parse_args_cpu_only("Inference")


class TestInference(unittest.TestCase):
    def setUp(self, *args):
        numpy.random.seed(1024)

    def test_likelihood_evaluator_init(self):

        # data args
        seglen = 4
        sample_rate = 2048
        N = seglen * sample_rate / 2 + 1
        fmin = 30.

        # setup waveform generator and signal parameters
示例#22
0
import unittest
from pycbc import distributions
from pycbc.inference import entropy
from utils import parse_args_cpu_only
from utils import simple_exit
from pycbc.workflow import WorkflowConfigParser

# distributions to exclude from one-dimensional distribution unit tests
# some of these distributons have their own specific unit test
EXCLUDE_DIST_NAMES = ["fromfile", "arbitrary",
                      "uniform_solidangle", "uniform_sky",
                      "independent_chip_chieff",
                      "uniform_component_masses"]

# tests only need to happen on the CPU
parse_args_cpu_only("Distributions")

def cartesian(arrays):
    """ Returns a cartesian product from a list of iterables.
    """
    return numpy.array([numpy.array(element)
                        for element in itertools.product(*arrays)])

class TestDistributions(unittest.TestCase):

    def setUp(self):

        # set random seed
        numpy.random.seed(1024)

        # path to example configuration file for testing
示例#23
0
These are the unittests for samplers in the pycbc.inference subpackage.
"""
import sys
import pycbc
import unittest
import numpy
from pycbc import distributions
from pycbc.inference import likelihood
from pycbc.inference import sampler
from pycbc.psd import analytical
from pycbc.waveform import generator
from utils import parse_args_cpu_only
from utils import simple_exit

# tests only need to happen on the CPU
parse_args_cpu_only("Samplers")

class TestSamplers(unittest.TestCase):

    def setUp(self, *args):

        # set random seed
        numpy.random.seed(1024)

        # set data parameters
        self.ifos = ["H1", "L1", "V1"]
        self.data_length = 4 # in seconds
        self.sample_rate = 2048 # in Hertz
        self.fdomain_samples = self.data_length * self.sample_rate / 2 + 1
        self.delta_f = 1.0 / self.data_length
        self.fmin = 30.0