Coverage for python/lsst/daf/butler/script/register_dataset_type.py: 36%
12 statements
« prev ^ index » next coverage.py v7.2.3, created at 2023-04-19 03:42 -0700
« prev ^ index » next coverage.py v7.2.3, created at 2023-04-19 03:42 -0700
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
23__all__ = ("register_dataset_type",)
25from .._butler import Butler
26from ..core import DatasetType
29def register_dataset_type(
30 repo: str,
31 dataset_type: str,
32 storage_class: str,
33 dimensions: tuple[str, ...],
34 is_calibration: bool = False,
35) -> bool:
36 """Register a new dataset type.
38 Parameters
39 ----------
40 repo : `str`
41 URI string of the Butler repo to use.
42 dataset_type : `str`
43 The name of the new dataset type.
44 storage_class : `str`
45 The name of the storage class associated with this dataset type.
46 dimensions : `tuple` [`str`]
47 Dimensions associated with this dataset type. Can be empty.
48 is_calibration : `bool`
49 If `True` this dataset type may be included in calibration
50 collections.
52 Returns
53 -------
54 inserted : `bool`
55 `True` if the dataset type was added; `False` if it was already
56 there.
58 Raises
59 ------
60 ValueError
61 Raised if an attempt is made to register a component dataset type.
62 Component dataset types are not real dataset types and so can not
63 be created by this command. They are always derived from the composite
64 dataset type.
65 """
67 butler = Butler(repo, writeable=True)
69 composite, component = DatasetType.splitDatasetTypeName(dataset_type)
70 if component:
71 raise ValueError("Component dataset types are created automatically when the composite is created.")
73 # mypy does not think that Tuple[str, ...] is allowed for DatasetType
74 # constructor so we have to do the conversion here.
75 graph = butler.registry.dimensions.extract(dimensions)
77 datasetType = DatasetType(
78 dataset_type,
79 graph,
80 storage_class,
81 parentStorageClass=None,
82 isCalibration=is_calibration,
83 universe=butler.registry.dimensions,
84 )
86 return butler.registry.registerDatasetType(datasetType)