Coverage for python/lsst/daf/butler/script/queryDatasetTypes.py: 25%

16 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-11-08 22:06 -0800

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 

22 

23from typing import Any, List 

24 

25from astropy.table import Table 

26from numpy import array 

27 

28from .._butler import Butler 

29 

30 

31def queryDatasetTypes(repo, verbose, glob, components): 

32 """Get the dataset types in a repository. 

33 

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. 

51 

52 Returns 

53 ------- 

54 collections : `dict` [`str`, [`str`]] 

55 A dict whose key is "datasetTypes" and whose value is a list of 

56 collection names. 

57 """ 

58 butler = Butler(repo) 

59 if not glob: 

60 glob = ... 

61 datasetTypes = butler.registry.queryDatasetTypes(components=components, expression=glob) 

62 info: List[Any] 

63 if verbose: 

64 table = Table( 

65 array( 

66 [(d.name, str(list(d.dimensions.names)) or "None", d.storageClass_name) for d in datasetTypes] 

67 ), 

68 names=("name", "dimensions", "storage class"), 

69 ) 

70 else: 

71 rows = ([d.name for d in datasetTypes],) 

72 table = Table(rows, names=("name",)) 

73 table.sort("name") 

74 return table