FileFormatter

class lsst.daf.butler.formatters.file.FileFormatter(fileDescriptor: FileDescriptor, dataId: DataCoordinate, writeParameters: dict[str, Any] | None = None, writeRecipes: dict[str, Any] | None = None)

Bases: Formatter

Interface for reading and writing files on a POSIX file system.

Attributes Summary

extension

Default file extension to use for writing files.

Methods Summary

fromBytes(serializedDataset[, component])

Read serialized data into a Dataset or its component.

read([component])

Read data from a file.

toBytes(inMemoryDataset)

Serialize the Dataset to bytes based on formatter.

write(inMemoryDataset)

Write a Python object to a file.

Attributes Documentation

extension: str | None = None

Default file extension to use for writing files. None means that no modifications will be made to the supplied file extension. (str)

Methods Documentation

fromBytes(serializedDataset: bytes, component: str | None = None) Any

Read serialized data into a Dataset or its component.

Parameters:
serializedDatasetbytes

Bytes object to unserialize.

componentstr, optional

Component to read from the Dataset. Only used if the StorageClass for reading differed from the StorageClass used to write the file.

Returns:
inMemoryDatasetobject

The requested data as a Python object. The type of object is controlled by the specific formatter.

Raises:
NotImplementedError

Formatter does not support reading from bytes.

read(component: str | None = None) Any

Read data from a file.

Parameters:
componentstr, optional

Component to read from the file. Only used if the StorageClass for reading differed from the StorageClass used to write the file.

Returns:
inMemoryDatasetobject

The requested data as a Python object. The type of object is controlled by the specific formatter.

Raises:
ValueError

Component requested but this file does not seem to be a concrete composite.

NotImplementedError

Formatter does not implement a method to read from files.

toBytes(inMemoryDataset: Any) bytes

Serialize the Dataset to bytes based on formatter.

Parameters:
inMemoryDatasetobject

Object to serialize.

Returns:
serializedDatasetbytes

Bytes representing the serialized dataset.

Raises:
NotImplementedError

Formatter does not support reading from bytes.

write(inMemoryDataset: Any) None

Write a Python object to a file.

Parameters:
inMemoryDatasetobject

The Python object to store.

Returns:
pathstr

The path where the primary file is stored within the datastore.