Coverage for tests/cameraMapper.py: 24%
Shortcuts 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
Shortcuts 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# LSST Data Management System
3# Copyright 2008, 2009, 2010 LSST Corporation.
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#
24import re
25import lsst.daf.persistence as dafPersist
28class CameraMapper(dafPersist.Mapper):
30 def __init__(self, *args, **kwargs):
31 self.templates = dict(
32 raw="raw_v%(visit)d_R%(raft)s_S%(sensor)s_C%(amp)s_E%(snap)03d.pickle",
33 flat="flat_R%(raft)s_S%(sensor)s_C%(amp)s_E%(snap)03d.pickle",
34 calexp="calexp_v%(visit)d_R%(raft)s_S%(sensor)s.pickle")
35 self.synonyms = dict(
36 ccd="sensor",
37 channel="amp"
38 )
39 self.levels = dict(
40 skyTile=["visit", "raft", "sensor"],
41 visit=["snap", "raft", "sensor", "amp"],
42 raft=["snap", "sensor", "amp"],
43 sensor=["snap", "amp"],
44 amp=[])
46 def _formatMap(self, ch, k, datasetType):
47 if ch in "diouxX":
48 return int
49 elif ch in "eEfFgG":
50 return float
51 elif ch in "crs":
52 return str
53 else:
54 raise RuntimeError("Unexpected format specifier %s"
55 " for field %s in template for dataset %s" %
56 (ch, k, datasetType))
58 def getKeys(self, datasetType, level):
59 if level == '':
60 level = self.getDefaultLevel()
62 keyDict = dict()
63 if datasetType is None:
64 for t in self.templates:
65 keyDict.update(self.getKeys(t))
66 else:
67 d = dict([
68 (k, self._formatMap(v, k, datasetType))
69 for k, v in
70 re.findall(r'\%\((\w+)\).*?([diouxXeEfFgGcrs])',
71 self.templates[datasetType])
72 ])
73 keyDict.update(d)
74 if level is not None:
75 for lev in self.levels[level]:
76 if lev in keyDict:
77 del keyDict[lev]
78 return keyDict
80 def getDefaultLevel(self):
81 return "sensor"
83 def getDefaultSubLevel(self, level):
84 if level == '':
85 level = self.getDefaultLevel()
86 return dict(
87 sensor="amp",
88 raft="sensor",
89 visit="sensor",
90 skyTile="sensor")[level]
92 def query(self, datasetType, format, dataId):
93 return self.registry.query(datasetType, format, dataId)
95 def map(self, datasetType, dataId, write=False):
96 path = self.templates[datasetType] % dataId
97 return dafPersist.ButlerLocation(
98 None, None, "PickleStorage", path, {}, self,
99 dafPersist.Storage.makeFromURI(self.root))
102for datasetType in ["raw", "flat", "calexp"]:
103 setattr(CameraMapper, "map_" + datasetType, 103 ↛ exitline 103 didn't jump to the function exit
104 lambda self, dataId, write:
105 CameraMapper.map(self, datasetType, dataId, write))
106 setattr(CameraMapper, "query_" + datasetType, 106 ↛ exitline 106 didn't jump to the function exit
107 lambda self, format, dataId:
108 CameraMapper.query(self, datasetType, format, dataId))