photons.io module

Custom file writer.

class photons.io.PhotonWriter(file, *, log_size=None)[source]

Bases: JSONWriter

A custom file writer.

Parameters:
  • file (str) – The path of the file to create.

  • log_size (int) – The initial size of DatasetLogging. If None or 0 then do not include log messages in the writer.

add_equipment(*records)[source]

Add equipment records to an ‘equipment’ Group.

Automatically creates the ‘equipment’ Group if it does not already exist.

Return type:

None

append(*data, name=None)[source]

Append data to a dataset.

Parameters:
  • data – The data to append. The timestamp when this method is called is automatically added to the dataset.

  • name (str) – The name of the dataset to append the data to. If not specified then appends to the latest dataset that was initialized.

Return type:

None

data(name=None)[source]

Return the current data of a dataset.

Parameters:

name (str) – The name of the dataset. If not specified then uses the name of the latest dataset that was initialized.

Return type:

ndarray

initialize(*header, microseconds=False, name='dataset', size=100, types=None, **metadata)[source]

Initialize a dataset.

Parameters:
  • *header (str) – The names of the header fields. The first field name is timestamp and it is automatically created.

  • microseconds (bool) – Whether to include microseconds in the timestamp.

  • name (str) – The name of the dataset to initialize. Can contain / to specify a subgroup (relative to the root Group).

  • size (int) – The initial size of the dataset. The dataset will automatically increase in size when it needs to.

  • types (list[type]) – The data types of each header field. If not specified then uses float for each field.

  • **metadata – The metadata to associate with the dataset.

Return type:

None

meta(name=None)[source]

Return the current metadata of a dataset.

Parameters:

name (str) – The name of the dataset. If not specified then uses the name of the latest dataset that was initialized.

Return type:

dict

static now_iso(ignore_microsecond=True)[source]

Get the current time in ISO-8601 format.

Parameters:

ignore_microsecond (bool) – Whether to ignore the microsecond part.

Return type:

str

update_metadata(name=None, **metadata)[source]

Update the metadata for a dataset.

Parameters:
  • name (str) – The name of the dataset to append the data to. If not specified then appends to the latest dataset that was initialized.

  • **metadata – The metadata to associate with the dataset.

Return type:

None

write(**kwargs)[source]

Overrides the write() method.

Return type:

None