Python carla.WeatherParameters() Examples
The following are 14
code examples of carla.WeatherParameters().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
carla
, or try the search function
.
Example #1
Source File: openscenario_configuration.py From scenario_runner with MIT License | 6 votes |
def __init__(self, filename, client): self.xml_tree = ET.parse(filename) self._filename = filename self._validate_openscenario_configuration() self.client = client self.catalogs = {} self.other_actors = [] self.ego_vehicles = [] self.trigger_points = [] self.weather = carla.WeatherParameters() self.storyboard = self.xml_tree.find("Storyboard") self.story = self.storyboard.find("Story") self.init = self.storyboard.find("Init") logging.basicConfig() self.logger = logging.getLogger("[SR:OpenScenarioConfiguration]") self._set_parameters() self._parse_openscenario_configuration()
Example #2
Source File: bridge.py From ros-bridge with MIT License | 6 votes |
def on_weather_changed(self, weather_parameters): """ Callback on new weather parameters :return: """ if not self.carla_world: return rospy.loginfo("Applying weather parameters...") weather = carla.WeatherParameters() weather.cloudiness = weather_parameters.cloudiness weather.precipitation = weather_parameters.precipitation weather.precipitation_deposits = weather_parameters.precipitation_deposits weather.wind_intensity = weather_parameters.wind_intensity weather.fog_density = weather_parameters.fog_density weather.fog_distance = weather_parameters.fog_distance weather.wetness = weather_parameters.wetness weather.sun_azimuth_angle = weather_parameters.sun_azimuth_angle weather.sun_altitude_angle = weather_parameters.sun_altitude_angle self.carla_world.set_weather(weather)
Example #3
Source File: carla_data_provider.py From scenario_runner with MIT License | 5 votes |
def find_weather_presets(): """ Get weather presets from CARLA """ rgx = re.compile('.+?(?:(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|$)') name = lambda x: ' '.join(m.group(0) for m in rgx.finditer(x)) presets = [x for x in dir(carla.WeatherParameters) if re.match('[A-Z].+', x)] return [(getattr(carla.WeatherParameters, x), name(x)) for x in presets]
Example #4
Source File: route_parser.py From scenario_runner with MIT License | 5 votes |
def parse_weather(route): """ Returns a carla.WeatherParameters with the corresponding weather for that route. If the route has no weather attribute, the default one is triggered. """ route_weather = route.find("weather") if route_weather is None: weather = carla.WeatherParameters(sun_altitude_angle=70) else: weather = carla.WeatherParameters() for weather_attrib in route.iter("weather"): if 'cloudiness' in weather_attrib.attrib: weather.cloudiness = float(weather_attrib.attrib['cloudiness']) if 'precipitation' in weather_attrib.attrib: weather.precipitation = float(weather_attrib.attrib['precipitation']) if 'precipitation_deposits' in weather_attrib.attrib: weather.precipitation_deposits = float(weather_attrib.attrib['precipitation_deposits']) if 'wind_intensity' in weather_attrib.attrib: weather.wind_intensity = float(weather_attrib.attrib['wind_intensity']) if 'sun_azimuth_angle' in weather_attrib.attrib: weather.sun_azimuth_angle = float(weather_attrib.attrib['sun_azimuth_angle']) if 'sun_altitude_angle' in weather_attrib.attrib: weather.sun_altitude_angle = float(weather_attrib.attrib['sun_altitude_angle']) if 'wetness' in weather_attrib.attrib: weather.wetness = float(weather_attrib.attrib['wetness']) if 'fog_distance' in weather_attrib.attrib: weather.fog_distance = float(weather_attrib.attrib['fog_distance']) if 'fog_density' in weather_attrib.attrib: weather.fog_density = float(weather_attrib.attrib['fog_density']) return weather
Example #5
Source File: carla_scenic_task.py From VerifAI with BSD 3-Clause "New" or "Revised" License | 5 votes |
def use_sample(self, sample): print('USE_SAMPLE Sample:', sample) weather = carla.WeatherParameters(**{k: sample.params._asdict()[k] for k in WEATHER_PARAMS}) self.world.world.set_weather(weather) for obj in sample.objects: spawn = Transform(self.snap_to_ground(Location(x=obj.position[0], y=-obj.position[1], z=1)), Rotation(yaw=-obj.heading * 180 / math.pi - 90)) attrs = dict() if 'color' in obj._fields: color = str(int(obj.color.r * 255)) + ',' \ + str(int(obj.color.g * 255)) + ',' + str(int(obj.color.b * 255)) attrs['color'] = color if 'blueprint' in obj._fields: attrs['blueprint_filter'] = obj.blueprint agent = BrakeAgent if 'agent' in obj._fields: agent = AGENTS[obj.agent] if obj.type in ['Vehicle', 'Car', 'Truck', 'Bicycle', 'Motorcycle']: self.world.add_vehicle(agent, spawn=spawn, has_collision_sensor=False, has_lane_sensor=False, ego=obj is sample.objects[0], **attrs) elif obj.type == 'Pedestrian': self.world.add_pedestrian(spawn=spawn, **attrs) elif obj.type in ['Prop', 'Trash', 'Cone']: self.world.add_prop(spawn=spawn, **attrs) else: print('Unsupported object type:', obj.type)
Example #6
Source File: carla_world.py From VerifAI with BSD 3-Clause "New" or "Revised" License | 5 votes |
def find_weather_presets(): rgx = re.compile('.+?(?:(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|$)') name = lambda x: ' '.join(m.group(0) for m in rgx.finditer(x)) presets = [x for x in dir(carla.WeatherParameters) if re.match('[A-Z].+', x)] return [(getattr(carla.WeatherParameters, x), name(x)) for x in presets]
Example #7
Source File: carla09interface.py From coiltraine with MIT License | 5 votes |
def find_weather_presets(): rgx = re.compile('.+?(?:(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|$)') name = lambda x: ' '.join(m.group(0) for m in rgx.finditer(x)) presets = [x for x in dir(carla.WeatherParameters) if re.match('[A-Z].+', x)] return [(getattr(carla.WeatherParameters, x), name(x)) for x in presets]
Example #8
Source File: manual_control.py From macad-gym with MIT License | 5 votes |
def find_weather_presets(): rgx = re.compile('.+?(?:(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|$)') name = lambda x: ' '.join(m.group(0) for m in rgx.finditer(x)) presets = [x for x in dir(carla.WeatherParameters) if re.match('[A-Z].+', x)] return [(getattr(carla.WeatherParameters, x), name(x)) for x in presets]
Example #9
Source File: spawn_control.py From macad-gym with MIT License | 5 votes |
def find_weather_presets(): rgx = re.compile('.+?(?:(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|$)') name = lambda x: ' '.join( # noqa: E731 m.group(0) for m in rgx.finditer(x)) presets = [ x for x in dir(carla.WeatherParameters) if re.match('[A-Z].+', x) ] return [(getattr(carla.WeatherParameters, x), name(x)) for x in presets]
Example #10
Source File: utils.py From pylot with Apache License 2.0 | 5 votes |
def set_weather(world, weather): """Sets the simulation weather.""" names = [ name for name in dir(carla.WeatherParameters) if re.match('[A-Z].+', name) ] weathers = {x: getattr(carla.WeatherParameters, x) for x in names} world.set_weather(weathers[weather]) return weathers
Example #11
Source File: sign_data_gatherer.py From pylot with Apache License 2.0 | 5 votes |
def change_weather(world, weather): world.set_weather(getattr(carla.WeatherParameters, weather))
Example #12
Source File: sign_data_gatherer.py From pylot with Apache License 2.0 | 5 votes |
def find_weather_presets(): presets = [ x for x in dir(carla.WeatherParameters) if re.match('[A-Z].+', x) ] return presets
Example #13
Source File: utils.py From Multiverse with Apache License 2.0 | 5 votes |
def setup_static(world, client, scene_elements, actor_list): this_weather = scene_elements["weather"] weather = carla.WeatherParameters( cloudyness=this_weather["cloudyness"], precipitation=this_weather["precipitation"], precipitation_deposits=this_weather["precipitation_deposits"], sun_altitude_angle=this_weather["sun_altitude_angle"], sun_azimuth_angle=this_weather["sun_azimuth_angle"], wind_intensity=this_weather["wind_intensity"]) world.set_weather(weather) spawn_cmds = [] for car in scene_elements["static_cars"]: car_location = carla.Location(x=car["location_xyz"][0], y=car["location_xyz"][1], z=car["location_xyz"][2]) car_rotation = carla.Rotation(pitch=car["rotation_pyr"][0], yaw=car["rotation_pyr"][1], roll=car["rotation_pyr"][2]) car_bp = world.get_blueprint_library().find(car["bp"]) assert car_bp is not None, car_bp # the static car can be walked though spawn_cmds.append( carla.command.SpawnActor( car_bp, carla.Transform( location=car_location, rotation=car_rotation)).then( carla.command.SetSimulatePhysics( carla.command.FutureActor, False))) # spawn the actors needed for the static scene setup if spawn_cmds: response = client.apply_batch_sync(spawn_cmds) all_actors = world.get_actors([x.actor_id for x in response]) actor_list += all_actors
Example #14
Source File: openscenario_parser.py From scenario_runner with MIT License | 4 votes |
def get_weather_from_env_action(xml_tree, catalogs): """ Extract the CARLA weather parameters from an OSC EnvironmentAction Args: xml_tree: Containing the EnvironmentAction, or the reference to the catalog it is defined in. catalogs: XML Catalogs that could contain the EnvironmentAction returns: Weather (srunner.scenariomanager.weather_sim.Weather) """ set_environment = next(xml_tree.iter("EnvironmentAction")) if sum(1 for _ in set_environment.iter("Weather")) != 0: environment = set_environment.find("Environment") elif set_environment.find("CatalogReference") is not None: catalog_reference = set_environment.find("CatalogReference") environment = catalogs[catalog_reference.attrib.get( "catalogName")][catalog_reference.attrib.get("entryName")] weather = environment.find("Weather") sun = weather.find("Sun") carla_weather = carla.WeatherParameters() carla_weather.sun_azimuth_angle = math.degrees(float(sun.attrib.get('azimuth', 0))) carla_weather.sun_altitude_angle = math.degrees(float(sun.attrib.get('elevation', 0))) carla_weather.cloudiness = 100 - float(sun.attrib.get('intensity', 0)) * 100 fog = weather.find("Fog") carla_weather.fog_distance = float(fog.attrib.get('visualRange', 'inf')) if carla_weather.fog_distance < 1000: carla_weather.fog_density = 100 carla_weather.precipitation = 0 carla_weather.precipitation_deposits = 0 carla_weather.wetness = 0 carla_weather.wind_intensity = 0 precepitation = weather.find("Precipitation") if precepitation.attrib.get('precipitationType') == "rain": carla_weather.precipitation = float(precepitation.attrib.get('intensity')) * 100 carla_weather.precipitation_deposits = 100 # if it rains, make the road wet carla_weather.wetness = carla_weather.precipitation elif precepitation.attrib.get('type') == "snow": raise AttributeError("CARLA does not support snow precipitation") time_of_day = environment.find("TimeOfDay") weather_animation = strtobool(time_of_day.attrib.get("animation")) time = time_of_day.attrib.get("dateTime") dtime = datetime.datetime.strptime(time, "%Y-%m-%dT%H:%M:%S") return Weather(carla_weather, dtime, weather_animation)