-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate_algorithmImplementation.py
More file actions
124 lines (105 loc) · 6.4 KB
/
template_algorithmImplementation.py
File metadata and controls
124 lines (105 loc) · 6.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# ABeL: template_algorithmImplementation.py +
# Copyright (C) 2025 Simon Huh +
# +
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public +
# License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any +
# later version. +
# +
# This program is distributed in the hope that it will be useful, but +
# WITHOUT ANY WARRANTY; without +
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +
# License for more details. +
# +
# You should have received a copy of the GNU General Public License along with this program. If not, see +
# <https://www.gnu.org/licenses/>. +
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
import logging
import numpy as np
from typing import TypeAlias, Union, Callable
from numpy.typing import NDArray
from Localization.utils.dataPreparation import DataPreparation
from globalUtils.decorators import iterateMethod, propertySetter
from globalUtils.customExceptions import FunctionError
from Localization.vizsualizationFunctions.precisionMetrics import LocalizationPrecisionMetrics
t_position: TypeAlias = tuple[float, float, float]
class PositioningAlgorithm(DataPreparation, LocalizationPrecisionMetrics):
"""
Template for implementing a positioning algorithm with ABeL. This class is only meant as an example,
you may change or modify it to fit your needs.
"""
def __init__(self) -> None:
DataPreparation.__init__(self)
LocalizationPrecisionMetrics.__init__(self)
self.localizedReceiverPositions: Union[list[t_position],
list[list[t_position]]] = []
def setupPositioning(self,
pathToRayTracingData: str,
pathToRayTracingConfig: str = "data/sionnaRayTracingConfig.yaml",
*args) -> None:
"""
Function for setting up the signal propagation data used for implementing and benchmarking a positioning
algorithm.
Parameters
----------
pathToRayTracingData: str
Path to your generated signal propagation data. If you used the "example_dataGeneration.py"
script, the data can generally be found at "data/output".
pathToRayTracingConfig: str, default="data/sionnaRayTracingConfig.yaml
Path to the ray tracing configuration you used for generating the data set.
args:
Placeholder for other arguments you may need to set up you own positioning algorithm.
Returns
-------
None
"""
# Load and prepare data for positioning algorithm
self.somePropData = ...
@propertySetter(propertyToSet="localizedReceiverPositions")
@iterateMethod(iteratorName="_localizationData")
def runPositioning(self, *args, **kwargs) -> list[t_position]:
"""
Calculates the position of all receivers for the positioning algorithm defined in the classes "__algorithm"
method. The "iterateMethod" decorator will automatically iterate over all simulation time steps, i.e.,
the positioning algorithm each simulation time step one after another. In other words, you'll only need to
implement the positioning algorithm like you would want to determine the position of all receivers for a
single simulation time step.
Parameters
----------
args:
Placeholder for other arguments you may need to configure your own positioning algorithm.
kwargs:
Mainly used to return the current index of the iterator, which the "iterateMethod" decorator iterates
over, i.e., the current index of trajectory. You can access this index by calling kwargs[
"<yourIterator>Index"], where <yourIterator> is the iterator you used for the "iterateMethod" decorator.
Returns
-------
list[t_position]:
The function itself returns a list containing the calculated receiver positions for a single simulation
time step. In conjunction with the "iterateMethod" decorator, a list containing the calculated receiver
positions for all simulation time steps is returned.
"""
currentTrajectoryIdx = kwargs["_localizationDataIndex"]
positions = self.__algorithm(propagationData=self.somePropData[currentTrajectoryIdx])
return positions
##################################
# ----- INTERNAL FUNCTIONS ----- #
##################################
@staticmethod
def __algorithm(propagationData, *args) -> list[t_position]:
"""
Implement your positioning algorithm here. Generally, you'll want to calculate the positions of all receivers
for a single simulation time step.
Parameters
----------
propagationData:
Some kind of propagation data (time of arrival, angle of arrival, etc.) for all receivers for a single
simulation time step.
args:
Placeholder for other arguments you may need to configure your own positioning algorithm.
Returns
-------
list[t_position]:
A list of calculated receiver positions for a single simulation time step.
"""
pass