def test_read_write_wav(self): array = self.create(dtype='float32') utils.test_read_write( array, 'wav', write_kw={'scale': 1}, assert_equal=utils.assert_quantity_sub_equal, assert_kw={'exclude': ['unit', 'name', 'channel', 'x0']})
def _read_write(**kwargs): read_kw = rw_kwargs.copy() read_kw.update(kwargs.pop('read_kw', {})) write_kw = rw_kwargs.copy() write_kw.update(kwargs.pop('write_kw', {})) return utils.test_read_write(instance, format, extension=ext, assert_equal=_assert, read_kw=read_kw, write_kw=write_kw, **kwargs)
def _read_write(**kwargs): read_kw = rw_kwargs.copy() read_kw.update(kwargs.pop('read_kw', {})) write_kw = rw_kwargs.copy() write_kw.update(kwargs.pop('write_kw', {})) return utils.test_read_write(instance, format, extension=ext, assert_equal=_assert, read_kw=read_kw, write_kw=write_kw, **kwargs)
def test_read_write_gwf(self, api): array = self.create(name='TEST') # map API to format name if api is None: fmt = 'gwf' else: fmt = 'gwf.%s' % api # test basic write/read try: utils.test_read_write(array, fmt, extension='gwf', read_args=[array.name], assert_equal=utils.assert_quantity_sub_equal, assert_kw={'exclude': ['channel']}) except ImportError as e: pytest.skip(str(e)) # test read keyword arguments suffix = '-%d-%d.gwf' % (array.t0.value, array.duration.value) with tempfile.NamedTemporaryFile(prefix='GWpy-', suffix=suffix) as f: array.write(f.name) def read_(**kwargs): return type(array).read(f, array.name, format='gwf', **kwargs) # test start, end start, end = array.span.contract(10) t = read_(start=start, end=end) utils.assert_quantity_sub_equal(t, array.crop(start, end), exclude=['channel']) assert t.span == (start, end) t = read_(start=start) utils.assert_quantity_sub_equal(t, array.crop(start=start), exclude=['channel']) t = read_(end=end) utils.assert_quantity_sub_equal(t, array.crop(end=end), exclude=['channel']) # test dtype t = read_(dtype='float32') assert t.dtype is numpy.dtype('float32') t = read_(dtype={f.name: 'float64'}) assert t.dtype is numpy.dtype('float64') # check errors with pytest.raises((ValueError, RuntimeError)): read_(start=array.span[1]) with pytest.raises((ValueError, RuntimeError)): read_(end=array.span[0] - 1) # check old format prints a deprecation warning if api: with pytest.warns(DeprecationWarning): type(array).read(f, array.name, format=api) # check reading from cache try: from glue.lal import Cache except ImportError: pass else: a2 = self.create(name='TEST', t0=array.span[1], dt=array.dx) suffix = '-%d-%d.gwf' % (a2.t0.value, a2.duration.value) with tempfile.NamedTemporaryFile(prefix='GWpy-', suffix=suffix) as f2: a2.write(f2.name) cache = Cache.from_urls([f.name, f2.name], coltype=int) comb = type(array).read(cache, 'TEST', format=fmt, nproc=2) utils.assert_quantity_sub_equal(comb, array.append( a2, inplace=False), exclude=['channel'])
def test_read_write_ascii(self, array, format): utils.test_read_write( array, format, assert_equal=utils.assert_quantity_sub_equal, assert_kw={'exclude': ['name', 'channel', 'unit']})
def test_read_write_hdf5(self): array = self.create(name='X1:TEST') utils.test_read_write(array, 'hdf5', write_kw={'overwrite': True})
def test_read_write(self, array, format): utils.test_read_write( array, format, assert_equal=utils.assert_quantity_sub_equal, assert_kw={'exclude': ['name', 'channel', 'unit', 'epoch']})