POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception package

Tests for the CARLA perception + prediction subpackage.

Subpackages

Submodules

POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception.test_carla_pipeline module

Tests for the standalone CARLA perception + prediction pipeline.

Covers the swappable PerceptionModel / MotionTracker interfaces and their defaults (LidarCameraPerceptionModel, OracleAgentPerceptionModel, AlphaBetaTracker), plus the composed, immutable CarlaPerceptionPipeline that turns a raw observation into an ego-frame agent block and a fused forward-obstacle distance. All tests run on hand-built sensor arrays.

POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception.test_carla_pipeline.test_alpha_beta_tracker_spawns_track_from_detection()[source]

The default tracker spawns a five-column track from a fresh detection.

Purpose: Validates the MotionTracker default wraps the constant-velocity tracker.

Given: No prior tracks and one detection 8 m ahead When: AlphaBetaTracker.update runs Then: One (rel_x, rel_y, vx, vy, confidence) track is returned

Test type: unit

POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception.test_carla_pipeline.test_detections_dataclass_carries_single_frame_fields()[source]

Detections bundles vehicle positions, forward clearance, and a traffic light.

Purpose: Validates the single-frame perception output structure.

Given: A hand-built Detections instance When: Its fields are read Then: The vehicle positions, clearance, and traffic light are returned as given

Test type: unit

POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception.test_carla_pipeline.test_lidar_camera_model_channel_source_reads_traffic_light_key()[source]

With traffic_light_source=’channel’ the model reads the ground-truth light channel.

Purpose: Validates the channel source bypasses camera inference and reads the channel.

Given: An observation whose traffic_light channel says stop at 10 m, camera green When: A channel-sourced LidarCameraPerceptionModel.detect runs Then: The reported light is the channel value, not the camera inference

Test type: unit

POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception.test_carla_pipeline.test_lidar_camera_model_detects_vehicle_and_clear_light()[source]

The default model clusters a lidar vehicle and reports a clear (green) light.

Purpose: Validates single-frame perception yields a vehicle detection and no stop signal.

Given: A lidar cloud with one vehicle-sized blob 8 m ahead and a dark camera frame When: LidarCameraPerceptionModel.detect runs Then: One vehicle position is returned and the traffic light is not a stop

Test type: unit

POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception.test_carla_pipeline.test_lidar_camera_model_infers_red_light_from_camera()[source]

A red bulb in the camera frame is inferred as a stop signal.

Purpose: Validates the default model infers the traffic light from the image, not a channel.

Given: An observation with a red bulb in the camera and no traffic_light channel When: LidarCameraPerceptionModel.detect runs Then: The perceived traffic light signals a stop

Test type: unit

POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception.test_carla_pipeline.test_oracle_model_reads_present_agents_as_positions()[source]

The oracle model returns only present agent slots as detections.

Purpose: Validates ground-truth agent positions are read, padding slots dropped.

Given: A two-slot agents channel with one present agent 8 m ahead and one empty slot When: OracleAgentPerceptionModel.detect runs Then: Exactly one detection at (8, 0) is returned

Test type: unit

POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception.test_carla_pipeline.test_pipeline_coasts_briefly_occluded_vehicle()[source]

A vehicle seen then lost is coasted by the tracker through a dropout.

Purpose: Validates the tracker’s coasting keeps a briefly occluded agent in the block.

Given: A pipeline that perceives a vehicle, then an empty observation When: process runs twice, threading the successor pipeline forward Then: The agent slot is still present after the dropout step

Test type: unit

POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception.test_carla_pipeline.test_pipeline_detects_object_type_from_model()[source]

The pipeline delegates single-frame detection to its perception model.

Purpose: Validates a swapped-in perception model drives the pipeline’s detections.

Given: A pipeline built with an OracleAgentPerceptionModel and an agents channel When: process runs Then: The agent block reflects the oracle-perceived vehicle

Test type: unit

POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception.test_carla_pipeline.test_pipeline_does_not_duplicate_a_tracked_obstacle()[source]

A lidar hazard already covered by a tracked vehicle adds no extra slot.

Purpose: Validates obstacle folding deduplicates against the perceived vehicles.

Given: A fusion pipeline whose lidar shows a vehicle-sized blob 8 m ahead When: process runs (the blob is both a tracked vehicle and the corridor obstacle) Then: Exactly one slot is present, not a vehicle plus a duplicate hazard

Test type: unit

POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception.test_carla_pipeline.test_pipeline_folds_lidar_obstacle_into_empty_agent_slot()[source]

A lidar obstacle no vehicle covers is folded into the agent block as a hazard.

Purpose: Validates the fused obstacle becomes a present agent slot for the planner.

Given: A fusion pipeline and a lidar return 6 m ahead with no clustered vehicle When: process runs Then: One present slot at ~6 m directly ahead appears in the agent block

Test type: unit

POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception.test_carla_pipeline.test_pipeline_is_immutable_across_process()[source]

process does not mutate the pipeline’s own tracker state.

Purpose: Validates immutability so a belief can thread perception forward safely.

Given: A fresh pipeline with empty tracks When: process runs on an observation with a vehicle Then: The original pipeline’s tracks stay empty while the successor carries the new track

Test type: unit

POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception.test_carla_pipeline.test_pipeline_process_produces_agent_block_and_successor()[source]

Processing a lidar vehicle fills an agent slot and returns a successor pipeline.

Purpose: Validates the composed pipeline perceives, tracks, and packs the agent block.

Given: A pipeline with one agent slot and an observation with a vehicle 8 m ahead When: process runs Then: The agent block marks a present agent near 8 m and a distinct successor is returned

Test type: unit

POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception.test_carla_pipeline.test_pipeline_reports_no_obstacle_when_disabled_and_clear()[source]

With fusion and light-stopping off, a clear scene reports no obstacle.

Purpose: Validates the obstacle channel is silent when both sources are disabled.

Given: A pipeline with sensor_fusion and stop_for_traffic_lights both off When: process runs on an empty observation Then: The obstacle distance is None

Test type: unit

POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception.test_carla_pipeline.test_pipeline_reports_red_light_as_forward_obstacle()[source]

A red camera light within range is reported as a forward-obstacle distance.

Purpose: Validates stop_for_traffic_lights folds the inferred light into the obstacle.

Given: A pipeline with traffic-light stopping and a red bulb 10 m ahead (channel source) When: process runs Then: The obstacle distance is the light’s stop distance

Test type: unit

POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception.test_carla_sensors module

Tests for the CARLA forward-obstacle perception helpers.

Covers the pure lidar/camera helpers that turn raw sensors into a forward-obstacle distance: lidar_forward_clearance() gating a point cloud to a forward, vehicle-height corridor, camera_looming_cue() scoring the lower-centre view, and fuse_forward_obstacle() combining them with lidar taking precedence. All tests run on hand-built arrays.

POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception.test_carla_sensors.test_camera_looming_cue_high_for_dark_near_object()[source]

A dark lower-centre view yields a high looming cue.

Purpose: Validates the cue rises when a large near object fills the view.

Given: An all-dark RGB frame and an all-bright RGB frame When: camera_looming_cue is computed for each Then: The dark frame scores near 1.0 and the bright frame near 0.0

Test type: unit

POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception.test_carla_sensors.test_camera_looming_cue_none_is_zero()[source]

A missing frame yields no looming cue.

Purpose: Validates the no-data path returns 0.0.

Given: None as the camera frame When: camera_looming_cue is computed Then: It returns 0.0

Test type: unit

POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception.test_carla_sensors.test_fuse_prefers_lidar_when_it_detects()[source]

A lidar detection overrides the camera cue.

Purpose: Validates lidar is authoritative on obstacle distance.

Given: A lidar clearance of 6 m and a strong camera cue When: fuse_forward_obstacle combines them Then: The lidar 6 m is returned

Test type: unit

POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception.test_carla_sensors.test_fuse_uses_camera_only_when_lidar_clear()[source]

The camera flags a near obstacle only when the lidar sees nothing.

Purpose: Validates the conservative camera fallback and the all-clear case.

Given: A clear lidar corridor with a strong cue, and the same with no cue When: fuse_forward_obstacle combines them Then: The strong cue yields the conservative camera range; no cue yields max range

Test type: unit

POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception.test_carla_sensors.test_lidar_clearance_empty_or_none_is_clear()[source]

A missing or empty scan reports a clear corridor.

Purpose: Validates the no-data path returns the sensor range, not an error.

Given: None and an empty array as the point cloud When: lidar_forward_clearance is computed Then: Both return the max range

Test type: unit

POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception.test_carla_sensors.test_lidar_clearance_ignores_ground_and_out_of_corridor_returns()[source]

Ground-height and off-corridor returns do not count as obstacles.

Purpose: Validates the height band and lateral gate exclude non-obstacles.

Given: A near ground return (z below the band) and a near return 3 m to the side When: lidar_forward_clearance is computed Then: Both are ignored and the corridor reads clear (max range)

Test type: unit

POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception.test_carla_sensors.test_lidar_clearance_returns_nearest_forward_return()[source]

The clearance is the nearest in-corridor forward return.

Purpose: Validates the corridor gate reports the closest obstacle distance.

Given: A cloud with forward returns at x = 9 m and x = 6 m in the corridor When: lidar_forward_clearance is computed Then: It returns the nearer 6 m

Test type: unit

POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception.test_carla_sensors.test_lidar_detection_ignores_ground_and_none()[source]

Ground-height returns and a missing cloud yield no detections.

Purpose: Validates the height gate and the no-data path.

Given: A blob at ground height (below the vehicle band) and None When: lidar_vehicle_detections is computed for each Then: Both return an empty (0, 3) detection array

Test type: unit

POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception.test_carla_sensors.test_lidar_detection_rejects_wall_sized_clusters()[source]

A long wall-sized cluster is rejected as not a vehicle.

Purpose: Validates the extent filter drops buildings / walls.

Given: A 20 m-long line of vehicle-height returns (extent far exceeds a vehicle) When: lidar_vehicle_detections clusters it Then: No detection is returned

Test type: unit

POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception.test_carla_sensors.test_lidar_detects_separate_vehicle_clusters_in_ego_frame()[source]

Two vehicle-sized point clusters become two ego-frame detections.

Purpose: Validates clustering finds each vehicle and converts to the ego frame.

Given: A cloud with two vehicle-height blobs at sensor (10, -3) and (10, 3) When: lidar_vehicle_detections clusters it Then: Two detections appear at rel_x ~ 10 with rel_y ~ +3 and -3 (sensor-y sign flipped)

Test type: unit

POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception.test_carla_sensors.test_traffic_light_from_camera_detects_amber_bulb_as_stop()[source]

An amber (yellow) bulb is also treated as a stop signal.

Purpose: Validates amber lights are perceived as stop, matching the world’s stop states.

Given: A dark frame with a yellow bulb in the upper region When: traffic_light_from_camera reads it Then: should_stop is 1.0

Test type: unit

POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception.test_carla_sensors.test_traffic_light_from_camera_detects_red_bulb_as_stop()[source]

A red bulb high in the frame is read as a stop signal at a finite distance.

Purpose: Validates camera-based traffic-light inference flags a red light to stop.

Given: A dark frame with a red bulb in the upper region When: traffic_light_from_camera reads it Then: should_stop is 1.0 and the estimated distance is finite and in range

Test type: unit

POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception.test_carla_sensors.test_traffic_light_from_camera_ignores_green_and_missing_frame()[source]

A green bulb or an absent frame yields no stop signal.

Purpose: Validates green lights and missing frames produce [0, 0] (no stop).

Given: A frame with a green bulb, and separately None When: traffic_light_from_camera reads each Then: Both return [0.0, 0.0]

Test type: unit

POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception.test_carla_sensors.test_traffic_light_from_camera_larger_bulb_reads_nearer()[source]

A larger red bulb estimates a nearer stop distance than a smaller one.

Purpose: Validates the pinhole distance estimate is monotonic in bulb pixel size.

Given: Two red bulbs, one 20 px and one 8 px across When: traffic_light_from_camera estimates each distance Then: The larger bulb yields the smaller (nearer) distance

Test type: unit

POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception.test_carla_sensors.test_traffic_light_from_camera_rejects_sub_threshold_noise()[source]

A single stray red pixel is rejected as noise, not a bulb.

Purpose: Validates the minimum-blob-size gate suppresses spurious detections.

Given: A frame with a 1x1 red speck (below min_bulb_pixels) When: traffic_light_from_camera reads it Then: No stop signal is produced

Test type: unit

POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception.test_carla_sensors.test_traffic_light_stop_distance_reports_red_light_gap()[source]

A red/yellow stop signal reports its stop-line distance; otherwise the way is clear.

Purpose: Validates the traffic-light observation becomes an obstacle distance.

Given: a stop signal [1, 12] , a no-stop signal [0, 0] , and None When: traffic_light_stop_distance is computed Then: the stop signal yields 12 m; the others yield the max range

Test type: unit

POMDPPlanners.tests.test_environments.test_carla_pomdp.test_carla_perception.test_carla_tracking module