Data Writer

DataWriter is a class for writing data to a file.

class bosdyn.bddf.data_writer.DataWriter(outfile, annotations=None)[source]

Bases: object

Class for writing data to a file.

property file_index

Get the FileIndex proto used which describes how to access data in the file.

add_message_series(series_type, series_spec, content_type, type_name, is_metadata=False, annotations=None, additional_index_names=None)[source]

Add a new series for storing message data. Message data is variable-sized binary data.

Parameters
  • series_type – the kind of spec, corresponding to the set of keys expected in series_spec.

  • series_spec – dict of {key (string) -> value (string)| describing the series.

  • content_type – data encoding, like http content-type header (string)

  • type_name – string describing the kind of data

  • is_metadata – Metadata messages are needed to interpret other messages which may be stored in the file. If the file is split into parts, metadata messages must be duplicated into each part. (default=False)

  • annotations – optional dict of key (string) -> value (string) pairs to associate with the message channel

  • additional_index_names – names of additional timestamps to store with each message (list of string).

Returns series id (int).

add_pod_series(series_type, series_spec, type_enum, dimension=None, annotations=None)[source]

Add a new series for storing data POD data (float, double, int, etc….).

Parameters
  • series_type – the kind of spec, corresponding to the set of keys expected in series_spec.

  • series_spec – dict of {key (string) -> value (string)} describing the series.

  • type_enum – kind of values stored in the file (PodTypeEnum).

  • dimensions – None or empty-array means elements are single values, [3] means vectors of size 3, [4, 4] is a 4x4 matrix, etc….

  • annotations – optional dict of key (string) -> value (string) pairs to associate with the message channel

Returns series id (int).

add_series(series_type, series_spec, message_type=None, pod_type=None, annotations=None, additional_index_names=None)[source]

Register a new series for messages.

Parameters
  • series_type – the kind of spec, corresponding to the set of keys expected in series_spec.

  • series_spec – dict of {key (string) -> value (string)| describing the series.

  • message_type – MessageTypeDescriptor (need EITHER this OR pod_type)

  • pod_type – PodTypeDescriptor (need EITHER this OR pod_type)

  • annotations – optional dict of key (string) -> value (string) pairs to associate with the message channel

  • additional_index_names – names of additional timestamps to store with each message (list of string).

Returns series id (int).

Raises SeriesNotUniqueError if a series matching series_spec is already added.

write_data(series_index, timestamp_nsec, data, additional_indexes=None)[source]

Store binary data into the file, under a previously-defined channel.

Parameters
  • series_index – integer returned when series was registered with the file.

  • timestamp_nsec – nsec since unix epoch to timestamp the data

  • data – binary data to store

  • additional_indexss – additional timestamps if needed for this channel

Raises DataFormatError if the data or additional_indexes are not valid for this series.

run_on_close(thunk)[source]

Register a function to be called when file is closed, before index is written.