Skip to content

Commit

Permalink
Merge branch 'fix-matced-filter-port-selection' into 'master'
Browse files Browse the repository at this point in the history
Fix Duplex Operator Port Selection

See merge request barkhauseninstitut/wicon/hermespy!182
  • Loading branch information
adlerjan committed May 6, 2024
2 parents 68fa7b1 + 8395215 commit 655862c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
24 changes: 18 additions & 6 deletions hermespy/core/duplex.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from __future__ import annotations
from abc import abstractmethod
from h5py import Group
from typing import Generic
from typing import Generic, Sequence

from .device import Device, OperatorSlot, ReceptionType, Receiver, TransmissionType, Transmitter
from .signal_model import Signal
Expand All @@ -31,7 +31,12 @@ class DuplexOperator(
__device: Device | None

def __init__(
self, device: Device | None = None, reference: Device | None = None, seed: int | None = None
self,
device: Device | None = None,
reference: Device | None = None,
selected_transmit_ports: Sequence[int] | None = None,
selected_receive_ports: Sequence[int] | None = None,
seed: int | None = None,
):
"""
Args:
Expand All @@ -40,10 +45,11 @@ def __init__(
Device the duplex operator operates.
"""

Transmitter.__init__(self, seed=seed)
Receiver.__init__(self, seed=seed, reference=reference)

self.__device = None

Transmitter.__init__(self, seed, selected_transmit_ports)
Receiver.__init__(self, seed, reference, selected_receive_ports)

self.device = device

@property
Expand All @@ -57,7 +63,11 @@ def device(self) -> Device | None:

@device.setter
def device(self, value: Device | None) -> None:
if self.__device is not None:
# Abort if the device is already assigned
if self.__device is value:
return

if value is None and self.__device is not None:
self.__device.transmitters.remove(self)
self.__device.receivers.remove(self)

Expand All @@ -67,6 +77,8 @@ def device(self, value: Device | None) -> None:
value.transmitters.add(self)
value.receivers.add(self)

return

@Transmitter.slot.setter
def slot(self, value: OperatorSlot[Transmitter]) -> None:
if value is not None and self.device is not value.device:
Expand Down
24 changes: 21 additions & 3 deletions hermespy/jcas/jcas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations
from abc import abstractmethod
from typing import Generic, Type
from typing import Generic, Sequence, Type

from h5py import Group

Expand Down Expand Up @@ -68,7 +68,14 @@ class DuplexJCASOperator(
cube from the received backscattered power.
"""

def __init__(self, device: Device | None = None, waveform: CWT | None = None, **kwargs) -> None:
def __init__(
self,
device: Device | None = None,
waveform: CWT | None = None,
selected_transmit_ports: Sequence[int] | None = None,
selected_receive_ports: Sequence[int] | None = None,
**kwargs,
) -> None:
"""
Args:
Expand All @@ -78,12 +85,23 @@ def __init__(self, device: Device | None = None, waveform: CWT | None = None, **
waveform (CWT, optional):
Communication waveform emitted by this operator.
selected_transmit_ports (Sequence[int], optional):
Selected transmit ports of the device.
selected_receive_ports (Sequence[int], optional):
Selected receive ports of the device.
"""

# Initialize base classes
TransmittingModemBase.__init__(self)
ReceivingModemBase.__init__(self, **kwargs)
RadarBase.__init__(self, device=device)
RadarBase.__init__(
self,
device=device,
selected_transmit_ports=selected_transmit_ports,
selected_receive_ports=selected_receive_ports,
)

# Initialize class attributes
self.device = device
Expand Down

0 comments on commit 655862c

Please sign in to comment.