DataCoordinateQueryResults¶
- class lsst.daf.butler.registry.queries.DataCoordinateQueryResults¶
- Bases: - QueryResultsBase,- DataCoordinateIterable- An enhanced implementation of - DataCoordinateIterablethat represents data IDs retrieved from a database query.- Methods Summary - expanded()- Return a results object for which - hasRecordsreturns- True.- findDatasets(datasetType, collections, *[, ...])- Find datasets using the data IDs identified by this query. - findRelatedDatasets(datasetType, collections, *)- Find datasets using the data IDs identified by this query, and return them along with the original data IDs. - Insert this query's results into a temporary table. - subset([dimensions, unique])- Return a results object containing a subset of the dimensions of this one, and/or a unique near-subset of its rows. - Methods Documentation - abstract expanded() DataCoordinateQueryResults¶
- Return a results object for which - hasRecordsreturns- True.- This method may involve actually executing database queries to fetch - DimensionRecordobjects.- Returns:
- resultsDataCoordinateQueryResults
- A results object for which - hasRecordsreturns- True. May be- selfif that is already the case.
 
- results
 - Notes - For very result sets, it may be much more efficient to call - materializebefore calling- expanded, to avoid performing the original query multiple times (as a subquery) in the follow-up queries that fetch dimension records. For example:- with registry.queryDataIds(...).materialize() as tempDataIds: dataIdsWithRecords = tempDataIds.expanded() for dataId in dataIdsWithRecords: ... 
 - abstract findDatasets(datasetType: DatasetType | str, collections: Any, *, findFirst: bool = True) ParentDatasetQueryResults¶
- Find datasets using the data IDs identified by this query. - Parameters:
- datasetTypeDatasetTypeorstr
- Dataset type or the name of one to search for. Must have dimensions that are a subset of - self.graph.
- collectionsAny
- An expression that fully or partially identifies the collections to search for the dataset, such as a - str,- re.Pattern, or iterable thereof.- ...can be used to return all collections. See Collection expressions for more information.
- findFirstbool, optional
- If - True(default), for each result data ID, only yield one- DatasetRef, 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- ....
 
- datasetType
- Returns:
- datasetsParentDatasetQueryResults
- A lazy-evaluation object representing dataset query results, iterable over - DatasetRefobjects. If- self.hasRecords(), all nested data IDs in those dataset references will have records as well.
 
- datasets
- Raises:
- MissingDatasetTypeError
- Raised if the given dataset type is not registered. 
 
 
 - abstract findRelatedDatasets(datasetType: DatasetType | str, collections: Any, *, findFirst: bool = True, dimensions: DimensionGroup | Iterable[str] | None = None) Iterable[tuple[lsst.daf.butler.dimensions._coordinate.DataCoordinate, lsst.daf.butler._dataset_ref.DatasetRef]]¶
- Find datasets using the data IDs identified by this query, and return them along with the original data IDs. - This is a variant of - findDatasetsthat is often more useful when the target dataset type does not have all of the dimensions of the original data ID query, as is generally the case with calibration lookups.- Parameters:
- datasetTypeDatasetTypeorstr
- Dataset type or the name of one to search for. Must have dimensions that are a subset of - self.graph.
- collectionsAny
- An expression that fully or partially identifies the collections to search for the dataset, such as a - str,- re.Pattern, or iterable thereof.- ...can be used to return all collections. See Collection expressions for more information.
- findFirstbool, optional
- If - True(default), for each data ID in- self, only yield one- DatasetRef, 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- .... Note that this is not the same as yielding one- DatasetReffor each yielded data ID if- dimensionsis not- None.
- dimensionsDimensionGrouporIterable[str], optional
- The dimensions of the data IDs returned. Must be a subset of - self.dimensions.
 
- datasetType
- Returns:
- Raises:
- MissingDatasetTypeError
- Raised if the given dataset type is not registered. 
 
 
 - abstract materialize() AbstractContextManager[DataCoordinateQueryResults]¶
- Insert this query’s results into a temporary table. - Returns:
- contexttyping.ContextManager[DataCoordinateQueryResults]
- A context manager that ensures the temporary table is created and populated in - __enter__(returning a results object backed by that table), and dropped in- __exit__. If- selfis already materialized, the context manager may do nothing (reflecting the fact that an outer context manager should already take care of everything else).
 
- context
 - Notes - When using a very large result set to perform multiple queries (e.g. multiple calls to - subsetwith different arguments, or even a single call to- expanded), it may be much more efficient to start by materializing the query and only then performing the follow up queries. It may also be less efficient, depending on how well database engine’s query optimizer can simplify those particular follow-up queries and how efficiently it caches query results even when the are not explicitly inserted into a temporary table. See- expandedand- subsetfor examples.
 - abstract subset(dimensions: DimensionGroup | Iterable[str] | None = None, *, unique: bool = False) DataCoordinateQueryResults¶
- Return a results object containing a subset of the dimensions of this one, and/or a unique near-subset of its rows. - This method may involve actually executing database queries to fetch - DimensionRecordobjects.- Parameters:
- dimensionsDimensionGrouporIterable[str], optional
- Dimensions to include in the new results object. If - None,- self.dimensionsis used.
- uniquebool, optional
- If - True(- Falseis default), the query should only return unique data IDs. This is implemented in the database; to obtain unique results via Python-side processing (which may be more efficient in some cases), use- toSetto construct a- DataCoordinateSetfrom this results object instead.
 
- dimensions
- Returns:
- resultsDataCoordinateQueryResults
- A results object corresponding to the given criteria. May be - selfif it already qualifies.
 
- results
- Raises:
- ValueError
- Raised when - dimensionsis not a subset of the dimensions in this result.
 
 - Notes - This method can only return a “near-subset” of the original result rows in general because of subtleties in how spatial overlaps are implemented; see - Query.projectedfor more information.- When calling - subsetmultiple times on the same very large result set, it may be much more efficient to call- materializefirst. For example:- dimensions1 = DimensionGroup(...) dimensions2 = DimensionGroup(...) with registry.queryDataIds(...).materialize() as tempDataIds: for dataId1 in tempDataIds.subset(dimensions1, unique=True): ... for dataId2 in tempDataIds.subset(dimensions2, unique=True): ...