Module scenariogeneration.xosc.position
scenariogeneration https://github.com/pyoscx/scenariogeneration
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
Copyright (c) 2022 The scenariogeneration Authors.
Classes
class Clothoid (curvature: float,
curvature_change: float,
length: float,
startposition: scenariogeneration.xosc.utils._PositionType,
starttime: float | None = None,
stoptime: float | None = None)-
Expand source code
class Clothoid(_TrajectoryShape): """The Clothoid class creates a Clothoid shape. Parameters ---------- curvature : float Start curvature of the clothoid. curvature_change : float Rate of clothoid curvature change. length : float Length of the clothoid. startposition : _PositionType Start position of the clothoid. starttime : float, optional Start time of the clothoid. Default is None. stoptime : float, optional End time of the clothoid. Default is None. Attributes ---------- curvature : float Start curvature of the clothoid. curvature_change : float Rate of clothoid curvature change. length : float Length of the clothoid. startposition : _PositionType Start position of the clothoid. starttime : float Start time of the clothoid. Default is None. stoptime : float End time of the clothoid. Default is None. Methods ------- parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element() Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class. """ def __init__( self, curvature: float, curvature_change: float, length: float, startposition: _PositionType, starttime: Optional[float] = None, stoptime: Optional[float] = None, ) -> None: """Initialize the Clothoid. Parameters ---------- curvature : float Start curvature of the clothoid. curvature_change : float Rate of clothoid curvature change. length : float Length of the clothoid. startposition : _PositionType Start position of the clothoid. starttime : float, optional Start time of the clothoid. Default is None. stoptime : float, optional End time of the clothoid. Default is None. """ # TODO: The input order needs to be changed, curvature_change has # cardinality 0, breaking change! self.curvature = convert_float(curvature) self.curvature_change = convert_float(curvature_change) self.length = convert_float(length) if not isinstance(startposition, _PositionType): raise TypeError("position input is not a valid position") self.startposition = startposition self.starttime = convert_float(starttime) self.stoptime = convert_float(stoptime) if (self.starttime is None and self.stoptime is not None) or ( self.starttime is not None and self.stoptime is None ): raise ValueError( "Both start and stoptime has to be set, or none of them" ) def __eq__(self, other) -> bool: if isinstance(other, Clothoid): if ( self.get_attributes() == other.get_attributes() and self.startposition == other.startposition ): return True return False @staticmethod def parse(element: ET.Element) -> "Clothoid": """Parse the XML element of Clothoid. Parameters ---------- element : xml.etree.ElementTree.Element A Clothoid element (same as generated by the class itself). Returns ------- Clothoid A Clothoid object. """ clothoid_element = find_mandatory_field(element, "Clothoid") start_position = _PositionFactory.parse_position( find_mandatory_field(clothoid_element, "Position") ) length = convert_float(clothoid_element.attrib["length"]) curvature = convert_float(clothoid_element.attrib["curvature"]) starttime = None stoptime = None if "startTime" in clothoid_element.attrib: starttime = convert_float(clothoid_element.attrib["startTime"]) if "stopTime" in clothoid_element.attrib: stoptime = convert_float(clothoid_element.attrib["stopTime"]) if "curvatureDot" in clothoid_element.attrib: curvature_change = convert_float( clothoid_element.element["curvaturePrime"] ) elif "curvaturePrime" in clothoid_element.attrib: curvature_change = convert_float( clothoid_element.attrib["curvaturePrime"] ) else: raise XMLStructureError( "curatureDot or curvaturePrime not found in Clothoid" ) return Clothoid( curvature, curvature_change, length, start_position, starttime, stoptime, ) def get_attributes(self) -> dict: """Return the attributes of the Clothoid as a dictionary. Returns ------- dict A dictionary containing the attributes of the Clothoid. """ retdict = {} retdict["curvature"] = str(self.curvature) if self.isVersion(minor=0): retdict["curvatureDot"] = str(self.curvature_change) else: retdict["curvaturePrime"] = str(self.curvature_change) retdict["length"] = str(self.length) if self.starttime is not None: retdict["startTime"] = str(self.starttime) retdict["stopTime"] = str(self.stoptime) return retdict def get_element(self) -> ET.Element: """Return the ElementTree of the Clothoid. Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the Clothoid. """ shape = ET.Element("Shape") element = ET.SubElement( shape, "Clothoid", attrib=self.get_attributes() ) element.append(self.startposition.get_element()) return shapeThe Clothoid class creates a Clothoid shape.
Parameters
curvature:float- Start curvature of the clothoid.
curvature_change:float- Rate of clothoid curvature change.
length:float- Length of the clothoid.
startposition:_PositionType- Start position of the clothoid.
starttime:float, optional- Start time of the clothoid. Default is None.
stoptime:float, optional- End time of the clothoid. Default is None.
Attributes
curvature:float- Start curvature of the clothoid.
curvature_change:float- Rate of clothoid curvature change.
length:float- Length of the clothoid.
startposition:_PositionType- Start position of the clothoid.
starttime:float- Start time of the clothoid. Default is None.
stoptime:float- End time of the clothoid. Default is None.
Methods
parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element() Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class.
Initialize the Clothoid.
Parameters
curvature:float- Start curvature of the clothoid.
curvature_change:float- Rate of clothoid curvature change.
length:float- Length of the clothoid.
startposition:_PositionType- Start position of the clothoid.
starttime:float, optional- Start time of the clothoid. Default is None.
stoptime:float, optional- End time of the clothoid. Default is None.
Ancestors
- scenariogeneration.xosc.position._TrajectoryShape
- VersionBase
Static methods
def parse(element: xml.etree.ElementTree.Element) ‑> Clothoid-
Expand source code
@staticmethod def parse(element: ET.Element) -> "Clothoid": """Parse the XML element of Clothoid. Parameters ---------- element : xml.etree.ElementTree.Element A Clothoid element (same as generated by the class itself). Returns ------- Clothoid A Clothoid object. """ clothoid_element = find_mandatory_field(element, "Clothoid") start_position = _PositionFactory.parse_position( find_mandatory_field(clothoid_element, "Position") ) length = convert_float(clothoid_element.attrib["length"]) curvature = convert_float(clothoid_element.attrib["curvature"]) starttime = None stoptime = None if "startTime" in clothoid_element.attrib: starttime = convert_float(clothoid_element.attrib["startTime"]) if "stopTime" in clothoid_element.attrib: stoptime = convert_float(clothoid_element.attrib["stopTime"]) if "curvatureDot" in clothoid_element.attrib: curvature_change = convert_float( clothoid_element.element["curvaturePrime"] ) elif "curvaturePrime" in clothoid_element.attrib: curvature_change = convert_float( clothoid_element.attrib["curvaturePrime"] ) else: raise XMLStructureError( "curatureDot or curvaturePrime not found in Clothoid" ) return Clothoid( curvature, curvature_change, length, start_position, starttime, stoptime, )Parse the XML element of Clothoid.
Parameters
element:xml.etree.ElementTree.Element- A Clothoid element (same as generated by the class itself).
Returns
Clothoid- A Clothoid object.
Methods
def get_attributes(self) ‑> dict-
Expand source code
def get_attributes(self) -> dict: """Return the attributes of the Clothoid as a dictionary. Returns ------- dict A dictionary containing the attributes of the Clothoid. """ retdict = {} retdict["curvature"] = str(self.curvature) if self.isVersion(minor=0): retdict["curvatureDot"] = str(self.curvature_change) else: retdict["curvaturePrime"] = str(self.curvature_change) retdict["length"] = str(self.length) if self.starttime is not None: retdict["startTime"] = str(self.starttime) retdict["stopTime"] = str(self.stoptime) return retdictReturn the attributes of the Clothoid as a dictionary.
Returns
dict- A dictionary containing the attributes of the Clothoid.
def get_element(self) ‑> xml.etree.ElementTree.Element-
Expand source code
def get_element(self) -> ET.Element: """Return the ElementTree of the Clothoid. Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the Clothoid. """ shape = ET.Element("Shape") element = ET.SubElement( shape, "Clothoid", attrib=self.get_attributes() ) element.append(self.startposition.get_element()) return shapeReturn the ElementTree of the Clothoid.
Returns
xml.etree.ElementTree.Element- The ElementTree representation of the Clothoid.
class ClothoidSpline (segments: list[ClothoidSplineSegment],
time_end: float | None = None)-
Expand source code
class ClothoidSpline(_TrajectoryShape): """ The ClothoidSpline class creates a ClothoidSpline shape. Parameters ---------- segments : List[ClothoidSplineSegment] A list of ClothoidSplineSegments. time_end : float Optional time specification at the end of the clothoid spline curve. Required if timeStart in ClothoidSplineSegment is specified. Attributes ---------- segments : List[ClothoidSplineSegment] A list of ClothoidSplineSegment objects that define the segments of the clothoid spline. time_end : float, optional time specification at the end of the clothoid spline curve. Methods ------- parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element() Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class. """ def __init__( self, segments: list[ClothoidSplineSegment], time_end: Optional[float] = None, ): """Initialize the ClothoidSpline. Parameters ---------- segments : List[ClothoidSplineSegment] A list of ClothoidSplineSegments. time_end : float Optional time specification at the end of the clothoid spline curve. Required if timeStart in ClothoidSplineSegment is specified. """ self.segments = segments self.time_end = convert_float(time_end) def __eq__(self, other): if not isinstance(other, ClothoidSpline): return False return ( self.segments == other.segments and self.time_end == other.time_end ) def get_attributes(self) -> dict: """Return the attributes of the ClothoidSpline as a dictionary.""" attributes = {} if self.time_end is not None: attributes["timeEnd"] = str(self.time_end) return attributes def get_element(self) -> ET.Element: """Return the ElementTree representation of the ClothoidSpline.""" if self.isVersionEqLess(minor=2): raise OpenSCENARIOVersionError( "ClothoidSpline was introduced in OpenSCENARIO V1.3" ) shape = ET.Element("Shape") element = ET.SubElement( shape, "ClothoidSpline", attrib=self.get_attributes() ) for segment in self.segments: element.append(segment.get_element()) return shape @staticmethod def parse(element: ET.Element) -> "ClothoidSpline": """Parse the XML element of ClothoidSpline. Parameters ---------- element : xml.etree.ElementTree.Element A ClothoidSpline element. Returns ------- ClothoidSpline An instance of ClothoidSpline. """ clothoid_spline_element = find_mandatory_field( element, "ClothoidSpline" ) time_end = convert_float(clothoid_spline_element.attrib.get("timeEnd")) segments = [] for segment_element in clothoid_spline_element.findall( "ClothoidSplineSegment" ): segments.append(ClothoidSplineSegment.parse(segment_element)) return ClothoidSpline(segments=segments, time_end=time_end)The ClothoidSpline class creates a ClothoidSpline shape.
Parameters
segments:List[ClothoidSplineSegment]- A list of ClothoidSplineSegments.
time_end:float- Optional time specification at the end of the clothoid spline curve. Required if timeStart in ClothoidSplineSegment is specified.
Attributes
segments:List[ClothoidSplineSegment]- A list of ClothoidSplineSegment objects that define the segments of the clothoid spline.
time_end:float, optional- time specification at the end of the clothoid spline curve.
Methods
parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element() Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class.
Initialize the ClothoidSpline.
Parameters
segments:List[ClothoidSplineSegment]- A list of ClothoidSplineSegments.
time_end:float- Optional time specification at the end of the clothoid spline curve. Required if timeStart in ClothoidSplineSegment is specified.
Ancestors
- scenariogeneration.xosc.position._TrajectoryShape
- VersionBase
Static methods
def parse(element: xml.etree.ElementTree.Element) ‑> ClothoidSpline-
Expand source code
@staticmethod def parse(element: ET.Element) -> "ClothoidSpline": """Parse the XML element of ClothoidSpline. Parameters ---------- element : xml.etree.ElementTree.Element A ClothoidSpline element. Returns ------- ClothoidSpline An instance of ClothoidSpline. """ clothoid_spline_element = find_mandatory_field( element, "ClothoidSpline" ) time_end = convert_float(clothoid_spline_element.attrib.get("timeEnd")) segments = [] for segment_element in clothoid_spline_element.findall( "ClothoidSplineSegment" ): segments.append(ClothoidSplineSegment.parse(segment_element)) return ClothoidSpline(segments=segments, time_end=time_end)Parse the XML element of ClothoidSpline.
Parameters
element:xml.etree.ElementTree.Element- A ClothoidSpline element.
Returns
ClothoidSpline- An instance of ClothoidSpline.
Methods
def get_attributes(self) ‑> dict-
Expand source code
def get_attributes(self) -> dict: """Return the attributes of the ClothoidSpline as a dictionary.""" attributes = {} if self.time_end is not None: attributes["timeEnd"] = str(self.time_end) return attributesReturn the attributes of the ClothoidSpline as a dictionary.
def get_element(self) ‑> xml.etree.ElementTree.Element-
Expand source code
def get_element(self) -> ET.Element: """Return the ElementTree representation of the ClothoidSpline.""" if self.isVersionEqLess(minor=2): raise OpenSCENARIOVersionError( "ClothoidSpline was introduced in OpenSCENARIO V1.3" ) shape = ET.Element("Shape") element = ET.SubElement( shape, "ClothoidSpline", attrib=self.get_attributes() ) for segment in self.segments: element.append(segment.get_element()) return shapeReturn the ElementTree representation of the ClothoidSpline.
class ClothoidSplineSegment (curvature_start: float,
curvature_end: float,
length: float,
h_offset: float | None = None,
time_start: float | None = None,
position_start: scenariogeneration.xosc.utils._PositionType | None = None)-
Expand source code
class ClothoidSplineSegment(VersionBase): """ The ClothoidSplineSegment class creates a segment of a clothoid spline. Parameters ---------- curvature_start: float Start curvature of the clothoid spline segment.unit:[1/m] curvature_end: float End curvature of the clothoid spline segment.unit:[1/m] length: float Length of the clothoid segment.unit: [m] h_offset: float Optional heading offset in radians of the clothoid segment relative to end of the previous segment or to position_start if present. Default is 0. time_start: float Optional time specification at the start of the clothoid segment.unit: [s] position_start: list of _PositionType optional starting position of a clothoid segment. If position_start is omitted for the first segment, the entity's current position is used. For subsequent segments, the end position of the previous segment is used. If only the heading is omitted, the heading of the previous segment's end position shall be used. Attributes ---------- curvature_start : float Start curvature of the clothoid spline segment. unit: [1/m] curvature_end : float End curvature of the clothoid spline segment. unit: [1/m] length : float Length of the clothoid segment. unit: [m] h_offset : float Heading offset in radians of the clothoid segment relative to end of the previous segment or to position_start if present. time_start : float Time specification at the start of the clothoid segment. unit: [s] position_start : _PositionType Starting position of a clothoid segment. Methods ------- parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element() Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class. """ def __init__( self, curvature_start: float, curvature_end: float, length: float, h_offset: Optional[float] = None, time_start: Optional[float] = None, position_start: Optional[_PositionType] = None, ): """Initialize the ClothoidSplineSegment. Parameters ---------- curvature_start: float Start curvature of the clothoid spline segment.unit:[1/m] curvature_end: float End curvature of the clothoid spline segment.unit:[1/m] length: float Length of the clothoid segment.unit: [m] h_offset: float Optional heading offset in radians of the clothoid segment relative to end of the previous segment or to position_start if present. Default is 0. time_start: float Optional time specification at the start of the clothoid segment.unit: [s] position_start: list of _PositionType optional starting position of a clothoid segment. If position_start is omitted for the first segment, the entity's current position is used. For subsequent segments, the end position of the previous segment is used. If only the heading is omitted, the heading of the previous segment's end position shall be used. """ self.curvature_end = convert_float(curvature_end) self.curvature_start = convert_float(curvature_start) self.h_offset = convert_float(h_offset) if length <= 0: raise ValueError( "The clothoid segment length must be greater than zero" ) self.length = convert_float(length) self.time_start = convert_float(time_start) if position_start is not None: if not isinstance(position_start, list) or not all( isinstance(pos, _PositionType) for pos in position_start ): raise TypeError( "position_start elements must be of type _PositionType or None" ) self.position_start = position_start def __eq__(self, other): if not isinstance(other, ClothoidSplineSegment): return False return ( self.curvature_start == other.curvature_start and self.curvature_end == other.curvature_end and self.length == other.length and self.h_offset == other.h_offset and self.time_start == other.time_start and self.position_start == other.position_start ) def get_attributes(self) -> dict: """Return the attributes of the ClothoidSplineSegment as a dictionary.""" attributes = { "curvatureStart": str(self.curvature_start), "curvatureEnd": str(self.curvature_end), "length": str(self.length), } if self.h_offset is not None: attributes["hOffset"] = str(self.h_offset) if self.time_start is not None: attributes["timeStart"] = str(self.time_start) return attributes def get_element(self) -> ET.Element: """Return the ElementTree representation of the ClothoidSplineSegment.""" if self.isVersionEqLess(minor=2): raise OpenSCENARIOVersionError( "ClothoidSplineSegment was introduced in OpenSCENARIO V1.3" ) element = ET.Element( "ClothoidSplineSegment", attrib=self.get_attributes() ) if self.position_start: for position in self.position_start: element.append(position.get_element("PositionStart")) return element @staticmethod def parse(element: ET.Element) -> "ClothoidSplineSegment": """Parse the XML element of ClothoidSplineSegment. Parameters ---------- element : xml.etree.ElementTree.Element A ClothoidSplineSegment element. Returns ------- ClothoidSplineSegment An instance of ClothoidSplineSegment. """ curvature_start = convert_float(element.attrib["curvatureStart"]) curvature_end = convert_float(element.attrib["curvatureEnd"]) length = convert_float(element.attrib["length"]) h_offset = convert_float(element.attrib.get("hOffset")) time_start = convert_float(element.attrib.get("timeStart")) position_start = [] pos_start_elem = element.find("PositionStart") if pos_start_elem is not None: position_start.append( _PositionFactory.parse_position(pos_start_elem) ) return ClothoidSplineSegment( curvature_end=curvature_end, curvature_start=curvature_start, length=length, h_offset=h_offset, time_start=time_start, position_start=position_start, )The ClothoidSplineSegment class creates a segment of a clothoid spline.
Parameters
curvature_start: float Start curvature of the clothoid spline segment.unit:[1/m] curvature_end: float End curvature of the clothoid spline segment.unit:[1/m] length: float Length of the clothoid segment.unit: [m] h_offset: float Optional heading offset in radians of the clothoid segment relative to end of the previous segment or to position_start if present. Default is 0. time_start: float Optional time specification at the start of the clothoid segment.unit: [s] position_start: list of _PositionType optional starting position of a clothoid segment. If position_start is omitted for the first segment, the entity's current position is used. For subsequent segments, the end position of the previous segment is used. If only the heading is omitted, the heading of the previous segment's end position shall be used.
Attributes
curvature_start:float- Start curvature of the clothoid spline segment. unit: [1/m]
curvature_end:float- End curvature of the clothoid spline segment. unit: [1/m]
length:float- Length of the clothoid segment. unit: [m]
h_offset:float- Heading offset in radians of the clothoid segment relative to end of the previous segment or to position_start if present.
time_start:float- Time specification at the start of the clothoid segment. unit: [s]
position_start:_PositionType- Starting position of a clothoid segment.
Methods
parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element() Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class.
Initialize the ClothoidSplineSegment.
Parameters
curvature_start:float- Start curvature of the clothoid spline segment.unit:[1/m]
curvature_end:float- End curvature of the clothoid spline segment.unit:[1/m]
length:float- Length of the clothoid segment.unit: [m]
h_offset:float- Optional heading offset in radians of the clothoid segment relative to end of the previous segment or to position_start if present. Default is 0.
time_start:float- Optional time specification at the start of the clothoid segment.unit: [s]
position_start:listof_PositionType- optional starting position of a clothoid segment. If position_start is omitted for the first segment, the entity's current position is used. For subsequent segments, the end position of the previous segment is used. If only the heading is omitted, the heading of the previous segment's end position shall be used.
Ancestors
Static methods
def parse(element: xml.etree.ElementTree.Element) ‑> ClothoidSplineSegment-
Expand source code
@staticmethod def parse(element: ET.Element) -> "ClothoidSplineSegment": """Parse the XML element of ClothoidSplineSegment. Parameters ---------- element : xml.etree.ElementTree.Element A ClothoidSplineSegment element. Returns ------- ClothoidSplineSegment An instance of ClothoidSplineSegment. """ curvature_start = convert_float(element.attrib["curvatureStart"]) curvature_end = convert_float(element.attrib["curvatureEnd"]) length = convert_float(element.attrib["length"]) h_offset = convert_float(element.attrib.get("hOffset")) time_start = convert_float(element.attrib.get("timeStart")) position_start = [] pos_start_elem = element.find("PositionStart") if pos_start_elem is not None: position_start.append( _PositionFactory.parse_position(pos_start_elem) ) return ClothoidSplineSegment( curvature_end=curvature_end, curvature_start=curvature_start, length=length, h_offset=h_offset, time_start=time_start, position_start=position_start, )Parse the XML element of ClothoidSplineSegment.
Parameters
element:xml.etree.ElementTree.Element- A ClothoidSplineSegment element.
Returns
ClothoidSplineSegment- An instance of ClothoidSplineSegment.
Methods
def get_attributes(self) ‑> dict-
Expand source code
def get_attributes(self) -> dict: """Return the attributes of the ClothoidSplineSegment as a dictionary.""" attributes = { "curvatureStart": str(self.curvature_start), "curvatureEnd": str(self.curvature_end), "length": str(self.length), } if self.h_offset is not None: attributes["hOffset"] = str(self.h_offset) if self.time_start is not None: attributes["timeStart"] = str(self.time_start) return attributesReturn the attributes of the ClothoidSplineSegment as a dictionary.
def get_element(self) ‑> xml.etree.ElementTree.Element-
Expand source code
def get_element(self) -> ET.Element: """Return the ElementTree representation of the ClothoidSplineSegment.""" if self.isVersionEqLess(minor=2): raise OpenSCENARIOVersionError( "ClothoidSplineSegment was introduced in OpenSCENARIO V1.3" ) element = ET.Element( "ClothoidSplineSegment", attrib=self.get_attributes() ) if self.position_start: for position in self.position_start: element.append(position.get_element("PositionStart")) return elementReturn the ElementTree representation of the ClothoidSplineSegment.
class ControlPoint (position: scenariogeneration.xosc.utils._PositionType,
time: float | None = None,
weight: float | None = None)-
Expand source code
class ControlPoint(VersionBase): """The ControlPoint class is used by Nurbs to define points. Parameters ---------- position : _PositionType A position for the point. time : float, optional Optional time specification of the point. Default is None. weight : float, optional Optional weight of the point. Default is None. Attributes ---------- position : _PositionType A position for the point. time : float Optional time specification of the point. Default is None. weight : float Optional weight of the point. Default is None. Methods ------- parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element() Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class. """ def __init__( self, position: _PositionType, time: Optional[float] = None, weight: Optional[float] = None, ) -> None: """Initialize the ControlPoint. Parameters ---------- position : _PositionType A position for the point. time : float, optional Optional time specification of the point. Default is None. weight : float, optional Optional weight of the point. Default is None. """ if not isinstance(position, _PositionType): raise TypeError("position input is not a valid position") self.position = position self.time = convert_float(time) self.weight = convert_float(weight) def __eq__(self, other) -> bool: if isinstance(other, ControlPoint): if ( self.get_attributes() == other.get_attributes() and self.position == other.position ): return True return False @staticmethod def parse(element: ET.Element) -> "ControlPoint": """Parse the XML element of ControlPoint. Parameters ---------- element : xml.etree.ElementTree.Element A ControlPoint element (same as generated by the class itself). Returns ------- ControlPoint A ControlPoint object. """ time = None weight = None if "time" in element.attrib: time = convert_float(element.attrib["time"]) if "weight" in element.attrib: weight = convert_float(element.attrib["weight"]) pos_element = find_mandatory_field(element, "Position") position = _PositionFactory.parse_position(pos_element) return ControlPoint(position, time, weight) def get_attributes(self) -> dict: """Return the attributes of the ControlPoint as a dictionary. Returns ------- dict A dictionary containing the attributes of the ControlPoint. """ retdict = {} if self.time is not None: retdict["time"] = str(self.time) if self.weight is not None: retdict["weight"] = str(self.weight) return retdict def get_element(self) -> ET.Element: """Return the ElementTree of the ControlPoint. Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the ControlPoint. """ element = ET.Element("ControlPoint", attrib=self.get_attributes()) element.append(self.position.get_element()) return elementThe ControlPoint class is used by Nurbs to define points.
Parameters
position:_PositionType- A position for the point.
time:float, optional- Optional time specification of the point. Default is None.
weight:float, optional- Optional weight of the point. Default is None.
Attributes
position:_PositionType- A position for the point.
time:float- Optional time specification of the point. Default is None.
weight:float- Optional weight of the point. Default is None.
Methods
parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element() Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class.
Initialize the ControlPoint.
Parameters
position:_PositionType- A position for the point.
time:float, optional- Optional time specification of the point. Default is None.
weight:float, optional- Optional weight of the point. Default is None.
Ancestors
Static methods
def parse(element: xml.etree.ElementTree.Element) ‑> ControlPoint-
Expand source code
@staticmethod def parse(element: ET.Element) -> "ControlPoint": """Parse the XML element of ControlPoint. Parameters ---------- element : xml.etree.ElementTree.Element A ControlPoint element (same as generated by the class itself). Returns ------- ControlPoint A ControlPoint object. """ time = None weight = None if "time" in element.attrib: time = convert_float(element.attrib["time"]) if "weight" in element.attrib: weight = convert_float(element.attrib["weight"]) pos_element = find_mandatory_field(element, "Position") position = _PositionFactory.parse_position(pos_element) return ControlPoint(position, time, weight)Parse the XML element of ControlPoint.
Parameters
element:xml.etree.ElementTree.Element- A ControlPoint element (same as generated by the class itself).
Returns
ControlPoint- A ControlPoint object.
Methods
def get_attributes(self) ‑> dict-
Expand source code
def get_attributes(self) -> dict: """Return the attributes of the ControlPoint as a dictionary. Returns ------- dict A dictionary containing the attributes of the ControlPoint. """ retdict = {} if self.time is not None: retdict["time"] = str(self.time) if self.weight is not None: retdict["weight"] = str(self.weight) return retdictReturn the attributes of the ControlPoint as a dictionary.
Returns
dict- A dictionary containing the attributes of the ControlPoint.
def get_element(self) ‑> xml.etree.ElementTree.Element-
Expand source code
def get_element(self) -> ET.Element: """Return the ElementTree of the ControlPoint. Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the ControlPoint. """ element = ET.Element("ControlPoint", attrib=self.get_attributes()) element.append(self.position.get_element()) return elementReturn the ElementTree of the ControlPoint.
Returns
xml.etree.ElementTree.Element- The ElementTree representation of the ControlPoint.
class GeoPosition (latitude: float,
longitude: float,
height: float | None = None,
orientation: Orientation = <scenariogeneration.xosc.utils.Orientation object>,
vertical_road_selection: int = None)-
Expand source code
class GeoPosition(_PositionType): """GeoPosition creates a GeoPosition in OpenSCENARIO. Parameters ---------- latitue : float Latitude point on earth. longitude : float Longitude point on earth. height : float, optional Height above surface. Default is None. orientation : Orientation, optional Orientation of the entity. Default is Orientation(). vertical_road_selection : int, optional Specifies which road to choose at a given lat/lon when multiple roads overlap, with 0 for the top road and negative values for roads below. Default is 0. Attributes ---------- latitue : float Latitude point on earth. longitude : float Longitude point on earth. height : float Height above surface. Default is None. orientation : Orientation Orientation of the entity. vertical_road_selection : int Road selected at the given lat/lon when multiple roads overlap. Methods ------- parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element() Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class. """ def __init__( self, latitude: float, longitude: float, height: Optional[float] = None, orientation: Orientation = Orientation(), vertical_road_selection: int = None, ) -> None: """Initialize the GeoPosition class. Parameters ---------- latitue : float Latitude point on earth. longitude : float Longitude point on earth. height : float, optional Height above surface. Default is None. orientation : Orientation, optional Orientation of the entity. Default is Orientation(). vertical_road_selection : int, optional Specifies which road to choose at a given lat/lon when multiple roads overlap, with 0 for the top road and negative values for roads below. Default is 0. """ self.longitude = convert_float(longitude) self.latitude = convert_float(latitude) self.height = convert_float(height) if not isinstance(orientation, Orientation): raise TypeError("input orientation is not of type Orientation") self.orientation = orientation self.vertical_road_selection = convert_int(vertical_road_selection) def __eq__(self, other) -> bool: if isinstance(other, GeoPosition): if ( self.get_attributes() == other.get_attributes() and self.orientation == other.orientation ): return True return False @staticmethod def parse(element: ET.Element) -> "GeoPosition": """Parse the XML element of GeoPosition. Parameters ---------- element : xml.etree.ElementTree.Element A position element (same as generated by the class itself). Returns ------- GeoPosition A GeoPosition object. """ position_element = find_mandatory_field(element, "GeoPosition") if "longitude" in position_element.attrib: longitude = convert_float(position_element.attrib["longitude"]) elif "longitudeDeg" in position_element.attrib: longitude = convert_float(position_element.attrib["longitudeDeg"]) else: raise KeyError("Cannot find valid longitude for GeoPosition") if "latitude" in position_element.attrib: latitude = convert_float(position_element.attrib["latitude"]) elif "latitudeDeg" in position_element.attrib: latitude = convert_float(position_element.attrib["latitudeDeg"]) else: raise KeyError("Cannot find valid latitude for GeoPosition") if "height" in position_element.attrib: height = convert_float(position_element.attrib["height"]) elif "altitude" in position_element.attrib: height = convert_float(position_element.attrib["altitude"]) else: height = None vertical_road_selection = None if "verticalRoadSelection" in position_element.attrib: vertical_road_selection = convert_int( position_element.attrib["verticalRoadSelection"] ) if position_element.find("Orientation") is not None: orientation = Orientation.parse( find_mandatory_field(position_element, "Orientation") ) else: orientation = Orientation() return GeoPosition( latitude, longitude, height, orientation, vertical_road_selection ) def get_attributes(self) -> dict: """Return the attributes of the GeoPosition as a dictionary. Returns ------- dict A dictionary containing the attributes of the GeoPosition. """ retdict = {} if self.isVersion(minor=1): retdict["longitude"] = str(self.longitude) retdict["latitude"] = str(self.latitude) if self.height is not None: retdict["height"] = str(self.height) else: retdict["longitudeDeg"] = str(self.longitude) retdict["latitudeDeg"] = str(self.latitude) if self.height is not None: retdict["altitude"] = str(self.height) if self.isVersionEqLarger(minor=3): if self.vertical_road_selection is not None: retdict["verticalRoadSelection"] = str( self.vertical_road_selection ) return retdict def get_element(self, elementname: str = "Position") -> ET.Element: """Return the ElementTree of the GeoPosition. Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the GeoPosition. """ if self.isVersion(minor=0): raise OpenSCENARIOVersionError( "GeoPosition was introduced in OpenSCENARIO V1.1" ) element = ET.Element(elementname) traj_element = ET.SubElement( element, "GeoPosition", self.get_attributes() ) traj_element.append(self.orientation.get_element()) return elementGeoPosition creates a GeoPosition in OpenSCENARIO.
Parameters
latitue:float- Latitude point on earth.
longitude:float- Longitude point on earth.
height:float, optional- Height above surface. Default is None.
orientation:Orientation, optional- Orientation of the entity. Default is Orientation().
vertical_road_selection:int, optional- Specifies which road to choose at a given lat/lon when multiple roads overlap, with 0 for the top road and negative values for roads below. Default is 0.
Attributes
latitue:float- Latitude point on earth.
longitude:float- Longitude point on earth.
height:float- Height above surface. Default is None.
orientation:Orientation- Orientation of the entity.
vertical_road_selection:int
Road selected at the given lat/lon when multiple roads overlap.
Methods
parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element() Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class.
Initialize the GeoPosition class.
Parameters
latitue:float- Latitude point on earth.
longitude:float- Longitude point on earth.
height:float, optional- Height above surface. Default is None.
orientation:Orientation, optional- Orientation of the entity. Default is Orientation().
vertical_road_selection:int, optional- Specifies which road to choose at a given lat/lon when multiple roads overlap, with 0 for the top road and negative values for roads below. Default is 0.
Ancestors
- scenariogeneration.xosc.utils._PositionType
- VersionBase
Static methods
def parse(element: xml.etree.ElementTree.Element) ‑> GeoPosition-
Expand source code
@staticmethod def parse(element: ET.Element) -> "GeoPosition": """Parse the XML element of GeoPosition. Parameters ---------- element : xml.etree.ElementTree.Element A position element (same as generated by the class itself). Returns ------- GeoPosition A GeoPosition object. """ position_element = find_mandatory_field(element, "GeoPosition") if "longitude" in position_element.attrib: longitude = convert_float(position_element.attrib["longitude"]) elif "longitudeDeg" in position_element.attrib: longitude = convert_float(position_element.attrib["longitudeDeg"]) else: raise KeyError("Cannot find valid longitude for GeoPosition") if "latitude" in position_element.attrib: latitude = convert_float(position_element.attrib["latitude"]) elif "latitudeDeg" in position_element.attrib: latitude = convert_float(position_element.attrib["latitudeDeg"]) else: raise KeyError("Cannot find valid latitude for GeoPosition") if "height" in position_element.attrib: height = convert_float(position_element.attrib["height"]) elif "altitude" in position_element.attrib: height = convert_float(position_element.attrib["altitude"]) else: height = None vertical_road_selection = None if "verticalRoadSelection" in position_element.attrib: vertical_road_selection = convert_int( position_element.attrib["verticalRoadSelection"] ) if position_element.find("Orientation") is not None: orientation = Orientation.parse( find_mandatory_field(position_element, "Orientation") ) else: orientation = Orientation() return GeoPosition( latitude, longitude, height, orientation, vertical_road_selection )Parse the XML element of GeoPosition.
Parameters
element:xml.etree.ElementTree.Element- A position element (same as generated by the class itself).
Returns
GeoPosition- A GeoPosition object.
Methods
def get_attributes(self) ‑> dict-
Expand source code
def get_attributes(self) -> dict: """Return the attributes of the GeoPosition as a dictionary. Returns ------- dict A dictionary containing the attributes of the GeoPosition. """ retdict = {} if self.isVersion(minor=1): retdict["longitude"] = str(self.longitude) retdict["latitude"] = str(self.latitude) if self.height is not None: retdict["height"] = str(self.height) else: retdict["longitudeDeg"] = str(self.longitude) retdict["latitudeDeg"] = str(self.latitude) if self.height is not None: retdict["altitude"] = str(self.height) if self.isVersionEqLarger(minor=3): if self.vertical_road_selection is not None: retdict["verticalRoadSelection"] = str( self.vertical_road_selection ) return retdictReturn the attributes of the GeoPosition as a dictionary.
Returns
dict- A dictionary containing the attributes of the GeoPosition.
def get_element(self, elementname: str = 'Position') ‑> xml.etree.ElementTree.Element-
Expand source code
def get_element(self, elementname: str = "Position") -> ET.Element: """Return the ElementTree of the GeoPosition. Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the GeoPosition. """ if self.isVersion(minor=0): raise OpenSCENARIOVersionError( "GeoPosition was introduced in OpenSCENARIO V1.1" ) element = ET.Element(elementname) traj_element = ET.SubElement( element, "GeoPosition", self.get_attributes() ) traj_element.append(self.orientation.get_element()) return elementReturn the ElementTree of the GeoPosition.
Returns
xml.etree.ElementTree.Element- The ElementTree representation of the GeoPosition.
class LanePosition (s: float,
offset: float,
lane_id: str,
road_id: str,
orientation: Orientation = <scenariogeneration.xosc.utils.Orientation object>)-
Expand source code
class LanePosition(_PositionType): """The LanePosition creates a LanePosition in OpenScenario. Parameters ---------- s : float Length along the road. offset : float Offset from the center of the lane. lane_id : str Lane of the road. road_id : str ID of the road. orientation : Orientation, optional The angular orientation of the entity. Default is Orientation(). Attributes ---------- s : float Length along the road. offset : float Offset from the center of the lane. lane_id : str Lane of the road. road_id : str ID of the road. orient : Orientation The angular orientation of the entity. Methods ------- parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element(elementname) Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class. """ def __init__( self, s: float, offset: float, lane_id: str, road_id: str, orientation: Orientation = Orientation(), ) -> None: """Initialize the LanePosition. Parameters ---------- s : float Length along the road. offset : float Offset from the center of the lane. lane_id : str Lane of the road. road_id : str ID of the road. orientation : Orientation, optional The angular orientation of the entity. Default is Orientation(). """ self.s = convert_float(s) self.lane_id = lane_id self.offset = convert_float(offset) self.road_id = road_id if not isinstance(orientation, Orientation): raise TypeError("input orientation is not of type Orientation") self.orient = orientation def __eq__(self, other) -> bool: if isinstance(other, LanePosition): if ( self.get_attributes() == other.get_attributes() and self.orient == other.orient ): return True return False @staticmethod def parse(element: ET.Element) -> "LanePosition": """Parse the XML element of LanePosition. Parameters ---------- element : xml.etree.ElementTree.Element A position element (same as generated by the class itself). Returns ------- LanePosition A LanePosition object. """ position_element = find_mandatory_field(element, "LanePosition") roadId = position_element.attrib["roadId"] s = convert_float(position_element.attrib["s"]) offset = convert_float(position_element.attrib["offset"]) laneid = position_element.attrib["laneId"] if position_element.find("Orientation") is not None: orientation = Orientation.parse( find_mandatory_field(position_element, "Orientation") ) else: orientation = Orientation() return LanePosition(s, offset, laneid, roadId, orientation) def get_attributes(self) -> dict: """Return the attributes of the LanePosition as a dictionary. Returns ------- dict A dictionary containing the attributes of the LanePosition. """ retdict = {} retdict["roadId"] = str(self.road_id) retdict["laneId"] = str(self.lane_id) retdict["s"] = str(self.s) retdict["offset"] = str(self.offset) return retdict def get_element(self, elementname: str = "Position") -> ET.Element: """Return the ElementTree of the LanePosition. Parameters ---------- elementname : str, optional Used if another name is needed for the position. Default is "Position". Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the LanePosition. """ element = ET.Element(elementname) lanepos = ET.SubElement( element, "LanePosition", attrib=self.get_attributes() ) if self.orient.is_filled(): lanepos.append(self.orient.get_element()) return elementThe LanePosition creates a LanePosition in OpenScenario.
Parameters
s:float- Length along the road.
offset:float- Offset from the center of the lane.
lane_id:str- Lane of the road.
road_id:str- ID of the road.
orientation:Orientation, optional- The angular orientation of the entity. Default is Orientation().
Attributes
s:float- Length along the road.
offset:float- Offset from the center of the lane.
lane_id:str- Lane of the road.
road_id:str- ID of the road.
orient:Orientation- The angular orientation of the entity.
Methods
parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element(elementname) Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class.
Initialize the LanePosition.
Parameters
s:float- Length along the road.
offset:float- Offset from the center of the lane.
lane_id:str- Lane of the road.
road_id:str- ID of the road.
orientation:Orientation, optional- The angular orientation of the entity. Default is Orientation().
Ancestors
- scenariogeneration.xosc.utils._PositionType
- VersionBase
Static methods
def parse(element: xml.etree.ElementTree.Element) ‑> LanePosition-
Expand source code
@staticmethod def parse(element: ET.Element) -> "LanePosition": """Parse the XML element of LanePosition. Parameters ---------- element : xml.etree.ElementTree.Element A position element (same as generated by the class itself). Returns ------- LanePosition A LanePosition object. """ position_element = find_mandatory_field(element, "LanePosition") roadId = position_element.attrib["roadId"] s = convert_float(position_element.attrib["s"]) offset = convert_float(position_element.attrib["offset"]) laneid = position_element.attrib["laneId"] if position_element.find("Orientation") is not None: orientation = Orientation.parse( find_mandatory_field(position_element, "Orientation") ) else: orientation = Orientation() return LanePosition(s, offset, laneid, roadId, orientation)Parse the XML element of LanePosition.
Parameters
element:xml.etree.ElementTree.Element- A position element (same as generated by the class itself).
Returns
LanePosition- A LanePosition object.
Methods
def get_attributes(self) ‑> dict-
Expand source code
def get_attributes(self) -> dict: """Return the attributes of the LanePosition as a dictionary. Returns ------- dict A dictionary containing the attributes of the LanePosition. """ retdict = {} retdict["roadId"] = str(self.road_id) retdict["laneId"] = str(self.lane_id) retdict["s"] = str(self.s) retdict["offset"] = str(self.offset) return retdictReturn the attributes of the LanePosition as a dictionary.
Returns
dict- A dictionary containing the attributes of the LanePosition.
def get_element(self, elementname: str = 'Position') ‑> xml.etree.ElementTree.Element-
Expand source code
def get_element(self, elementname: str = "Position") -> ET.Element: """Return the ElementTree of the LanePosition. Parameters ---------- elementname : str, optional Used if another name is needed for the position. Default is "Position". Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the LanePosition. """ element = ET.Element(elementname) lanepos = ET.SubElement( element, "LanePosition", attrib=self.get_attributes() ) if self.orient.is_filled(): lanepos.append(self.orient.get_element()) return elementReturn the ElementTree of the LanePosition.
Parameters
elementname:str, optional- Used if another name is needed for the position. Default is "Position".
Returns
xml.etree.ElementTree.Element- The ElementTree representation of the LanePosition.
class Nurbs (order: int)-
Expand source code
class Nurbs(_TrajectoryShape): """The Nurbs class creates a Nurbs shape. Parameters ---------- order : int Order of the nurbs. Attributes ---------- order : int Order of the nurbs. controlpoints : list of ControlPoint A list of control points creating the nurbs. knots : list of float Knots of the nurbs (must be order + len(controlpoints)) in descending order. Methods ------- parse(element) Parses an ElementTree created by the class and returns an instance of the class. add_knots(knots) Adds the knots to the nurbs. add_control_point(controlpoint) Adds a control point to the nurbs. get_element() Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class. """ def __init__(self, order: int) -> None: """Initialize the Nurbs. Parameters ---------- order : int Order of the nurbs. """ self.order = convert_int(order) self.controlpoints = [] self.knots = [] def __eq__(self, other) -> bool: if isinstance(other, Nurbs): if ( self.get_attributes() == other.get_attributes() and self.controlpoints == other.controlpoints and self.knots == other.knots ): return True return False @staticmethod def parse(element: ET.Element) -> "Nurbs": """Parse the XML element of Nurbs. Parameters ---------- element : xml.etree.ElementTree.Element A Nurbs element (same as generated by the class itself). Returns ------- Nurbs A Nurbs object. """ nurbs_element = find_mandatory_field(element, "Nurbs") order = convert_int(nurbs_element.attrib["order"]) # print(pos_element) # position = _PositionFactory.parse_position(pos_element) nurbs = Nurbs(order) control_point_elements = nurbs_element.findall("ControlPoint") for cp in control_point_elements: nurbs.add_control_point(ControlPoint.parse(cp)) knots_elements = nurbs_element.findall("Knot") knots = [] for k in knots_elements: print(k) knots.append(convert_float(k.attrib["value"])) nurbs.add_knots(knots) return nurbs def add_knots(self, knots: list[float]) -> "Nurbs": """Add a list of knots to the Nurbs. Parameters ---------- knots : list of float Knots of the nurbs (must be order + len(controlpoints)) in descending order. """ self.knots = knots return self def add_control_point(self, controlpoint: ControlPoint) -> "Nurbs": """Add a control point to the Nurbs. Parameters ---------- controlpoint : ControlPoint A contact point to add to the nurbs. """ if not isinstance(controlpoint, ControlPoint): raise TypeError("controlpoint input is not of type ControlPoint") self.controlpoints.append(controlpoint) return self def get_attributes(self) -> dict: """Return the attributes of the Nurbs as a dictionary. Returns ------- dict A dictionary containing the attributes of the Nurbs. """ retdict = {} retdict["order"] = str(self.order) return retdict def get_element(self) -> ET.Element: """Return the ElementTree of the Nurbs. Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the Nurbs. """ shape = ET.Element("Shape") element = ET.SubElement(shape, "Nurbs", attrib=self.get_attributes()) if (len(self.controlpoints) + self.order) != len(self.knots): raise ValueError( "Number of knots is not equal to the number of contactpoints + order" ) for c in self.controlpoints: element.append(c.get_element()) for k in self.knots: ET.SubElement(element, "Knot", attrib={"value": str(k)}) return shapeThe Nurbs class creates a Nurbs shape.
Parameters
order:int- Order of the nurbs.
Attributes
order:int- Order of the nurbs.
controlpoints:listofControlPoint- A list of control points creating the nurbs.
knots:listoffloat- Knots of the nurbs (must be order + len(controlpoints)) in descending order.
Methods
parse(element) Parses an ElementTree created by the class and returns an instance of the class. add_knots(knots) Adds the knots to the nurbs. add_control_point(controlpoint) Adds a control point to the nurbs. get_element() Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class.
Initialize the Nurbs.
Parameters
order:int- Order of the nurbs.
Ancestors
- scenariogeneration.xosc.position._TrajectoryShape
- VersionBase
Static methods
def parse(element: xml.etree.ElementTree.Element) ‑> Nurbs-
Expand source code
@staticmethod def parse(element: ET.Element) -> "Nurbs": """Parse the XML element of Nurbs. Parameters ---------- element : xml.etree.ElementTree.Element A Nurbs element (same as generated by the class itself). Returns ------- Nurbs A Nurbs object. """ nurbs_element = find_mandatory_field(element, "Nurbs") order = convert_int(nurbs_element.attrib["order"]) # print(pos_element) # position = _PositionFactory.parse_position(pos_element) nurbs = Nurbs(order) control_point_elements = nurbs_element.findall("ControlPoint") for cp in control_point_elements: nurbs.add_control_point(ControlPoint.parse(cp)) knots_elements = nurbs_element.findall("Knot") knots = [] for k in knots_elements: print(k) knots.append(convert_float(k.attrib["value"])) nurbs.add_knots(knots) return nurbsParse the XML element of Nurbs.
Parameters
element:xml.etree.ElementTree.Element- A Nurbs element (same as generated by the class itself).
Returns
Nurbs- A Nurbs object.
Methods
def add_control_point(self,
controlpoint: ControlPoint) ‑> Nurbs-
Expand source code
def add_control_point(self, controlpoint: ControlPoint) -> "Nurbs": """Add a control point to the Nurbs. Parameters ---------- controlpoint : ControlPoint A contact point to add to the nurbs. """ if not isinstance(controlpoint, ControlPoint): raise TypeError("controlpoint input is not of type ControlPoint") self.controlpoints.append(controlpoint) return selfAdd a control point to the Nurbs.
Parameters
controlpoint:ControlPoint- A contact point to add to the nurbs.
def add_knots(self, knots: list[float]) ‑> Nurbs-
Expand source code
def add_knots(self, knots: list[float]) -> "Nurbs": """Add a list of knots to the Nurbs. Parameters ---------- knots : list of float Knots of the nurbs (must be order + len(controlpoints)) in descending order. """ self.knots = knots return selfAdd a list of knots to the Nurbs.
Parameters
knots:listoffloat- Knots of the nurbs (must be order + len(controlpoints)) in descending order.
def get_attributes(self) ‑> dict-
Expand source code
def get_attributes(self) -> dict: """Return the attributes of the Nurbs as a dictionary. Returns ------- dict A dictionary containing the attributes of the Nurbs. """ retdict = {} retdict["order"] = str(self.order) return retdictReturn the attributes of the Nurbs as a dictionary.
Returns
dict- A dictionary containing the attributes of the Nurbs.
def get_element(self) ‑> xml.etree.ElementTree.Element-
Expand source code
def get_element(self) -> ET.Element: """Return the ElementTree of the Nurbs. Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the Nurbs. """ shape = ET.Element("Shape") element = ET.SubElement(shape, "Nurbs", attrib=self.get_attributes()) if (len(self.controlpoints) + self.order) != len(self.knots): raise ValueError( "Number of knots is not equal to the number of contactpoints + order" ) for c in self.controlpoints: element.append(c.get_element()) for k in self.knots: ET.SubElement(element, "Knot", attrib={"value": str(k)}) return shapeReturn the ElementTree of the Nurbs.
Returns
xml.etree.ElementTree.Element- The ElementTree representation of the Nurbs.
class Polygon (positions: list[scenariogeneration.xosc.utils._PositionType])-
Expand source code
class Polygon(VersionBase): """The Polygon class creates a polygon used by the TrafficArea class. Parameters ---------- positions : list of Position A list of positions that define the polygon. Attributes ---------- positions : list of Position A list of positions that define the polygon. """ def __init__(self, positions: list[_PositionType]) -> None: if len(positions) < 3: raise ValueError("Polygon must have at least 3 positions") if not isinstance(positions, list) or not all( isinstance(p, _PositionType) for p in positions ): raise TypeError( "positions input is not a list of PositionType objects" ) if positions: first_type = type(positions[0]) if not all(isinstance(p, first_type) for p in positions): raise TypeError( "All positions in Polygon must be of the same type" ) self.positions = positions def __eq__(self, other: object) -> bool: return isinstance(other, Polygon) and self.positions == other.positions @staticmethod def parse(element: ET.Element) -> "Polygon": """Parses the XML element of Polygon. Parameters ---------- element : ET.Element A polygon element (same as generated by the class itself). Returns ------- Polygon A Polygon object. """ positions = [] for pos_element in element.findall("Position"): position = _PositionFactory.parse_position(pos_element) positions.append(position) return Polygon(positions) def get_element(self) -> ET.Element: """Returns the ElementTree of the Polygon. Returns ------- ET.Element The ElementTree representation of the Polygon. """ if not self.isVersionEqLarger(minor=3): raise OpenSCENARIOVersionError( "Polygon was introduced in OpenSCENARIO V1.3" ) element = ET.Element("Polygon") for pos in self.positions: element.append(pos.get_element()) return elementThe Polygon class creates a polygon used by the TrafficArea class.
Parameters
positions:listofPosition- A list of positions that define the polygon.
Attributes
positions:listofPosition- A list of positions that define the polygon.
Ancestors
Static methods
def parse(element: xml.etree.ElementTree.Element) ‑> Polygon-
Expand source code
@staticmethod def parse(element: ET.Element) -> "Polygon": """Parses the XML element of Polygon. Parameters ---------- element : ET.Element A polygon element (same as generated by the class itself). Returns ------- Polygon A Polygon object. """ positions = [] for pos_element in element.findall("Position"): position = _PositionFactory.parse_position(pos_element) positions.append(position) return Polygon(positions)Parses the XML element of Polygon.
Parameters
element:ET.Element- A polygon element (same as generated by the class itself).
Returns
Polygon- A Polygon object.
Methods
def get_element(self) ‑> xml.etree.ElementTree.Element-
Expand source code
def get_element(self) -> ET.Element: """Returns the ElementTree of the Polygon. Returns ------- ET.Element The ElementTree representation of the Polygon. """ if not self.isVersionEqLarger(minor=3): raise OpenSCENARIOVersionError( "Polygon was introduced in OpenSCENARIO V1.3" ) element = ET.Element("Polygon") for pos in self.positions: element.append(pos.get_element()) return elementReturns the ElementTree of the Polygon.
Returns
ET.Element- The ElementTree representation of the Polygon.
class Polyline (time: list[float],
positions: list[scenariogeneration.xosc.utils._PositionType])-
Expand source code
class Polyline(_TrajectoryShape): """The Polyline class creates a polyline of (minimum 2) positions. Parameters ---------- time : list of float A list of timings for the positions. positions : list of _PositionType List of positions to create the polyline. Attributes ---------- time : list of float A list of timings for the positions. positions : list of _PositionType List of positions to create the polyline. Methods ------- parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element() Returns the full ElementTree of the class. """ def __init__( self, time: list[float], positions: list[_PositionType] ) -> None: """Initialize the Polyline. Parameters ---------- time : list of float A list of timings for the positions (as of OpenSCENARIO V1.1 this can be empty). positions : list of _PositionType List of positions to create the polyline. """ if time and len(time) < 2: raise ValueError("not enough time inputs") if len(positions) < 2: raise ValueError("not enough position inputs") if time and (len(time) != len(positions)): raise ValueError("time and positions are not the same length") for p in positions: if not isinstance(p, _PositionType): raise TypeError("position input is not a valid position") self.positions = positions self.time = [convert_float(x) for x in time] def __eq__(self, other) -> bool: if isinstance(other, Polyline): if self.time == other.time and self.positions == other.positions: return True return False @staticmethod def parse(element: ET.Element) -> "Polyline": """Parse the XML element of Polyline. Parameters ---------- element : xml.etree.ElementTree.Element A Polyline element (same as generated by the class itself). Returns ------- Polyline A Polyline object. """ polyline_element = find_mandatory_field(element, "Polyline") vertexes = polyline_element.findall("Vertex") time_list = [] position_list = [] for vertex in vertexes: if "time" in vertex.attrib: time_list.append(convert_float(vertex.attrib["time"])) position_list.append( _PositionFactory.parse_position( find_mandatory_field(vertex, "Position") ) ) return Polyline(time_list, position_list) def get_element(self) -> ET.Element: """Return the ElementTree of the Polyline. Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the Polyline. """ shape = ET.Element("Shape") element = ET.SubElement(shape, ("Polyline")) for i, pos in enumerate(self.positions): time_dict = {} if self.time: time_dict = {"time": str(self.time[i])} vert = ET.SubElement(element, "Vertex", attrib=time_dict) vert.append(pos.get_element()) return shapeThe Polyline class creates a polyline of (minimum 2) positions.
Parameters
time:listoffloat- A list of timings for the positions.
positions:listof_PositionType- List of positions to create the polyline.
Attributes
time:listoffloat- A list of timings for the positions.
positions:listof_PositionType- List of positions to create the polyline.
Methods
parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element() Returns the full ElementTree of the class.
Initialize the Polyline.
Parameters
time:listoffloat- A list of timings for the positions (as of OpenSCENARIO V1.1 this can be empty).
positions:listof_PositionType- List of positions to create the polyline.
Ancestors
- scenariogeneration.xosc.position._TrajectoryShape
- VersionBase
Static methods
def parse(element: xml.etree.ElementTree.Element) ‑> Polyline-
Expand source code
@staticmethod def parse(element: ET.Element) -> "Polyline": """Parse the XML element of Polyline. Parameters ---------- element : xml.etree.ElementTree.Element A Polyline element (same as generated by the class itself). Returns ------- Polyline A Polyline object. """ polyline_element = find_mandatory_field(element, "Polyline") vertexes = polyline_element.findall("Vertex") time_list = [] position_list = [] for vertex in vertexes: if "time" in vertex.attrib: time_list.append(convert_float(vertex.attrib["time"])) position_list.append( _PositionFactory.parse_position( find_mandatory_field(vertex, "Position") ) ) return Polyline(time_list, position_list)Parse the XML element of Polyline.
Parameters
element:xml.etree.ElementTree.Element- A Polyline element (same as generated by the class itself).
Returns
Polyline- A Polyline object.
Methods
def get_element(self) ‑> xml.etree.ElementTree.Element-
Expand source code
def get_element(self) -> ET.Element: """Return the ElementTree of the Polyline. Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the Polyline. """ shape = ET.Element("Shape") element = ET.SubElement(shape, ("Polyline")) for i, pos in enumerate(self.positions): time_dict = {} if self.time: time_dict = {"time": str(self.time[i])} vert = ET.SubElement(element, "Vertex", attrib=time_dict) vert.append(pos.get_element()) return shapeReturn the ElementTree of the Polyline.
Returns
xml.etree.ElementTree.Element- The ElementTree representation of the Polyline.
class RelativeLanePosition (lane_id: int,
entity: str,
offset: float = 0,
ds: float | None = None,
dsLane: float | None = None,
orientation: Orientation = <scenariogeneration.xosc.utils.Orientation object>)-
Expand source code
class RelativeLanePosition(_PositionType): """The RelativeLanePosition creates a RelativeLanePosition in OpenScenario. Parameters ---------- lane_id : int Lane of the road. entity : str ID of the entity. offset : float, optional Offset from the center of the lane. Default is 0. ds : float, optional Length along the road (use this or dsLane). Default is None. dsLane : float, optional Relative offset along the lane (valid from V1.1) (use this or ds). Default is None. orientation : Orientation, optional The angular orientation of the entity. Default is Orientation(). Attributes ---------- ds : float Length along the road. dsLane : float Relative offset along the lane (valid from V1.1). offset : float Offset from the center of the lane. road_id : str ID of the road. lane_id : int Lane of the road. orient : Orientation The angular orientation of the entity. Methods ------- parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element(elementname) Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class. """ def __init__( self, lane_id: int, entity: str, offset: float = 0, ds: Optional[float] = None, dsLane: Optional[float] = None, orientation: Orientation = Orientation(), ) -> None: """Initialize the RelativeLanePosition. Parameters ---------- lane_id : int Lane of the road. entity : str ID of the entity. offset : float, optional Offset from the center of the lane. Default is 0. ds : float, optional Length along the road (use this or dsLane). Default is None. dsLane : float, optional Relative offset along the lane (valid from V1.1) (use this or ds). Default is None. orientation : Orientation, optional The angular orientation of the entity. Default is Orientation(). """ if ds is not None and dsLane is not None: raise ToManyOptionalArguments( "Not both of ds and dsLane can be used." ) if ds is None and dsLane is None: raise NotEnoughInputArguments( "Either ds or dsLane is needed as input." ) self.ds = convert_float(ds) self.dsLane = convert_float(dsLane) self.lane_id = convert_int(lane_id) self.offset = convert_float(offset) self.entity = entity if not isinstance(orientation, Orientation): raise TypeError("input orientation is not of type Orientation") self.orient = orientation def __eq__(self, other) -> bool: if isinstance(other, RelativeLanePosition): if ( self.get_attributes() == other.get_attributes() and self.orient == other.orient ): return True return False @staticmethod def parse(element: ET.Element) -> "RelativeLanePosition": """Parse the XML element of RelativeLanePosition. Parameters ---------- element : xml.etree.ElementTree.Element A position element (same as generated by the class itself). Returns ------- RelativeLanePosition A RelativeLanePosition object. """ position_element = find_mandatory_field( element, "RelativeLanePosition" ) ds = None dslane = None if "ds" in position_element.attrib: ds = convert_float(position_element.attrib["ds"]) offset = convert_float(position_element.attrib["offset"]) if "dsLane" in position_element.attrib: dslane = convert_float(position_element.attrib["dsLane"]) dLane = convert_int(position_element.attrib["dLane"]) entityref = position_element.attrib["entityRef"] if position_element.find("Orientation") is not None: orientation = Orientation.parse( find_mandatory_field(position_element, "Orientation") ) else: orientation = Orientation() return RelativeLanePosition( dLane, entityref, offset, ds, dslane, orientation ) def get_attributes(self) -> dict: """Return the attributes of the RelativeLanePosition as a dictionary. Returns ------- dict A dictionary containing the attributes of the RelativeLanePosition. """ retdict = {} retdict["entityRef"] = self.entity if self.ds is not None: retdict["ds"] = str(self.ds) if self.dsLane is not None and not self.isVersion(minor=0): retdict["dsLane"] = str(self.dsLane) elif self.dsLane is not None and self.isVersion(minor=0): raise OpenSCENARIOVersionError( "dsLane was introduced in OpenSCENARIO V1.1, not in 1.0" ) retdict["offset"] = str(self.offset) retdict["dLane"] = str(self.lane_id) return retdict def get_element(self, elementname: str = "Position") -> ET.Element: """Return the ElementTree of the RelativeLanePosition. Parameters ---------- elementname : str, optional Used if another name is needed for the position. Default is "Position". Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the RelativeLanePosition. """ element = ET.Element(elementname) lanepos = ET.SubElement( element, "RelativeLanePosition", attrib=self.get_attributes() ) if self.orient.is_filled(): lanepos.append(self.orient.get_element()) return elementThe RelativeLanePosition creates a RelativeLanePosition in OpenScenario.
Parameters
lane_id:int- Lane of the road.
entity:str- ID of the entity.
offset:float, optional- Offset from the center of the lane. Default is 0.
ds:float, optional- Length along the road (use this or dsLane). Default is None.
dsLane:float, optional- Relative offset along the lane (valid from V1.1) (use this or ds). Default is None.
orientation:Orientation, optional- The angular orientation of the entity. Default is Orientation().
Attributes
ds:float- Length along the road.
dsLane:float- Relative offset along the lane (valid from V1.1).
offset:float- Offset from the center of the lane.
road_id:str- ID of the road.
lane_id:int- Lane of the road.
orient:Orientation- The angular orientation of the entity.
Methods
parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element(elementname) Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class.
Initialize the RelativeLanePosition.
Parameters
lane_id:int- Lane of the road.
entity:str- ID of the entity.
offset:float, optional- Offset from the center of the lane. Default is 0.
ds:float, optional- Length along the road (use this or dsLane). Default is None.
dsLane:float, optional- Relative offset along the lane (valid from V1.1) (use this or ds). Default is None.
orientation:Orientation, optional- The angular orientation of the entity. Default is Orientation().
Ancestors
- scenariogeneration.xosc.utils._PositionType
- VersionBase
Static methods
def parse(element: xml.etree.ElementTree.Element) ‑> RelativeLanePosition-
Expand source code
@staticmethod def parse(element: ET.Element) -> "RelativeLanePosition": """Parse the XML element of RelativeLanePosition. Parameters ---------- element : xml.etree.ElementTree.Element A position element (same as generated by the class itself). Returns ------- RelativeLanePosition A RelativeLanePosition object. """ position_element = find_mandatory_field( element, "RelativeLanePosition" ) ds = None dslane = None if "ds" in position_element.attrib: ds = convert_float(position_element.attrib["ds"]) offset = convert_float(position_element.attrib["offset"]) if "dsLane" in position_element.attrib: dslane = convert_float(position_element.attrib["dsLane"]) dLane = convert_int(position_element.attrib["dLane"]) entityref = position_element.attrib["entityRef"] if position_element.find("Orientation") is not None: orientation = Orientation.parse( find_mandatory_field(position_element, "Orientation") ) else: orientation = Orientation() return RelativeLanePosition( dLane, entityref, offset, ds, dslane, orientation )Parse the XML element of RelativeLanePosition.
Parameters
element:xml.etree.ElementTree.Element- A position element (same as generated by the class itself).
Returns
RelativeLanePosition- A RelativeLanePosition object.
Methods
def get_attributes(self) ‑> dict-
Expand source code
def get_attributes(self) -> dict: """Return the attributes of the RelativeLanePosition as a dictionary. Returns ------- dict A dictionary containing the attributes of the RelativeLanePosition. """ retdict = {} retdict["entityRef"] = self.entity if self.ds is not None: retdict["ds"] = str(self.ds) if self.dsLane is not None and not self.isVersion(minor=0): retdict["dsLane"] = str(self.dsLane) elif self.dsLane is not None and self.isVersion(minor=0): raise OpenSCENARIOVersionError( "dsLane was introduced in OpenSCENARIO V1.1, not in 1.0" ) retdict["offset"] = str(self.offset) retdict["dLane"] = str(self.lane_id) return retdictReturn the attributes of the RelativeLanePosition as a dictionary.
Returns
dict- A dictionary containing the attributes of the RelativeLanePosition.
def get_element(self, elementname: str = 'Position') ‑> xml.etree.ElementTree.Element-
Expand source code
def get_element(self, elementname: str = "Position") -> ET.Element: """Return the ElementTree of the RelativeLanePosition. Parameters ---------- elementname : str, optional Used if another name is needed for the position. Default is "Position". Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the RelativeLanePosition. """ element = ET.Element(elementname) lanepos = ET.SubElement( element, "RelativeLanePosition", attrib=self.get_attributes() ) if self.orient.is_filled(): lanepos.append(self.orient.get_element()) return elementReturn the ElementTree of the RelativeLanePosition.
Parameters
elementname:str, optional- Used if another name is needed for the position. Default is "Position".
Returns
xml.etree.ElementTree.Element- The ElementTree representation of the RelativeLanePosition.
class RelativeObjectPosition (entity: str,
dx: float,
dy: float,
dz: float | None = None,
orientation: Orientation = <scenariogeneration.xosc.utils.Orientation object>)-
Expand source code
class RelativeObjectPosition(_PositionType): """The RelativeObjectPosition creates a RelativePosition with the option of object as reference. Parameters ---------- entity : str The entity to be relative to. dx : float Relative x-coordinate. dy : float Relative y-coordinate. dz : float, optional Relative z-coordinate. Default is None. orientation : Orientation, optional The angular orientation of the entity. Default is Orientation(). Attributes ---------- target : str The entity to be relative to. dx : float Relative x-coordinate. dy : float Relative y-coordinate. dz : float Relative z-coordinate. orient : Orientation The angular orientation of the entity. Methods ------- parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element(elementname) Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class. """ def __init__( self, entity: str, dx: float, dy: float, dz: Optional[float] = None, orientation: Orientation = Orientation(), ) -> None: """Initialize the RelativeObjectPosition. Parameters ---------- entity : str The entity to be relative to. dx : float Relative x-coordinate. dy : float Relative y-coordinate. dz : float, optional Relative z-coordinate. Default is None. orientation : Orientation, optional The angular orientation of the entity. Default is Orientation(). """ self.target = entity self.dx = convert_float(dx) self.dy = convert_float(dy) self.dz = convert_float(dz) if not isinstance(orientation, Orientation): raise TypeError("input orientation is not of type Orientation") self.orient = orientation def __eq__(self, other) -> bool: if isinstance(other, RelativeObjectPosition): if ( self.get_attributes() == other.get_attributes() and self.orient == other.orient ): return True return False @staticmethod def parse(element: ET.Element) -> "RelativeObjectPosition": """Parse the XML element of RelativeObjectPosition. Parameters ---------- element : xml.etree.ElementTree.Element A position element (same as generated by the class itself). Returns ------- RelativeObjectPosition A RelativeObjectPosition object. """ position_element = find_mandatory_field( element, "RelativeObjectPosition" ) dx = convert_float(position_element.attrib["dx"]) dy = convert_float(position_element.attrib["dy"]) if "dz" in position_element.attrib: dz = convert_float(position_element.attrib["dz"]) else: dz = None entityref = position_element.attrib["entityRef"] if position_element.find("Orientation") is not None: orientation = Orientation.parse( find_mandatory_field(position_element, "Orientation") ) else: orientation = Orientation() return RelativeObjectPosition(entityref, dx, dy, dz, orientation) def get_attributes(self) -> dict: """Return the attributes of the RelativeObjectPosition as a dictionary. Returns ------- dict A dictionary containing the attributes of the RelativeObjectPosition. """ retdict = {} retdict["entityRef"] = self.target retdict["dx"] = str(self.dx) retdict["dy"] = str(self.dy) if self.dz is not None: retdict["dz"] = str(self.dz) return retdict def get_element(self, elementname: str = "Position") -> ET.Element: """Return the ElementTree of the RelativeObjectPosition. Parameters ---------- elementname : str, optional Used if another name is needed for the position. Default is "Position". Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the RelativeObjectPosition. """ element = ET.Element(elementname) relpos = ET.SubElement( element, "RelativeObjectPosition", attrib=self.get_attributes() ) if self.orient.is_filled(): relpos.append(self.orient.get_element()) return elementThe RelativeObjectPosition creates a RelativePosition with the option of object as reference.
Parameters
entity:str- The entity to be relative to.
dx:float- Relative x-coordinate.
dy:float- Relative y-coordinate.
dz:float, optional- Relative z-coordinate. Default is None.
orientation:Orientation, optional- The angular orientation of the entity. Default is Orientation().
Attributes
target:str- The entity to be relative to.
dx:float- Relative x-coordinate.
dy:float- Relative y-coordinate.
dz:float- Relative z-coordinate.
orient:Orientation- The angular orientation of the entity.
Methods
parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element(elementname) Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class.
Initialize the RelativeObjectPosition.
Parameters
entity:str- The entity to be relative to.
dx:float- Relative x-coordinate.
dy:float- Relative y-coordinate.
dz:float, optional- Relative z-coordinate. Default is None.
orientation:Orientation, optional- The angular orientation of the entity. Default is Orientation().
Ancestors
- scenariogeneration.xosc.utils._PositionType
- VersionBase
Static methods
def parse(element: xml.etree.ElementTree.Element) ‑> RelativeObjectPosition-
Expand source code
@staticmethod def parse(element: ET.Element) -> "RelativeObjectPosition": """Parse the XML element of RelativeObjectPosition. Parameters ---------- element : xml.etree.ElementTree.Element A position element (same as generated by the class itself). Returns ------- RelativeObjectPosition A RelativeObjectPosition object. """ position_element = find_mandatory_field( element, "RelativeObjectPosition" ) dx = convert_float(position_element.attrib["dx"]) dy = convert_float(position_element.attrib["dy"]) if "dz" in position_element.attrib: dz = convert_float(position_element.attrib["dz"]) else: dz = None entityref = position_element.attrib["entityRef"] if position_element.find("Orientation") is not None: orientation = Orientation.parse( find_mandatory_field(position_element, "Orientation") ) else: orientation = Orientation() return RelativeObjectPosition(entityref, dx, dy, dz, orientation)Parse the XML element of RelativeObjectPosition.
Parameters
element:xml.etree.ElementTree.Element- A position element (same as generated by the class itself).
Returns
RelativeObjectPosition- A RelativeObjectPosition object.
Methods
def get_attributes(self) ‑> dict-
Expand source code
def get_attributes(self) -> dict: """Return the attributes of the RelativeObjectPosition as a dictionary. Returns ------- dict A dictionary containing the attributes of the RelativeObjectPosition. """ retdict = {} retdict["entityRef"] = self.target retdict["dx"] = str(self.dx) retdict["dy"] = str(self.dy) if self.dz is not None: retdict["dz"] = str(self.dz) return retdictReturn the attributes of the RelativeObjectPosition as a dictionary.
Returns
dict- A dictionary containing the attributes of the RelativeObjectPosition.
def get_element(self, elementname: str = 'Position') ‑> xml.etree.ElementTree.Element-
Expand source code
def get_element(self, elementname: str = "Position") -> ET.Element: """Return the ElementTree of the RelativeObjectPosition. Parameters ---------- elementname : str, optional Used if another name is needed for the position. Default is "Position". Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the RelativeObjectPosition. """ element = ET.Element(elementname) relpos = ET.SubElement( element, "RelativeObjectPosition", attrib=self.get_attributes() ) if self.orient.is_filled(): relpos.append(self.orient.get_element()) return elementReturn the ElementTree of the RelativeObjectPosition.
Parameters
elementname:str, optional- Used if another name is needed for the position. Default is "Position".
Returns
xml.etree.ElementTree.Element- The ElementTree representation of the RelativeObjectPosition.
class RelativeRoadPosition (ds: float,
dt: float,
entity: str,
orientation: Orientation = <scenariogeneration.xosc.utils.Orientation object>)-
Expand source code
class RelativeRoadPosition(_PositionType): """The RelativeRoadPosition creates a RelativeRoadPosition in OpenScenario. Parameters ---------- ds : float Length along the road. dt : float Lateral offset from the center. entity : str ID of the entity. orientation : Orientation, optional The angular orientation of the entity. Default is Orientation(). Attributes ---------- ds : float Length along the road. dt : float Lateral offset from the center. target : str ID of the entity. orient : Orientation The angular orientation of the entity. Methods ------- parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element(elementname) Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class. """ def __init__( self, ds: float, dt: float, entity: str, orientation: Orientation = Orientation(), ) -> None: """Initialize the RelativeRoadPosition. Parameters ---------- ds : float Length along the road. dt : float Lateral offset from the center. entity : str ID of the entity. orientation : Orientation, optional The angular orientation of the entity. Default is Orientation(). """ self.ds = convert_float(ds) self.dt = convert_float(dt) self.target = entity if not isinstance(orientation, Orientation): raise TypeError("input orientation is not of type Orientation") self.orient = orientation def __eq__(self, other) -> bool: if isinstance(other, RelativeRoadPosition): if ( self.get_attributes() == other.get_attributes() and self.orient == other.orient ): return True return False @staticmethod def parse(element: ET.Element) -> "RelativeRoadPosition": """Parse the XML element of RelativeRoadPosition. Parameters ---------- element : xml.etree.ElementTree.Element A position element (same as generated by the class itself). Returns ------- RelativeRoadPosition A RelativeRoadPosition object. """ position_element = find_mandatory_field( element, "RelativeRoadPosition" ) ds = convert_float(position_element.attrib["ds"]) dt = convert_float(position_element.attrib["dt"]) entityref = position_element.attrib["entityRef"] if position_element.find("Orientation") is not None: orientation = Orientation.parse( find_mandatory_field(position_element, "Orientation") ) else: orientation = Orientation() return RelativeRoadPosition(ds, dt, entityref, orientation) def get_attributes(self) -> dict: """Return the attributes of the RelativeRoadPosition as a dictionary. Returns ------- dict A dictionary containing the attributes of the RelativeRoadPosition. """ retdict = {} retdict["entityRef"] = self.target retdict["ds"] = str(self.ds) retdict["dt"] = str(self.dt) return retdict def get_element(self, elementname: str = "Position") -> ET.Element: """Return the ElementTree of the RelativeRoadPosition. Parameters ---------- elementname : str, optional Used if another name is needed for the position. Default is "Position". Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the RelativeRoadPosition. """ element = ET.Element(elementname) roadpos = ET.SubElement( element, "RelativeRoadPosition", attrib=self.get_attributes() ) if self.orient.is_filled(): roadpos.append(self.orient.get_element()) return elementThe RelativeRoadPosition creates a RelativeRoadPosition in OpenScenario.
Parameters
ds:float- Length along the road.
dt:float- Lateral offset from the center.
entity:str- ID of the entity.
orientation:Orientation, optional- The angular orientation of the entity. Default is Orientation().
Attributes
ds:float- Length along the road.
dt:float- Lateral offset from the center.
target:str- ID of the entity.
orient:Orientation- The angular orientation of the entity.
Methods
parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element(elementname) Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class.
Initialize the RelativeRoadPosition.
Parameters
ds:float- Length along the road.
dt:float- Lateral offset from the center.
entity:str- ID of the entity.
orientation:Orientation, optional- The angular orientation of the entity. Default is Orientation().
Ancestors
- scenariogeneration.xosc.utils._PositionType
- VersionBase
Static methods
def parse(element: xml.etree.ElementTree.Element) ‑> RelativeRoadPosition-
Expand source code
@staticmethod def parse(element: ET.Element) -> "RelativeRoadPosition": """Parse the XML element of RelativeRoadPosition. Parameters ---------- element : xml.etree.ElementTree.Element A position element (same as generated by the class itself). Returns ------- RelativeRoadPosition A RelativeRoadPosition object. """ position_element = find_mandatory_field( element, "RelativeRoadPosition" ) ds = convert_float(position_element.attrib["ds"]) dt = convert_float(position_element.attrib["dt"]) entityref = position_element.attrib["entityRef"] if position_element.find("Orientation") is not None: orientation = Orientation.parse( find_mandatory_field(position_element, "Orientation") ) else: orientation = Orientation() return RelativeRoadPosition(ds, dt, entityref, orientation)Parse the XML element of RelativeRoadPosition.
Parameters
element:xml.etree.ElementTree.Element- A position element (same as generated by the class itself).
Returns
RelativeRoadPosition- A RelativeRoadPosition object.
Methods
def get_attributes(self) ‑> dict-
Expand source code
def get_attributes(self) -> dict: """Return the attributes of the RelativeRoadPosition as a dictionary. Returns ------- dict A dictionary containing the attributes of the RelativeRoadPosition. """ retdict = {} retdict["entityRef"] = self.target retdict["ds"] = str(self.ds) retdict["dt"] = str(self.dt) return retdictReturn the attributes of the RelativeRoadPosition as a dictionary.
Returns
dict- A dictionary containing the attributes of the RelativeRoadPosition.
def get_element(self, elementname: str = 'Position') ‑> xml.etree.ElementTree.Element-
Expand source code
def get_element(self, elementname: str = "Position") -> ET.Element: """Return the ElementTree of the RelativeRoadPosition. Parameters ---------- elementname : str, optional Used if another name is needed for the position. Default is "Position". Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the RelativeRoadPosition. """ element = ET.Element(elementname) roadpos = ET.SubElement( element, "RelativeRoadPosition", attrib=self.get_attributes() ) if self.orient.is_filled(): roadpos.append(self.orient.get_element()) return elementReturn the ElementTree of the RelativeRoadPosition.
Parameters
elementname:str, optional- Used if another name is needed for the position. Default is "Position".
Returns
xml.etree.ElementTree.Element- The ElementTree representation of the RelativeRoadPosition.
class RelativeWorldPosition (entity: str,
dx: float,
dy: float,
dz: float,
orientation: Orientation = <scenariogeneration.xosc.utils.Orientation object>)-
Expand source code
class RelativeWorldPosition(_PositionType): """The RelativeWorldPosition creates a RelativePosition with the option of world as reference. Parameters ---------- entity : str The entity to be relative to. dx : float Relative x-coordinate. dy : float Relative y-coordinate. dz : float Relative z-coordinate. orientation : Orientation, optional The angular orientation of the entity. Default is Orientation(). Attributes ---------- target : str The entity to be relative to. dx : float Relative x-coordinate. dy : float Relative y-coordinate. dz : float Relative z-coordinate. orient : Orientation The angular orientation of the entity. Methods ------- parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element(elementname) Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class. """ def __init__( self, entity: str, dx: float, dy: float, dz: float, orientation: Orientation = Orientation(), ) -> None: """Initialize the RelativeWorldPosition. Parameters ---------- entity : str The entity to be relative to. dx : float Relative x-coordinate. dy : float Relative y-coordinate. dz : float Relative z-coordinate. orientation : Orientation, optional The angular orientation of the entity. Default is Orientation(). """ self.target = entity self.dx = convert_float(dx) self.dy = convert_float(dy) self.dz = convert_float(dz) if not isinstance(orientation, Orientation): raise TypeError("input orientation is not of type Orientation") self.orient = orientation def __eq__(self, other) -> bool: if isinstance(other, RelativeWorldPosition): if ( self.get_attributes() == other.get_attributes() and self.orient == other.orient ): return True return False @staticmethod def parse(element: ET.Element) -> "RelativeWorldPosition": """Parse the XML element of RelativeWorldPosition. Parameters ---------- element : xml.etree.ElementTree.Element A position element (same as generated by the class itself). Returns ------- RelativeWorldPosition A RelativeWorldPosition object. """ position_element = find_mandatory_field( element, "RelativeWorldPosition" ) dx = convert_float(position_element.attrib["dx"]) dy = convert_float(position_element.attrib["dy"]) dz = convert_float(position_element.attrib["dz"]) entityref = position_element.attrib["entityRef"] if position_element.find("Orientation") is not None: orientation = Orientation.parse( find_mandatory_field(position_element, "Orientation") ) else: orientation = Orientation() return RelativeWorldPosition(entityref, dx, dy, dz, orientation) def get_attributes(self) -> dict: """Return the attributes of the RelativeWorldPosition as a dictionary. Returns ------- dict A dictionary containing the attributes of the RelativeWorldPosition. """ retdict = {} retdict["entityRef"] = self.target retdict["dx"] = str(self.dx) retdict["dy"] = str(self.dy) retdict["dz"] = str(self.dz) return retdict def get_element(self, elementname: str = "Position") -> ET.Element: """Return the ElementTree of the RelativeWorldPosition. Parameters ---------- elementname : str, optional Used if another name is needed for the position. Default is "Position". Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the RelativeWorldPosition. """ element = ET.Element(elementname) relpos = ET.SubElement( element, "RelativeWorldPosition", attrib=self.get_attributes() ) if self.orient.is_filled(): relpos.append(self.orient.get_element()) return elementThe RelativeWorldPosition creates a RelativePosition with the option of world as reference.
Parameters
entity:str- The entity to be relative to.
dx:float- Relative x-coordinate.
dy:float- Relative y-coordinate.
dz:float- Relative z-coordinate.
orientation:Orientation, optional- The angular orientation of the entity. Default is Orientation().
Attributes
target:str- The entity to be relative to.
dx:float- Relative x-coordinate.
dy:float- Relative y-coordinate.
dz:float- Relative z-coordinate.
orient:Orientation- The angular orientation of the entity.
Methods
parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element(elementname) Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class.
Initialize the RelativeWorldPosition.
Parameters
entity:str- The entity to be relative to.
dx:float- Relative x-coordinate.
dy:float- Relative y-coordinate.
dz:float- Relative z-coordinate.
orientation:Orientation, optional- The angular orientation of the entity. Default is Orientation().
Ancestors
- scenariogeneration.xosc.utils._PositionType
- VersionBase
Static methods
def parse(element: xml.etree.ElementTree.Element) ‑> RelativeWorldPosition-
Expand source code
@staticmethod def parse(element: ET.Element) -> "RelativeWorldPosition": """Parse the XML element of RelativeWorldPosition. Parameters ---------- element : xml.etree.ElementTree.Element A position element (same as generated by the class itself). Returns ------- RelativeWorldPosition A RelativeWorldPosition object. """ position_element = find_mandatory_field( element, "RelativeWorldPosition" ) dx = convert_float(position_element.attrib["dx"]) dy = convert_float(position_element.attrib["dy"]) dz = convert_float(position_element.attrib["dz"]) entityref = position_element.attrib["entityRef"] if position_element.find("Orientation") is not None: orientation = Orientation.parse( find_mandatory_field(position_element, "Orientation") ) else: orientation = Orientation() return RelativeWorldPosition(entityref, dx, dy, dz, orientation)Parse the XML element of RelativeWorldPosition.
Parameters
element:xml.etree.ElementTree.Element- A position element (same as generated by the class itself).
Returns
RelativeWorldPosition- A RelativeWorldPosition object.
Methods
def get_attributes(self) ‑> dict-
Expand source code
def get_attributes(self) -> dict: """Return the attributes of the RelativeWorldPosition as a dictionary. Returns ------- dict A dictionary containing the attributes of the RelativeWorldPosition. """ retdict = {} retdict["entityRef"] = self.target retdict["dx"] = str(self.dx) retdict["dy"] = str(self.dy) retdict["dz"] = str(self.dz) return retdictReturn the attributes of the RelativeWorldPosition as a dictionary.
Returns
dict- A dictionary containing the attributes of the RelativeWorldPosition.
def get_element(self, elementname: str = 'Position') ‑> xml.etree.ElementTree.Element-
Expand source code
def get_element(self, elementname: str = "Position") -> ET.Element: """Return the ElementTree of the RelativeWorldPosition. Parameters ---------- elementname : str, optional Used if another name is needed for the position. Default is "Position". Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the RelativeWorldPosition. """ element = ET.Element(elementname) relpos = ET.SubElement( element, "RelativeWorldPosition", attrib=self.get_attributes() ) if self.orient.is_filled(): relpos.append(self.orient.get_element()) return elementReturn the ElementTree of the RelativeWorldPosition.
Parameters
elementname:str, optional- Used if another name is needed for the position. Default is "Position".
Returns
xml.etree.ElementTree.Element- The ElementTree representation of the RelativeWorldPosition.
class RoadPosition (s: float,
t: float,
reference_id: int,
orientation: Orientation = <scenariogeneration.xosc.utils.Orientation object>)-
Expand source code
class RoadPosition(_PositionType): """The RoadPosition creates a RoadPosition in OpenScenario. Parameters ---------- s : float Length along the road. t : float Lateral offset from the center. reference_id : str ID of the road. orientation : Orientation, optional The angular orientation of the entity. Default is Orientation(). Attributes ---------- s : float Length along the road. t : float Lateral offset from the center. id : str ID of the road. orient : Orientation The angular orientation of the entity. Methods ------- parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element(elementname) Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class. """ def __init__( self, s: float, t: float, reference_id: int, orientation: Orientation = Orientation(), ) -> None: """Initialize the RoadPosition. Parameters ---------- s : float Length along the road. t : float Lateral offset from the center. reference_id : int ID of the road. orientation : Orientation, optional The angular orientation of the entity. Default is Orientation(). """ self.s = convert_float(s) self.t = convert_float(t) self.id = convert_int(reference_id) if not isinstance(orientation, Orientation): raise TypeError("input orientation is not of type Orientation") self.orient = orientation def __eq__(self, other) -> bool: if isinstance(other, RoadPosition): if ( self.get_attributes() == other.get_attributes() and self.orient == other.orient ): return True return False @staticmethod def parse(element: ET.Element) -> "RoadPosition": """Parse the XML element of RoadPosition. Parameters ---------- element : xml.etree.ElementTree.Element A position element (same as generated by the class itself). Returns ------- RoadPosition A RoadPosition object. """ position_element = find_mandatory_field(element, "RoadPosition") roadId = convert_int(position_element.attrib["roadId"]) s = convert_float(position_element.attrib["s"]) t = convert_float(position_element.attrib["t"]) if position_element.find("Orientation") is not None: orientation = Orientation.parse( find_mandatory_field(position_element, "Orientation") ) else: orientation = Orientation() return RoadPosition(s, t, roadId, orientation) def get_attributes(self) -> dict: """Return the attributes of the RoadPosition as a dictionary. Returns ------- dict A dictionary containing the attributes of the RoadPosition. """ retdict = {} retdict["roadId"] = str(self.id) retdict["s"] = str(self.s) retdict["t"] = str(self.t) return retdict def get_element(self, elementname: str = "Position") -> ET.Element: """Return the ElementTree of the RoadPosition. Parameters ---------- elementname : str, optional Used if another name is needed for the position. Default is "Position". Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the RoadPosition. """ element = ET.Element(elementname) roadpos = ET.SubElement( element, "RoadPosition", attrib=self.get_attributes() ) if self.orient.is_filled(): roadpos.append(self.orient.get_element()) return elementThe RoadPosition creates a RoadPosition in OpenScenario.
Parameters
s:float- Length along the road.
t:float- Lateral offset from the center.
reference_id:str- ID of the road.
orientation:Orientation, optional- The angular orientation of the entity. Default is Orientation().
Attributes
s:float- Length along the road.
t:float- Lateral offset from the center.
id:str- ID of the road.
orient:Orientation- The angular orientation of the entity.
Methods
parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element(elementname) Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class.
Initialize the RoadPosition.
Parameters
s:float- Length along the road.
t:float- Lateral offset from the center.
reference_id:int- ID of the road.
orientation:Orientation, optional- The angular orientation of the entity. Default is Orientation().
Ancestors
- scenariogeneration.xosc.utils._PositionType
- VersionBase
Static methods
def parse(element: xml.etree.ElementTree.Element) ‑> RoadPosition-
Expand source code
@staticmethod def parse(element: ET.Element) -> "RoadPosition": """Parse the XML element of RoadPosition. Parameters ---------- element : xml.etree.ElementTree.Element A position element (same as generated by the class itself). Returns ------- RoadPosition A RoadPosition object. """ position_element = find_mandatory_field(element, "RoadPosition") roadId = convert_int(position_element.attrib["roadId"]) s = convert_float(position_element.attrib["s"]) t = convert_float(position_element.attrib["t"]) if position_element.find("Orientation") is not None: orientation = Orientation.parse( find_mandatory_field(position_element, "Orientation") ) else: orientation = Orientation() return RoadPosition(s, t, roadId, orientation)Parse the XML element of RoadPosition.
Parameters
element:xml.etree.ElementTree.Element- A position element (same as generated by the class itself).
Returns
RoadPosition- A RoadPosition object.
Methods
def get_attributes(self) ‑> dict-
Expand source code
def get_attributes(self) -> dict: """Return the attributes of the RoadPosition as a dictionary. Returns ------- dict A dictionary containing the attributes of the RoadPosition. """ retdict = {} retdict["roadId"] = str(self.id) retdict["s"] = str(self.s) retdict["t"] = str(self.t) return retdictReturn the attributes of the RoadPosition as a dictionary.
Returns
dict- A dictionary containing the attributes of the RoadPosition.
def get_element(self, elementname: str = 'Position') ‑> xml.etree.ElementTree.Element-
Expand source code
def get_element(self, elementname: str = "Position") -> ET.Element: """Return the ElementTree of the RoadPosition. Parameters ---------- elementname : str, optional Used if another name is needed for the position. Default is "Position". Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the RoadPosition. """ element = ET.Element(elementname) roadpos = ET.SubElement( element, "RoadPosition", attrib=self.get_attributes() ) if self.orient.is_filled(): roadpos.append(self.orient.get_element()) return elementReturn the ElementTree of the RoadPosition.
Parameters
elementname:str, optional- Used if another name is needed for the position. Default is "Position".
Returns
xml.etree.ElementTree.Element- The ElementTree representation of the RoadPosition.
class RoadRange (length: float | None = None, roadcursors: list | None = None)-
Expand source code
class RoadRange(VersionBase): """The RoadRange class creates a road range used by the TrafficArea class. Defines an area by a range on a specific road. Parameters ---------- length : float Limits the length of the road range starting from the first road cursor. If omitted or if length exceeds last road cursor, then last road cursor defines the end of the road range. Unit: [m]. roadcursor : list of RoadCursor A minimum of 2 road cursors must be provided to specify the start and end of the road range. Intermediate cursors can be used to change the lane "validity". Attributes ---------- length : float Limits the length of the road range starting from the first road cursor. If omitted or if length exceeds last road cursor, then last road cursor defines the end of the road range. Unit: [m]. roadcursor : list of RoadCursor A minimum of 2 road cursors must be provided to specify the start and end of the road range. Intermediate cursors can be used to change the lane "validity". """ def __init__( self, length: Optional[float] = None, roadcursors: Optional[list] = None, ) -> None: """Initializes the RoadRange. Parameters ---------- length : float, optional Limits the length of the road range starting from the first road cursor. Default is None. roadcursors : list of RoadCursor A minimum of 2 road cursors must be provided to specify the start and end of the road range. Intermediate cursors can be used to change the lane "validity". """ self.length = convert_float(length) if length is not None else None self.roadcursors = roadcursors if roadcursors is not None else [] def __eq__(self, other: object) -> bool: return ( isinstance(other, RoadRange) and self.length == other.length and self.roadcursors == other.roadcursors ) def add_cursor( self, roadid: str, s: Optional[float] = 0.0, lanes: Optional[list[int]] = None, ) -> "RoadRange": """Adds a road cursor to the road range. Parameters ---------- roadid : str The ID of the target road taken from the respective road network definition file. s : float, optional The s-coordinate taken along the road's reference line from the start point of the target road. If s is omitted and the road cursor depicts the start of a road range, then s=0 is assumed. If s is omitted and the road cursor depicts the end of a road range, then s=max_length is assumed. Unit: [m]. lane : list of int, optional Restriction of the road cursor to specific lanes of a road. If omitted, road cursor is valid for all lanes of the road. """ self.roadcursors.append( [roadid, s, lanes if lanes is not None else []] ) return self @staticmethod def parse(element: ET.Element) -> "RoadRange": """Parses the XML element of RoadRange. Parameters ---------- element : ET.Element A road range element (same as generated by the class itself). Returns ------- RoadRange A RoadRange object. """ length = convert_float(element.attrib.get("length")) roadcursors = [] for cursor in element.findall("RoadCursor"): roadid = cursor.attrib.get("roadId", "") s_value = convert_float(cursor.attrib.get("s", 0.0)) lane_elements = cursor.findall("Lane") lanes = ( [int(lane.attrib.get("id", "")) for lane in lane_elements] if lane_elements else [] ) roadcursors.append([roadid, s_value, lanes]) return RoadRange(length, roadcursors) def get_attributes(self) -> dict: """Returns the attributes of the RoadRange as a dictionary.""" retdict = {} if self.length is not None: retdict["length"] = str(self.length) return retdict def get_element(self) -> ET.Element: """Returns the ElementTree of the RoadRange. Returns ------- ET.Element The ElementTree representation of the RoadRange. """ if not self.isVersionEqLarger(minor=3): raise OpenSCENARIOVersionError( "RoadRange was introduced in OpenSCENARIO V1.3" ) if len(self.roadcursors) < 2: raise ValueError( "At least two road cursors are required for a RoadRange" ) element = ET.Element("RoadRange", attrib=self.get_attributes()) for roadid, s, lanes in self.roadcursors: road_cursor_attributes = {"roadId": str(roadid), "s": str(s)} cursor_el = ET.SubElement( element, "RoadCursor", attrib=road_cursor_attributes ) if lanes is not None: for lane in lanes: ET.SubElement(cursor_el, "Lane", {"id": str(lane)}) return elementThe RoadRange class creates a road range used by the TrafficArea class. Defines an area by a range on a specific road.
Parameters
length:float- Limits the length of the road range starting from the first road cursor. If omitted or if length exceeds last road cursor, then last road cursor defines the end of the road range. Unit: [m].
roadcursor:listofRoadCursor- A minimum of 2 road cursors must be provided to specify the start and end of the road range. Intermediate cursors can be used to change the lane "validity".
Attributes
length:float- Limits the length of the road range starting from the first road cursor. If omitted or if length exceeds last road cursor, then last road cursor defines the end of the road range. Unit: [m].
roadcursor:listofRoadCursor- A minimum of 2 road cursors must be provided to specify the start and end of the road range. Intermediate cursors can be used to change the lane "validity".
Initializes the RoadRange.
Parameters
length:float, optional- Limits the length of the road range starting from the first road cursor. Default is None.
roadcursors:listofRoadCursor- A minimum of 2 road cursors must be provided to specify the start and end of the road range. Intermediate cursors can be used to change the lane "validity".
Ancestors
Static methods
def parse(element: xml.etree.ElementTree.Element) ‑> RoadRange-
Expand source code
@staticmethod def parse(element: ET.Element) -> "RoadRange": """Parses the XML element of RoadRange. Parameters ---------- element : ET.Element A road range element (same as generated by the class itself). Returns ------- RoadRange A RoadRange object. """ length = convert_float(element.attrib.get("length")) roadcursors = [] for cursor in element.findall("RoadCursor"): roadid = cursor.attrib.get("roadId", "") s_value = convert_float(cursor.attrib.get("s", 0.0)) lane_elements = cursor.findall("Lane") lanes = ( [int(lane.attrib.get("id", "")) for lane in lane_elements] if lane_elements else [] ) roadcursors.append([roadid, s_value, lanes]) return RoadRange(length, roadcursors)Parses the XML element of RoadRange.
Parameters
element:ET.Element- A road range element (same as generated by the class itself).
Returns
RoadRange- A RoadRange object.
Methods
def add_cursor(self, roadid: str, s: float | None = 0.0, lanes: list[int] | None = None) ‑> RoadRange-
Expand source code
def add_cursor( self, roadid: str, s: Optional[float] = 0.0, lanes: Optional[list[int]] = None, ) -> "RoadRange": """Adds a road cursor to the road range. Parameters ---------- roadid : str The ID of the target road taken from the respective road network definition file. s : float, optional The s-coordinate taken along the road's reference line from the start point of the target road. If s is omitted and the road cursor depicts the start of a road range, then s=0 is assumed. If s is omitted and the road cursor depicts the end of a road range, then s=max_length is assumed. Unit: [m]. lane : list of int, optional Restriction of the road cursor to specific lanes of a road. If omitted, road cursor is valid for all lanes of the road. """ self.roadcursors.append( [roadid, s, lanes if lanes is not None else []] ) return selfAdds a road cursor to the road range.
Parameters
roadid:str- The ID of the target road taken from the respective road network definition file.
s:float, optional- The s-coordinate taken along the road's reference line from the start point of the target road. If s is omitted and the road cursor depicts the start of a road range, then s=0 is assumed. If s is omitted and the road cursor depicts the end of a road range, then s=max_length is assumed. Unit: [m].
lane:listofint, optional- Restriction of the road cursor to specific lanes of a road. If omitted, road cursor is valid for all lanes of the road.
def get_attributes(self) ‑> dict-
Expand source code
def get_attributes(self) -> dict: """Returns the attributes of the RoadRange as a dictionary.""" retdict = {} if self.length is not None: retdict["length"] = str(self.length) return retdictReturns the attributes of the RoadRange as a dictionary.
def get_element(self) ‑> xml.etree.ElementTree.Element-
Expand source code
def get_element(self) -> ET.Element: """Returns the ElementTree of the RoadRange. Returns ------- ET.Element The ElementTree representation of the RoadRange. """ if not self.isVersionEqLarger(minor=3): raise OpenSCENARIOVersionError( "RoadRange was introduced in OpenSCENARIO V1.3" ) if len(self.roadcursors) < 2: raise ValueError( "At least two road cursors are required for a RoadRange" ) element = ET.Element("RoadRange", attrib=self.get_attributes()) for roadid, s, lanes in self.roadcursors: road_cursor_attributes = {"roadId": str(roadid), "s": str(s)} cursor_el = ET.SubElement( element, "RoadCursor", attrib=road_cursor_attributes ) if lanes is not None: for lane in lanes: ET.SubElement(cursor_el, "Lane", {"id": str(lane)}) return elementReturns the ElementTree of the RoadRange.
Returns
ET.Element- The ElementTree representation of the RoadRange.
class Route (name: str, closed: bool = False)-
Expand source code
class Route(_BaseCatalog): """The Route class creates a route, needs at least two waypoints to be valid. Parameters ---------- name : str Name of the Route. closed : bool, optional If the waypoints form a loop. Default is False. Attributes ---------- name : str Name of the Route. closed : bool If the waypoints form a loop. waypoints : list of Waypoint A list of waypoints. parameters : ParameterDeclarations Parameters for the route. Methods ------- parse(element) Parses an ElementTree created by the class and returns an instance of the class. add_waypoint(position, routestrategy) Adds a waypoint to the route (minimum two). add_parameter(parameter) Adds a parameter to the route. append_to_catalog(filename) Adds the Route to an existing catalog. dump_to_catalog(filename, name, description, author) Creates a new catalog with the Route. get_element() Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class. """ def __init__(self, name: str, closed: bool = False) -> None: """Initialize the Route. Parameters ---------- name : str Name of the Route. closed : bool, optional If the waypoints form a loop. Default is False. """ super().__init__() self.name = name self.closed = convert_bool(closed) self.waypoints = [] def __eq__(self, other) -> bool: if isinstance(other, Route): if ( self.get_attributes() == other.get_attributes() and self.parameters == other.parameters and self.waypoints == other.waypoints ): return True return False @staticmethod def parse(element: ET.Element) -> "Route": """Parse the XML element of Route. Parameters ---------- element : xml.etree.ElementTree.Element A Route element (same as generated by the class itself). Returns ------- Route A Route object. """ name = element.attrib["name"] closed = convert_bool(element.attrib["closed"]) route = Route(name, closed) all_wps = element.findall("Waypoint") for wp in all_wps: waypoint = Waypoint.parse(wp) route.waypoints.append(waypoint) return route def add_waypoint( self, position: _PositionType, routestrategy: RouteStrategy ) -> "Route": """Add a waypoint to the Route. Parameters ---------- position : _PositionType Any position for the route. routestrategy : RouteStrategy Routing strategy for this waypoint. """ # note: the checks for types are done in Waypoint self.waypoints.append(Waypoint(position, routestrategy)) return self def get_attributes(self) -> dict: """Return the attributes of the Route as a dictionary. Returns ------- dict A dictionary containing the attributes of the Route. """ retdict = {} retdict["name"] = self.name retdict["closed"] = get_bool_string(self.closed) return retdict def get_element(self) -> ET.Element: """Return the ElementTree of the Route. Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the Route. """ if len(self.waypoints) < 2: raise ValueError("Too few waypoints") element = ET.Element("Route", attrib=self.get_attributes()) self.add_parameters_to_element(element) for w in self.waypoints: element.append(w.get_element()) return elementThe Route class creates a route, needs at least two waypoints to be valid.
Parameters
name:str- Name of the Route.
closed:bool, optional- If the waypoints form a loop. Default is False.
Attributes
name:str- Name of the Route.
closed:bool- If the waypoints form a loop.
waypoints:listofWaypoint- A list of waypoints.
parameters:ParameterDeclarations- Parameters for the route.
Methods
parse(element) Parses an ElementTree created by the class and returns an instance of the class. add_waypoint(position, routestrategy) Adds a waypoint to the route (minimum two). add_parameter(parameter) Adds a parameter to the route. append_to_catalog(filename) Adds the Route to an existing catalog. dump_to_catalog(filename, name, description, author) Creates a new catalog with the Route. get_element() Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class.
Initialize the Route.
Parameters
name:str- Name of the Route.
closed:bool, optional- If the waypoints form a loop. Default is False.
Ancestors
- scenariogeneration.xosc.utils._BaseCatalog
- VersionBase
Static methods
def parse(element: xml.etree.ElementTree.Element) ‑> Route-
Expand source code
@staticmethod def parse(element: ET.Element) -> "Route": """Parse the XML element of Route. Parameters ---------- element : xml.etree.ElementTree.Element A Route element (same as generated by the class itself). Returns ------- Route A Route object. """ name = element.attrib["name"] closed = convert_bool(element.attrib["closed"]) route = Route(name, closed) all_wps = element.findall("Waypoint") for wp in all_wps: waypoint = Waypoint.parse(wp) route.waypoints.append(waypoint) return routeParse the XML element of Route.
Parameters
element:xml.etree.ElementTree.Element- A Route element (same as generated by the class itself).
Returns
Route- A Route object.
Methods
def add_waypoint(self,
position: scenariogeneration.xosc.utils._PositionType,
routestrategy: RouteStrategy) ‑> Route-
Expand source code
def add_waypoint( self, position: _PositionType, routestrategy: RouteStrategy ) -> "Route": """Add a waypoint to the Route. Parameters ---------- position : _PositionType Any position for the route. routestrategy : RouteStrategy Routing strategy for this waypoint. """ # note: the checks for types are done in Waypoint self.waypoints.append(Waypoint(position, routestrategy)) return selfAdd a waypoint to the Route.
Parameters
position:_PositionType- Any position for the route.
routestrategy:RouteStrategy- Routing strategy for this waypoint.
def get_attributes(self) ‑> dict-
Expand source code
def get_attributes(self) -> dict: """Return the attributes of the Route as a dictionary. Returns ------- dict A dictionary containing the attributes of the Route. """ retdict = {} retdict["name"] = self.name retdict["closed"] = get_bool_string(self.closed) return retdictReturn the attributes of the Route as a dictionary.
Returns
dict- A dictionary containing the attributes of the Route.
def get_element(self) ‑> xml.etree.ElementTree.Element-
Expand source code
def get_element(self) -> ET.Element: """Return the ElementTree of the Route. Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the Route. """ if len(self.waypoints) < 2: raise ValueError("Too few waypoints") element = ET.Element("Route", attrib=self.get_attributes()) self.add_parameters_to_element(element) for w in self.waypoints: element.append(w.get_element()) return elementReturn the ElementTree of the Route.
Returns
xml.etree.ElementTree.Element- The ElementTree representation of the Route.
class RoutePositionInLaneCoordinates (route_ref: VersionBase,
s: float,
laneid: int,
offset: float,
orientation: Orientation = <scenariogeneration.xosc.utils.Orientation object>)-
Expand source code
class RoutePositionInLaneCoordinates(_PositionType): """RoutePositionInLaneCoordinates creates a RoutePosition with the InRoutePosition of type PositionInLaneCoordinates. Parameters ---------- route_ref : Route or CatalogReference Reference to the route the position is calculated from. s : float S coordinate of the road. laneid : int T coordinate of the road. offset : float, optional Lateral offset relative to the lane. Default is 0. orientation : Orientation, optional Orientation of the entity. Default is Orientation(). Attributes ---------- route_ref : Route or CatalogReference Reference to the route the position is calculated from. s : float S coordinate of the road. laneid : int T coordinate of the road. offset : float Lateral offset relative to the lane. orientation : Orientation Orientation of the entity. Methods ------- parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element() Returns the full ElementTree of the class. """ def __init__( self, route_ref: VersionBase, s: float, laneid: int, offset: float, orientation: Orientation = Orientation(), ) -> None: """Initialize the RoutePositionInLaneCoordinates class. Parameters ---------- route_ref : Route or CatalogReference Reference to the route the position is calculated from. s : float S coordinate of the road. laneid : int T coordinate of the road. offset : float, optional Lateral offset relative to the lane. Default is 0. orientation : Orientation, optional Orientation of the entity. Default is Orientation(). """ if not isinstance(route_ref, (Route, CatalogReference)): raise TypeError( "route input not of type Route or CatalogReference" ) self.route_ref = route_ref self.s = convert_float(s) self.laneid = convert_int(laneid) self.offset = convert_float(offset) if not isinstance(orientation, Orientation): raise TypeError("input orientation is not of type Orientation") self.orientation = orientation def __eq__(self, other) -> bool: if isinstance(other, RoutePositionInLaneCoordinates): if ( self.s == other.s and self.laneid == other.laneid and self.offset == other.offset and self.orientation == other.orientation and self.route_ref == other.route_ref ): return True return False @staticmethod def parse(element: ET.Element) -> "RoutePositionInLaneCoordinates": """Parse the XML element of RoutePositionInLaneCoordinates. Parameters ---------- element : xml.etree.ElementTree.Element A position element (same as generated by the class itself). Returns ------- RoutePositionInLaneCoordinates A RoutePositionInLaneCoordinates object. """ position_element = find_mandatory_field(element, "RoutePosition") if position_element.find("Orientation") is not None: orientation = Orientation.parse( find_mandatory_field(position_element, "Orientation") ) else: orientation = Orientation() lane_coord_element = find_mandatory_field( position_element, "InRoutePosition/FromLaneCoordinates" ) s = convert_float(lane_coord_element.attrib["pathS"]) lane_id = convert_int(lane_coord_element.attrib["laneId"]) try: offset = convert_float(lane_coord_element.attrib["laneOffset"]) except KeyError: offset = 0 route_element = find_mandatory_field(position_element, "RouteRef") if route_element.find("Route") is not None: routeref = Route.parse( find_mandatory_field(route_element, "Route") ) else: routeref = CatalogReference.parse( find_mandatory_field(route_element, "CatalogReference") ) return RoutePositionInLaneCoordinates( routeref, s, lane_id, offset, orientation ) def get_element(self, elementname: str = "Position") -> ET.Element: """Return the ElementTree of the RoutePositionInLaneCoordinates. Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the RoutePositionInLaneCoordinates. """ element = ET.Element(elementname) relement = ET.SubElement(element, "RoutePosition") routeref = ET.SubElement(relement, "RouteRef") routeref.append(self.route_ref.get_element()) relement.append(self.orientation.get_element()) inroute = ET.SubElement(relement, "InRoutePosition") ET.SubElement( inroute, "FromLaneCoordinates", attrib={ "pathS": str(self.s), "laneId": str(self.laneid), "laneOffset": str(self.offset), }, ) return elementRoutePositionInLaneCoordinates creates a RoutePosition with the InRoutePosition of type PositionInLaneCoordinates.
Parameters
route_ref:RouteorCatalogReference- Reference to the route the position is calculated from.
s:float- S coordinate of the road.
laneid:int- T coordinate of the road.
offset:float, optional- Lateral offset relative to the lane. Default is 0.
orientation:Orientation, optional- Orientation of the entity. Default is Orientation().
Attributes
route_ref:RouteorCatalogReference- Reference to the route the position is calculated from.
s:float- S coordinate of the road.
laneid:int- T coordinate of the road.
offset:float- Lateral offset relative to the lane.
orientation:Orientation- Orientation of the entity.
Methods
parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element() Returns the full ElementTree of the class.
Initialize the RoutePositionInLaneCoordinates class.
Parameters
route_ref:RouteorCatalogReference- Reference to the route the position is calculated from.
s:float- S coordinate of the road.
laneid:int- T coordinate of the road.
offset:float, optional- Lateral offset relative to the lane. Default is 0.
orientation:Orientation, optional- Orientation of the entity. Default is Orientation().
Ancestors
- scenariogeneration.xosc.utils._PositionType
- VersionBase
Static methods
def parse(element: xml.etree.ElementTree.Element) ‑> RoutePositionInLaneCoordinates-
Expand source code
@staticmethod def parse(element: ET.Element) -> "RoutePositionInLaneCoordinates": """Parse the XML element of RoutePositionInLaneCoordinates. Parameters ---------- element : xml.etree.ElementTree.Element A position element (same as generated by the class itself). Returns ------- RoutePositionInLaneCoordinates A RoutePositionInLaneCoordinates object. """ position_element = find_mandatory_field(element, "RoutePosition") if position_element.find("Orientation") is not None: orientation = Orientation.parse( find_mandatory_field(position_element, "Orientation") ) else: orientation = Orientation() lane_coord_element = find_mandatory_field( position_element, "InRoutePosition/FromLaneCoordinates" ) s = convert_float(lane_coord_element.attrib["pathS"]) lane_id = convert_int(lane_coord_element.attrib["laneId"]) try: offset = convert_float(lane_coord_element.attrib["laneOffset"]) except KeyError: offset = 0 route_element = find_mandatory_field(position_element, "RouteRef") if route_element.find("Route") is not None: routeref = Route.parse( find_mandatory_field(route_element, "Route") ) else: routeref = CatalogReference.parse( find_mandatory_field(route_element, "CatalogReference") ) return RoutePositionInLaneCoordinates( routeref, s, lane_id, offset, orientation )Parse the XML element of RoutePositionInLaneCoordinates.
Parameters
element:xml.etree.ElementTree.Element- A position element (same as generated by the class itself).
Returns
RoutePositionInLaneCoordinates- A RoutePositionInLaneCoordinates object.
Methods
def get_element(self, elementname: str = 'Position') ‑> xml.etree.ElementTree.Element-
Expand source code
def get_element(self, elementname: str = "Position") -> ET.Element: """Return the ElementTree of the RoutePositionInLaneCoordinates. Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the RoutePositionInLaneCoordinates. """ element = ET.Element(elementname) relement = ET.SubElement(element, "RoutePosition") routeref = ET.SubElement(relement, "RouteRef") routeref.append(self.route_ref.get_element()) relement.append(self.orientation.get_element()) inroute = ET.SubElement(relement, "InRoutePosition") ET.SubElement( inroute, "FromLaneCoordinates", attrib={ "pathS": str(self.s), "laneId": str(self.laneid), "laneOffset": str(self.offset), }, ) return elementReturn the ElementTree of the RoutePositionInLaneCoordinates.
Returns
xml.etree.ElementTree.Element- The ElementTree representation of the RoutePositionInLaneCoordinates.
class RoutePositionInRoadCoordinates (route_ref: VersionBase,
s: float,
t: float,
orientation: Orientation = <scenariogeneration.xosc.utils.Orientation object>)-
Expand source code
class RoutePositionInRoadCoordinates(_PositionType): """RoutePositionInRoadCoordinates creates a RoutePosition with the InRoutePosition of type PositionInRoadCoordinates. Parameters ---------- route_ref : Route or CatalogReference Reference to the route the position is calculated from. s : float S coordinate of the road. t : float T coordinate of the road. orientation : Orientation, optional Orientation of the entity. Default is Orientation(). Attributes ---------- route_ref : Route or CatalogReference Reference to the route the position is calculated from. s : float S coordinate of the road. t : float T coordinate of the road. orientation : Orientation Orientation of the entity. Methods ------- parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element() Returns the full ElementTree of the class. """ def __init__( self, route_ref: VersionBase, s: float, t: float, orientation: Orientation = Orientation(), ) -> None: """Initialize the RoutePositionInRoadCoordinates class. Parameters ---------- route_ref : Route or CatalogReference Reference to the route the position is calculated from. s : float S coordinate of the road. t : float T coordinate of the road. orientation : Orientation, optional Orientation of the entity. Default is Orientation(). """ if not isinstance(route_ref, (Route, CatalogReference)): raise TypeError( "route input not of type Route or CatalogReference" ) self.route_ref = route_ref self.s = convert_float(s) self.t = convert_float(t) if not isinstance(orientation, Orientation): raise TypeError("input orientation is not of type Orientation") self.orientation = orientation def __eq__(self, other) -> bool: if isinstance(other, RoutePositionInRoadCoordinates): if ( self.s == other.s and self.t == other.t and self.orientation == other.orientation and self.route_ref == other.route_ref ): return True return False @staticmethod def parse(element: ET.Element) -> "RoutePositionInRoadCoordinates": """Parse the XML element of RoutePositionInRoadCoordinates. Parameters ---------- element : xml.etree.ElementTree.Element A position element (same as generated by the class itself). Returns ------- RoutePositionInRoadCoordinates A RoutePositionInRoadCoordinates object. """ position_element = find_mandatory_field(element, "RoutePosition") if position_element.find("Orientation") is not None: orientation = Orientation.parse( find_mandatory_field(position_element, "Orientation") ) else: orientation = Orientation() road_coord_element = find_mandatory_field( position_element, "InRoutePosition/FromRoadCoordinates" ) s = convert_float(road_coord_element.attrib["pathS"]) t = convert_float(road_coord_element.attrib["t"]) route_element = find_mandatory_field(position_element, "RouteRef") if route_element.find("Route") is not None: routeref = Route.parse( find_mandatory_field(route_element, "Route") ) else: routeref = CatalogReference.parse( find_mandatory_field(route_element, "CatalogReference") ) return RoutePositionInRoadCoordinates(routeref, s, t, orientation) def get_element(self, elementname: str = "Position") -> ET.Element: """Return the ElementTree of the RoutePositionInRoadCoordinates. Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the RoutePositionInRoadCoordinates. """ element = ET.Element(elementname) relement = ET.SubElement(element, "RoutePosition") routeref = ET.SubElement(relement, "RouteRef") routeref.append(self.route_ref.get_element()) relement.append(self.orientation.get_element()) inroute = ET.SubElement(relement, "InRoutePosition") ET.SubElement( inroute, "FromRoadCoordinates", attrib={"pathS": str(self.s), "t": str(self.t)}, ) return elementRoutePositionInRoadCoordinates creates a RoutePosition with the InRoutePosition of type PositionInRoadCoordinates.
Parameters
route_ref:RouteorCatalogReference- Reference to the route the position is calculated from.
s:float- S coordinate of the road.
t:float- T coordinate of the road.
orientation:Orientation, optional- Orientation of the entity. Default is Orientation().
Attributes
route_ref:RouteorCatalogReference- Reference to the route the position is calculated from.
s:float- S coordinate of the road.
t:float- T coordinate of the road.
orientation:Orientation- Orientation of the entity.
Methods
parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element() Returns the full ElementTree of the class.
Initialize the RoutePositionInRoadCoordinates class.
Parameters
route_ref:RouteorCatalogReference- Reference to the route the position is calculated from.
s:float- S coordinate of the road.
t:float- T coordinate of the road.
orientation:Orientation, optional- Orientation of the entity. Default is Orientation().
Ancestors
- scenariogeneration.xosc.utils._PositionType
- VersionBase
Static methods
def parse(element: xml.etree.ElementTree.Element) ‑> RoutePositionInRoadCoordinates-
Expand source code
@staticmethod def parse(element: ET.Element) -> "RoutePositionInRoadCoordinates": """Parse the XML element of RoutePositionInRoadCoordinates. Parameters ---------- element : xml.etree.ElementTree.Element A position element (same as generated by the class itself). Returns ------- RoutePositionInRoadCoordinates A RoutePositionInRoadCoordinates object. """ position_element = find_mandatory_field(element, "RoutePosition") if position_element.find("Orientation") is not None: orientation = Orientation.parse( find_mandatory_field(position_element, "Orientation") ) else: orientation = Orientation() road_coord_element = find_mandatory_field( position_element, "InRoutePosition/FromRoadCoordinates" ) s = convert_float(road_coord_element.attrib["pathS"]) t = convert_float(road_coord_element.attrib["t"]) route_element = find_mandatory_field(position_element, "RouteRef") if route_element.find("Route") is not None: routeref = Route.parse( find_mandatory_field(route_element, "Route") ) else: routeref = CatalogReference.parse( find_mandatory_field(route_element, "CatalogReference") ) return RoutePositionInRoadCoordinates(routeref, s, t, orientation)Parse the XML element of RoutePositionInRoadCoordinates.
Parameters
element:xml.etree.ElementTree.Element- A position element (same as generated by the class itself).
Returns
RoutePositionInRoadCoordinates- A RoutePositionInRoadCoordinates object.
Methods
def get_element(self, elementname: str = 'Position') ‑> xml.etree.ElementTree.Element-
Expand source code
def get_element(self, elementname: str = "Position") -> ET.Element: """Return the ElementTree of the RoutePositionInRoadCoordinates. Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the RoutePositionInRoadCoordinates. """ element = ET.Element(elementname) relement = ET.SubElement(element, "RoutePosition") routeref = ET.SubElement(relement, "RouteRef") routeref.append(self.route_ref.get_element()) relement.append(self.orientation.get_element()) inroute = ET.SubElement(relement, "InRoutePosition") ET.SubElement( inroute, "FromRoadCoordinates", attrib={"pathS": str(self.s), "t": str(self.t)}, ) return elementReturn the ElementTree of the RoutePositionInRoadCoordinates.
Returns
xml.etree.ElementTree.Element- The ElementTree representation of the RoutePositionInRoadCoordinates.
class RoutePositionOfCurrentEntity (route_ref: VersionBase,
entity: str,
orientation: Orientation = <scenariogeneration.xosc.utils.Orientation object>)-
Expand source code
class RoutePositionOfCurrentEntity(_PositionType): """RoutePositionOfCurrentEntity creates a RoutePosition with the InRoutePosition of type PositionOfCurrentEntity. Parameters ---------- route_ref : Route or CatalogReference Reference to the route the position is calculated from. entity : str Reference to the entity on the route. orientation : Orientation, optional Orientation of the entity. Default is Orientation(). Attributes ---------- route_ref : Route or CatalogReference Reference to the route the position is calculated from. entity : str Reference to the entity on the route. orientation : Orientation Orientation of the entity. Methods ------- parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element() Returns the full ElementTree of the class. """ def __init__( self, route_ref: VersionBase, entity: str, orientation: Orientation = Orientation(), ) -> None: """Initialize the RoutePositionOfCurrentEntity class. Parameters ---------- route_ref : Route or CatalogReference Reference to the route the position is calculated from. entity : str Reference to the entity on the route. orientation : Orientation, optional Orientation of the entity. Default is Orientation(). """ if not isinstance(route_ref, (Route, CatalogReference)): raise TypeError( "route input not of type Route or CatalogReference" ) self.route_ref = route_ref self.entity = entity if not isinstance(orientation, Orientation): raise TypeError("input orientation is not of type Orientation") self.orientation = orientation def __eq__(self, other) -> bool: if isinstance(other, RoutePositionOfCurrentEntity): if ( self.entity == other.entity and self.orientation == other.orientation and self.route_ref == other.route_ref ): return True return False @staticmethod def parse(element: ET.Element) -> "RoutePositionOfCurrentEntity": """Parse the XML element of RoutePositionOfCurrentEntity. Parameters ---------- element : xml.etree.ElementTree.Element A position element (same as generated by the class itself). Returns ------- RoutePositionOfCurrentEntity A RoutePositionOfCurrentEntity object. """ position_element = find_mandatory_field(element, "RoutePosition") if position_element.find("Orientation") is not None: orientation = Orientation.parse( find_mandatory_field(position_element, "Orientation") ) else: orientation = Orientation() entityelement = find_mandatory_field( position_element, "InRoutePosition/FromCurrentEntity" ) entity = entityelement.attrib["entityRef"] route_element = find_mandatory_field(position_element, "RouteRef") if route_element.find("Route") is not None: routeref = Route.parse( find_mandatory_field(route_element, "Route") ) else: routeref = CatalogReference.parse( find_mandatory_field(route_element, "CatalogReference") ) return RoutePositionOfCurrentEntity(routeref, entity, orientation) def get_element(self, elementname: str = "Position") -> ET.Element: """Return the ElementTree of the RoutePositionOfCurrentEntity. Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the RoutePositionOfCurrentEntity. """ element = ET.Element(elementname) relement = ET.SubElement(element, "RoutePosition") routeref = ET.SubElement(relement, "RouteRef") routeref.append(self.route_ref.get_element()) relement.append(self.orientation.get_element()) inroute = ET.SubElement(relement, "InRoutePosition") ET.SubElement( inroute, "FromCurrentEntity", attrib={"entityRef": self.entity} ) return elementRoutePositionOfCurrentEntity creates a RoutePosition with the InRoutePosition of type PositionOfCurrentEntity.
Parameters
route_ref:RouteorCatalogReference- Reference to the route the position is calculated from.
entity:str- Reference to the entity on the route.
orientation:Orientation, optional- Orientation of the entity. Default is Orientation().
Attributes
route_ref:RouteorCatalogReference- Reference to the route the position is calculated from.
entity:str- Reference to the entity on the route.
orientation:Orientation- Orientation of the entity.
Methods
parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element() Returns the full ElementTree of the class.
Initialize the RoutePositionOfCurrentEntity class.
Parameters
route_ref:RouteorCatalogReference- Reference to the route the position is calculated from.
entity:str- Reference to the entity on the route.
orientation:Orientation, optional- Orientation of the entity. Default is Orientation().
Ancestors
- scenariogeneration.xosc.utils._PositionType
- VersionBase
Static methods
def parse(element: xml.etree.ElementTree.Element) ‑> RoutePositionOfCurrentEntity-
Expand source code
@staticmethod def parse(element: ET.Element) -> "RoutePositionOfCurrentEntity": """Parse the XML element of RoutePositionOfCurrentEntity. Parameters ---------- element : xml.etree.ElementTree.Element A position element (same as generated by the class itself). Returns ------- RoutePositionOfCurrentEntity A RoutePositionOfCurrentEntity object. """ position_element = find_mandatory_field(element, "RoutePosition") if position_element.find("Orientation") is not None: orientation = Orientation.parse( find_mandatory_field(position_element, "Orientation") ) else: orientation = Orientation() entityelement = find_mandatory_field( position_element, "InRoutePosition/FromCurrentEntity" ) entity = entityelement.attrib["entityRef"] route_element = find_mandatory_field(position_element, "RouteRef") if route_element.find("Route") is not None: routeref = Route.parse( find_mandatory_field(route_element, "Route") ) else: routeref = CatalogReference.parse( find_mandatory_field(route_element, "CatalogReference") ) return RoutePositionOfCurrentEntity(routeref, entity, orientation)Parse the XML element of RoutePositionOfCurrentEntity.
Parameters
element:xml.etree.ElementTree.Element- A position element (same as generated by the class itself).
Returns
RoutePositionOfCurrentEntity- A RoutePositionOfCurrentEntity object.
Methods
def get_element(self, elementname: str = 'Position') ‑> xml.etree.ElementTree.Element-
Expand source code
def get_element(self, elementname: str = "Position") -> ET.Element: """Return the ElementTree of the RoutePositionOfCurrentEntity. Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the RoutePositionOfCurrentEntity. """ element = ET.Element(elementname) relement = ET.SubElement(element, "RoutePosition") routeref = ET.SubElement(relement, "RouteRef") routeref.append(self.route_ref.get_element()) relement.append(self.orientation.get_element()) inroute = ET.SubElement(relement, "InRoutePosition") ET.SubElement( inroute, "FromCurrentEntity", attrib={"entityRef": self.entity} ) return elementReturn the ElementTree of the RoutePositionOfCurrentEntity.
Returns
xml.etree.ElementTree.Element- The ElementTree representation of the RoutePositionOfCurrentEntity.
class Trajectory (name: str, closed: bool)-
Expand source code
class Trajectory(_BaseCatalog): """The Trajectory class creates a Trajectory. Parameters ---------- name : str Name of the trajectory. closed : bool If the trajectory is closed at the end. Attributes ---------- name : str Name of the trajectory. closed : bool If the trajectory is closed at the end. parameters : ParameterDeclarations Parameters for the trajectory. shapes : _TrajectoryShape The shape building the trajectory. Methods ------- parse(element) Parses an ElementTree created by the class and returns an instance of the class. add_shape(shape) Adds a shape to the trajectory. add_parameter(parameter) Adds a parameter to the route. append_to_catalog(filename) Adds the vehicle to an existing catalog. dump_to_catalog(filename, name, description, author) Creates a new catalog with the vehicle. get_element() Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class. """ def __init__(self, name: str, closed: bool) -> None: """Initialize the Trajectory. Parameters ---------- name : str Name of the trajectory. closed : bool If the trajectory is closed at the end. """ super().__init__() self.name = name self.closed = convert_bool(closed) self.shapes = None def __eq__(self, other) -> bool: if isinstance(other, Trajectory): if ( self.get_attributes() == other.get_attributes() and self.parameters == other.parameters and self.shapes == other.shapes ): return True return False @staticmethod def parse(element: ET.Element) -> "Trajectory": """Parse the XML element of Trajectory. Parameters ---------- element : xml.etree.ElementTree.Element A Trajectory element (same as generated by the class itself). Returns ------- Trajectory A Trajectory object. """ name = element.attrib["name"] closed = convert_bool(element.attrib["closed"]) pos_element = find_mandatory_field(element, "Shape") shape = _ShapeFactory.parse_shape(pos_element) params_element = element.find("ParameterDeclarations") if type(params_element) is ET.Element: params = ParameterDeclarations.parse(params_element) else: params = ParameterDeclarations() trajectory = Trajectory(name, closed) trajectory.add_shape(shape) for param in params.parameters: trajectory.add_parameter(param) return trajectory def add_shape(self, shape: _TrajectoryShape) -> "Trajectory": """Add a shape to the trajectory (only the same shape can be used). Parameters ---------- shape : _TrajectoryShape The shape to be added to the trajectory. """ if not isinstance(shape, (Polyline, Clothoid, Nurbs, ClothoidSpline)): raise TypeError("shape input neither of type _TrajectoryShape") self.shapes = shape return self def get_attributes(self) -> dict: """Return the attributes of the Trajectory as a dictionary. Returns ------- dict A dictionary containing the attributes of the Trajectory. """ retdict = {} retdict["name"] = self.name retdict["closed"] = get_bool_string(self.closed) return retdict def get_element(self) -> ET.Element: """Return the ElementTree of the Trajectory. Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the Trajectory. """ element = ET.Element("Trajectory", attrib=self.get_attributes()) self.add_parameters_to_element(element) if self.shapes: element.append(self.shapes.get_element()) else: raise NotEnoughInputArguments( "No shape has been added to the trajectory" ) return elementThe Trajectory class creates a Trajectory.
Parameters
name:str- Name of the trajectory.
closed:bool- If the trajectory is closed at the end.
Attributes
name:str- Name of the trajectory.
closed:bool- If the trajectory is closed at the end.
parameters:ParameterDeclarations- Parameters for the trajectory.
shapes:_TrajectoryShape- The shape building the trajectory.
Methods
parse(element) Parses an ElementTree created by the class and returns an instance of the class. add_shape(shape) Adds a shape to the trajectory. add_parameter(parameter) Adds a parameter to the route. append_to_catalog(filename) Adds the vehicle to an existing catalog. dump_to_catalog(filename, name, description, author) Creates a new catalog with the vehicle. get_element() Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class.
Initialize the Trajectory.
Parameters
name:str- Name of the trajectory.
closed:bool- If the trajectory is closed at the end.
Ancestors
- scenariogeneration.xosc.utils._BaseCatalog
- VersionBase
Static methods
def parse(element: xml.etree.ElementTree.Element) ‑> Trajectory-
Expand source code
@staticmethod def parse(element: ET.Element) -> "Trajectory": """Parse the XML element of Trajectory. Parameters ---------- element : xml.etree.ElementTree.Element A Trajectory element (same as generated by the class itself). Returns ------- Trajectory A Trajectory object. """ name = element.attrib["name"] closed = convert_bool(element.attrib["closed"]) pos_element = find_mandatory_field(element, "Shape") shape = _ShapeFactory.parse_shape(pos_element) params_element = element.find("ParameterDeclarations") if type(params_element) is ET.Element: params = ParameterDeclarations.parse(params_element) else: params = ParameterDeclarations() trajectory = Trajectory(name, closed) trajectory.add_shape(shape) for param in params.parameters: trajectory.add_parameter(param) return trajectoryParse the XML element of Trajectory.
Parameters
element:xml.etree.ElementTree.Element- A Trajectory element (same as generated by the class itself).
Returns
Trajectory- A Trajectory object.
Methods
def add_shape(self, shape: scenariogeneration.xosc.position._TrajectoryShape) ‑> Trajectory-
Expand source code
def add_shape(self, shape: _TrajectoryShape) -> "Trajectory": """Add a shape to the trajectory (only the same shape can be used). Parameters ---------- shape : _TrajectoryShape The shape to be added to the trajectory. """ if not isinstance(shape, (Polyline, Clothoid, Nurbs, ClothoidSpline)): raise TypeError("shape input neither of type _TrajectoryShape") self.shapes = shape return selfAdd a shape to the trajectory (only the same shape can be used).
Parameters
shape:_TrajectoryShape- The shape to be added to the trajectory.
def get_attributes(self) ‑> dict-
Expand source code
def get_attributes(self) -> dict: """Return the attributes of the Trajectory as a dictionary. Returns ------- dict A dictionary containing the attributes of the Trajectory. """ retdict = {} retdict["name"] = self.name retdict["closed"] = get_bool_string(self.closed) return retdictReturn the attributes of the Trajectory as a dictionary.
Returns
dict- A dictionary containing the attributes of the Trajectory.
def get_element(self) ‑> xml.etree.ElementTree.Element-
Expand source code
def get_element(self) -> ET.Element: """Return the ElementTree of the Trajectory. Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the Trajectory. """ element = ET.Element("Trajectory", attrib=self.get_attributes()) self.add_parameters_to_element(element) if self.shapes: element.append(self.shapes.get_element()) else: raise NotEnoughInputArguments( "No shape has been added to the trajectory" ) return elementReturn the ElementTree of the Trajectory.
Returns
xml.etree.ElementTree.Element- The ElementTree representation of the Trajectory.
class TrajectoryPosition (trajectory: VersionBase,
s: float,
t: float | None = None,
orientation: Orientation = <scenariogeneration.xosc.utils.Orientation object>)-
Expand source code
class TrajectoryPosition(_PositionType): """TrajectoryPosition creates a TrajectoryPosition in OpenSCENARIO. Parameters ---------- trajectory : Trajectory or CatalogReference T coordinate of the road. s : float S coordinate of the trajectory. t : float, optional S coordinate of the road. Default is None. orientation : Orientation, optional Orientation of the entity. Default is Orientation(). Attributes ---------- trajectory : Trajectory or CatalogReference T coordinate of the road. s : float S coordinate of the trajectory. t : float S coordinate of the road. Default is None. orientation : Orientation Orientation of the entity. Methods ------- parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element() Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class. """ def __init__( self, trajectory: VersionBase, s: float, t: Optional[float] = None, orientation: Orientation = Orientation(), ) -> None: """Initialize the TrajectoryPosition class. Parameters ---------- trajectory : Trajectory or CatalogReference T coordinate of the road. s : float S coordinate of the trajectory. t : float, optional S coordinate of the road. Default is None. orientation : Orientation, optional Orientation of the entity. Default is Orientation(). """ if not isinstance(trajectory, (Trajectory, CatalogReference)): raise TypeError( "trajectory input not of type Trajectory or CatalogReference" ) self.trajectory = trajectory self.s = convert_float(s) self.t = convert_float(t) if not isinstance(orientation, Orientation): raise TypeError("input orientation is not of type Orientation") self.orientation = orientation def __eq__(self, other) -> bool: if isinstance(other, TrajectoryPosition): if ( self.get_attributes() == other.get_attributes() and self.orientation == other.orientation and self.trajectory == other.trajectory ): return True return False @staticmethod def parse(element: ET.Element) -> "TrajectoryPosition": """Parse the XML element of TrajectoryPosition. Parameters ---------- element : xml.etree.ElementTree.Element A position element (same as generated by the class itself). Returns ------- TrajectoryPosition A TrajectoryPosition object. """ position_element = find_mandatory_field(element, "TrajectoryPosition") if position_element.find("Orientation") is not None: orientation = Orientation.parse( find_mandatory_field(position_element, "Orientation") ) else: orientation = Orientation() s = position_element.attrib["s"] t = None if "t" in position_element: s = position_element.attrib["s"] trajectory_element = find_mandatory_field( position_element, "TrajectoryRef" ) if trajectory_element.find("Trajectory") is not None: trajectory = Trajectory.parse( find_mandatory_field(trajectory_element, "Trajectory") ) else: trajectory = CatalogReference.parse( find_mandatory_field(trajectory_element, "CatalogReference") ) return TrajectoryPosition(trajectory, s, t, orientation) def get_attributes(self) -> dict: """Return the attributes of the TrajectoryPosition as a dictionary. Returns ------- dict A dictionary containing the attributes of the TrajectoryPosition. """ retdict = {} retdict["s"] = str(self.s) if self.t is not None: retdict["t"] = str(self.t) return retdict def get_element(self, elementname: str = "Position") -> ET.Element: """Return the ElementTree of the TrajectoryPosition. Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the TrajectoryPosition. """ if self.isVersion(minor=0): raise OpenSCENARIOVersionError( "TrajectoryPosition was introduced in OpenSCENARIO V1.1" ) element = ET.Element(elementname) traj_element = ET.SubElement( element, "TrajectoryPosition", attrib=self.get_attributes() ) trajref_element = ET.SubElement(traj_element, "TrajectoryRef") trajref_element.append(self.trajectory.get_element()) traj_element.append(self.orientation.get_element()) return elementTrajectoryPosition creates a TrajectoryPosition in OpenSCENARIO.
Parameters
trajectory:TrajectoryorCatalogReference- T coordinate of the road.
s:float- S coordinate of the trajectory.
t:float, optional- S coordinate of the road. Default is None.
orientation:Orientation, optional- Orientation of the entity. Default is Orientation().
Attributes
trajectory:TrajectoryorCatalogReference- T coordinate of the road.
s:float- S coordinate of the trajectory.
t:float- S coordinate of the road. Default is None.
orientation:Orientation- Orientation of the entity.
Methods
parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element() Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class.
Initialize the TrajectoryPosition class.
Parameters
trajectory:TrajectoryorCatalogReference- T coordinate of the road.
s:float- S coordinate of the trajectory.
t:float, optional- S coordinate of the road. Default is None.
orientation:Orientation, optional- Orientation of the entity. Default is Orientation().
Ancestors
- scenariogeneration.xosc.utils._PositionType
- VersionBase
Static methods
def parse(element: xml.etree.ElementTree.Element) ‑> TrajectoryPosition-
Expand source code
@staticmethod def parse(element: ET.Element) -> "TrajectoryPosition": """Parse the XML element of TrajectoryPosition. Parameters ---------- element : xml.etree.ElementTree.Element A position element (same as generated by the class itself). Returns ------- TrajectoryPosition A TrajectoryPosition object. """ position_element = find_mandatory_field(element, "TrajectoryPosition") if position_element.find("Orientation") is not None: orientation = Orientation.parse( find_mandatory_field(position_element, "Orientation") ) else: orientation = Orientation() s = position_element.attrib["s"] t = None if "t" in position_element: s = position_element.attrib["s"] trajectory_element = find_mandatory_field( position_element, "TrajectoryRef" ) if trajectory_element.find("Trajectory") is not None: trajectory = Trajectory.parse( find_mandatory_field(trajectory_element, "Trajectory") ) else: trajectory = CatalogReference.parse( find_mandatory_field(trajectory_element, "CatalogReference") ) return TrajectoryPosition(trajectory, s, t, orientation)Parse the XML element of TrajectoryPosition.
Parameters
element:xml.etree.ElementTree.Element- A position element (same as generated by the class itself).
Returns
TrajectoryPosition- A TrajectoryPosition object.
Methods
def get_attributes(self) ‑> dict-
Expand source code
def get_attributes(self) -> dict: """Return the attributes of the TrajectoryPosition as a dictionary. Returns ------- dict A dictionary containing the attributes of the TrajectoryPosition. """ retdict = {} retdict["s"] = str(self.s) if self.t is not None: retdict["t"] = str(self.t) return retdictReturn the attributes of the TrajectoryPosition as a dictionary.
Returns
dict- A dictionary containing the attributes of the TrajectoryPosition.
def get_element(self, elementname: str = 'Position') ‑> xml.etree.ElementTree.Element-
Expand source code
def get_element(self, elementname: str = "Position") -> ET.Element: """Return the ElementTree of the TrajectoryPosition. Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the TrajectoryPosition. """ if self.isVersion(minor=0): raise OpenSCENARIOVersionError( "TrajectoryPosition was introduced in OpenSCENARIO V1.1" ) element = ET.Element(elementname) traj_element = ET.SubElement( element, "TrajectoryPosition", attrib=self.get_attributes() ) trajref_element = ET.SubElement(traj_element, "TrajectoryRef") trajref_element.append(self.trajectory.get_element()) traj_element.append(self.orientation.get_element()) return elementReturn the ElementTree of the TrajectoryPosition.
Returns
xml.etree.ElementTree.Element- The ElementTree representation of the TrajectoryPosition.
class Waypoint (position: scenariogeneration.xosc.utils._PositionType,
routestrategy: RouteStrategy)-
Expand source code
class Waypoint(VersionBase): """The Waypoint class creates a waypoint for a route. Parameters ---------- position : _PositionType Any position for the route. routestrategy : RouteStrategy Routing strategy for this waypoint. Attributes ---------- position : _PositionType Any position for the route. routestrategy : RouteStrategy Routing strategy for this waypoint. Methods ------- parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element() Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class. """ def __init__( self, position: _PositionType, routestrategy: RouteStrategy ) -> None: """Initialize the Waypoint. Parameters ---------- position : _PositionType Any position for the route. routestrategy : RouteStrategy Routing strategy for this waypoint. """ if not isinstance(position, _PositionType): raise TypeError("position input not a valid Position") self.position = position self.routestrategy = convert_enum(routestrategy, RouteStrategy) def __eq__(self, other) -> bool: if isinstance(other, Waypoint): if ( self.get_attributes() == other.get_attributes() and self.position == other.position ): return True return False @staticmethod def parse(element: ET.Element) -> "Waypoint": """Parse the XML element of Waypoint. Parameters ---------- element : xml.etree.ElementTree.Element A Waypoint element (same as generated by the class itself). Returns ------- Waypoint A Waypoint object. """ pos_element = find_mandatory_field(element, "Position") position = _PositionFactory.parse_position(pos_element) strategy = convert_enum(element.attrib["routeStrategy"], RouteStrategy) return Waypoint(position, strategy) def get_attributes(self) -> dict: """Return the attributes of the Waypoint as a dictionary. Returns ------- dict A dictionary containing the attributes of the Waypoint. """ return {"routeStrategy": self.routestrategy.get_name()} def get_element(self) -> ET.Element: """Return the ElementTree of the Waypoint. Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the Waypoint. """ element = ET.Element("Waypoint", attrib=self.get_attributes()) element.append(self.position.get_element()) return elementThe Waypoint class creates a waypoint for a route.
Parameters
position:_PositionType- Any position for the route.
routestrategy:RouteStrategy- Routing strategy for this waypoint.
Attributes
position:_PositionType- Any position for the route.
routestrategy:RouteStrategy- Routing strategy for this waypoint.
Methods
parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element() Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class.
Initialize the Waypoint.
Parameters
position:_PositionType- Any position for the route.
routestrategy:RouteStrategy- Routing strategy for this waypoint.
Ancestors
Static methods
def parse(element: xml.etree.ElementTree.Element) ‑> Waypoint-
Expand source code
@staticmethod def parse(element: ET.Element) -> "Waypoint": """Parse the XML element of Waypoint. Parameters ---------- element : xml.etree.ElementTree.Element A Waypoint element (same as generated by the class itself). Returns ------- Waypoint A Waypoint object. """ pos_element = find_mandatory_field(element, "Position") position = _PositionFactory.parse_position(pos_element) strategy = convert_enum(element.attrib["routeStrategy"], RouteStrategy) return Waypoint(position, strategy)Parse the XML element of Waypoint.
Parameters
element:xml.etree.ElementTree.Element- A Waypoint element (same as generated by the class itself).
Returns
Waypoint- A Waypoint object.
Methods
def get_attributes(self) ‑> dict-
Expand source code
def get_attributes(self) -> dict: """Return the attributes of the Waypoint as a dictionary. Returns ------- dict A dictionary containing the attributes of the Waypoint. """ return {"routeStrategy": self.routestrategy.get_name()}Return the attributes of the Waypoint as a dictionary.
Returns
dict- A dictionary containing the attributes of the Waypoint.
def get_element(self) ‑> xml.etree.ElementTree.Element-
Expand source code
def get_element(self) -> ET.Element: """Return the ElementTree of the Waypoint. Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the Waypoint. """ element = ET.Element("Waypoint", attrib=self.get_attributes()) element.append(self.position.get_element()) return elementReturn the ElementTree of the Waypoint.
Returns
xml.etree.ElementTree.Element- The ElementTree representation of the Waypoint.
class WorldPosition (x: float = 0,
y: float = 0,
z: float | None = None,
h: float | None = None,
p: float | None = None,
r: float | None = None)-
Expand source code
class WorldPosition(_PositionType): """The WorldPosition creates a world position in OpenScenario. Parameters ---------- x : float X-coordinate of the entity. y : float Y-coordinate of the entity. z : float, optional Z-coordinate of the entity. Default is None. h : float, optional Heading of the entity. Default is None. p : float, optional Pitch of the entity. Default is None. r : float, optional Roll of the entity. Default is None. Attributes ---------- x : float X-coordinate of the entity. y : float Y-coordinate of the entity. z : float Z-coordinate of the entity. h : float Heading of the entity. p : float Pitch of the entity. r : float Roll of the entity. Methods ------- parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element(elementname) Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class. """ def __init__( self, x: float = 0, y: float = 0, z: Optional[float] = None, h: Optional[float] = None, p: Optional[float] = None, r: Optional[float] = None, ) -> None: """Initialize the WorldPosition. Parameters ---------- x : float X-coordinate of the entity. y : float Y-coordinate of the entity. z : float, optional Z-coordinate of the entity. Default is None. h : float, optional Heading of the entity. Default is None. p : float, optional Pitch of the entity. Default is None. r : float, optional Roll of the entity. Default is None. """ self.x = convert_float(x) self.y = convert_float(y) self.z = convert_float(z) self.h = convert_float(h) self.p = convert_float(p) self.r = convert_float(r) def __eq__(self, other) -> bool: if isinstance(other, WorldPosition): if self.get_attributes() == other.get_attributes(): return True return False @staticmethod def parse(element: ET.Element) -> "WorldPosition": """Parse the XML element of WorldPosition. Parameters ---------- element : xml.etree.ElementTree.Element A position element (same as generated by the class itself). Returns ------- WorldPosition A WorldPosition object. """ position_element = find_mandatory_field(element, "WorldPosition") x = convert_float(position_element.attrib["x"]) y = convert_float(position_element.attrib["y"]) z = None h = None r = None p = None if "z" in position_element.attrib: z = convert_float(position_element.attrib["z"]) if "h" in position_element.attrib: h = convert_float(position_element.attrib["h"]) if "p" in position_element.attrib: p = convert_float(position_element.attrib["p"]) if "r" in position_element.attrib: r = convert_float(position_element.attrib["r"]) return WorldPosition(x, y, z, h, p, r) def get_attributes(self) -> dict: """Return the attributes of the WorldPosition as a dictionary. Returns ------- dict A dictionary containing the attributes of the WorldPosition. """ retdict = {"x": str(self.x), "y": str(self.y)} if self.z is not None: retdict["z"] = str(self.z) if self.h is not None: retdict["h"] = str(self.h) if self.p is not None: retdict["p"] = str(self.p) if self.r is not None: retdict["r"] = str(self.r) return retdict def get_element(self, elementname: str = "Position") -> ET.Element: """Return the ElementTree of the WorldPosition. Parameters ---------- elementname : str, optional Used if another name is needed for the position. Default is "Position". Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the WorldPosition. """ element = ET.Element(elementname) ET.SubElement(element, "WorldPosition", attrib=self.get_attributes()) return elementThe WorldPosition creates a world position in OpenScenario.
Parameters
x:float- X-coordinate of the entity.
y:float- Y-coordinate of the entity.
z:float, optional- Z-coordinate of the entity. Default is None.
h:float, optional- Heading of the entity. Default is None.
p:float, optional- Pitch of the entity. Default is None.
r:float, optional- Roll of the entity. Default is None.
Attributes
x:float- X-coordinate of the entity.
y:float- Y-coordinate of the entity.
z:float- Z-coordinate of the entity.
h:float- Heading of the entity.
p:float- Pitch of the entity.
r:float- Roll of the entity.
Methods
parse(element) Parses an ElementTree created by the class and returns an instance of the class. get_element(elementname) Returns the full ElementTree of the class. get_attributes() Returns a dictionary of all attributes of the class.
Initialize the WorldPosition.
Parameters
x:float- X-coordinate of the entity.
y:float- Y-coordinate of the entity.
z:float, optional- Z-coordinate of the entity. Default is None.
h:float, optional- Heading of the entity. Default is None.
p:float, optional- Pitch of the entity. Default is None.
r:float, optional- Roll of the entity. Default is None.
Ancestors
- scenariogeneration.xosc.utils._PositionType
- VersionBase
Static methods
def parse(element: xml.etree.ElementTree.Element) ‑> WorldPosition-
Expand source code
@staticmethod def parse(element: ET.Element) -> "WorldPosition": """Parse the XML element of WorldPosition. Parameters ---------- element : xml.etree.ElementTree.Element A position element (same as generated by the class itself). Returns ------- WorldPosition A WorldPosition object. """ position_element = find_mandatory_field(element, "WorldPosition") x = convert_float(position_element.attrib["x"]) y = convert_float(position_element.attrib["y"]) z = None h = None r = None p = None if "z" in position_element.attrib: z = convert_float(position_element.attrib["z"]) if "h" in position_element.attrib: h = convert_float(position_element.attrib["h"]) if "p" in position_element.attrib: p = convert_float(position_element.attrib["p"]) if "r" in position_element.attrib: r = convert_float(position_element.attrib["r"]) return WorldPosition(x, y, z, h, p, r)Parse the XML element of WorldPosition.
Parameters
element:xml.etree.ElementTree.Element- A position element (same as generated by the class itself).
Returns
WorldPosition- A WorldPosition object.
Methods
def get_attributes(self) ‑> dict-
Expand source code
def get_attributes(self) -> dict: """Return the attributes of the WorldPosition as a dictionary. Returns ------- dict A dictionary containing the attributes of the WorldPosition. """ retdict = {"x": str(self.x), "y": str(self.y)} if self.z is not None: retdict["z"] = str(self.z) if self.h is not None: retdict["h"] = str(self.h) if self.p is not None: retdict["p"] = str(self.p) if self.r is not None: retdict["r"] = str(self.r) return retdictReturn the attributes of the WorldPosition as a dictionary.
Returns
dict- A dictionary containing the attributes of the WorldPosition.
def get_element(self, elementname: str = 'Position') ‑> xml.etree.ElementTree.Element-
Expand source code
def get_element(self, elementname: str = "Position") -> ET.Element: """Return the ElementTree of the WorldPosition. Parameters ---------- elementname : str, optional Used if another name is needed for the position. Default is "Position". Returns ------- xml.etree.ElementTree.Element The ElementTree representation of the WorldPosition. """ element = ET.Element(elementname) ET.SubElement(element, "WorldPosition", attrib=self.get_attributes()) return elementReturn the ElementTree of the WorldPosition.
Parameters
elementname:str, optional- Used if another name is needed for the position. Default is "Position".
Returns
xml.etree.ElementTree.Element- The ElementTree representation of the WorldPosition.