|
3 | 3 |
|
4 | 4 | import pytest |
5 | 5 |
|
6 | | -from stonesoup.sensor.radar.radar import RadarElevationBearingRangeRate |
| 6 | +from stonesoup.models.measurement.nonlinear import CartesianToBearingRange, \ |
| 7 | + CartesianToElevationBearingRange |
| 8 | +from stonesoup.movable import FixedMovable |
| 9 | +from stonesoup.sensor.radar.radar import RadarElevationBearingRangeRate, RadarBearingRange, \ |
| 10 | + RadarElevationBearingRange |
7 | 11 | from stonesoup.platform import FixedPlatform |
| 12 | +from stonesoup.types.groundtruth import GroundTruthPath, GroundTruthState |
8 | 13 | from ..base import PlatformMountable |
9 | | -from ..sensor import Sensor |
| 14 | +from ..sensor import Sensor, SensorSuite |
10 | 15 | from ...types.array import StateVector, CovarianceMatrix |
11 | 16 | from ...types.state import State |
12 | 17 |
|
@@ -68,7 +73,7 @@ def test_changing_platform_from_default(): |
68 | 73 | position = StateVector([0, 0, 1]) |
69 | 74 | sensor = DummySensor(position=StateVector([0, 0, 1])) |
70 | 75 |
|
71 | | - platform_state = State(state_vector=position+1, timestamp=datetime.datetime.now()) |
| 76 | + platform_state = State(state_vector=position + 1, timestamp=datetime.datetime.now()) |
72 | 77 | platform = FixedPlatform(states=platform_state, position_mapping=[0, 1, 2]) |
73 | 78 | with pytest.raises(AttributeError): |
74 | 79 | platform.add_sensor(sensor) |
@@ -157,3 +162,70 @@ def test_sensor_assignment(radar_platform_target): |
157 | 162 | platform.remove_sensor(radar_3) |
158 | 163 | assert len(platform.sensors) == 2 |
159 | 164 | assert platform.sensors == (radar_1, radar_2) |
| 165 | + |
| 166 | + |
| 167 | +def test_informative(): |
| 168 | + dummy_truth1 = GroundTruthPath([GroundTruthState([1, 1, 1, 1]), |
| 169 | + GroundTruthState([2, 1, 2, 1]), |
| 170 | + GroundTruthState([3, 1, 3, 1])]) |
| 171 | + dummy_truth2 = GroundTruthPath([GroundTruthState([1, 0, -1, -1]), |
| 172 | + GroundTruthState([1, 0, -2, -1]), |
| 173 | + GroundTruthState([1, 0, -3, -1])]) |
| 174 | + |
| 175 | + position = State(StateVector([0, 0, 0, 0])) |
| 176 | + orientation = StateVector([np.radians(90), 0, 0]) |
| 177 | + test_radar = RadarBearingRange(ndim_state=4, |
| 178 | + position_mapping=(0, 2), |
| 179 | + noise_covar=np.diag([np.radians(1) ** 2, 5 ** 2]), |
| 180 | + movement_controller=FixedMovable(states=[position], |
| 181 | + orientation=orientation, |
| 182 | + position_mapping=(0, 2)) |
| 183 | + ) |
| 184 | + test_sensor = SensorSuite(attributes_inform=['position', 'orientation'], |
| 185 | + sensors=[test_radar]) |
| 186 | + |
| 187 | + detections = test_sensor.measure({dummy_truth1, dummy_truth2}) |
| 188 | + |
| 189 | + assert len(detections) == 2 |
| 190 | + |
| 191 | + for detection in detections: |
| 192 | + assert isinstance(detection.measurement_model, CartesianToBearingRange) |
| 193 | + metadata_position = detection.metadata.get('position') |
| 194 | + assert np.allclose(metadata_position, position.state_vector[(0, 2), :]) |
| 195 | + metadata_orientation = detection.metadata.get('orientation') |
| 196 | + assert np.allclose(metadata_orientation, orientation) |
| 197 | + |
| 198 | + position2 = State(StateVector([50, 0, 50, 0])) |
| 199 | + orientation2 = StateVector([np.radians(-90), np.radians(10), 0]) |
| 200 | + test_radar2 = RadarElevationBearingRange(ndim_state=4, |
| 201 | + position_mapping=(0, 2, 3), |
| 202 | + noise_covar=np.diag( |
| 203 | + [np.radians(10) ** 2, |
| 204 | + np.radians(2) ** 2, |
| 205 | + 0.1 ** 2] |
| 206 | + ), |
| 207 | + movement_controller=FixedMovable( |
| 208 | + states=[position2], |
| 209 | + orientation=orientation2, |
| 210 | + position_mapping=(0, 2, 3) |
| 211 | + ) |
| 212 | + ) |
| 213 | + |
| 214 | + test_sensor = SensorSuite(attributes_inform=['position', 'orientation'], |
| 215 | + sensors=[test_radar, test_radar2]) |
| 216 | + |
| 217 | + detections = test_sensor.measure({dummy_truth1, dummy_truth2}) |
| 218 | + |
| 219 | + assert len(detections) == 4 |
| 220 | + |
| 221 | + for detection in detections: |
| 222 | + assert isinstance(detection.measurement_model, CartesianToBearingRange) \ |
| 223 | + or isinstance(detection.measurement_model, CartesianToElevationBearingRange) |
| 224 | + metadata_position = detection.metadata.get('position') |
| 225 | + metadata_orientation = detection.metadata.get('orientation') |
| 226 | + if isinstance(detection.measurement_model, CartesianToBearingRange): |
| 227 | + assert np.allclose(metadata_position, position.state_vector[(0, 2), :]) |
| 228 | + assert np.allclose(metadata_orientation, orientation) |
| 229 | + else: |
| 230 | + assert np.allclose(metadata_position, position2.state_vector[(0, 2, 3), :]) |
| 231 | + assert np.allclose(metadata_orientation, orientation2) |
0 commit comments