Coverage for python / lsst / daf / butler / script / queryDatasetTypes.py: 26%
19 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-26 08:49 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-26 08:49 +0000
1# This file is part of daf_butler.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (http://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This software is dual licensed under the GNU General Public License and also
10# under a 3-clause BSD license. Recipients may choose which of these licenses
11# to use; please see the files gpl-3.0.txt and/or bsd_license.txt,
12# respectively. If you choose the GPL option then the following text applies
13# (but note that there is still no warranty even if you opt for BSD instead):
14#
15# This program is free software: you can redistribute it and/or modify
16# it under the terms of the GNU General Public License as published by
17# the Free Software Foundation, either version 3 of the License, or
18# (at your option) any later version.
19#
20# This program is distributed in the hope that it will be useful,
21# but WITHOUT ANY WARRANTY; without even the implied warranty of
22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23# GNU General Public License for more details.
24#
25# You should have received a copy of the GNU General Public License
26# along with this program. If not, see <http://www.gnu.org/licenses/>.
27from __future__ import annotations
29from collections.abc import Iterable
31from astropy.table import Table
32from numpy import array
34from .._butler import Butler
37def queryDatasetTypes(
38 repo: str, verbose: bool, glob: Iterable[str], collections: Iterable[str] | None = None
39) -> Table:
40 """Get the dataset types in a repository.
42 Parameters
43 ----------
44 repo : `str`
45 URI to the location of the repo or URI to a config file describing the
46 repo and its location.
47 verbose : `bool`
48 If false only return the name of the dataset types. If false return
49 name, dimensions, and storage class of each dataset type.
50 glob : `~collections.abc.Iterable` [`str`]
51 A list of glob-style search string that fully or partially identify
52 the dataset type names to search for.
53 collections : `~collections.abc.Iterable` [`str`] or `None`, optional
54 Constrains resulting dataset types such that only dataset type
55 found (at some point) in these collections will be returned.
57 Returns
58 -------
59 dataset_types_table : `astropy.table.Table`
60 A dict whose key is "datasetTypes" and whose value is a list of
61 collection names.
62 """
63 with Butler.from_config(repo, without_datastore=True) as butler:
64 expression = glob or ...
65 datasetTypes = butler.registry.queryDatasetTypes(expression=expression)
67 if collections:
68 collections_info = butler.collections.query_info(collections, include_summary=True)
69 filtered_dataset_types = set(
70 butler.collections._filter_dataset_types([d.name for d in datasetTypes], collections_info)
71 )
72 datasetTypes = [d for d in datasetTypes if d.name in filtered_dataset_types]
74 if verbose:
75 table = Table(
76 array(
77 [
78 (d.name, str(list(d.dimensions.names)) or "None", d.storageClass_name)
79 for d in datasetTypes
80 ]
81 ),
82 names=("name", "dimensions", "storage class"),
83 )
84 else:
85 rows = ([d.name for d in datasetTypes],)
86 table = Table(rows, names=("name",))
87 table.sort("name")
88 return table