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.
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
- can_read_from_local_file: ClassVar[bool] = True#
This formatter can read from a local file.
Methods Documentation
- get_write_extension() str#
Extension to use when writing a file.
- 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#
- path
str Path to a local file that should be read.
- component
strorNone, optional The component to be read from the dataset.
- expected_size
int, optional If known, the expected size of the resource to read. This can be
-1indicates the file size is not known.
Returns#
- in_memory_dataset
objectorNotImplemented The Python object read from the resource or
NotImplemented.
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.- path
- 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.
Returns#
- supported
dict Those parameters supported by this formatter.
- unsupported
dict Those parameters not supported by this formatter.
- parameters
- to_bytes(in_memory_dataset: Any) bytes#
Serialize the in-memory dataset to bytes.
Parameters#
- in_memory_dataset
object The Python object to serialize.
Returns#
- serialized_dataset
bytes Bytes representing the 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.
- in_memory_dataset
- 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.
Parameters#
- recipes
dict Recipes to validate.
Returns#
- validated
dict Validated recipes.
Raises#
- RuntimeError
Raised if validation fails. The default implementation raises if any recipes are given.
- recipes
- 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.
Notes#
By default this method will attempt to call
to_bytesand then write these bytes to the file.Raises#
- FormatterNotImplementedError
Raised if the formatter subclass has not implemented this method or has failed to implement the
to_bytesmethod.
- in_memory_dataset
- file_descriptor