l5kit.geometry package

l5kit.geometry.angle_between_vectors(v1: numpy.ndarray, v2: numpy.ndarray) → float

angle_between_vectors returns the angle in radians between two vectors.

Parameters
  • v1 (np.ndarray) – Vector 1 of shape (N)

  • v2 (np.ndarray) – Vector 2 of same shape as v1

Returns

angle in radians

Return type

float

l5kit.geometry.compute_yaw_around_north_from_direction(direction_vector: numpy.ndarray) → float

compute_yaw_from_direction computes the yaw as angle between a 2D input direction vector and the y-axis direction vector (0, 1).

Args:

direction_vector (np.ndarray): Vector of shape (2,)

Returns:

float: angle to (0,1) vector in radians

l5kit.geometry.crop_rectangle_from_image(image: numpy.ndarray, corners: numpy.ndarray) → numpy.ndarray

crop_rectangle_from_image takes an image and 4 corners in pixel coordinates, it returns the sub-image inside that cropped area, rotated upright.

Parameters
  • image (np.ndarray) – image to crop from

  • corners (np.ndarray) – corners, array of shape (4,2)

Returns

crop from input containing the corners

Return type

np.ndarray

l5kit.geometry.ecef_to_geodetic(point: Union[numpy.ndarray, Sequence[float]]) → numpy.ndarray

Convert given ECEF coordinate into latitude, longitude, altitude.

Parameters

point (Union[np.ndarray, Sequence[float]]) – ECEF coordinate vector

Returns

latitude, altitude, longitude

Return type

np.ndarray

l5kit.geometry.flip_y_axis(tm: numpy.ndarray, y_dim_size: int) → numpy.ndarray

Return a new matrix that also performs a flip on the y axis.

Parameters
  • tm – the original 3x3 matrix

  • y_dim_size – this should match the resolution on y. It makes all coordinates positive

Returns: a new 3x3 matrix.

l5kit.geometry.geodetic_to_ecef(lla_point: Union[numpy.ndarray, Sequence[float]]) → numpy.ndarray

Convert given latitude, longitude, and optionally altitude into ECEF coordinates. If no altitude is given, altitude 0 is assumed.

Parameters

lla_point (Union[np.ndarray, Sequence[float]]) – Latitude, Longitude and optionally Altitude

Returns

3D ECEF coordinate

Return type

np.ndarray

l5kit.geometry.get_transformation_matrix(translation: numpy.ndarray, rotation: numpy.ndarray) → numpy.ndarray

Get a 3D transformation matrix from translation vector and quaternion rotation

Parameters
  • translation (np.ndarray) – 3D translation vector

  • rotation (np.ndarray) – 4 quaternion values

Returns

4x4 transformation matrix

Return type

np.ndarray

l5kit.geometry.normalize_intensity(x: numpy.ndarray, max_intensity: float) → numpy.ndarray

Normalize (divide by max) and clip intensity values to fall between 0 and 1.

Parameters
  • x (np.npdarray) – numpy array of any shape

  • max_intensity (float) – Maximum intensity value (anything above this will become 1)

Returns

np.ndarray – array of same type and shape as x with values between 0 and 1 only

l5kit.geometry.points_within_bounds(coords: numpy.ndarray, shape: Union[Collection[int], numpy.ndarray]) → numpy.ndarray
Parameters
  • coords (np.ndarray) – (N,3)-shaped array containing points.

  • shape (tuple of ints or np.ndarray) – shape to use as bounds, should be length 3

Returns

Binary mask for given coords array which is True for points that fall within the bounds of shape.

l5kit.geometry.rotation33_as_yaw(rotation: numpy.ndarray) → float

Compute the yaw component of given 3x3 rotation matrix.

Parameters

rotation (np.ndarray) – 3x3 rotation matrix (np.float64 dtype recommended)

Returns

yaw rotation in radians

Return type

float

l5kit.geometry.transform_point(point: numpy.ndarray, transf_matrix: numpy.ndarray) → numpy.ndarray

Transform a single vector using transformation matrix.

Parameters
  • point (np.ndarray) – vector of shape (N)

  • transf_matrix (np.ndarray) – transformation matrix of shape (N+1, N+1)

Returns

vector of same shape as input point

Return type

np.ndarray

l5kit.geometry.transform_points(points: numpy.ndarray, transf_matrix: numpy.ndarray) → numpy.ndarray

Transform points using transformation matrix.

Parameters
  • points (np.ndarray) – Input points (Nx2), (Nx3) or (Nx4).

  • transf_matrix (np.ndarray) – 3x3 or 4x4 transformation matrix for 2D and 3D input respectively

Returns

array of shape (N,2) for 2D input points, or (N,3) points for 3D input points

Return type

np.ndarray

l5kit.geometry.transform_points_transposed(points: numpy.ndarray, transf_matrix: numpy.ndarray) → numpy.ndarray

Transform points using transformation matrix.

Parameters
  • points (np.ndarray) – Input points (2xN), (3xN) or (4xN).

  • transf_matrix (np.ndarray) – 3x3 or 4x4 transformation matrix for 2D and 3D input respectively

Returns

array of shape (2,N) for 2D input points, or (3,N) points for 3D input points

Return type

np.ndarray

l5kit.geometry.voxel_coords_to_intensity_grid(voxel_coords: numpy.ndarray, shape: tuple, dtype: numpy.dtype = <class 'numpy.float32'>, drop_out_of_bounds: bool = True) → numpy.ndarray

Puts coords into a grid: for each grid cell the number of points is written there.

Parameters
  • voxel_coords (np.ndarray) – input array with coords (N,3) in intensity grid

  • shape (tuple of ints) – intensity grid shape

Keyword Arguments
  • dtype (data-type) – data type for the intensity grid (default: {np.float32})

  • drop_out_of_bounds (bool) – [description] (default: {True})

Returns

np.ndarray – Array with given shape, the value of each cell is the amount of coords for that point.

l5kit.geometry.world_to_image_pixels_matrix(image_shape: Tuple[int, int], pixel_size_m: numpy.ndarray, ego_translation_m: numpy.ndarray, ego_yaw_rad: Optional[float] = None, ego_center_in_image_ratio: Optional[numpy.ndarray] = None) → numpy.ndarray

Constructs a transformation matrix from world coordinates to image pixels. Note: we’re ignoring Z coord, with the assumption that it won’t change dramatically. This means last row of the matrix will be [0,0,1] and we will transform 2D points in fact (X,Y)

Args: image_shape (Tuple[int, int]): the size of the image pixel_size_m (np.ndarray): how many meters a pixel cover in the two directions ego_translation_m (np.ndarray): translation of the ego in meters in world-coordinates ego_yaw_rad (Optional[float]):if defined, rotation is applied so that ego will always face to the right

in the resulting image coordinates

ego_center_in_image_ratio (Optional[np.ndarray]): enables to position the ego in different places

in the resulting image. The [0.5, 0.5] value puts it in the center

Returns

3x3 transformation matrix

Return type

np.ndarray

l5kit.geometry.yaw_as_rotation33(yaw: float) → numpy.ndarray

Create a 3x3 rotation matrix from given yaw. The rotation is counter-clockwise and it is equivalent to: [cos(yaw), -sin(yaw), 0.0], [sin(yaw), cos(yaw), 0.0], [0.0, 0.0, 1.0],

Parameters

yaw (float) – yaw rotation in radians

Returns

3x3 rotation matrix

Return type

np.ndarray