(semi-)revert ab20db4: Antenna encapsulates a digitizer

Antenna should not encapsulate a Digitizer in this way.
Maybe it can be added later, but I see mostly complexiy in that
design.
This commit is contained in:
Eric Teunis de Boone 2022-04-06 18:20:50 +02:00
parent 10d91519bf
commit d04dfac64e

View file

@ -1,7 +1,6 @@
from functools import partial from functools import partial
from .location import Location from .location import Location
from ..sampling import Digitizer
class Antenna(Location): class Antenna(Location):
""" """
@ -12,56 +11,27 @@ class Antenna(Location):
Optionally uses digitizer to transform the signal Optionally uses digitizer to transform the signal
when receiving. when receiving.
""" """
def __init__(self, x, digitizer=None): def __init__(self, x):
super().__init__(x) super().__init__(x)
self.digitizer = digitizer
def __repr__(self): def __repr__(self):
return "Antenna({}, {})".format(repr(self.x), repr(self.x)) return "Antenna({}, {})".format(repr(self.x), repr(self.x))
def _digitise_partial(self, signal: callable, *args, digitise=True, **kwargs) -> callable: def emit(self, signal: callable) -> callable:
"""
A wrapper around functools.partial to support optionally
digitising the returned signal.
"""
if self.digitizer and digitise:
signal = self.digitizer.digitise(signal)
return partial(signal, *args, **kwargs)
def emit(self, signal: callable, digitise=False) -> callable:
""" """
Return a function that emits a signal from the antenna's location Return a function that emits a signal from the antenna's location
""" """
return self._digitise_partial(signal, x_0=self.x, digitise=digitise) return partial(signal, x_0=self.x)
def recv(self, signal: callable, digitise=True) -> callable: def recv(self, signal: callable) -> callable:
""" """
Return a function that traces the signal as a function of time Return a function that traces the signal as a function of time
at the antenna's location at the antenna's location
""" """
return self._digitise_partial(signal, x_f=self.x, digitise=digitise) return partial(signal, x_f=self.x)
receive = recv receive = recv
# math
def __add__(self, other):
if isinstance(other, Location):
other = other.x
return self.__class__(self.x + other, self.digitizer)
def __sub__(self, other):
if isinstance(other, Location):
other = other.x
return self.__class__(self.x - other, self.digitizer)
def __mul__(self, other):
return self.__class__(self.x * other, self.digitizer)
class Receiver(Antenna): class Receiver(Antenna):
""" """
An antenna which main purpose is to trace a signal over time. An antenna which main purpose is to trace a signal over time.