LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
coaddDataIdContainer.py
Go to the documentation of this file.
1 #
2 # LSST Data Management System
3 # Copyright 2008-2015 AURA/LSST.
4 #
5 # This product includes software developed by the
6 # LSST Project (http://www.lsst.org/).
7 #
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the LSST License Statement and
19 # the GNU General Public License along with this program. If not,
20 # see <http://www.lsstcorp.org/LegalNotices/>.
21 #
22 import lsst.pipe.base as pipeBase
23 
24 __all__=["CoaddDataIdContainer", "ExistingCoaddDataIdContainer"]
25 
26 import argparse
27 
28 class CoaddDataIdContainer(pipeBase.DataIdContainer):
29  """A version of lsst.pipe.base.DataIdContainer specialized for coaddition.
30 
31  Required because butler.subset does not support patch and tract
32 
33  This code was originally in pipe_tasks (coaddBase.py)
34  """
35  def getSkymap(self, namespace, datasetType):
36  """Only retrieve skymap if required"""
37  if not hasattr(self, "_skymap"):
38  self._skymap = namespace.butler.get(datasetType + "_skyMap")
39  return self._skymap
40 
41  def makeDataRefList(self, namespace):
42  """Make self.refList from self.idList
43  """
44  datasetType = namespace.config.coaddName + "Coadd"
45  validKeys = namespace.butler.getKeys(datasetType=datasetType, level=self.level)
46 
47  for dataId in self.idList:
48  for key in validKeys:
49  if key in ("tract", "patch"):
50  # Will deal with these explicitly
51  continue
52  if key not in dataId:
53  raise argparse.ArgumentError(None, "--id must include " + key)
54 
55  # tract and patch are required; iterate over them if not provided
56  if not "tract" in dataId:
57  if "patch" in dataId:
58  raise RuntimeError("'patch' cannot be specified without 'tract'")
59  addList = [dict(tract=tract.getId(), patch="%d,%d" % patch.getIndex(), **dataId)
60  for tract in self.getSkymap(namespace, datasetType) for patch in tract]
61  elif not "patch" in dataId:
62  tract = self.getSkymap(namespace, datasetType)[dataId["tract"]]
63  import pdb
64  pdb.set_trace()
65  addList = [dict(patch="%d,%d" % patch.getIndex(), **dataId) for patch in tract]
66  else:
67  addList = [dataId]
68 
69  self.refList += [namespace.butler.dataRef(datasetType=datasetType, dataId=addId)
70  for addId in addList]
71 
73  """A version of CoaddDataIdContainer that only produces references that exist"""
74  def makeDataRefList(self, namespace):
75  super(ExistingCoaddDataIdContainer, self).makeDataRefList(namespace)
76  self.refList = [ref for ref in self.refList if ref.datasetExists()]