Coverage for python/lsst/ap/verify/pipeline_driver.py : 25%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#
2# This file is part of ap_verify.
3#
4# Developed for the LSST Data Management System.
5# This product includes software developed by the LSST Project
6# (http://www.lsst.org).
7# See the COPYRIGHT file at the top-level directory of this distribution
8# for details of code ownership.
9#
10# This program is free software: you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation, either version 3 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program. If not, see <http://www.gnu.org/licenses/>.
22#
24"""Interface between `ap_verify` and `ap_pipe`.
26This module handles calling `ap_pipe` and converting any information
27as needed.
28"""
30__all__ = ["ApPipeParser", "runApPipe"]
32import argparse
33import os
35import lsst.log
36import lsst.pipe.base as pipeBase
37import lsst.ap.pipe as apPipe
38from lsst.ap.pipe.make_apdb import makeApdb
41class ApPipeParser(argparse.ArgumentParser):
42 """An argument parser for data needed by ``ap_pipe`` activities.
44 This parser is not complete, and is designed to be passed to another parser
45 using the `parent` parameter.
46 """
48 def __init__(self):
49 # Help and documentation will be handled by main program's parser
50 argparse.ArgumentParser.__init__(self, add_help=False)
51 self.add_argument('--id', dest='dataIds', action='append', default=[],
52 help='An identifier for the data to process.')
53 self.add_argument("-j", "--processes", default=1, type=int,
54 help="Number of processes to use.")
55 self.add_argument("--skip-pipeline", action="store_true",
56 help="Do not run the AP pipeline itself. This argument is useful "
57 "for testing metrics on a fixed data set.")
60def runApPipe(workspace, parsedCmdLine):
61 """Run `ap_pipe` on this object's dataset.
63 Parameters
64 ----------
65 workspace : `lsst.ap.verify.workspace.Workspace`
66 The abstract location containing input and output repositories.
67 parsedCmdLine : `argparse.Namespace`
68 Command-line arguments, including all arguments supported by `ApPipeParser`.
70 Returns
71 -------
72 apPipeReturn : `Struct`
73 The `Struct` returned from `~lsst.ap.pipe.ApPipeTask.parseAndRun` with
74 ``doReturnResults=False``. This object is valid even if
75 `~lsst.ap.pipe.ApPipeTask` was never run.
76 """
77 log = lsst.log.Log.getLogger('ap.verify.pipeline_driver.runApPipe')
79 configArgs = _getConfigArguments(workspace)
80 makeApdb(configArgs)
82 pipelineArgs = [workspace.dataRepo,
83 "--output", workspace.outputRepo,
84 "--calib", workspace.calibRepo,
85 "--template", workspace.templateRepo]
86 pipelineArgs.extend(configArgs)
87 if parsedCmdLine.dataIds:
88 for singleId in parsedCmdLine.dataIds:
89 pipelineArgs.extend(["--id", *singleId.split(" ")])
90 else:
91 pipelineArgs.extend(["--id"])
92 pipelineArgs.extend(["--processes", str(parsedCmdLine.processes)])
93 pipelineArgs.extend(["--noExit"])
95 if not parsedCmdLine.skip_pipeline:
96 results = apPipe.ApPipeTask.parseAndRun(pipelineArgs)
97 log.info('Pipeline complete')
98 else:
99 log.info('Skipping AP pipeline entirely.')
100 apPipeParser = apPipe.ApPipeTask._makeArgumentParser()
101 apPipeParsed = apPipeParser.parse_args(config=apPipe.ApPipeTask.ConfigClass(), args=pipelineArgs)
102 results = pipeBase.Struct(
103 argumentParser=apPipeParser,
104 parsedCmd=apPipeParsed,
105 taskRunner=apPipe.ApPipeTask.RunnerClass(TaskClass=apPipe.ApPipeTask, parsedCmd=apPipeParsed),
106 resultList=[],
107 )
109 return results
112def _getConfigArguments(workspace):
113 """Return the config options for running ApPipeTask on this workspace, as
114 command-line arguments.
116 Parameters
117 ----------
118 workspace : `lsst.ap.verify.workspace.Workspace`
119 A Workspace whose config directory may contain an
120 `~lsst.ap.pipe.ApPipeTask` config.
122 Returns
123 -------
124 args : `list` of `str`
125 Command-line arguments calling ``--config`` or ``--configFile``,
126 following the conventions of `sys.argv`.
127 """
128 overrideFile = apPipe.ApPipeTask._DefaultName + ".py"
129 overridePath = os.path.join(workspace.configDir, overrideFile)
131 args = ["--configfile", overridePath]
132 # ApVerify will use the sqlite hooks for the Apdb.
133 args.extend(["--config", "diaPipe.apdb.db_url=sqlite:///" + workspace.dbLocation])
134 args.extend(["--config", "diaPipe.apdb.isolation_level=READ_UNCOMMITTED"])
135 # Put output alerts into the workspace.
136 args.extend(["--config", "diaPipe.alertPackager.alertWriteLocation=" + workspace.workDir + "/alerts"])
138 return args