pyvrs.filter module¶
- class pyvrs.filter.FilteredVRSReader(reader: BaseVRSReader, record_filter: RecordFilter)[source]¶
Bases:
BaseVRSReader,ABCFilteredVRSReader represents subset of VRSReader after applying filter. This class essentially has the exact same methods as VRSReader but operates against subset of the file. Note that you can’t re-filter an already filtered VRSReader.
- property file_tags: Mapping[str, str]¶
Return a dict of all file tags present in this VRS file.
- Returns:
{<tag>: <value>}
- Return type:
Dictionary of all file tags
- find_stream(recordable_type_id: int, tag_name: str, tag_value: str) str[source]¶
Find stream matching recordable type and tag, and return its stream id. This call isn’t affected by the filter.
- Parameters:
recordable_type_id – stream_id is <recordable_type_id>-<instance_id>
tag_name – tag name that you are interested in
tag_value – tag value that you are interested in
- Returns:
Stream ID that starts with recordable_type_id and has a given tag pair.
- find_streams(recordable_type_id: int, flavor: str = '') List[str][source]¶
Find streams matching recordable type and flavor, and return sets of stream ids. This call isn’t affected by the filter.
- Parameters:
recordable_type_id – stream_id is <recordable_type_id>-<instance_id>
tag_name – tag name that you are interested in
tag_value – tag value that you are interested in
- Returns:
A set of stream IDs that start with recordable_type_id and has a given flavor.
- get_estimated_frame_rate(stream_id: str) float[source]¶
Get the estimated frame rate for the given stream_id.
- Parameters:
stream_id – stream_id that you are interested in.
- Returns:
The estimated frame rate.
- get_record_index_by_time(stream_id: str, timestamp: float, epsilon: float | None = None, record_type: RecordType | None = None) int[source]¶
Get index in filtered records by timestamp.
- Parameters:
stream_id – stream_id that you are interested in.
timestamp – timestamp that you are interested in.
epsilon – Optional argument. If specified we search for record in range of (timestamp-epsilon)-(timestamp+epsilon) and returns the nearest record.
record_type – Optional argument. If specified we search for record with the record_type.
- get_records_count(stream_id: str, record_type: RecordType) int[source]¶
Get the number of records for the stream_id & record_type.
- Parameters:
stream_id – stream_id you are interested in.
record_type – record type you are interested in.
- Returns:
The number of records for stream_id & record type
- get_stream_info(stream_id: str) Mapping[str, str][source]¶
Get details about a stream.
- Parameters:
stream_id – stream_id you are interested in.
- Returns:
An information about the stream in a dictionary.
- get_timestamp_for_index(index: int) float[source]¶
Get the timestamp corresponding to the given index.
- Parameters:
index – the index for the record
- Returns:
A timestamp corresponds to the index
- get_timestamp_list() List[float][source]¶
Get the list of timestamps corresponding to the given indices.
- Parameters:
indices – the list of indices we want to get the timestamp.
- Returns:
A list of timestamps correspond to the indices, if indices are None, we get the full timestamp list.
- property max_filter_timestamp: float¶
The value of max_timestamp when user called filter method on VRSReader.
- property max_timestamp: float¶
The timestamp for the last record that this reader is configured to read, given current filters. Return 0 if there are no record.
- might_contain_audio(stream_id: str) bool[source]¶
Check if the given stream_id contains an audio data.
- Parameters:
stream_id – stream_id that you are interested in.
- Returns:
Based on the config record, return if the stream contains an audio data.
- might_contain_images(stream_id: str) bool[source]¶
Check if the given stream_id contains an image data.
- Parameters:
stream_id – stream_id that you are interested in.
- Returns:
Based on the config record, return if the stream contains an image data.
- property min_filter_timestamp: float¶
The value of min_timestamp when user called filter method on VRSReader.
- property min_timestamp: float¶
The timestamp for the first record that this reader is configured to read, given current filters. Return 0 if there are no record.
- property n_records: int¶
The number of records that this reader is configured to read, given current filters.
- read_next_record(stream_id: str, record_type: str, index: int) VRSRecord | None[source]¶
Read the first record that matches stream_id and record_type and its index is greater or equal than given index.
- Parameters:
stream_id – stream_id that you are interested in.
record_type – record_type that you are interested in.
index – the absolute index in the file. Based on this index, try to find the previous record that matches stream_id & record_type
- Returns:
VRSRecord if there is a record, otherwise None
- read_prev_record(stream_id: str, record_type: str, index: int) VRSRecord | None[source]¶
Read the last record that matches stream_id and record_type and its index is smaller or equal than given index.
- Parameters:
stream_id – stream_id that you are interested in.
record_type – record_type that you are interested in.
index – the absolute index in the file. Based on this index, try to find the previous record that matches stream_id & record_type
- Returns:
VRSRecord if there is a record, otherwise None
- read_record_by_time(stream_id: str, timestamp: float, epsilon: float | None = None, record_type: RecordType | None = None) VRSRecord[source]¶
Read record by timestamp.
- Parameters:
stream_id – stream_id that you are interested in.
timestamp – timestamp that you are interested in.
epsilon – Optional argument. If specified we search for record in range of (timestamp-epsilon)-(timestamp+epsilon) and returns the nearest record.
record_type – Optional argument. If specified we search for record with the record_type.
- Returns:
VRSRecord corresponds to the stream_id & timestamp.
- Raises:
TimestampNotFoundError – If epsilon is not None and the record doesn’t exist within the time range.
ValueError – If epsilon is None and the record isn’t found using lower_bound.
- property record_types: Set[str]¶
The set of record types that this reader is configured to read, given current filters.
- set_image_conversion(conversion: ImageConversion) None[source]¶
Set default image conversion policy, and clears any stream specific setting.
- Parameters:
conversion – The image conversion you want to apply for all streams.
- set_stream_image_conversion(stream_id: str, conversion: ImageConversion) None[source]¶
Set image conversion policy for a specific stream.
- Parameters:
stream_id – The stream_id you want to apply image conversion to.
conversion – The image conversion you want to apply for a specific stream.
- set_stream_type_image_conversion(recordable_type_id: str, conversion: ImageConversion) int[source]¶
Set image conversion policy for streams of a specific device type.
- Parameters:
recordable_type_id – The recordable_type_id you want to apply image conversion to. If you specify 1000, streams with id 1000-* are the targets.
conversion – The image conversion you want to apply for a specific stream.
- Returns:
The number of streams affected.
- property stream_ids: Set[str]¶
The set of stream ids that this reader is configured to read, given current filters.
- property stream_tags: Mapping[str, Mapping[str, Any]]¶
Return a dict of all per-stream tags present in this VRS file.
- Returns:
{<stream_id>: {<tag>: <value>}}
- Return type:
Dictionary of all per-stream tags
- class pyvrs.filter.RecordFilter(record_types: Set[str], stream_ids: Set[str], min_timestamp: float, max_timestamp: float)[source]¶
Bases:
objectRecordFilter represents a filter that’s applied to the VRS file.
- max_timestamp: float¶
- min_timestamp: float¶
- record_types: Set[str]¶
- stream_ids: Set[str]¶
- class pyvrs.filter.SyncFilteredVRSReader(reader: BaseVRSReader, record_filter: RecordFilter)[source]¶
Bases:
FilteredVRSReaderSynchrnous version of FilteredVRSReader.