2018-03-26 21:49:57 -04:00
|
|
|
# domain.py
|
|
|
|
# Eryn Wells <eryn@erynwells.me>
|
|
|
|
'''
|
|
|
|
Some utilities for dealing with signal domains: time, frequency, etc.
|
|
|
|
'''
|
2018-03-26 21:32:38 -04:00
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
__default_time = 2.0
|
|
|
|
__default_steps = 200
|
|
|
|
|
|
|
|
class Time:
|
|
|
|
__DefaultTime = 2.0
|
|
|
|
__DefaultSteps = 200
|
|
|
|
|
2018-03-26 21:49:57 -04:00
|
|
|
def __init__(self, sec=__DefaultTime, samples=__DefaultSteps):
|
2018-03-26 21:32:38 -04:00
|
|
|
self.sec = sec
|
|
|
|
self.samples = samples
|
|
|
|
self._domain = None
|
|
|
|
|
|
|
|
@property
|
|
|
|
def domain(self):
|
2018-03-27 07:21:22 -07:00
|
|
|
# TODO: This a really dumb hack around numpy arrays not supporting None testing. There must be a better way...
|
|
|
|
try:
|
|
|
|
self._domain.size
|
|
|
|
except AttributeError:
|
2018-03-26 21:32:38 -04:00
|
|
|
self._domain = np.linspace(0, self.sec, num=self.samples + 1)
|
2018-03-27 07:21:22 -07:00
|
|
|
finally:
|
|
|
|
return self._domain
|
2018-03-26 21:32:38 -04:00
|
|
|
|
|
|
|
@property
|
|
|
|
def rate(self):
|
2018-03-27 07:21:22 -07:00
|
|
|
'''Number of samples per second, in Hertz.'''
|
2018-03-26 21:32:38 -04:00
|
|
|
return self.samples / self.sec
|
|
|
|
|
|
|
|
@property
|
|
|
|
def interval(self):
|
|
|
|
'''Amount of time between samples, in seconds.'''
|
|
|
|
return self.sec / self.samples
|
2018-03-26 21:49:57 -04:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return repr(self)
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return '{}(sec={}, samples={})'.format(self.__class__.__name__, self.sec, self.samples)
|