isac-uav-dataset-demo / dataset.py
St0nedB's picture
initial commit
6e4ade2
from dataclasses import dataclass, field
import h5py
import numpy as np
H5_CDATA = "Channel/FrequencyResponses/Data"
H5_TARGET_DELAY = "TargetParameters/Delay/Data"
H5_TARGET_DOPPLER = "TargetParameters/Doppler/Data"
H5_TXANTENNA = "AntennaPositions/PositionTx/Data"
H5_RXANTENNA = "AntennaPositions/PositionRx/Data"
H5_UAVPOSITIONS = "Positions/Data"
@dataclass
class UAVDataset:
channelfile: str
"""The path to the channel file"""
targetfile: str = None
"""The path to the target file"""
channel: np.ndarray = field(init=False)
"""Property to store the channel data as a numpy array"""
groundtruth: np.ndarray = field(init=False)
"""Property to store the delay and Doppler groundtruth of the UAV as a numpy array"""
tx: np.ndarray = field(init=False)
"""Property to store the transmitter antenna positions as a numpy array"""
rx: np.ndarray = field(init=False)
"""Property to store the receiver antenna positions as a numpy array"""
uav: np.ndarray = field(init=False)
"""Property to store the UAV positions as a numpy array"""
def __post_init__(self) -> None:
# load channel, positions
h5_channel = h5py.File(self.channelfile, "r")
self.channel = np.array(h5_channel[H5_CDATA]).view(
np.complex64).squeeze()
self.groundtruth = np.concatenate(
(
np.array(h5_channel[H5_TARGET_DELAY]),
np.array(h5_channel[H5_TARGET_DOPPLER]),
),
axis=1,
)
self.tx = np.array(h5_channel[H5_TXANTENNA]).view(np.float64).squeeze()
self.rx = np.array(h5_channel[H5_RXANTENNA]).view(np.float64).squeeze()
if self.targetfile is not None:
h5_target = h5py.File(self.targetfile, "r")
self.uav = np.array(h5_target[H5_UAVPOSITIONS]).view(
np.float64).squeeze()
return
def __len__(self) -> int:
return self.channel.shape[0]