Skip to content

Commit 627d245

Browse files
committed
revert
1 parent 0d62fba commit 627d245

1 file changed

Lines changed: 18 additions & 25 deletions

File tree

pycbc/types/timeseries.py

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,18 @@
1919
"""
2020
import os as _os
2121
import h5py
22+
23+
import numpy as _numpy
24+
from scipy.io.wavfile import write as write_wav
25+
2226
from pycbc.types.array import Array, _convert, complex_same_precision_as, zeros
27+
from pycbc.types.utils import determine_epoch
2328
from pycbc.types.array import _nocomplex
2429
from pycbc.types.frequencyseries import FrequencySeries
2530
from pycbc.types import float32, float64
26-
import lal as _lal
27-
import numpy as _numpy
28-
from scipy.io.wavfile import write as write_wav
31+
from pycbc.libutils import import_optional
2932

33+
_lal = import_optional('lal')
3034

3135
class TimeSeries(Array):
3236
"""Models a time series consisting of uniformly sampled scalar values.
@@ -46,7 +50,7 @@ class TimeSeries(Array):
4650
"""
4751

4852
def __init__(self, initial_array, delta_t=None,
49-
epoch=None, dtype=None, copy=True):
53+
epoch="", dtype=None, copy=True):
5054
if len(initial_array) < 1:
5155
raise ValueError('initial_array must contain at least one sample.')
5256
if delta_t is None:
@@ -57,20 +61,7 @@ def __init__(self, initial_array, delta_t=None,
5761
if not delta_t > 0:
5862
raise ValueError('delta_t must be a positive number')
5963

60-
# Get epoch from initial_array if epoch not given (or is None)
61-
# If initialy array has no epoch, set epoch to 0.
62-
# If epoch is provided, use that.
63-
if not isinstance(epoch, _lal.LIGOTimeGPS):
64-
if epoch is None:
65-
if isinstance(initial_array, TimeSeries):
66-
epoch = initial_array._epoch
67-
else:
68-
epoch = _lal.LIGOTimeGPS(0)
69-
elif epoch is not None:
70-
try:
71-
epoch = _lal.LIGOTimeGPS(epoch)
72-
except:
73-
raise TypeError('epoch must be either None or a lal.LIGOTimeGPS')
64+
self._epoch = determine_epoch(epoch, initial_array)
7465
Array.__init__(self, initial_array, dtype=dtype, copy=copy)
7566
self._delta_t = delta_t
7667
self._epoch = epoch
@@ -91,6 +82,8 @@ def to_astropy(self, name='pycbc'):
9182

9283
def epoch_close(self, other):
9384
""" Check if the epoch is close enough to allow operations """
85+
if self._epoch is None or other._epoch is None:
86+
return False
9487
dt = abs(float(self.start_time - other.start_time))
9588
return dt <= 1e-7
9689

@@ -125,8 +118,8 @@ def _typecheck(self, other):
125118
self.start_time, other.start_time))
126119

127120
def _getslice(self, index):
128-
# Set the new epoch---note that index.start may also be None
129-
if index.start is None:
121+
# Set the new epoch - index.start or self._epoch may be None
122+
if index.start is None or self._epoch is None:
130123
new_epoch = self._epoch
131124
else:
132125
if index.start < 0:
@@ -209,7 +202,7 @@ def time_slice(self, start, end, mode='floor'):
209202

210203
@property
211204
def delta_f(self):
212-
"""Return the delta_f this ts would have in the frequency domain
205+
"""Return time series start time.
213206
"""
214207
return 1.0 / self.duration
215208

@@ -223,14 +216,14 @@ def start_time(self):
223216
def start_time(self, time):
224217
""" Set the start time
225218
"""
226-
self._epoch = _lal.LIGOTimeGPS(time)
219+
self._epoch = float64(time)
227220

228221
def get_end_time(self):
229-
"""Return time series end time as a LIGOTimeGPS.
222+
"""Return time series end time.
230223
"""
231224
return self._epoch + self.get_duration()
232225
end_time = property(get_end_time,
233-
doc="Time series end time as a LIGOTimeGPS.")
226+
doc="Time series end time.")
234227

235228
def get_sample_times(self):
236229
"""Return an Array containing the sample times.
@@ -491,7 +484,7 @@ def lal(self):
491484
If time series is stored in GPU memory.
492485
"""
493486
lal_data = None
494-
ep = self._epoch
487+
ep = _lal.LIGOTimeGPS(self._epoch)
495488

496489
if self._data.dtype == _numpy.float32:
497490
lal_data = _lal.CreateREAL4TimeSeries("",ep,0,self.delta_t,_lal.SecondUnit,len(self))

0 commit comments

Comments
 (0)