Skip to content

Commit

Permalink
Use compressed template bank test files (#4476)
Browse files Browse the repository at this point in the history
* Use compressed AnStar test

* More tests use compressed inputs

* Add more time
  • Loading branch information
spxiwh authored Sep 12, 2023
1 parent c1ae0d5 commit 96d6ee3
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions test/test_tmpltbank.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
"""

import math
import gzip
import numpy
from astropy.utils.data import download_file
from astropy.utils.data import conf
import pycbc.tmpltbank
# Old LigoLW output functions are not imported at tmpltbank level
import pycbc.tmpltbank.bank_output_utils as llw_output
Expand All @@ -51,6 +53,8 @@
parser = argparse.ArgumentParser()

DATA_FILE_URL = 'https://github.com/gwastro/pycbc-config/raw/master/test_data_files/{}'
# Allow astropy more time before downloads timeout
conf.remote_timeout = 100

def update_mass_parameters(tmpltbank_class):
"""
Expand Down Expand Up @@ -132,16 +136,17 @@ def setUp(self):
self.psdSize = int(self.segLen * self.sampleRate / 2.) + 1

apy_fname = download_file(
DATA_FILE_URL.format('ZERO_DET_high_P.txt'),
DATA_FILE_URL.format('ZERO_DET_high_P.txt.gz'),
cache=True
)

self.psd = pycbc.psd.from_txt(apy_fname, self.psdSize, self.deltaF,
self.f_low, is_asd_file=True)
match_psd_size = int(256 * self.sampleRate / 2.) + 1
self.psd_for_match = pycbc.psd.from_txt(apy_fname, match_psd_size,
1./256., self.f_low,
is_asd_file=True)
with gzip.open(apy_fname) as apy_fp:
self.psd = pycbc.psd.from_txt(apy_fp, self.psdSize, self.deltaF,
self.f_low, is_asd_file=True)
apy_fp.seek(0) # Reset file-pointer to start of file
self.psd_for_match = pycbc.psd.from_txt(apy_fp, match_psd_size,
1./256., self.f_low,
is_asd_file=True)

metricParams = pycbc.tmpltbank.metricParameters(self.pnOrder,\
self.f_low, self.f_upper, self.deltaF, self.f0)
Expand Down Expand Up @@ -195,13 +200,15 @@ def setUp(self):
self.xis = vals

def test_eigen_directions(self):
fname='stockEvals.dat'
fname='stockEvals.dat.gz'
apy_fname = download_file(DATA_FILE_URL.format(fname), cache=False)
evalsStock = Array(numpy.loadtxt(apy_fname))
with gzip.open(apy_fname) as apy_fp:
evalsStock = Array(numpy.loadtxt(apy_fp))

fname='stockEvecs.dat'
fname='stockEvecs.dat.gz'
apy_fname = download_file(DATA_FILE_URL.format(fname), cache=False)
evecsStock = Array(numpy.loadtxt(apy_fname))
with gzip.open(apy_fname) as apy_fp:
evecsStock = Array(numpy.loadtxt(apy_fp))

maxEval = max(evalsStock)
evalsCurr = Array(self.metricParams.evals[self.f_upper])
Expand Down Expand Up @@ -411,19 +418,21 @@ def test_metric_match_prediction(self):
def test_chirp_params(self):
chirps=pycbc.tmpltbank.get_chirp_params(2.2, 1.8, 0.2, 0.3,
self.metricParams.f0, self.metricParams.pnOrder)
fname = 'stockChirps.dat'
fname = 'stockChirps.dat.gz'
apy_fname = download_file(DATA_FILE_URL.format(fname), cache=False)
stockChirps = numpy.loadtxt(apy_fname)
with gzip.open(apy_fname) as apy_fp:
stockChirps = numpy.loadtxt(apy_fp)
diff = (chirps - stockChirps) / stockChirps
errMsg = "Calculated chirp params differ from that expected."
self.assertTrue( not (abs(diff) > 1E-4).any(), msg=errMsg)

def test_hexagonal_placement(self):
arrz = pycbc.tmpltbank.generate_hexagonal_lattice(10, 0, 10, 0, 0.03)
arrz = numpy.array(arrz)
fname = 'stockHexagonal.dat'
fname = 'stockHexagonal.dat.gz'
apy_fname = download_file(DATA_FILE_URL.format(fname), cache=False)
stockGrid = numpy.loadtxt(apy_fname)
with gzip.open(apy_fname) as apy_fp:
stockGrid = numpy.loadtxt(apy_fp)
diff = arrz - stockGrid
errMsg = "Calculated lattice differs from that expected."
self.assertTrue( not (diff > 1E-4).any(), msg=errMsg)
Expand All @@ -432,9 +441,10 @@ def test_anstar_placement(self):
arrz = pycbc.tmpltbank.generate_anstar_3d_lattice(0, 10, 0, 10, 0, \
10, 0.03)
arrz = numpy.array(arrz)
fname = 'stockAnstar3D.dat'
fname = 'stockAnstar3D.dat.gz'
apy_fname = download_file(DATA_FILE_URL.format(fname), cache=False)
stockGrid = numpy.loadtxt(apy_fname)
with gzip.open(apy_fname) as apy_fp:
stockGrid = numpy.loadtxt(apy_fp)
# Uncomment this line to regenerate the data file
#numpy.savetxt("new_example.dat", arrz)
errMsg = "Calculated lattice differs from that expected."
Expand Down

0 comments on commit 96d6ee3

Please sign in to comment.