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