Coverage for python/lsst/daf/butler/script/transferDatasets.py: 40%
18 statements
« prev ^ index » next coverage.py v7.2.5, created at 2023-05-18 09:12 +0000
« prev ^ index » next coverage.py v7.2.5, created at 2023-05-18 09:12 +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
23__all__ = ("transferDatasets",)
25import logging
27from lsst.utils.ellipsis import Ellipsis, EllipsisType
29from .._butler import Butler
30from ..registry.queries import DatasetQueryResults
32log = logging.getLogger(__name__)
35def transferDatasets(
36 source: str,
37 dest: str,
38 dataset_type: tuple[str, ...],
39 collections: tuple[str, ...],
40 where: str,
41 find_first: bool,
42 transfer: str,
43 register_dataset_types: bool,
44 transfer_dimensions: bool = True,
45) -> int:
46 """Transfer datasets from run in source to dest.
48 Parameters
49 ----------
50 source : `str`
51 URI string of the source Butler repo.
52 dest : `str`
53 URI string of the destination Butler repo.
54 dataset_type : `tuple` of `str`
55 Dataset type names. An empty tuple implies all dataset types.
56 collections : `tuple` of `str`
57 Names of collection globs to match. An empty tuple implies all
58 collections.
59 where : `str`
60 Query modification string.
61 find_first : `bool`
62 Whether only the first match should be used.
63 transfer : `str`
64 Transfer mode to use when placing artifacts in the destination.
65 register_dataset_types : `bool`
66 Indicate whether missing dataset types should be registered.
67 transfer_dimensions : `bool`
68 Indicate whether dimensions should be transferred along with
69 datasets. It can be more efficient to disable this if it is known
70 that all dimensions exist.
71 """
72 source_butler = Butler(source, writeable=False)
73 dest_butler = Butler(dest, writeable=True)
75 dataset_type_expr = ... if not dataset_type else dataset_type
76 collections_expr: tuple[str, ...] | EllipsisType = Ellipsis if not collections else collections
78 source_refs = source_butler.registry.queryDatasets(
79 datasetType=dataset_type_expr, collections=collections_expr, where=where, findFirst=find_first
80 )
82 # Might need expanded results if datastore records have to be derived.
83 # Not all registries return the same form for results.
84 if isinstance(source_refs, DatasetQueryResults):
85 source_refs = source_refs.expanded()
87 # Place results in a set to remove duplicates
88 source_refs_set = set(source_refs)
90 transferred = dest_butler.transfer_from(
91 source_butler,
92 source_refs_set,
93 transfer=transfer,
94 register_dataset_types=register_dataset_types,
95 transfer_dimensions=transfer_dimensions,
96 )
97 return len(transferred)