Butler¶
- 
class lsst.daf.butler.Butler(config: Union[lsst.daf.butler.core.config.Config, str, None] = None, *, butler: Optional[lsst.daf.butler._butler.Butler] = None, collection: Optional[str] = None, run: Optional[str] = None, searchPaths: Optional[List[str]] = None, writeable: Optional[bool] = None)¶
- Bases: - object- Main entry point for the data access system. - Parameters: - config : ButlerConfig,Configorstr, optional.
- Configuration. Anything acceptable to the - ButlerConfigconstructor. If a directory path is given the configuration will be read from a- butler.yamlfile in that location. If- Noneis given default values will be used.
- butler : Butler, optional.
- If provided, construct a new Butler that uses the same registry and datastore as the given one, but with the given collection and run. Incompatible with the - config,- searchPaths, and- writeablearguments.
- collection : str, optional
- Collection to use for all input lookups. May be - Noneto either use the value passed to- run, or to defer passing a collection until the methods that require one are called.
- run : str, optional
- Name of the run datasets should be output to; also used as a tagged collection name these dataset will be associated with. If the run does not exist, it will be created. If - collectionis- None, this collection will be used for input lookups as well; if not, it must have the same value as- run.
- searchPaths : listofstr, optional
- Directory paths to search when calculating the full Butler configuration. Not used if the supplied config is already a - ButlerConfig.
- writeable : bool, optional
- Explicitly sets whether the butler supports write operations. If not provided, a read-only butler is created unless - runis passed.
 - Raises: - ValueError
- Raised if neither “collection” nor “run” are provided by argument or config, or if both are provided and are inconsistent. 
 - Attributes: - config : str,ButlerConfigorConfig, optional
- (filename to) configuration. If this is not a - ButlerConfig, defaults will be read. If a- str, may be the path to a directory containing a “butler.yaml” file.
- datastore : Datastore
- Datastore to use for storage. 
- registry : Registry
- Registry to use for lookups. 
 - Attributes Summary - GENERATION- This is a Generation 3 Butler. - Methods Summary - datasetExists(datasetRefOrType, …)- Return True if the Dataset is actually present in the Datastore. - export(*, directory, filename, format, transfer)- Export datasets from the repository represented by this - Butler.- get(datasetRefOrType, …)- Retrieve a stored dataset. - getDeferred(datasetRefOrType, …)- Create a - DeferredDatasetHandlewhich can later retrieve a dataset- getDirect(ref, *, parameters, Any]] = None)- Retrieve a stored dataset. - getUri(datasetRefOrType, …)- Return the URI to the Dataset. - import_(*, directory, filename, format, transfer)- Import datasets exported from a different butler repository. - ingest(*datasets, transfer, run)- Store and register one or more datasets that already exist on disk. - isWriteable()- Return - Trueif this- Butlersupports write operations.- makeRepo(root, config, str, None] = None, …)- Create an empty data repository by adding a butler.yaml config to a repository root directory. - put(obj, datasetRefOrType, …)- Store and register a dataset. - remove(datasetRefOrType, …)- Remove a dataset from the collection and possibly the repository. - transaction()- Context manager supporting - Butlertransactions.- validateConfiguration(logFailures, …)- Validate butler configuration. - Attributes Documentation - 
GENERATION= 3¶
- This is a Generation 3 Butler. - This attribute may be removed in the future, once the Generation 2 Butler interface has been fully retired; it should only be used in transitional code. 
 - Methods Documentation - 
datasetExists(datasetRefOrType: Union[lsst.daf.butler.core.datasets.ref.DatasetRef, lsst.daf.butler.core.datasets.type.DatasetType, str], dataId: Union[lsst.daf.butler.core.dimensions.coordinate.DataCoordinate, Mapping[str, Any], None] = None, *, collection: Optional[str] = None, **kwds) → bool¶
- Return True if the Dataset is actually present in the Datastore. - Parameters: - datasetRefOrType : DatasetRef,DatasetType, orstr
- When - DatasetRefthe- dataIdshould be- None. Otherwise the- DatasetTypeor name thereof.
- dataId : dictorDataCoordinate
- A - dictof- Dimensionlink name, value pairs that label the- DatasetRefwithin a Collection. When- None, a- DatasetRefshould be provided as the first argument.
- collection : str, optional
- Collection to search, overriding - self.collection.
- kwds
- Additional keyword arguments used to augment or construct a - DataCoordinate. See- DataCoordinate.standardizeparameters.
 - Raises: - LookupError
- Raised if the dataset is not even present in the Registry. 
- ValueError
- Raised if a resolved - DatasetRefwas passed as an input, but it differs from the one found in the registry in this collection.
- TypeError
- Raised if - collectionand- self.collectionare both- None.
 
- datasetRefOrType : 
 - 
export(*, directory: Optional[str] = None, filename: Optional[str] = None, format: Optional[str] = None, transfer: Optional[str] = None) → AbstractContextManager[lsst.daf.butler.core.repoTransfers.RepoExport]¶
- Export datasets from the repository represented by this - Butler.- This method is a context manager that returns a helper object ( - RepoExport) that is used to indicate what information from the repository should be exported.- Parameters: - directory : str, optional
- Directory dataset files should be written to if - transferis not- None.
- filename : str, optional
- Name for the file that will include database information associated with the exported datasets. If this is not an absolute path and - directoryis not- None, it will be written to- directoryinstead of the current working directory. Defaults to “export.{format}”.
- format : str, optional
- File format for the database information file. If - None, the extension of- filenamewill be used.
- transfer : str, optional
- Transfer mode passed to - Datastore.export.
 - Raises: - TypeError
- Raised if the set of arguments passed is inconsistent. 
 - Examples - Typically the - Registry.queryDimensionsand- Registry.queryDatasetsmethods are used to provide the iterables over data IDs and/or datasets to be exported:- with butler.export("exports.yaml") as export: # Export all flats, and the calibration_label dimensions # associated with them. export.saveDatasets(butler.registry.queryDatasets("flat"), elements=[butler.registry.dimensions["calibration_label"]]) # Export all datasets that start with "deepCoadd_" and all of # their associated data ID information. export.saveDatasets(butler.registry.queryDatasets("deepCoadd_*")) 
- directory : 
 - 
get(datasetRefOrType: Union[lsst.daf.butler.core.datasets.ref.DatasetRef, lsst.daf.butler.core.datasets.type.DatasetType, str], dataId: Union[lsst.daf.butler.core.dimensions.coordinate.DataCoordinate, Mapping[str, Any], None] = None, *, parameters: Optional[Dict[str, Any]] = None, collection: Optional[str] = None, **kwds) → Any¶
- Retrieve a stored dataset. - Parameters: - datasetRefOrType : DatasetRef,DatasetType, orstr
- When - DatasetRefthe- dataIdshould be- None. Otherwise the- DatasetTypeor name thereof.
- dataId : dictorDataCoordinate
- A - dictof- Dimensionlink name, value pairs that label the- DatasetRefwithin a Collection. When- None, a- DatasetRefshould be provided as the first argument.
- parameters : dict
- Additional StorageClass-defined options to control reading, typically used to efficiently read only a subset of the dataset. 
- collection : str, optional
- Collection to search, overriding - self.collection.
- kwds
- Additional keyword arguments used to augment or construct a - DataCoordinate. See- DataCoordinate.standardizeparameters.
 - Returns: - obj : object
- The dataset. 
 - Raises: - ValueError
- Raised if a resolved - DatasetRefwas passed as an input, but it differs from the one found in the registry in this collection.
- LookupError
- Raised if no matching dataset exists in the - Registry.
- TypeError
- Raised if - collectionand- self.collectionare both- None.
 
- datasetRefOrType : 
 - 
getDeferred(datasetRefOrType: Union[lsst.daf.butler.core.datasets.ref.DatasetRef, lsst.daf.butler.core.datasets.type.DatasetType, str], dataId: Union[lsst.daf.butler.core.dimensions.coordinate.DataCoordinate, Mapping[str, Any], None] = None, *, parameters: Optional[dict] = None, collection: Optional[str] = None, **kwds) → lsst.daf.butler._deferredDatasetHandle.DeferredDatasetHandle¶
- Create a - DeferredDatasetHandlewhich can later retrieve a dataset- Parameters: - datasetRefOrType : DatasetRef,DatasetType, orstr
- When - DatasetRefthe- dataIdshould be- None. Otherwise the- DatasetTypeor name thereof.
- dataId : dictorDataCoordinate, optional
- A - dictof- Dimensionlink name, value pairs that label the- DatasetRefwithin a Collection. When- None, a- DatasetRefshould be provided as the first argument.
- collection : str, optional
- Name of the collection to search, overriding - self.collection.
- parameters : dict
- Additional StorageClass-defined options to control reading, typically used to efficiently read only a subset of the dataset. 
- collection : str, optional
- Collection to search, overriding - self.collection.
- kwds
- Additional keyword arguments used to augment or construct a - DataId. See- DataIdparameters.
 - Returns: - obj : DeferredDatasetHandle
- A handle which can be used to retrieve a dataset at a later time. 
 - Raises: - LookupError
- Raised if no matching dataset exists in the - Registry(and- allowUnresolved is False).
- ValueError
- Raised if a resolved - DatasetRefwas passed as an input, but it differs from the one found in the registry in this collection.
- TypeError
- Raised if - collectionand- self.collectionare both- None.
 
- datasetRefOrType : 
 - 
getDirect(ref: lsst.daf.butler.core.datasets.ref.DatasetRef, *, parameters: Optional[Dict[str, Any]] = None)¶
- Retrieve a stored dataset. - Unlike - Butler.get, this method allows datasets outside the Butler’s collection to be read as long as the- DatasetRefthat identifies them can be obtained separately.- Parameters: - ref : DatasetRef
- Reference to an already stored dataset. 
- parameters : dict
- Additional StorageClass-defined options to control reading, typically used to efficiently read only a subset of the dataset. 
 - Returns: - obj : object
- The dataset. 
 
- ref : 
 - 
getUri(datasetRefOrType: Union[lsst.daf.butler.core.datasets.ref.DatasetRef, lsst.daf.butler.core.datasets.type.DatasetType, str], dataId: Union[lsst.daf.butler.core.dimensions.coordinate.DataCoordinate, Mapping[str, Any], None] = None, *, predict: bool = False, collection: Optional[str] = None, run: Optional[str] = None, **kwds) → str¶
- Return the URI to the Dataset. - Parameters: - datasetRefOrType : DatasetRef,DatasetType, orstr
- When - DatasetRefthe- dataIdshould be- None. Otherwise the- DatasetTypeor name thereof.
- dataId : dictorDataCoordinate
- A - dictof- Dimensionlink name, value pairs that label the- DatasetRefwithin a Collection. When- None, a- DatasetRefshould be provided as the first argument.
- predict : bool
- If - True, allow URIs to be returned of datasets that have not been written.
- collection : str, optional
- Collection to search, overriding - self.collection.
- run : str, optional
- Run to use for predictions, overriding - self.run.
- kwds
- Additional keyword arguments used to augment or construct a - DataCoordinate. See- DataCoordinate.standardizeparameters.
 - Returns: - uri : str
- URI string pointing to the Dataset within the datastore. If the Dataset does not exist in the datastore, and if - predictis- True, the URI will be a prediction and will include a URI fragment “#predicted”. If the datastore does not have entities that relate well to the concept of a URI the returned URI string will be descriptive. The returned URI is not guaranteed to be obtainable.
 - Raises: - LookupError
- A URI has been requested for a dataset that does not exist and guessing is not allowed. 
- ValueError
- Raised if a resolved - DatasetRefwas passed as an input, but it differs from the one found in the registry in this collection.
- TypeError
- Raised if - collectionand- self.collectionare both- None.
 
- datasetRefOrType : 
 - 
import_(*, directory: Optional[str] = None, filename: Optional[str] = None, format: Optional[str] = None, transfer: Optional[str] = None)¶
- Import datasets exported from a different butler repository. - Parameters: - directory : str, optional
- Directory containing dataset files. If - None, all file paths must be absolute.
- filename : str, optional
- Name for the file that containing database information associated with the exported datasets. If this is not an absolute path, does not exist in the current working directory, and - directoryis not- None, it is assumed to be in- directory. Defaults to “export.{format}”.
- format : str, optional
- File format for the database information file. If - None, the extension of- filenamewill be used.
- transfer : str, optional
- Transfer mode passed to - Datastore.export.
 - Raises: - TypeError
- Raised if the set of arguments passed is inconsistent, or if the butler is read-only. 
 
- directory : 
 - 
ingest(*datasets, transfer: Optional[str] = None, run: Optional[str] = None)¶
- Store and register one or more datasets that already exist on disk. - Parameters: - datasets : FileDataset
- Each positional argument is a struct containing information about a file to be ingested, including its path (either absolute or relative to the datastore root, if applicable), a - DatasetRef, and optionally a formatter class or its fully-qualified string name. If a formatter is not provided, the formatter that would be used for- putis assumed. On successful return, all- FileDataset.refattributes will have their- DatasetRef.idattribute populated and all- FileDataset.formatterattributes will be set to the formatter class used.- FileDataset.pathattributes may be modified to put paths in whatever the datastore considers a standardized form.
- transfer : str, optional
- If not - None, must be one of ‘move’, ‘copy’, ‘hardlink’, or ‘symlink’, indicating how to transfer the file.
- run : str, optional
- The name of the run ingested datasets should be added to, overriding - self.run.
 - Raises: - TypeError
- Raised if the butler is read-only or if no run was provided. 
- NotImplementedError
- Raised if the - Datastoredoes not support the given transfer mode.
- DatasetTypeNotSupportedError
- Raised if one or more files to be ingested have a dataset type that is not supported by the - Datastore..
- FileNotFoundError
- Raised if one of the given files does not exist. 
- FileExistsError
- Raised if transfer is not - Nonebut the (internal) location the file would be moved to is already occupied.
 - Notes - This operation is not fully exception safe: if a database operation fails, the given - FileDatasetinstances may be only partially updated.- It is atomic in terms of database operations (they will either all succeed or all fail) providing the database engine implements transactions correctly. It will attempt to be atomic in terms of filesystem operations as well, but this cannot be implemented rigorously for most datastores. 
- datasets : 
 - 
static makeRepo(root: str, config: Union[lsst.daf.butler.core.config.Config, str, None] = None, standalone: bool = False, createRegistry: bool = True, searchPaths: Optional[List[str]] = None, forceConfigRoot: bool = True, outfile: Optional[str] = None) → lsst.daf.butler.core.config.Config¶
- Create an empty data repository by adding a butler.yaml config to a repository root directory. - Parameters: - root : str
- Filesystem path to the root of the new repository. Will be created if it does not exist. 
- config : Configorstr, optional
- Configuration to write to the repository, after setting any root-dependent Registry or Datastore config options. Can not be a - ButlerConfigor a- ConfigSubset. If- None, default configuration will be used. Root-dependent config options specified in this config are overwritten if- forceConfigRootis- True.
- standalone : bool
- If True, write all expanded defaults, not just customized or repository-specific settings. This (mostly) decouples the repository from the default configuration, insulating it from changes to the defaults (which may be good or bad, depending on the nature of the changes). Future additions to the defaults will still be picked up when initializing - Butlersto repos created with- standalone=True.
- createRegistry : bool, optional
- If - Truecreate a new Registry.
- searchPaths : listofstr, optional
- Directory paths to search when calculating the full butler configuration. 
- forceConfigRoot : bool, optional
- If - False, any values present in the supplied- configthat would normally be reset are not overridden and will appear directly in the output config. This allows non-standard overrides of the root directory for a datastore or registry to be given. If this parameter is- Truethe values for- rootwill be forced into the resulting config if appropriate.
- outfile : str, optional
- If not- - None, the output configuration will be written to this location rather than into the repository itself. Can be a URI string. Can refer to a directory that will be used to write- butler.yaml.
 - Returns: - Raises: - ValueError
- Raised if a ButlerConfig or ConfigSubset is passed instead of a regular Config (as these subclasses would make it impossible to support - standalone=False).
- os.error
- Raised if the directory does not exist, exists but is not a directory, or cannot be created. 
 - Notes - Note that when - standalone=False(the default), the configuration search path (see- ConfigSubset.defaultSearchPaths) that was used to construct the repository should also be used to construct any Butlers to avoid configuration inconsistencies.
- root : 
 - 
put(obj: Any, datasetRefOrType: Union[lsst.daf.butler.core.datasets.ref.DatasetRef, lsst.daf.butler.core.datasets.type.DatasetType, str], dataId: Union[lsst.daf.butler.core.dimensions.coordinate.DataCoordinate, Mapping[str, Any], None] = None, *, producer: Optional[lsst.daf.butler.core.quantum.Quantum] = None, run: Optional[str] = None, **kwds) → lsst.daf.butler.core.datasets.ref.DatasetRef¶
- Store and register a dataset. - Parameters: - obj : object
- The dataset. 
- datasetRefOrType : DatasetRef,DatasetType, orstr
- When - DatasetRefis provided,- dataIdshould be- None. Otherwise the- DatasetTypeor name thereof.
- dataId : dictorDataCoordinate
- A - dictof- Dimensionlink name, value pairs that label the- DatasetRefwithin a Collection. When- None, a- DatasetRefshould be provided as the second argument.
- producer : Quantum, optional
- The producer. 
- run : str, optional
- The name of the run the dataset should be added to, overriding - self.run.
- kwds
- Additional keyword arguments used to augment or construct a - DataCoordinate. See- DataCoordinate.standardizeparameters.
 - Returns: - ref : DatasetRef
- A reference to the stored dataset, updated with the correct id if given. 
 - Raises: - TypeError
- Raised if the butler is read-only or if no run has been provided. 
 
- obj : 
 - 
remove(datasetRefOrType: Union[lsst.daf.butler.core.datasets.ref.DatasetRef, lsst.daf.butler.core.datasets.type.DatasetType, str], dataId: Union[lsst.daf.butler.core.dimensions.coordinate.DataCoordinate, Mapping[str, Any], None] = None, *, delete: bool = True, remember: bool = True, collection: Optional[str] = None, **kwds)¶
- Remove a dataset from the collection and possibly the repository. - The identified dataset is always at least removed from the Butler’s collection. By default it is also deleted from the Datastore (e.g. files are actually deleted), but the dataset is “remembered” by retaining its row in the dataset and provenance tables in the registry. - If the dataset is a composite, all components will also be removed. - Parameters: - datasetRefOrType : DatasetRef,DatasetType, orstr
- When - DatasetRefthe- dataIdshould be- None. Otherwise the- DatasetTypeor name thereof.
- dataId : dictorDataId
- A - dictof- Dimensionlink name, value pairs that label the- DatasetRefwithin a Collection. When- None, a- DatasetRefshould be provided as the first argument.
- delete : bool
- If - True(default) actually delete the dataset from the Datastore (i.e. actually remove files).
- remember : bool
- If - True(default), retain dataset and provenance records in the- Registryfor this dataset.
- collection : str, optional
- Collection to search, overriding - self.collection.
- kwds
- Additional keyword arguments used to augment or construct a - DataId. See- DataIdparameters.
 - Raises: - TypeError
- Raised if the butler is read-only, if no collection was provided, or if - deleteand- rememberare both- False; a dataset cannot remain in a- Datastoreif its- Registryentries is removed.
- OrphanedRecordError
- Raised if - rememberis- Falsebut the dataset is still present in a- Datastorenot recognized by this- Butlerclient.
- ValueError
- Raised if a resolved - DatasetRefwas passed as an input, but it differs from the one found in the registry in this collection.
 
- datasetRefOrType : 
 - 
validateConfiguration(logFailures: bool = False, datasetTypeNames: Optional[Iterable[str]] = None, ignore: Optional[Iterable[str]] = None)¶
- Validate butler configuration. - Checks that each - DatasetTypecan be stored in the- Datastore.- Parameters: - logFailures : bool, optional
- If - True, output a log message for every validation error detected.
- datasetTypeNames : iterable of str, optional
- The - DatasetTypenames that should be checked. This allows only a subset to be selected.
- ignore : iterable of str, optional
- Names of DatasetTypes to skip over. This can be used to skip known problems. If a named - DatasetTypecorresponds to a composite, all component of that- DatasetTypewill also be ignored.
 - Raises: - ButlerValidationError
- Raised if there is some inconsistency with how this Butler is configured. 
 
- logFailures : 
 
- config :