From 806c10062654c2b45d18944d2f1b3791a101151e Mon Sep 17 00:00:00 2001 From: Jan Adler Date: Mon, 6 May 2024 16:46:35 +0000 Subject: [PATCH] Fix Duplex Operator Port Selection --- hermespy/core/duplex.py | 24 ++++++++++++++++++------ hermespy/jcas/jcas.py | 24 +++++++++++++++++++++--- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/hermespy/core/duplex.py b/hermespy/core/duplex.py index d8f5e7a7..96163003 100644 --- a/hermespy/core/duplex.py +++ b/hermespy/core/duplex.py @@ -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 @@ -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: @@ -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 @@ -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 not self.__device and self.__device is not None: self.__device.transmitters.remove(self) self.__device.receivers.remove(self) @@ -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: diff --git a/hermespy/jcas/jcas.py b/hermespy/jcas/jcas.py index 2fcd0cd7..57a5b8fd 100644 --- a/hermespy/jcas/jcas.py +++ b/hermespy/jcas/jcas.py @@ -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 @@ -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: @@ -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