Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change return type and add track ID metadata to Track2GaussianDetectionFeeder #871

Merged
merged 3 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions stonesoup/feeder/tests/test_track.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,22 @@ def test_Track2GaussianDetectionFeeder(tracks):
assert len(detections) == len(tracks)

# Check that the correct state was taken from each track
assert np.all([detections[i].timestamp == tracks[i][-1].timestamp for i in range(len(tracks))])
assert np.all([detections[i].timestamp == time for i in range(len(tracks))])
assert np.all([detection.timestamp == track.timestamp
for track in tracks
for detection in detections if detection.metadata['track_id'] == track.id])
assert np.all([detection.timestamp == time for detection in detections])

# Check that the dimension of each detection is correct
assert np.all([len(detections[i].state_vector) == len(tracks[i][-1].state_vector)
for i in range(len(tracks))])
assert np.all([len(detection.state_vector) == len(track.state_vector)
for track in tracks
for detection in detections if detection.metadata['track_id'] == track.id])
assert np.all([len(detection.state_vector) == detection.measurement_model.ndim
for detection in detections])

# Check that the detection has the correct mean and covariance
for i in range(len(tracks)):
assert np.all(detections[i].state_vector == tracks[i][-1].state_vector)
assert np.all(detections[i].covar == tracks[i][-1].covar)
for track in tracks:
detection = next(iter(detection
for detection in detections
if detection.metadata['track_id'] == track.id))
assert np.all(detection.state_vector == track.state_vector)
assert np.all(detection.covar == track.covar)
7 changes: 5 additions & 2 deletions stonesoup/feeder/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ class Tracks2GaussianDetectionFeeder(DetectionFeeder):
@BufferedGenerator.generator_method
def data_gen(self):
for time, tracks in self.reader:
detections = []
detections = set()
for track in tracks:
dim = len(track.state.state_vector)
detections.append(
metadata = track.metadata.copy()
metadata['track_id'] = track.id
detections.add(
GaussianDetection.from_state(
track.state,
measurement_model=LinearGaussian(
dim, list(range(dim)), np.asarray(track.covar)),
metadata=metadata,
target_type=GaussianDetection)
)

Expand Down