Coverage for python / lsst / pipe / base / script / retrieve_artifacts_for_quanta.py: 50%

14 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-14 23:47 +0000

1# This file is part of pipe_base. 

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 software is dual licensed under the GNU General Public License and also 

10# under a 3-clause BSD license. Recipients may choose which of these licenses 

11# to use; please see the files gpl-3.0.txt and/or bsd_license.txt, 

12# respectively. If you choose the GPL option then the following text applies 

13# (but note that there is still no warranty even if you opt for BSD instead): 

14# 

15# This program is free software: you can redistribute it and/or modify 

16# it under the terms of the GNU General Public License as published by 

17# the Free Software Foundation, either version 3 of the License, or 

18# (at your option) any later version. 

19# 

20# This program is distributed in the hope that it will be useful, 

21# but WITHOUT ANY WARRANTY; without even the implied warranty of 

22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

23# GNU General Public License for more details. 

24# 

25# You should have received a copy of the GNU General Public License 

26# along with this program. If not, see <http://www.gnu.org/licenses/>. 

27 

28__all__ = ["retrieve_artifacts_for_quanta"] 

29 

30import logging 

31 

32from lsst.daf.butler import QuantumBackedButler 

33from lsst.pipe.base import QuantumGraph 

34from lsst.resources import ResourcePath 

35 

36_LOG = logging.getLogger(__name__) 

37 

38 

39def retrieve_artifacts_for_quanta( 

40 graph: str, 

41 repo: str, 

42 dest: str, 

43 transfer: str, 

44 preserve_path: bool, 

45 clobber: bool, 

46 qgraph_node_id: list[str], 

47 include_inputs: bool, 

48 include_outputs: bool, 

49) -> list[ResourcePath]: 

50 """Retrieve artifacts referenced in a graph and store locally. 

51 

52 Parameters 

53 ---------- 

54 graph : `str` 

55 URI string of the quantum graph. 

56 repo : `str` 

57 URI string of the Butler repo to use. 

58 dest : `str` 

59 URI string of the directory to write the artifacts. 

60 transfer : `str` 

61 Transfer mode to use when placing artifacts in the destination. 

62 preserve_path : `bool` 

63 If `True` the full datastore path will be retained within the 

64 destination directory, else only the filename will be used. 

65 clobber : `bool` 

66 If `True` allow transfers to overwrite files at the destination. 

67 qgraph_node_id : `tuple` [ `str` ] 

68 Quanta to extract. 

69 include_inputs : `bool` 

70 Whether to include input datasets in retrieval. 

71 include_outputs : `bool` 

72 Whether to include output datasets in retrieval. 

73 

74 Returns 

75 ------- 

76 paths : `list` [ `lsst.resources.ResourcePath` ] 

77 The paths to the artifacts that were written. 

78 """ 

79 # Read graph into memory. 

80 nodes = qgraph_node_id or None 

81 qgraph = QuantumGraph.loadUri(graph, nodes=nodes) 

82 

83 refs, datastore_records = qgraph.get_refs( 

84 include_inputs=include_inputs, 

85 include_init_inputs=include_inputs, 

86 include_outputs=include_outputs, 

87 include_init_outputs=include_outputs, 

88 conform_outputs=True, # Need to look for predicted outputs with correct storage class. 

89 ) 

90 

91 # Get data repository definitions from the QuantumGraph; these can have 

92 # different storage classes than those in the quanta. 

93 dataset_types = {dstype.name: dstype for dstype in qgraph.registryDatasetTypes()} 

94 

95 # Make QBB, its config is the same as output Butler. 

96 with QuantumBackedButler.from_predicted( 

97 config=repo, 

98 predicted_inputs=[ref.id for ref in refs], 

99 predicted_outputs=[], 

100 dimensions=qgraph.universe, 

101 datastore_records=datastore_records, 

102 dataset_types=dataset_types, 

103 ) as qbb: 

104 paths = qbb.retrieve_artifacts( 

105 refs, dest, transfer=transfer, overwrite=clobber, preserve_path=preserve_path 

106 ) 

107 return paths