22 """Retrieve collections of metadata or data based on a set of data references 24 Use this as a base task for creating graphs and reports for a set of data. 26 from __future__
import absolute_import, division, print_function
27 import lsst.pex.config
as pexConfig
28 import lsst.pipe.base
as pipeBase
30 __all__ = [
"DataRefListRunner",
"GetRepositoryDataTask"]
34 """A task runner that calls run with a list of data references 36 Differs from the default TaskRunner by providing all data references at once, 37 instead of iterating over them one at a time. 41 """Return a list of targets (arguments for __call__); one entry per invocation 43 return [parsedCmd.id.refList]
46 """Run GetRepositoryDataTask.run on a single target 48 @param dataRefList: argument dict for run; contains one key: dataRefList 51 - None if doReturnResults false 52 - A pipe_base Struct containing these fields if doReturnResults true: 53 - dataRefList: the argument dict sent to runDataRef 54 - metadata: task metadata after execution of runDataRef 55 - result: result returned by task runDataRef 57 task = self.TaskClass(config=self.config, log=self.log)
58 result = task.run(dataRefList)
60 if self.doReturnResults:
61 return pipeBase.Struct(
62 dataRefList=dataRefList,
63 metadata=task.metadata,
69 """Retrieve data from a repository, e.g. for plotting or analysis purposes 71 ConfigClass = pexConfig.Config
72 RunnerClass = DataRefListRunner
73 _DefaultName =
"getTaskData" 76 pipeBase.CmdLineTask.__init__(self, *args, **kwargs)
79 def run(self, dataRefList):
80 """Get data from a repository for a collection of data references 82 @param dataRefList: a list of data references 84 raise NotImplementedError(
"subclass must specify a run method")
87 """Get a list of data IDs in a form that can be used as dictionary keys 89 @param dataRefList: a list of data references 90 @return a pipe_base Struct with fields: 91 - idKeyTuple: a tuple of dataRef data ID keys 92 - idValList: a list of data ID value tuples, each tuple contains values in the order in idKeyTuple 95 raise RuntimeError(
"No data refs")
96 idKeyTuple = tuple(sorted(dataRefList[0].dataId.keys()))
99 for dataRef
in dataRefList:
100 idValTuple = tuple(dataRef.dataId[key]
for key
in idKeyTuple)
101 idValList.append(idValTuple)
103 return pipeBase.Struct(
104 idKeyTuple=idKeyTuple,
109 """Retrieve a list of data 111 @param dataRefList: a list of data references 112 @param datasetType: datasetType of data to be retrieved 113 @return a list of data, one entry per dataRef in dataRefList (in order) 115 return [dataRef.get(datasetType=datasetType)
for dataRef
in dataRefList]
118 """Retrieve a list of dictionaries of metadata 120 @param dataRefList: a list of data references 121 @param datasetType: datasetType of metadata (or any object that supports get(name)) 122 @return a list of dicts of metadata: 123 - each entry in the list corresponds to a dataRef in dataRefList 124 - each dict contains name: item of metadata, for each name in nameList 127 for dataRef
in dataRefList:
128 metadata = dataRef.get(datasetType=datasetType)
129 valList.append(dict((name, metadata.get(name))
for name
in nameList))
def getMetadataItems(self, dataRefList, datasetType, nameList)
def __init__(self, args, kwargs)
def getIdList(self, dataRefList)
def run(self, dataRefList)
def getTargetList(parsedCmd)
def __call__(self, dataRefList)
def getDataList(self, dataRefList, datasetType)