Query¶
- class lsst.daf.butler.Query¶
Bases:
ABCInterface 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:
- dimensions
DimensionGroup,str, orIterable[str] The dimensions of the data IDs to yield, as either
DimensionGroupinstances orstr. Will be automatically expanded to a completeDimensionGroup.- data_id
dictorDataCoordinate, optional A data ID whose key-value pairs are used as equality constraints in the query.
- where
str, 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.
- bind
Mapping, 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 thedata_idargument (and may be used to provide a constraining data ID even when thedata_idargument isNone).
- dimensions
- Returns:
- dataIds
DataCoordinateQueryResults Data IDs matching the given query parameters. These are guaranteed to identify all dimensions (
DataCoordinate.hasFullreturnsTrue), but will not containDimensionRecordobjects (DataCoordinate.hasRecordsreturnsFalse). Callexpandedon the returned object to fetch those (and consider usingmaterializeon 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 allRUNcollections, because this will still find all datasets). If not provided, the default collections are used. See Collection expressions for more information.- find_first
bool, optional If
True(default), for each result data ID, only yield oneDatasetRefof eachDatasetType, from the first collection in which a dataset of that dataset type appears (according to the order ofcollectionspassed in). IfTrue,collectionsmust not contain regular expressions and may not be....- data_id
dictorDataCoordinate, optional A data ID whose key-value pairs are used as equality constraints in the query.
- where
str, 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.
- bind
Mapping, 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 thedata_idargument (and may be used to provide a constraining data ID even when thedata_idargument isNone).
- Returns:
- refs
queries.DatasetQueryResults Dataset references matching the given query criteria. Nested data IDs are guaranteed to include values for all implied dimensions (i.e.
DataCoordinate.hasFullwill returnTrue), but will not include dimension records (DataCoordinate.hasRecordswill beFalse) unlessexpandedis 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_firstisTrue, or whencollectionsisNoneand 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:
- element
str The name of a dimension element to obtain records for.
- data_id
dictorDataCoordinate, optional A data ID whose key-value pairs are used as equality constraints in the query.
- where
str, optional A string expression similar to a SQL WHERE clause. See
queryDataIdsand Dimension expressions for more information.- bind
Mapping, 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 thedata_idargument (and may be used to provide a constraining data ID even when thedata_idargument isNone).
- element
- Returns:
- records
queries.DimensionRecordQueryResults Data IDs matching the given query parameters.
- records
- Raises:
- lsst.daf.butler.registry.NoDefaultCollectionError
Raised if
collectionsisNoneandself.defaults.collectionsisNone.- 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.