xpark.dataset.read_mcap#
- xpark.dataset.read_mcap(paths: str | list[str], *, topics: list[str] | set[str] | None = None, time_range: tuple[int, int] | TimeRange | None = None, message_types: list[str] | set[str] | None = None, include_metadata: bool = True, filesystem: pyarrow.fs.FileSystem | None = None, parallelism: int = -1, num_cpus: float | None = None, num_gpus: float | None = None, memory: float | None = None, ray_remote_args: dict[str, Any] | None = None, partition_filter: PathPartitionFilter | None = None, partitioning: Partitioning | None = None, include_paths: bool = False, ignore_missing_paths: bool = False, shuffle: Literal['files'] | FileShuffleConfig | None = None, file_extensions: list[str] | None = None, concurrency: int | None = None, override_num_blocks: int | None = None, packed: bool = False) Dataset#
Create a
Datasetfrom MCAP (Message Capture) files.MCAP is a format commonly used in robotics and autonomous systems for storing ROS2 messages and other time-series data. This reader provides predicate pushdown optimization for efficient filtering by topics, time ranges, and message types.
Message payloads are kept as raw bytes; decode them in downstream
map/map_batchesoperators.Examples
Read all MCAP files in a directory.
>>> import xpark >>> ds = xpark.dataset.read_mcap("s3://bucket/mcap-data/")
Read with filtering for specific topics and time range.
>>> from xpark.dataset.datasource import TimeRange >>> ds = xpark.dataset.read_mcap( ... "s3://bucket/mcap-data/", ... topics={"/camera/image_raw", "/lidar/points"}, ... time_range=TimeRange(start_time=1000000000, end_time=5000000000), ... )
Alternatively, use a tuple for time range (backwards compatible).
>>> ds = xpark.dataset.read_mcap( ... "s3://bucket/mcap-data/", ... topics={"/camera/image_raw", "/lidar/points"}, ... time_range=(1000000000, 5000000000), ... )
Read with file-level packing, aggregating an episode without any shuffle.
>>> ds = xpark.dataset.read_mcap("/data/logs/", packed=True) >>> ds = ds.map(decode_episode_fn)
- Parameters:
paths – A single file or directory, or a list of file or directory paths. A list of paths can contain both files and directories.
topics – Optional list or set of topic names to include. If specified, only messages from these topics will be read.
time_range – Optional time range for filtering messages by timestamp. Can be either a tuple of (start_time, end_time) in nanoseconds (for backwards compatibility) or a TimeRange object. Both values must be non-negative and start_time < end_time.
message_types – Optional list or set of message type names (schema names) to include. Only messages with matching schema names will be read.
include_metadata – Whether to include MCAP metadata fields in the output. Defaults to True. When True, includes schema, channel, and message metadata.
filesystem – The PyArrow filesystem implementation to read from.
parallelism – This argument is deprecated. Use
override_num_blocksargument.num_cpus – The number of CPUs to reserve for each parallel read worker.
num_gpus – The number of GPUs to reserve for each parallel read worker. For example, specify num_gpus=1 to request 1 GPU for each parallel read worker.
memory – The heap memory in bytes to reserve for each parallel read worker.
ray_remote_args – kwargs passed to
ray.remote()in the read tasks.partition_filter – A
PathPartitionFilter. Use with a custom callback to read only selected partitions of a dataset.partitioning – A
Partitioningobject that describes how paths are organized. Defaults toNone.include_paths – If
True, include the path to each file. File paths are stored in the'path'column.ignore_missing_paths – If True, ignores any file paths in
pathsthat are not found. Defaults to False.shuffle – If setting to “files”, randomly shuffle input files order before read. If setting to
FileShuffleConfig, you can pass a seed to shuffle the input files. Defaults to not shuffle withNone.file_extensions – A list of file extensions to filter files by. Defaults to
["mcap"].concurrency – The maximum number of Xpark tasks to run concurrently. Set this to control number of tasks to run concurrently. This doesn’t change the total number of tasks run or the total number of output blocks. By default, concurrency is dynamically decided based on the available resources.
override_num_blocks – Override the number of output blocks from all read tasks. By default, the number of output blocks is dynamically decided based on input data size and available resources. You shouldn’t manually set this value in most cases.
packed – Whether to output one row per MCAP file (file-level packing) instead of one row per message. When True, every message-level column is packed into a position-aligned list column (the i-th element of every list column belongs to the i-th message), so a full episode can be aggregated downstream from a single row without any shuffle. The output always contains the
pathcolumn, andinclude_metadatais forced to True because episode aggregation relies on schema metadata. Payload bytes are never json-decoded in packed mode, unlike the message-level output. Defaults to False (message-level, one row per message).
- Returns:
Datasetproducing records read from the specified MCAP files.