Esempio n. 1
0
import pycbc
from pycbc.fft.fftw import set_measure_level
set_measure_level(0)
from pycbc.filter import  matched_filter_core
from pycbc.types import Array, TimeSeries, FrequencySeries, float32, complex64, zeros
from pycbc.types import complex_same_precision_as,real_same_precision_as
import pycbc.waveform
from pycbc.waveform import *
from pycbc.vetoes import *
import numpy as np
from math import cos, sin, sqrt, pi, atan2, exp
import unittest
from utils import parse_args_all_schemes, simple_exit
import time

_scheme, _context = parse_args_all_schemes("Auto Chi-squared Veto")


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

        self.Msun = 4.92549095e-6
        self.sample_rate = 4096
        self.segment_length = 256
        self.low_frequency_cutoff = 30.0

        # chirp params
        self.m1 = 2.0
        self.m2 = 2.5
        self.del_t = 1.0/self.sample_rate
        self.Dl = 40.0
'''
These are the unittests for the pycbc frequencyseries type
'''

import pycbc
import unittest
from pycbc.types import *
from pycbc.scheme import *
import numpy
import lal
import sys
import os
import tempfile
from utils import array_base, parse_args_all_schemes, simple_exit

_scheme, _context = parse_args_all_schemes("FrequencySeries")

# By importing the current schemes array type, it will make it
# easier to check the  array types later
if _scheme == 'cuda':
    import pycuda
    import pycuda.gpuarray
    from pycuda.gpuarray import GPUArray as SchemeArray
elif _scheme == 'cpu':
    from numpy import ndarray as SchemeArray

from numpy import ndarray as CPUArray


class TestFrequencySeriesBase(array_base, unittest.TestCase):
    def setUp(self):
Esempio n. 3
0
from numpy import zeros, argmax, array
from pycbc import DYN_RANGE_FAC
from pycbc.waveform import get_td_waveform, get_fd_waveform, td_approximants, fd_approximants
from pycbc.pnutils import nearest_larger_binary_number
from pycbc.types import FrequencySeries, TimeSeries, complex_same_precision_as
from pycbc.types import load_frequencyseries
from pycbc.filter import sigmasq, overlap_cplx, matched_filter_core
from pycbc.filter import compute_max_snr_over_sky_loc_stat
from pycbc.filter import compute_max_snr_over_sky_loc_stat_no_phase
from pycbc.filter import compute_u_val_for_sky_loc_stat_no_phase
from pycbc.filter import compute_u_val_for_sky_loc_stat
from pycbc import psd
from pycbc import vetoes
from utils import parse_args_all_schemes, simple_exit

_scheme, _context = parse_args_all_schemes("correlate")

expected_results = {}
for idx in range(4):
    expected_results[idx] = {}
    for jdx in range(4):
        expected_results[idx][jdx] = {}

expected_results[0][0]['Ip_snr'] = 100.0
expected_results[0][0]['Ip_angle'] = -1.88619488652e-18
expected_results[0][0]['Ip_argmax'] = 0
expected_results[0][0]['Ic_snr'] = 98.7349100759
expected_results[0][0]['Ic_angle'] = 1.60960753393
expected_results[0][0]['Ic_argmax'] = 3

expected_results[0][1]['Ip_snr'] = 96.3390579783
#
#                                   Preamble
#
# =============================================================================
#
"""
These are the unit-tests for the pycbc.fft subpackage, testing only unthreaded
backends for the various schemes.
"""

import pycbc.fft
import unittest
from utils import parse_args_all_schemes, simple_exit
from fft_base import _BaseTestFFTClass

_scheme, _context = parse_args_all_schemes("FFT")

# Most of the work is now done in fft_base.  Below are factories for
# creating a test for each backend of each scheme.

# Get our list of backends:

backends = pycbc.fft.get_backend_names()

FFTTestClasses = []
for backend in backends:
    # This creates, for each backend, a new class derived from
    # both _BaseTestFFTClass and unittest.TestCase, and with
    # the additional property 'self.backend' set to the value
    # of backend.  One such class for each backend is appended
    # to the list
Esempio n. 5
0
#
#                                   Preamble
#
# =============================================================================
#
"""
These are the unittests for the pycbc.filter.matchedfilter module
"""
import sys
import unittest
from pycbc.types import *
from pycbc.scheme import *
from lal import LIGOTimeGPS as LTG
from utils import array_base, parse_args_all_schemes, simple_exit

_scheme, _context = parse_args_all_schemes("lal() method")

class TestUtils(unittest.TestCase):
    def setUp(self,*args):
        self.context = _context
        self.delta_t = 1.0 / 4096
        self.epoch = LTG(0,0)

        self.at = TimeSeries([1], delta_t=self.delta_t, dtype=float32,epoch=self.epoch)
        self.bt = TimeSeries([1], delta_t=self.delta_t, dtype=float64,epoch=self.epoch)
        self.ct = TimeSeries([1], delta_t=self.delta_t, dtype=complex64,epoch=self.epoch)
        self.dt = TimeSeries([1], delta_t=self.delta_t, dtype=complex128,epoch=self.epoch)

        self.a = Array([1], dtype=float32)
        self.b = Array([1], dtype=float64)
        self.c = Array([1], dtype=complex64)
Esempio n. 6
0
are raised.  We only attempt this for two representative functions: one basic
arithemtic operation, and one that should *not* move its data (regardless of scheme).

We do not specifically test that the lalwrapped functions raise exceptions from the
GPU, because that test is done in the test_lalwrap unit tests.
'''
import pycbc
import unittest
from pycbc.types import *
from pycbc.scheme import *
import numpy
from numpy import dtype, float32, float64, complex64, complex128
import lal
from utils import parse_args_all_schemes, simple_exit

_scheme, _context = parse_args_all_schemes("Scheme")

# By importing the current schemes array type, it will make it
# easier to check the  array types later
if isinstance(_context, CUDAScheme):
    import pycuda
    import pycuda.gpuarray
    from pycuda.gpuarray import GPUArray as SchemeArray
elif isinstance(_context, CPUScheme):
    from numpy import ndarray as SchemeArray

from numpy import ndarray as CPUArray


class SchemeTestBase(unittest.TestCase):
    __test__ = False
Esempio n. 7
0
These are the unittests for the pycbc array type
'''


import pycbc
import unittest
import itertools
from pycbc.types import *
from pycbc.scheme import *
import numpy
from utils import array_base, parse_args_all_schemes, simple_exit
import sys
import os
import tempfile

_scheme, _context = parse_args_all_schemes("Array")

# By importing the current schemes array type, it will make it
# easier to check the  array types later
if _scheme == 'cuda':
    import pycuda
    import pycuda.gpuarray
    from pycuda.gpuarray import GPUArray as SchemeArray
elif _scheme == 'cpu':
    from pycbc.types.aligned import ArrayWithAligned as SchemeArray

from pycbc.types.aligned import ArrayWithAligned as CPUArray

# ********************GENERIC ARRAY TESTS ***********************

class ArrayTestBase(array_base,unittest.TestCase):
Esempio n. 8
0
'''
These are the unittests for the pycbc timeseries type
'''

import pycbc
import unittest
from pycbc.types import *
from pycbc.scheme import *
import numpy
import lal
from utils import array_base, parse_args_all_schemes, simple_exit
import sys
import os
import tempfile

_scheme, _context = parse_args_all_schemes("TimeSeries")

# By importing the current schemes array type, it will make it
# easier to check the  array types later
if _scheme == 'cuda':
    import pycuda
    import pycuda.gpuarray
    from pycuda.gpuarray import GPUArray as SchemeArray
elif _scheme == 'cpu':
    from pycbc.types.aligned import ArrayWithAligned as SchemeArray

from pycbc.types.aligned import ArrayWithAligned as CPUArray

class TestTimeSeriesBase(array_base,unittest.TestCase):
    def setUp(self):
        self.scheme = _scheme
Esempio n. 9
0
#
#                                   Preamble
#
# =============================================================================
#
"""
These are the unit-tests for the pycbc.fft subpackage, testing only unthreaded
backends for the various schemes.
"""

import pycbc.fft
import unittest
from utils import parse_args_all_schemes, simple_exit
from fft_base import _BaseTestFFTClass

_scheme, _context = parse_args_all_schemes("FFT")

# Most of the work is now done in fft_base.  Below are factories for
# creating a test for each backend of each scheme.

# Get our list of backends:

backends = pycbc.fft.get_backend_names()

FFTTestClasses = []
for backend in backends:
    # This creates, for each backend, a new class derived from
    # both _BaseTestFFTClass and unittest.TestCase, and with
    # the additional property 'self.backend' set to the value
    # of backend.  One such class for each backend is appended
    # to the list
Esempio n. 10
0
#
#                                   Preamble
#
# =============================================================================
#
"""
These are the unittests for the pycbc.waveform module
"""
import unittest
import numpy
from pycbc.types import *
from pycbc.scheme import *
from pycbc.events import *
from utils import parse_args_all_schemes, simple_exit

_scheme, _context = parse_args_all_schemes("Threshold")

from pycbc.events.threshold_cpu import threshold_numpy
trusted_threshold = threshold_numpy


class TestThreshold(unittest.TestCase):
    def setUp(self, *args):
        self.context = _context
        self.scheme = _scheme
        r = numpy.random.uniform(low=-1, high=1.0, size=2**20)
        i = numpy.random.uniform(low=-1, high=1.0, size=2**20)
        v = r + i * 1.0j
        self.series = Array(v, dtype=complex64)
        self.threshold = 1.3
        self.locs, self.vals = trusted_threshold(self.series, self.threshold)
Esempio n. 11
0
# =============================================================================
#
"""
These are the unittests for the pycbc.filter.matchedfilter module
"""
import sys
import unittest
from pycbc.types import *
from pycbc.filter import *
from pycbc.scheme import *
from utils import parse_args_all_schemes, simple_exit
from numpy.random import uniform
import scipy.signal
from pycbc.filter.resample import lfilter

_scheme, _context = parse_args_all_schemes("Resampling")

class TestUtils(unittest.TestCase):
    def setUp(self,*args):
        self.scheme = _scheme
        self.context = _context
        self.delta_t = 1.0 / 4096
        self.target_delta_t = 1.0 / 1024
        self.a = TimeSeries([1,2,3,4], delta_t=self.delta_t, dtype=float32)
        self.b = TimeSeries([1,2,3,4], delta_t=self.delta_t, dtype=float64)
        self.c = TimeSeries([1,2,3,4], delta_t=self.delta_t, dtype=complex64)
        self.d = Array([1,2,3,4], dtype=float32)

    if _scheme == 'cpu':
        def test_resample_float32(self):
            ra = resample_to_delta_t(self.a, self.target_delta_t)
Esempio n. 12
0
#                                   Preamble
#
# =============================================================================
#
"""
These are the unittests for the pycbc.filter.matchedfilter module
"""
import unittest
from pycbc.types import *
from pycbc.scheme import *
from pycbc.filter import *
from math import sqrt
import numpy
from utils import parse_args_all_schemes, simple_exit

_scheme, _context = parse_args_all_schemes("Matched Filter")
#import pycbc.fft.fftw
#pycbc.fft.fftw.set_measure_level(0)


class TestMatchedFilter(unittest.TestCase):
    def setUp(self, *args):
        self.context = _context
        self.scheme = _scheme
        # Use sine wave as test signal
        data = numpy.sin(numpy.arange(0, 100, 100 / (4096.0 * 64)))
        self.filt = TimeSeries(data, dtype=float32, delta_t=1.0 / 4096)
        self.filt2 = (self.filt * 1)
        self.filt2[0:int(len(self.filt2) / 2)].fill(0)
        self.filt_offset = TimeSeries(numpy.roll(data, 4096 * 32),
                                      dtype=float32,
Esempio n. 13
0
# =============================================================================
#
"""
These are the unittests for the pycbc.waveform module
"""
import sys
import pycbc
import unittest
import numpy
from pycbc.types import *
from pycbc.scheme import *
from pycbc.events import *
import pycbc.fft
from utils import parse_args_all_schemes, simple_exit

_scheme, _context = parse_args_all_schemes("Threshold")

from pycbc.events.threshold_cpu import threshold_numpy
trusted_threshold = threshold_numpy

class TestThreshold(unittest.TestCase):
    def setUp(self,*args):
        self.context = _context
        self.scheme = _scheme
        r = numpy.random.uniform(low=-1, high=1.0, size=2**20)
        i = numpy.random.uniform(low=-1, high=1.0, size=2**20)
        v = r + i*1.0j
        self.series = Array(v, dtype=complex64)
        self.threshold = 1.3
        self.locs, self.vals = trusted_threshold(self.series, self.threshold) 
        self.tolerance = 1e-6
Esempio n. 14
0
are raised.  We only attempt this for two representative functions: one basic
arithemtic operation, and one that should *not* move its data (regardless of scheme).

We do not specifically test that the lalwrapped functions raise exceptions from the
GPU, because that test is done in the test_lalwrap unit tests.
'''
import pycbc
import unittest
from pycbc.types import *
from pycbc.scheme import *
import numpy
from numpy import dtype, float32, float64, complex64, complex128
import lal
from utils import parse_args_all_schemes, simple_exit

_scheme, _context = parse_args_all_schemes("Scheme")

# By importing the current schemes array type, it will make it
# easier to check the  array types later
if isinstance(_context,CUDAScheme):
    import pycuda
    import pycuda.gpuarray
    from pycuda.gpuarray import GPUArray as SchemeArray
elif isinstance(_context,CPUScheme):
    from pycbc.types.aligned import ArrayWithAligned as SchemeArray

from pycbc.types.aligned import ArrayWithAligned as CPUArray


class SchemeTestBase(unittest.TestCase):
    def setUp(self):
Esempio n. 15
0
These are the unittests for the pycbc PSD module.
'''
from __future__ import division
import os
import tempfile
import pycbc
import pycbc.psd
from pycbc.types import TimeSeries, FrequencySeries
from pycbc.fft import ifft
from pycbc.fft.fftw import set_measure_level
import unittest
import numpy
from utils import parse_args_all_schemes, simple_exit
set_measure_level(0)

_scheme, _context = parse_args_all_schemes("PSD")


class TestPSD(unittest.TestCase):
    def setUp(self):
        self.scheme = _scheme
        self.context = _context
        self.psd_len = 1024
        self.psd_delta_f = 0.1
        self.psd_low_freq_cutoff = 10.
        # generate 1/f noise for testing PSD estimation
        noise_size = 524288
        sample_freq = 4096.
        delta_f = sample_freq / noise_size
        numpy.random.seed(132435)
        noise = numpy.random.normal(loc=0, scale=1, size=noise_size//2+1) + \
Esempio n. 16
0
#
"""
These are the unittests for the pycbc.filter.matchedfilter module
"""
import sys
import pycbc
import unittest
from pycbc.types import *
from pycbc.scheme import *
from pycbc.filter import *
from math import sqrt
import pycbc.fft
import numpy
from utils import parse_args_all_schemes, simple_exit

_scheme, _context = parse_args_all_schemes("Matched Filter")
import pycbc.fft.fftw
pycbc.fft.fftw.set_measure_level(0)

class TestMatchedFilter(unittest.TestCase):
    def setUp(self,*args):
        self.context = _context
        self.scheme = _scheme
        from math import sin
        # Use sine wave as test signal
        data = numpy.sin(numpy.arange(0,100,100/(4096.0*64)))
        self.filt = TimeSeries(data,dtype=float32,delta_t=1.0/4096)
        self.filt2 = (self.filt*1)
        self.filt2[0:len(self.filt2)/2].fill(0)
        self.filt_offset = TimeSeries(numpy.roll(data,4096*32), dtype=float32,
                                      delta_t=1.0/4096)
Esempio n. 17
0
import sys
import pycbc
from pycbc.filter import  matched_filter_core
from pycbc.types import Array, TimeSeries, FrequencySeries, float32, complex64, zeros
from pycbc.types import complex_same_precision_as,real_same_precision_as
import pycbc.waveform
from pycbc.waveform import *
from pycbc.vetoes import *
import numpy as np
from math import cos, sin, sqrt, pi, atan2, exp 
import unittest
from utils import parse_args_all_schemes, simple_exit

_scheme, _context = parse_args_all_schemes("Auto Chi-squared Veto")


class TestAutochisquare(unittest.TestCase):
    def setUp(self):
	self.Msun = 4.92549095e-6
        self.sample_rate = 4096
        self.segment_length = 256
        self.low_frequency_cutoff = 30.0

        # chirp params
        self.m1 = 2.0
        self.m2 = 2.5
        self.del_t = 1.0/self.sample_rate
        self.Dl = 40.0
        self.iota = 1.0
        self.phi_c = 2.0
        self.tc_indx = 86*self.sample_rate ## offset from the beginnig of a segment
Esempio n. 18
0
'''
These are the unittests for the pycbc timeseries type
'''

import pycbc
import unittest
from pycbc.types import *
from pycbc.scheme import *
import numpy
import lal
from utils import array_base, parse_args_all_schemes, simple_exit
import sys
import os
import tempfile

_scheme, _context = parse_args_all_schemes("TimeSeries")

# By importing the current schemes array type, it will make it
# easier to check the  array types later
if _scheme == 'cuda':
    import pycuda
    import pycuda.gpuarray
    from pycuda.gpuarray import GPUArray as SchemeArray
elif _scheme == 'cpu':
    from numpy import ndarray as SchemeArray

from numpy import ndarray as CPUArray


class TestTimeSeriesBase(array_base, unittest.TestCase):
    def setUp(self):
Esempio n. 19
0
'''

import sys
import os
import tempfile
import pycbc
import pycbc.psd
from pycbc.types import TimeSeries, FrequencySeries
from pycbc.fft import ifft
from pycbc.fft.fftw import set_measure_level
import unittest
import numpy
from utils import parse_args_all_schemes, simple_exit
set_measure_level(0)

_scheme, _context = parse_args_all_schemes("PSD")

class TestPSD(unittest.TestCase):
    def setUp(self):
        self.scheme = _scheme
        self.context = _context
        self.psd_len = 1024
        self.psd_delta_f = 0.1
        self.psd_low_freq_cutoff = 10.
        # generate 1/f noise for testing PSD estimation
        noise_size = 524288
        sample_freq = 4096.
        delta_f = sample_freq / noise_size
        numpy.random.seed(132435)
        noise = numpy.random.normal(loc=0, scale=1, size=noise_size/2+1) + \
            1j * numpy.random.normal(loc=0, scale=1, size=noise_size/2+1)
Esempio n. 20
0
#                                   Preamble
#
# =============================================================================
#
"""
These are the unittests for the pycbc.waveform module
"""
import pycbc
import unittest
import numpy
from numpy import sqrt, cos, sin
from pycbc.scheme import CPUScheme
from pycbc.waveform import td_approximants, fd_approximants, get_td_waveform, get_fd_waveform
from utils import parse_args_all_schemes, simple_exit

_scheme, _context = parse_args_all_schemes("Waveform")

failing_wfs = ['PhenSpinTaylor', 'PhenSpinTaylorRD', 'EccentricTD',
              'SpinDominatedWf', 'EOBNRv2HM_ROM', 'EOBNRv2_ROM', 'EccentricFD',
              'NR_hdf5', 'TEOBResum_ROM', 'Lackey_Tidal_2013_SEOBNRv2_ROM']

class TestWaveform(unittest.TestCase):
    def setUp(self,*args):
        self.context = _context
        self.scheme = _scheme

    def test_generation(self):
        with self.context:
            for waveform in td_approximants():
                if waveform in failing_wfs:
                    continue
Esempio n. 21
0
'''
These are the unittests for the pycbc frequencyseries type
'''

import pycbc
import unittest
from pycbc.types import *
from pycbc.scheme import *
import numpy
import lal
import sys
import os
import tempfile
from utils import array_base, parse_args_all_schemes, simple_exit

_scheme, _context = parse_args_all_schemes("FrequencySeries")

# By importing the current schemes array type, it will make it
# easier to check the  array types later
if _scheme == 'cuda':
    import pycuda
    import pycuda.gpuarray
    from pycuda.gpuarray import GPUArray as SchemeArray
elif _scheme == 'opencl':
    import pyopencl
    import pyopencl.array
    from pyopencl.array import Array as SchemeArray
elif _scheme == 'cpu':
    from pycbc.types.aligned import ArrayWithAligned as SchemeArray

from pycbc.types.aligned import ArrayWithAligned as CPUArray
Esempio n. 22
0
#                                   Preamble
#
# =============================================================================
#
"""
These are the unittests for the pycbc.waveform module
"""
import pycbc
import unittest
import numpy
from numpy import sqrt, cos, sin
from pycbc.scheme import CPUScheme
from pycbc.waveform import td_approximants, fd_approximants, get_td_waveform, get_fd_waveform
from utils import parse_args_all_schemes, simple_exit

_scheme, _context = parse_args_all_schemes("Waveform")

# We only check a few as some require auxiliary files
good_waveforms = [
    'IMRPhenomD', 'TaylorF2', 'SEOBNRv4', 'SpinTaylorT5', 'IMRPhenomPv2',
    'IMRPhenomPv3HM', 'SEOBNRv4P', 'IMRPhenomPv3'
]


class TestWaveform(unittest.TestCase):
    def setUp(self, *args):
        self.context = _context
        self.scheme = _scheme

    def test_generation(self):
        with self.context:
Esempio n. 23
0
# =============================================================================
#
#                                   Preamble
#
# =============================================================================
#
"""
These are the unittests for the pycbc.waveform module
"""
import unittest
import numpy
from pycbc.types import *
from pycbc.scheme import *
from utils import parse_args_all_schemes, simple_exit

_scheme, _context = parse_args_all_schemes("correlate")

from pycbc.vetoes.chisq_cpu import chisq_accum_bin_numpy
from pycbc.vetoes import chisq_accum_bin, power_chisq_bins, power_chisq
from pycbc.vetoes import power_chisq_at_points_from_precomputed
from pycbc.filter import resample_to_delta_t
from pycbc.catalog import Merger
from pycbc.psd import interpolate, inverse_spectrum_truncation
from pycbc.waveform import get_fd_waveform
from pycbc.filter import matched_filter_core

trusted_accum = chisq_accum_bin_numpy


class TestChisq(unittest.TestCase):
    def setUp(self, *args):
Esempio n. 24
0
#
#                                   Preamble
#
# =============================================================================
#
"""
These are the unittests for the pycbc.filter.matchedfilter module
"""
import sys
import unittest
from pycbc.types import *
from pycbc.filter import *
from pycbc.scheme import *
from utils import parse_args_all_schemes, simple_exit

_scheme, _context = parse_args_all_schemes("Resampling")


class TestUtils(unittest.TestCase):
    def setUp(self, *args):
        self.scheme = _scheme
        self.context = _context
        self.delta_t = 1.0 / 4096
        self.target_delta_t = 1.0 / 1024
        self.a = TimeSeries([1, 2, 3, 4], delta_t=self.delta_t, dtype=float32)
        self.b = TimeSeries([1, 2, 3, 4], delta_t=self.delta_t, dtype=float64)
        self.c = TimeSeries([1, 2, 3, 4],
                            delta_t=self.delta_t,
                            dtype=complex64)
        self.d = Array([1, 2, 3, 4], dtype=float32)