Module ouster.sdk.osf

Copyright (c) 2021, Ouster, Inc. All rights reserved.

API to work with OSF files


Low-Level API

Writing OSF files

Writer to create OSF file

class Writer(*args, **kwargs)

Simple writer interface for OSF file

All jobs are done with MetadataStore for adding metadata entries and stream interfaces that encodes messages and passes them to internal chunks writer.

Overloaded function.

  1. __init__(self: ouster.sdk._bindings.osf.Writer, file_name: str, chunk_size: int = 0) -> None

    Creates a Writer with specified chunk_size.

    Default chunk_size is 2 MB.

  2. __init__(self: ouster.sdk._bindings.osf.Writer, filename: str, info: ouster.sdk._bindings.client.SensorInfo, fields_to_write: list[str] = [], chunk_size: int = 0, encoder: ouster::osf::Encoder = None) -> None

    Creates a Writer with deafault STREAMING layout chunks writer.

    Using default chunk_size of 2MB.

    Args:

    filename (str): The filename to output to. info (sensor_info): The sensor info vector to use for a multi stream OSF

    file.

    chunk_size (int): The chunk size in bytes to use for the OSF file. This arg

    is optional, and if not provided the default value of 2MB is used. If the current chunk being written exceeds the chunk_size, a new chunk will be started on the next call to save. This allows an application to tune the number of messages (e.g. lidar scans) per chunk, which affects the granularity of the message index stored in the StreamingInfo in the file metadata. A smaller chunk_size means more messages are indexed and a larger number of index entries. A more granular index allows for more precise seeking at the slight expense of a larger file.

    fields_to_write (List[str]): The fields from scans to

    actually save into the OSF. If not provided uses the fields from the first saved lidar scan for each stream. This parameter is optional.

  3. __init__(self: ouster.sdk._bindings.osf.Writer, filename: str, info: list[ouster.sdk._bindings.client.SensorInfo], fields_to_write: list[str] = [], chunk_size: int = 0, encoder: ouster::osf::Encoder = None) -> None

    Creates a Writer with specified chunk_size.

    Default chunk_size is 2MB.

    Args:

    filename (str): The filename to output to. info (List[sensor_info]): The sensor info vector to use for a

    multi stream OSF file.

    fields_to_write (List[str]): The fields from scans to

    actually save into the OSF. If not provided uses the fields from the first saved lidar scan for each stream. This parameter is optional.

    chunk_size (int): The chunksize to use for the OSF file, this arg

    is optional.

add_metadata(self: ouster.sdk._bindings.osf.Writer, m: object) int

Add metadata entry to a file

add_sensor(self: ouster.sdk._bindings.osf.Writer, info: ouster.sdk._bindings.client.SensorInfo, fields_to_write: list[str] = []) int

Add a sensor to the OSF file.

Parameters:
  • info (sensor_info) – Sensor to add.

  • fields_to_write (List[str]) – The fields from scans to actually save into the OSF. If not provided uses the fields from the first saved lidar scan for each stream. This parameter is optional.

Returns (int):

The stream index to use to write scans to this sensor.

close(self: ouster.sdk._bindings.osf.Writer) None

Finish OSF file and flush everything to disk.

filename(self: ouster.sdk._bindings.osf.Writer) str

Return the osf file name.

Returns (str):

The OSF filename.

is_closed(self: ouster.sdk._bindings.osf.Writer) bool

Return the closed status of the writer.

Returns (bool):

The closed status of the writer.

property meta_store

Returns the metadata store that gives an access to all metadata entries in the file.

metadata_id(self: ouster.sdk._bindings.osf.Writer) str

Return the metadata identifier string.

Returns (str):

The OSF metadata identifier string.

save(*args, **kwargs)

Overloaded function.

  1. save(self: ouster.sdk._bindings.osf.Writer, stream_index: int, scan: ouster.sdk._bindings.client.LidarScan) -> None

    Save a lidar scan to the OSF file.

    Args:
    stream_index (int): The index of the corresponding

    sensor_info to use.

    scan (LidarScan): The scan to save.

  2. save(self: ouster.sdk._bindings.osf.Writer, stream_index: int, scan: ouster.sdk._bindings.client.LidarScan, ts: int) -> None

    Save a lidar scan to the OSF file.

    Args:
    stream_index (int): The index of the corresponding

    sensor_info to use.

    scan (LidarScan): The scan to save. ts (int): The timestamp to index the scan with.

  3. save(self: ouster.sdk._bindings.osf.Writer, scan: list[ouster.sdk._bindings.client.LidarScan]) -> None

    Save a set of lidar scans to the OSF file.

    Args:
    scans (List[LidarScan]): The scans to save. This will correspond

    to the list of sensor_infos.

  4. save(self: ouster.sdk._bindings.osf.Writer, stream_index: int, scan: ouster.sdk._bindings.client.LidarScan) -> None

    Save a lidar scan to the OSF file.

    Args:
    stream_index (int): The index of the corresponding

    sensor_info to use.

    scan (LidarScan): The scan to save.

  5. save(self: ouster.sdk._bindings.osf.Writer, scan: list[ouster.sdk._bindings.client.LidarScan]) -> None

    Save a set of lidar scans to the OSF file.

    Args:
    scans (List[LidarScan]): The scans to save. This will correspond

    to the list of sensor_infos.

save_message(*args, **kwargs)

Overloaded function.

  1. save_message(self: ouster.sdk._bindings.osf.Writer, stream_id: int, receive_ts: int, sensor_ts: int, buffer: numpy.ndarray[numpy.uint8]) -> None

    Low-level save message routine.

    Directly saves the message buffer with id and ts (ns) without any further checks.

  2. save_message(self: ouster.sdk._bindings.osf.Writer, stream_id: int, receive_ts: int, sensor_ts: int, buffer: Buffer) -> None

    Low-level save message routine.

    Directly saves the message buffer with id and ts (ns) without any further checks.

sensor_info(*args, **kwargs)

Overloaded function.

  1. sensor_info(self: ouster.sdk._bindings.osf.Writer) -> list[ouster.sdk._bindings.client.SensorInfo]

    Return the sensor info list.

    Returns (List[sensor_info]):

    The sensor info list.

  2. sensor_info(self: ouster.sdk._bindings.osf.Writer, stream_index: int) -> ouster.sdk._bindings.client.SensorInfo

    Return the sensor info of the specifed stream_index.

    Args:
    stream_index (in): The index of the sensor to return

    info about.

    Returns (sensor_info):

    The correct sensor info

sensor_info_count(self: ouster.sdk._bindings.osf.Writer) int

Return the number of sensor_info objects.

Returns (int):

The number of sensor_info objects.

set_metadata_id(self: ouster.sdk._bindings.osf.Writer, arg0: str) None

Set the metadata identifier string.

High-Level API

osf.Scans just read LidarScan objects from a file

class Scans(osf_file, *, cycle=False, sensor_id=0)[source]

Deprecated: An iterable stream of LidarScan read from OSF file (for a single sensor).

Parameters:
  • osf_file (str) – OSF filename as scans source

  • cycle (bool) – repeat infinitely after iteration is finished is True

  • sensor_id (int) – id of the sensor which LidarScan stream data to read

  • type). ((i.e. id of the metadata entry with osf.LidarSensor) –

  • 0 (default) –

__iter__()[source]

Iterator that returns LidarScan objects.

Return type:

Iterator[LidarScan]

withTs()[source]

Iterator that returns tuple of (ts, LidarScan)

Where ts - is a timestamp (ns) of a LidarScan (usually as a timestamp of a first packet in a LidarScan)

Return type:

Iterator[Tuple[int, LidarScan]]

close()[source]

Manually release any underlying resource.

Return type:

None

property metadata: SensorInfo

Return metadata of a Lidar Sensor used.

property is_live: bool

Returns true if the source is a live data stream.

property is_seekable: bool

True for non-live sources, This property can be True regardless of scan source being indexed or not.

property is_indexed: bool

True for IndexedPcap and OSF scan sources, this property tells users whether the underlying source allows for random access of scans, see __getitem__.

property field_types: List[FieldType]

Field types are present in the LidarScan objects on read from iterator

property fields: List[str]

Fields are present in the LidarScan objects on read from iterator

property scans_num: int | None

Number of scans available, in case of a live sensor or non-indexable scan source this method returns None

slice(_)[source]

Constructs a ScanSource matching the specificed slice

Return type:

ScanSource

clip(fields, lower, upper)[source]

Constructs a ScanSource matching the specificed clip options

Return type:

ScanSource

reduce(beams)[source]

Constructs a reduced ScanSource matching the beam count

Return type:

ScanSource

mask(fields, mask)[source]

Constructs a masked ScanSource matching the beam count

Return type:

ScanSource