File writers#
A file writer records sampled data to disk. Pass one as the rec_options argument of scene.start_recording, and the recorder manager samples your data function on schedule and writes each sample to the file. See Recording and playback for the recording workflow and the shared options (hz, buffer_size, save_on_reset) that every writer inherits.
gs.recorders.NPZFile#
Writes samples to a NumPy .npz archive. Best for numeric arrays you load back with numpy.load.
- class genesis.options.recorders.NPZFile(*, hz: float | None = None, buffer_size: int = 0, buffer_full_wait_time: float = 0.1, filename: str, save_on_reset: bool = False) None[source]#
Buffers all data and writes to a .npz file at cleanup.
Can handle any numeric or array-like or dict[str, array-like] data, e.g. from sensors.
- Parameters:
filename (str) – The name of the .npz file to save the data.
save_on_reset (bool, optional) – Whether to save the data on reset. Defaults to False. If True, a counter will be added to the filename and incremented on each reset.
gs.recorders.CSVFile#
Writes samples as rows in a .csv file. Best for scalar or low-dimensional data you inspect in a spreadsheet.
- class genesis.options.recorders.CSVFile(*, hz: float | None = None, buffer_size: int = 0, buffer_full_wait_time: float = 0.1, filename: str, save_on_reset: bool = False, header: tuple[str, ...] | None = None, save_every_write: bool = False) None[source]#
Writes to a .csv file using csv.writer.
Can handle any array-like or dict[str, array-like] output, e.g. from sensors. Values must be N-dimensional tensors, arrays or scalars (np.generic, int, float, str) If the data or header is a dict, it cannot be further nested. Values are processed in order.
- Parameters:
filename (str) – The name of the CSV file to save the data.
header (tuple[str] | None, optional) – Column headers for the CSV file. It should match the format of the incoming data, where each scalar value has an associated header. If the data is a dict, the header should match the total length of the number of values after flattening the values.
save_every_write (bool, optional) – Whether to flush the data to disk as soon as new data is recieved. Defaults to False.
save_on_reset (bool, optional) – Whether to save the data on scene reset. Defaults to False. If True, a counter will be added to the filename and incremented on each reset.
gs.recorders.VideoFile#
Encodes a stream of image frames to a video file. Pair it with a data function that returns a rendered frame.
- class genesis.options.recorders.VideoFile(*, hz: float | None = None, buffer_size: int = 0, buffer_full_wait_time: float = 0.1, filename: str, save_on_reset: bool = False, fps: int | None = None, name: str = '', codec: str = '', bitrate: float = 1.0, codec_options: dict[str, str] = <factory>) None[source]#
Stream video frames to file using PyAV.
The PyAV writer streams data directly to the file instead of buffering it in memory. Incoming data should either be grayscale [H, W] or color [H, W, RGB] where values are uint8 (0, 255).
- Parameters:
filename (str) – The path of the output video file ending in “.mp4”.
name (str) – The name of the video. Note that it may be different from filename. If empty, then filename will be used as a fallback. Default to “”.
fps (int, optional) – Frames per second for the video. Defaults to the data collection Hz (“real-time”).
codec (str, optional) – The codec to use for the video file. Defaults to “libx264”.
bitrate (float) – The bitrate of the video. This higher the better the quality of the video. Defaults to 1.0.
codec_options (dict[str, str]) – Additional low-level codec options that will be pass to ffmpeg. Empty by default.
save_on_reset (bool, optional) – Whether to save the data on reset. If True, a counter will be added to the filename and incremented on each reset. Defaults to False.
See also#
Recording and playback: the recording workflow and shared recorder options.
Plotters: live plotting instead of writing to a file.