Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:CARLA simulator Carla Python Weather Bindings

From Leeroopedia
Knowledge Sources
Domains Python Bindings, Weather System
Last Updated 2026-02-15 05:00 GMT

Overview

Boost.Python binding file that exposes the CARLA WeatherParameters class and weather presets to the Python API.

Description

This file defines the export_weather() function that registers the WeatherParameters class with 14 configurable float properties: cloudiness, precipitation, precipitation_deposits, wind_intensity, sun_azimuth_angle, sun_altitude_angle, fog_density, fog_distance, fog_falloff, wetness, scattering_intensity, mie_scattering_scale, rayleigh_scattering_scale, and dust_storm. All default to 0.0 except rayleigh_scattering_scale (0.0331). The class supports equality comparison and string representation. Predefined weather presets are registered as class attributes: Default, ClearNoon, CloudyNoon, WetNoon, WetCloudyNoon, MidRainyNoon, HardRainNoon, SoftRainNoon, ClearSunset, CloudySunset, WetSunset, WetCloudySunset, MidRainSunset, HardRainSunset, SoftRainSunset, ClearNight, CloudyNight, WetNight, WetCloudyNight, SoftRainNight, MidRainyNight, HardRainNight, and DustStorm.

Usage

This binding is used to dynamically change the simulation weather conditions, affecting visual appearance, sensor behavior, and driving conditions in the CARLA world.

Code Reference

Source Location

  • Repository: CARLA
  • File: PythonAPI/carla/src/Weather.cpp

Signature

void export_weather();

// Key class exposed:
class_<cr::WeatherParameters>("WeatherParameters")
    .def(init<float, float, float, float, float, float, float, float, float, float, float, float, float, float>())

Import

import carla
weather = carla.WeatherParameters.ClearNoon
world.set_weather(weather)

I/O Contract

Inputs

Name Type Required Description
cloudiness float No Cloud cover percentage (0-100, default: 0)
precipitation float No Rain intensity (0-100, default: 0)
sun_azimuth_angle float No Sun horizontal angle in degrees (default: 0)
sun_altitude_angle float No Sun vertical angle in degrees (default: 0)
fog_density float No Fog thickness (0-100, default: 0)
dust_storm float No Dust storm intensity (0-100, default: 0)

Outputs

Name Type Description
WeatherParameters carla.WeatherParameters Configured weather object to apply to the world

Usage Examples

import carla

client = carla.Client('localhost', 2000)
world = client.get_world()

# Use a preset
world.set_weather(carla.WeatherParameters.HardRainNoon)

# Custom weather
weather = carla.WeatherParameters(
    cloudiness=80.0,
    precipitation=60.0,
    sun_altitude_angle=45.0,
    fog_density=20.0,
    wetness=50.0
)
world.set_weather(weather)

# Read current weather
current = world.get_weather()
print(f"Cloudiness: {current.cloudiness}")

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment