Query¶
- class lsst.daf.butler.Query¶
- Bases: - ABC- Interface for construction and execution of complex queries. - Methods Summary - data_ids(dimensions, *[, data_id, where, bind])- Query for data IDs matching user-provided criteria. - datasets(dataset_type[, collections, ...])- Query for and iterate over dataset references matching user-provided criteria. - dimension_records(element, *[, data_id, ...])- Query for dimension information matching user-provided criteria. - Methods Documentation - abstract data_ids(dimensions: DimensionGroup | Iterable[str] | str, *, data_id: DataId | None = None, where: str = '', bind: Mapping[str, Any] | None = None, **kwargs: Any) DataCoordinateQueryResults¶
- Query for data IDs matching user-provided criteria. - Parameters:
- dimensionsDimensionGroup,str, orIterable[str]
- The dimensions of the data IDs to yield, as either - DimensionGroupinstances or- str. Will be automatically expanded to a complete- DimensionGroup.
- data_iddictorDataCoordinate, optional
- A data ID whose key-value pairs are used as equality constraints in the query. 
- wherestr, optional
- A string expression similar to a SQL WHERE clause. May involve any column of a dimension table or (as a shortcut for the primary key column of a dimension table) dimension name. See Dimension expressions for more information. 
- bindMapping, optional
- Mapping containing literal values that should be injected into the - whereexpression, keyed by the identifiers they replace. Values of collection type can be expanded in some cases; see Identifiers for more information.
- **kwargs
- Additional keyword arguments are forwarded to - DataCoordinate.standardizewhen processing the- data_idargument (and may be used to provide a constraining data ID even when the- data_idargument is- None).
 
- dimensions
- Returns:
- dataIdsDataCoordinateQueryResults
- Data IDs matching the given query parameters. These are guaranteed to identify all dimensions ( - DataCoordinate.hasFullreturns- True), but will not contain- DimensionRecordobjects (- DataCoordinate.hasRecordsreturns- False). Call- expandedon the returned object to fetch those (and consider using- materializeon the returned object first if the expected number of rows is very large). See documentation for those methods for additional information.
 
- dataIds
- Raises:
- lsst.daf.butler.registry.DataIdError
- Raised when - data_idor keyword arguments specify unknown dimensions or values, or when they contain inconsistent values.
- lsst.daf.butler.registry.UserExpressionError
- Raised when - whereexpression is invalid.
 
 
 - abstract datasets(dataset_type: Any, collections: CollectionArgType | None = None, *, find_first: bool = True, data_id: DataId | None = None, where: str = '', bind: Mapping[str, Any] | None = None, **kwargs: Any) DatasetQueryResults¶
- Query for and iterate over dataset references matching user-provided criteria. - Parameters:
- dataset_typedataset type expression
- An expression that fully or partially identifies the dataset types to be queried. Allowed types include - DatasetType,- str,- re.Pattern, and iterables thereof. The special value- ...can be used to query all dataset types. See DatasetType expressions for more information.
- collectionscollection expression, optional
- An expression that identifies the collections to search, such as a - str(for full matches or partial matches via globs),- re.Pattern(for partial matches), or iterable thereof.- ...can be used to search all collections (actually just all- RUNcollections, because this will still find all datasets). If not provided, the default collections are used. See Collection expressions for more information.
- find_firstbool, optional
- If - True(default), for each result data ID, only yield one- DatasetRefof each- DatasetType, from the first collection in which a dataset of that dataset type appears (according to the order of- collectionspassed in). If- True,- collectionsmust not contain regular expressions and may not be- ....
- data_iddictorDataCoordinate, optional
- A data ID whose key-value pairs are used as equality constraints in the query. 
- wherestr, optional
- A string expression similar to a SQL WHERE clause. May involve any column of a dimension table or (as a shortcut for the primary key column of a dimension table) dimension name. See Dimension expressions for more information. 
- bindMapping, optional
- Mapping containing literal values that should be injected into the - whereexpression, keyed by the identifiers they replace. Values of collection type can be expanded in some cases; see Identifiers for more information.
- **kwargs
- Additional keyword arguments are forwarded to - DataCoordinate.standardizewhen processing the- data_idargument (and may be used to provide a constraining data ID even when the- data_idargument is- None).
 
- Returns:
- refsqueries.DatasetQueryResults
- Dataset references matching the given query criteria. Nested data IDs are guaranteed to include values for all implied dimensions (i.e. - DataCoordinate.hasFullwill return- True), but will not include dimension records (- DataCoordinate.hasRecordswill be- False) unless- expandedis called on the result object (which returns a new one).
 
- refs
- Raises:
- lsst.daf.butler.registry.DatasetTypeExpressionError
- Raised when - dataset_typeexpression is invalid.
- TypeError
- Raised when the arguments are incompatible, such as when a collection wildcard is passed when - find_firstis- True, or when- collectionsis- Noneand default butler collections are not defined.
- lsst.daf.butler.registry.DataIdError
- Raised when - data_idor keyword arguments specify unknown dimensions or values, or when they contain inconsistent values.
- lsst.daf.butler.registry.UserExpressionError
- Raised when - whereexpression is invalid.
 
 - Notes - When multiple dataset types are queried in a single call, the results of this operation are equivalent to querying for each dataset type separately in turn, and no information about the relationships between datasets of different types is included. 
 - abstract dimension_records(element: str, *, data_id: DataId | None = None, where: str = '', bind: Mapping[str, Any] | None = None, **kwargs: Any) DimensionRecordQueryResults¶
- Query for dimension information matching user-provided criteria. - Parameters:
- elementstr
- The name of a dimension element to obtain records for. 
- data_iddictorDataCoordinate, optional
- A data ID whose key-value pairs are used as equality constraints in the query. 
- wherestr, optional
- A string expression similar to a SQL WHERE clause. See - queryDataIdsand Dimension expressions for more information.
- bindMapping, optional
- Mapping containing literal values that should be injected into the - whereexpression, keyed by the identifiers they replace. Values of collection type can be expanded in some cases; see Identifiers for more information.
- **kwargs
- Additional keyword arguments are forwarded to - DataCoordinate.standardizewhen processing the- data_idargument (and may be used to provide a constraining data ID even when the- data_idargument is- None).
 
- element
- Returns:
- recordsqueries.DimensionRecordQueryResults
- Data IDs matching the given query parameters. 
 
- records
- Raises:
- lsst.daf.butler.registry.NoDefaultCollectionError
- Raised if - collectionsis- Noneand- self.defaults.collectionsis- None.
- lsst.daf.butler.registry.CollectionExpressionError
- Raised when - collectionsexpression is invalid.
- lsst.daf.butler.registry.DataIdError
- Raised when - data_idor keyword arguments specify unknown dimensions or values, or when they contain inconsistent values.
- lsst.daf.butler.registry.DatasetTypeExpressionError
- Raised when - datasetTypeexpression is invalid.
- lsst.daf.butler.registry.UserExpressionError
- Raised when - whereexpression is invalid.