Coverage for python/lsst/daf/butler/script/queryDatasetTypes.py: 29%
15 statements
« prev ^ index » next coverage.py v7.2.5, created at 2023-05-15 00:10 +0000
« prev ^ index » next coverage.py v7.2.5, created at 2023-05-15 00:10 +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 program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
21from __future__ import annotations
23from collections.abc import Iterable
25from astropy.table import Table
26from numpy import array
28from .._butler import Butler
31def queryDatasetTypes(repo: str, verbose: bool, glob: Iterable[str], components: bool | None) -> Table:
32 """Get the dataset types in a repository.
34 Parameters
35 ----------
36 repo : `str`
37 URI to the location of the repo or URI to a config file describing the
38 repo and its location.
39 verbose : `bool`
40 If false only return the name of the dataset types. If false return
41 name, dimensions, and storage class of each dataset type.
42 glob : iterable [`str`]
43 A list of glob-style search string that fully or partially identify
44 the dataset type names to search for.
45 components : `bool` or `None`
46 If `True`, apply all glob patterns to component dataset type
47 names as well. If `False`, never apply patterns to components. If
48 `None` (default), apply patterns to components only if their parent
49 datasets were not matched by the expression. Fully-specified component
50 datasets (`str` or `DatasetType` instances) are always included.
52 Returns
53 -------
54 collections : `astropy.table.Table`
55 A dict whose key is "datasetTypes" and whose value is a list of
56 collection names.
57 """
58 butler = Butler(repo)
59 expression = glob if glob else ...
60 datasetTypes = butler.registry.queryDatasetTypes(components=components, expression=expression)
61 if verbose:
62 table = Table(
63 array(
64 [(d.name, str(list(d.dimensions.names)) or "None", d.storageClass_name) for d in datasetTypes]
65 ),
66 names=("name", "dimensions", "storage class"),
67 )
68 else:
69 rows = ([d.name for d in datasetTypes],)
70 table = Table(rows, names=("name",))
71 table.sort("name")
72 return table