2022-03-24 12:13:34 +01:00
|
|
|
from functools import partial
|
2022-04-06 18:40:08 +02:00
|
|
|
import copy
|
|
|
|
from typing import Union
|
2022-03-24 12:13:34 +01:00
|
|
|
|
2022-03-24 15:45:40 +01:00
|
|
|
from .location import Location
|
2022-04-06 18:40:08 +02:00
|
|
|
from ..signals import Signal
|
2022-03-24 12:13:34 +01:00
|
|
|
|
|
|
|
class Antenna(Location):
|
|
|
|
"""
|
|
|
|
A location able to interact with a signal.
|
|
|
|
|
|
|
|
Either emitting or receiving.
|
|
|
|
|
2022-03-24 17:14:47 +01:00
|
|
|
Optionally uses digitizer to transform the signal
|
|
|
|
when receiving.
|
2022-03-24 12:13:34 +01:00
|
|
|
"""
|
2022-04-06 18:20:50 +02:00
|
|
|
def __init__(self, x):
|
2022-03-24 17:14:47 +01:00
|
|
|
super().__init__(x)
|
|
|
|
|
2022-03-24 12:13:34 +01:00
|
|
|
def __repr__(self):
|
2022-03-24 17:14:47 +01:00
|
|
|
return "Antenna({}, {})".format(repr(self.x), repr(self.x))
|
|
|
|
|
2022-04-06 18:40:08 +02:00
|
|
|
def emit(self, signal: Union[Signal, callable]) -> Union[Signal, callable]:
|
2022-03-24 17:14:47 +01:00
|
|
|
"""
|
2022-04-06 18:40:08 +02:00
|
|
|
Emit signal from this antenna's location.
|
|
|
|
|
|
|
|
Note that this merely sets a default argument.
|
2022-03-24 17:14:47 +01:00
|
|
|
"""
|
2022-04-06 18:40:08 +02:00
|
|
|
if not isinstance(signal, Signal):
|
|
|
|
return partial(signal, x_0=self.x)
|
|
|
|
else:
|
|
|
|
new_signal = copy.copy(signal)
|
|
|
|
new_signal.x_0 = self.x
|
|
|
|
|
|
|
|
return new_signal
|
2022-03-24 17:14:47 +01:00
|
|
|
|
2022-04-06 18:40:08 +02:00
|
|
|
def recv(self, signal: Union[Signal, callable]) -> Union[Signal, callable]:
|
2022-03-24 12:13:34 +01:00
|
|
|
"""
|
2022-04-06 18:40:08 +02:00
|
|
|
Trace signal as a function of time at this antenna's
|
|
|
|
location.
|
|
|
|
|
|
|
|
Note that this merely sets a default argument.
|
2022-03-24 12:13:34 +01:00
|
|
|
"""
|
2022-04-06 18:40:08 +02:00
|
|
|
if not isinstance(signal, Signal):
|
|
|
|
return partial(signal, x_f=self.x)
|
|
|
|
else:
|
|
|
|
new_signal = copy.copy(signal)
|
|
|
|
new_signal.x_f = self.x
|
|
|
|
|
|
|
|
return new_signal
|
2022-03-24 12:13:34 +01:00
|
|
|
|
|
|
|
receive = recv
|
|
|
|
|
|
|
|
class Receiver(Antenna):
|
|
|
|
"""
|
|
|
|
An antenna which main purpose is to trace a signal over time.
|
|
|
|
|
|
|
|
Optionally applies a transformation to the traced signal.
|
|
|
|
"""
|
|
|
|
def __repr__(self):
|
|
|
|
return "Receiver({})".format(repr(self.x))
|
|
|
|
|
|
|
|
class Emitter(Antenna):
|
|
|
|
"""
|
|
|
|
An antenna which main purpose is to emit a signal.
|
|
|
|
"""
|
|
|
|
def __repr__(self):
|
|
|
|
return "Emitter({})".format(repr(self.x))
|