FormatterV1inV2¶
- class lsst.daf.butler.FormatterV1inV2(file_descriptor: FileDescriptor, *, ref: DatasetRef, formatter: Formatter, write_parameters: Mapping[str, Any] | None = None, write_recipes: Mapping[str, Any] | None = None, **kwargs: Any)¶
Bases:
FormatterV2An implementation of a V2 formatter that provides a compatibility interface for V1 formatters.
- Parameters:
- file_descriptor
FileDescriptor, optional Identifies the file to read or write, and the associated storage classes and parameter information. Its value can be
Noneif the caller will never callFormatter.readorFormatter.write.- ref
DatasetRef The dataset associated with this formatter. Should not be a component dataset ref.
- formatter
Formatter A version 1
Formatterinstance. The V2 formatter layer forwards calls to this formatter.- write_parameters
dict, optional Any parameters to be hard-coded into this instance to control how the dataset is serialized.
- write_recipes
dict, optional Detailed write Recipes indexed by recipe name.
- **kwargs
Additional arguments that will be ignored but allow for
FormatterV1 parameters to be given.
- file_descriptor
Attributes Summary
This formatter can read from a local file.
Methods Summary
Extension to use when writing a file.
read_from_local_file(path[, component, ...])Read a dataset from a URI guaranteed to refer to the local file system.
segregate_parameters([parameters])Segregate the supplied parameters.
to_bytes(in_memory_dataset)Serialize the in-memory dataset to bytes.
validate_write_recipes(recipes)Validate supplied recipes for this formatter.
write_local_file(in_memory_dataset, uri)Serialize the in-memory dataset to a local file.
Attributes Documentation
Methods Documentation
- read_from_local_file(path: str, component: str | None = None, expected_size: int = -1) Any¶
Read a dataset from a URI guaranteed to refer to the local file system.
- Parameters:
- Returns:
- in_memory_dataset
objectorNotImplemented The Python object read from the resource or
NotImplemented.
- in_memory_dataset
- Raises:
- FormatterNotImplementedError
Raised if there is no implementation written to read data from a local file.
Notes
This method will only be called if the class property
can_read_from_local_fileisTrueand other options were not used.
- segregate_parameters(parameters: dict[str, Any] | None = None) tuple[dict, dict]¶
Segregate the supplied parameters.
This splits the parameters into those understood by the formatter and those not understood by the formatter.
Any unsupported parameters are assumed to be usable by associated assemblers.
- Parameters:
- parameters
dict, optional Parameters with values that have been supplied by the caller and which might be relevant for the formatter. If
Noneparameters will be read from the registeredFileDescriptor.
- parameters
- Returns:
- to_bytes(in_memory_dataset: Any) bytes¶
Serialize the in-memory dataset to bytes.
- Parameters:
- in_memory_dataset
object The Python object to serialize.
- in_memory_dataset
- Returns:
- serialized_dataset
bytes Bytes representing the serialized dataset.
- serialized_dataset
- Raises:
- FormatterNotImplementedError
Raised if the formatter has not implemented the method. This will not cause a problem if
write_local_filehas been implemented.
- validate_write_recipes(recipes: Mapping[str, Any] | None) Mapping[str, Any] | None¶
Validate supplied recipes for this formatter.
The recipes are supplemented with default values where appropriate.
- write_local_file(in_memory_dataset: Any, uri: ResourcePath) None¶
Serialize the in-memory dataset to a local file.
- Parameters:
- in_memory_dataset
object The Python object to serialize.
- uri
ResourcePath The URI to use when writing the file.
- in_memory_dataset
- Raises:
- FormatterNotImplementedError
Raised if the formatter subclass has not implemented this method or has failed to implement the
to_bytesmethod.
Notes
By default this method will attempt to call
to_bytesand then write these bytes to the file.