Coverage for python/lsst/obs/sdss/sdssMapper.py : 83%

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# 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#
23import os
24import re
26import lsst.daf.persistence as dafPersist
27from lsst.obs.base import CameraMapper, exposureFromImage
28from lsst.obs.sdss.convertfpM import convertfpM
29from lsst.obs.sdss.convertpsField import convertpsField
30from lsst.obs.sdss.convertasTrans import convertasTrans
31from lsst.obs.sdss.converttsField import converttsField
32import lsst.afw.image.utils as afwImageUtils
35class SdssMapper(CameraMapper):
36 packageName = 'obs_sdss'
38 def __init__(self, inputPolicy=None, **kwargs):
39 policyFile = dafPersist.Policy.defaultPolicyFile(self.packageName, "SdssMapper.yaml", "policy")
40 policy = dafPersist.Policy(policyFile)
42 self.doFootprints = False
43 if inputPolicy is not None: 43 ↛ 44line 43 didn't jump to line 44, because the condition on line 43 was never true
44 for kw in inputPolicy.paramNames(True):
45 if kw == "doFootprints":
46 self.doFootprints = True
47 else:
48 kwargs[kw] = inputPolicy.get(kw)
50 super(SdssMapper, self).__init__(policy, os.path.dirname(policyFile), **kwargs)
51 # define filters?
52 self.filterIdMap = dict(u=0, g=1, r=2, i=3, z=4)
54 afwImageUtils.defineFilter('u', lambdaEff=380)
55 afwImageUtils.defineFilter('g', lambdaEff=450)
56 afwImageUtils.defineFilter('r', lambdaEff=600)
57 afwImageUtils.defineFilter('i', lambdaEff=770)
58 afwImageUtils.defineFilter('z', lambdaEff=900)
60 def _computeCcdExposureId(self, dataId):
61 """Compute the 64-bit (long) identifier for a CCD exposure.
63 @param dataId (dict) Data identifier with run, rerun, filter, camcol, field
64 """
65 return ((int(dataId['run']) * 10
66 + self.filterIdMap[dataId['filter']]) * 10
67 + dataId['camcol']) * 10000 + dataId['field']
69 def _computeCoaddExposureId(self, dataId, singleFilter):
70 """Compute the 64-bit (long) identifier for a coadd.
72 @param dataId (dict) Data identifier with tract and patch.
73 @param singleFilter (bool) True means the desired ID is for a single-
74 filter coadd, in which case dataId
75 must contain filter.
76 """
77 tract = int(dataId['tract'])
78 if tract < 0 or tract >= 128: 78 ↛ 79line 78 didn't jump to line 79, because the condition on line 78 was never true
79 raise RuntimeError('tract not in range [0,128)')
80 patchX, patchY = [int(n) for n in dataId['patch'].split(',')]
81 for p in (patchX, patchY):
82 if p < 0 or p >= 2**13: 82 ↛ 83line 82 didn't jump to line 83, because the condition on line 82 was never true
83 raise RuntimeError('patch component not in range [0, 8192)')
84 id = (tract * 2**13 + patchX) * 2**13 + patchY
85 if singleFilter: 85 ↛ 87line 85 didn't jump to line 87, because the condition on line 85 was never false
86 return id * 8 + self.filterIdMap[dataId['filter']]
87 return id
89 def _setCcdExposureId(self, propertyList, dataId):
90 propertyList.set("Computed_ccdExposureId", self._computeCcdExposureId(dataId))
91 return propertyList
93 def _standardizeExposure(self, mapping, item, dataId, filter=True,
94 trimmed=True):
95 """Default standardization function for images.
96 @param mapping (lsst.obs.base.Mapping)
97 @param[in,out] item (lsst.afw.image.Exposure)
98 @param dataId (dict) Dataset identifier
99 @param filter (bool) Set filter?
100 @param trimmed (bool) Should detector be marked as trimmed?
101 @return (lsst.afw.image.Exposure) the standardized Exposure"""
103 if (re.search(r'Exposure', mapping.python) and re.search(r'Image', mapping.persistable)):
104 item = exposureFromImage(item, logger=self.log)
105 return item
107###############################################################################
109 def bypass_fpM(self, datasetType, pythonType, location, dataId):
110 return convertfpM(location.getLocationsWithRoot()[0])
112 def bypass_psField(self, datasetType, pythonType, location, dataId):
113 return convertpsField(location.getLocationsWithRoot()[0], dataId['filter'])
115 def bypass_asTrans(self, datasetType, pythonType, location, dataId):
116 return convertasTrans(location.getLocationsWithRoot()[0], dataId['filter'],
117 dataId['camcol'], dataId['field'])
119 def bypass_tsField(self, datasetType, pythonType, location, dataId):
120 return converttsField(location.getLocationsWithRoot()[0], dataId['filter'])
122 def bypass_ccdExposureId(self, datasetType, pythonType, location, dataId):
123 return self._computeCcdExposureId(dataId)
125 def bypass_ccdExposureId_bits(self, datasetType, pythonType, location, dataId):
126 return 38
128 def bypass_deepCoaddId(self, datasetType, pythonType, location, dataId):
129 return self._computeCoaddExposureId(dataId, True)
131 def bypass_deepCoaddId_bits(self, datasetType, pythonType, location, dataId):
132 return 1 + 7 + 13*2 + 3
134 # Keith coadds use run, camcol, field, filter just like CCD exposures
135 bypass_keithCoaddId = bypass_ccdExposureId
136 bypass_keithCoaddId_bits = bypass_ccdExposureId_bits
139###############################################################################
142for dsType in ("fpC", "fpM", "calexp"):
143 setattr(SdssMapper, "std_" + dsType + "_md",
144 lambda self, item, dataId: self._setCcdExposureId(item, dataId))