예제 #1
0
 def get_sample_times(self):
     """Return an Array containing the sample times.
     """
     if self._epoch is None:
         return Array(range(len(self))) * self._delta_t
     else:
         return Array(range(len(self))) * self._delta_t + float(self._epoch)
예제 #2
0
    def __init__(self, initial_array, delta_t=None,
                 epoch=None, dtype=None, copy=True):
        if len(initial_array) < 1:
            raise ValueError('initial_array must contain at least one sample.')
        if delta_t is None:
            try:
                delta_t = initial_array.delta_t
            except AttributeError:
                raise TypeError('must provide either an initial_array with a delta_t attribute, or a value for delta_t')
        if not delta_t > 0:
            raise ValueError('delta_t must be a positive number')

        # Get epoch from initial_array if epoch not given (or is None)
        # If initialy array has no epoch, set epoch to 0.
        # If epoch is provided, use that.
        if not isinstance(epoch, _lal.LIGOTimeGPS):
            if epoch is None:
                if isinstance(initial_array, TimeSeries):
                    epoch = initial_array._epoch
                else:
                    epoch = _lal.LIGOTimeGPS(0)
            elif epoch is not None:
                try:
                    epoch = _lal.LIGOTimeGPS(epoch)
                except:
                    raise TypeError('epoch must be either None or a lal.LIGOTimeGPS')
        Array.__init__(self, initial_array, dtype=dtype, copy=copy)
        self._delta_t = delta_t
        self._epoch = epoch
예제 #3
0
 def __init__(self, initial_array, delta_t=None, epoch="", dtype=None, copy=True):
     if len(initial_array) < 1:
         raise ValueError('initial_array must contain at least one sample.')
     if delta_t is None:
         try:
             delta_t = initial_array.delta_t
         except AttributeError:
             raise TypeError('must provide either an initial_array with a delta_t attribute, or a value for delta_t')
     if not delta_t > 0:
         raise ValueError('delta_t must be a positive number')
     # We gave a nonsensical default value to epoch so we can test if it's been set.
     # If the user passes in an initial_array that has an 'epoch' attribute and doesn't
     # pass in a value of epoch, then our new object's epoch comes from initial_array.
     # But if the user passed in a value---even 'None'---that will take precedence over
     # anything set in initial_array.  Finally, if the user passes in something without
     # an epoch attribute *and* doesn't pass in a value of epoch, it becomes 'None'
     if not isinstance(epoch,_lal.LIGOTimeGPS):
         if epoch == "":
             if isinstance(initial_array, TimeSeries):
                 epoch = initial_array._epoch
             else:
                 epoch = _lal.LIGOTimeGPS(0)
         elif epoch is not None:
             try:
                 epoch = _lal.LIGOTimeGPS(epoch)
             except:
                 raise TypeError('epoch must be either None or a lal.LIGOTimeGPS')
     Array.__init__(self, initial_array, dtype=dtype, copy=copy)
     self._delta_t = delta_t
     self._epoch = epoch
예제 #4
0
 def __init__(self, initial_array, delta_f=None, epoch="", dtype=None, copy=True):
     if len(initial_array) < 1:
         raise ValueError('initial_array must contain at least one sample.')
     if delta_f == None:
         try:
             delta_f = initial_array.delta_f
         except AttributeError:
             raise TypeError('must provide either an initial_array with a delta_f attribute, or a value for delta_f')
     if not delta_f > 0:
         raise ValueError('delta_f must be a positive number')
     # We gave a nonsensical default value to epoch so we can test if it's been set.
     # If the user passes in an initial_array that has an 'epoch' attribute and doesn't
     # pass in a value of epoch, then our new object's epoch comes from initial_array.
     # But if the user passed in a value---even 'None'---that will take precedence over
     # anything set in initial_array.  Finally, if the user passes in something without
     # an epoch attribute *and* doesn't pass in a value of epoch, it becomes 'None'
     if not isinstance(epoch,_lal.LIGOTimeGPS):
         if epoch == "":
             if isinstance(initial_array,FrequencySeries):
                 epoch = initial_array._epoch
             else:
                 epoch = _lal.LIGOTimeGPS(0)
         elif epoch is not None:
             try: 
                 epoch = _lal.LIGOTimeGPS(epoch)
             except:
                 raise TypeError('epoch must be either None or a lal.LIGOTimeGPS')
     Array.__init__(self, initial_array, dtype=dtype, copy=copy)
     self._delta_f = delta_f
     self._epoch = epoch
예제 #5
0
 def __getitem__(self, index):
     if isinstance(index, slice):
         # Set the new epoch---note that index.start may also be None
         if self._epoch is None:
             new_epoch = None
         elif index.start is None:
             new_epoch = self._epoch
         else:
             if index.start < 0:
                 raise ValueError('Negative start index not supported')
             new_epoch = self._epoch + index.start * self._delta_t
         return TimeSeries(Array.__getitem__(self, index), self._delta_t, new_epoch, copy=False)
     else:
         return Array.__getitem__(self, index)
예제 #6
0
파일: timeseries.py 프로젝트: AbhayMK/pycbc
 def __getitem__(self, index):
     if isinstance(index, slice):
         # Set the new epoch---note that index.start may also be None
         if self._epoch is None:
             new_epoch = None
         elif index.start is None:
             new_epoch = self._epoch
         else:
             if index.start < 0:
                 index.start += len(self)
             new_epoch = self._epoch + index.start * self._delta_t
         return TimeSeries(Array.__getitem__(self, index), self._delta_t, new_epoch, copy=False)
     else:
         return Array.__getitem__(self, index)
예제 #7
0
 def __getitem__(self, index):
     if isinstance(index, slice):
         # Set the new epoch---note that index.start may also be None
         if self._epoch is None:
             new_epoch = None
         elif index.start is None:
             new_epoch = self._epoch
         else:
             if index.start < 0:
                 raise ValueError('Negative start index not supported')
             new_epoch = self._epoch + index.start * self._delta_t
         return TimeSeries(Array.__getitem__(self, index), self._delta_t, new_epoch, copy=False)
     else:
         return Array.__getitem__(self, index)
예제 #8
0
 def __init__(self,
              initial_array,
              delta_f=None,
              epoch="",
              dtype=None,
              copy=True):
     if len(initial_array) < 1:
         raise ValueError('initial_array must contain at least one sample.')
     if delta_f is None:
         try:
             delta_f = initial_array.delta_f
         except AttributeError:
             raise TypeError(
                 'must provide either an initial_array with a delta_f attribute, or a value for delta_f'
             )
     if not delta_f > 0:
         raise ValueError('delta_f must be a positive number')
     # We gave a nonsensical default value to epoch so we can test if it's been set.
     # If the user passes in an initial_array that has an 'epoch' attribute and doesn't
     # pass in a value of epoch, then our new object's epoch comes from initial_array.
     # But if the user passed in a value---even 'None'---that will take precedence over
     # anything set in initial_array.  Finally, if the user passes in something without
     # an epoch attribute *and* doesn't pass in a value of epoch, it becomes 'None'
     if not isinstance(epoch, _lal.LIGOTimeGPS):
         if epoch == "":
             if isinstance(initial_array, FrequencySeries):
                 epoch = initial_array._epoch
             else:
                 epoch = _lal.LIGOTimeGPS(0)
         elif epoch is not None:
             try:
                 if isinstance(epoch, _numpy.generic):
                     # In python3 lal LIGOTimeGPS will not work on numpy
                     # types as input. A quick google on how to generically
                     # convert numpy floats/ints to the python equivalent
                     # https://stackoverflow.com/questions/9452775/
                     epoch = _lal.LIGOTimeGPS(epoch.item())
                 else:
                     epoch = _lal.LIGOTimeGPS(epoch)
             except:
                 raise TypeError(
                     'epoch must be either None or a lal.LIGOTimeGPS')
     Array.__init__(self, initial_array, dtype=dtype, copy=copy)
     self._delta_f = delta_f
     self._epoch = epoch
예제 #9
0
 def _getslice(self, index):
     if index.step is not None:
         new_delta_f = self._delta_f * index.step
     else:
         new_delta_f = self._delta_f
     return FrequencySeries(Array._getslice(self, index),
                            delta_f=new_delta_f,
                            epoch=self._epoch,
                            copy=False)
예제 #10
0
 def _getslice(self, index):
     if index.step is not None:
         new_delta_f = self._delta_f * index.step
     else:
         new_delta_f = self._delta_f
     return FrequencySeries(Array._getslice(self, index),
                            delta_f=new_delta_f,
                            epoch=self._epoch,
                            copy=False)
예제 #11
0
 def __getitem__(self, index):
     if isinstance(index, slice):
         if index.start > index.stop:
             raise ValueError('start index must be smaller than stop index')
         if index.step is None:
             new_delta_t = self._delta_t
         elif index.step < 0:
             raise ValueError('negative step is not supported')
         else:
             new_delta_t = index.step * self._delta_t
         if self._epoch is None:
             new_epoch = None
         else:
             new_epoch = self._epoch + index.start * self._delta_t
         return TimeSeries(Array.__getitem__(self, index),
                           new_delta_t,
                           new_epoch,
                           copy=False)
     else:
         return Array.__getitem__(self, index)
예제 #12
0
 def __init__(self,
              initial_array,
              delta_t,
              epoch=None,
              dtype=None,
              copy=True):
     """initial_array: array containing sampled data.
     delta_t: time between consecutive samples in seconds.
     epoch: time series start time in seconds. Must be a lal.LIGOTimeGPS object.
     """
     if len(initial_array) < 1:
         raise ValueError('initial_array must contain at least one sample.')
     if not delta_t > 0:
         raise ValueError('delta_t must be a positive number')
     if epoch is not None and not isinstance(epoch, _lal.LIGOTimeGPS):
         raise TypeError('epoch must be either None or a lal.LIGOTimeGPS')
     if epoch is None:
         epoch = _lal.LIGOTimeGPS(0, 0)
     else:
         epoch = _lal.LIGOTimeGPS(epoch)
     Array.__init__(self, initial_array, dtype=dtype, copy=copy)
     self._delta_t = delta_t
     self._epoch = epoch
예제 #13
0
 def __init__(self,
              initial_array,
              delta_f,
              epoch=None,
              dtype=None,
              copy=True):
     """initial_array: array containing sampled data.
     delta_f: frequency between consecutive samples in Hertz.
     epoch: start time of the associated time domain data, in seconds.
            Must be a lal.LIGOTimeGPS object.
     """
     if len(initial_array) < 1:
         raise ValueError('initial_array must contain at least one sample.')
     if not delta_f > 0:
         raise ValueError('delta_f must be a positive number')
     if epoch is not None and not isinstance(epoch, _lal.LIGOTimeGPS):
         raise TypeError('epoch must be either None or a lal.LIGOTimeGPS')
     if epoch is None:
         epoch = _lal.LIGOTimeGPS(0, 0)
     else:
         epoch = _lal.LIGOTimeGPS(epoch)
     Array.__init__(self, initial_array, dtype=dtype, copy=copy)
     self._delta_f = delta_f
     self._epoch = epoch
예제 #14
0
    def _getslice(self, index):
        # Set the new epoch---note that index.start may also be None
        if index.start is None:
            new_epoch = self._epoch
        else:
            if index.start < 0:
                raise ValueError(('Negative start index ({})'
                                  ' not supported').format(index.start))
            new_epoch = self._epoch + index.start * self._delta_t

        if index.step is not None:
            new_delta_t = self._delta_t * index.step
        else:
            new_delta_t = self._delta_t

        return TimeSeries(Array._getslice(self, index), new_delta_t,
                          new_epoch, copy=False)
예제 #15
0
파일: timeseries.py 프로젝트: cmbiwer/pycbc
    def _getslice(self, index):
        # Set the new epoch---note that index.start may also be None
        if self._epoch is None:
            new_epoch = None
        elif index.start is None:
            new_epoch = self._epoch
        else:
            if index.start < 0:
                raise ValueError('Negative start index not supported')
            new_epoch = self._epoch + index.start * self._delta_t

        if index.step is not None:
            new_delta_t = self._delta_t * index.step
        else:
            new_delta_t = self._delta_t
        
        return TimeSeries(Array._getslice(self, index), new_delta_t,
                          new_epoch, copy=False)
예제 #16
0
 def get_sample_frequencies(self):
     """Return an Array containing the sample frequencies.
     """
     return Array(range(len(self))) * self._delta_f