LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Classes | Functions | Variables
lsst.datarel.datasetScanner Namespace Reference

Classes

class  _FormatKey
 
class  _PathComponent
 
class  HfsScanner
 
class  DatasetScanner
 

Functions

def getMapperClass
 
def parseDataIdRules
 
def _mungeStr
 
def _mungeInt
 
def _mungeLsstSim
 
def _mungeSdss
 
def _mungeCfht
 

Variables

list __all__
 
dictionary _mapperClassName
 
dictionary _keyTypes
 
dictionary _mungeFunctions
 

Function Documentation

def lsst.datarel.datasetScanner._mungeCfht (   k,
  v,
  dataId 
)
private

Definition at line 370 of file datasetScanner.py.

371 def _mungeCfht(k, v, dataId):
372  dataId = dataId.copy()
373  if k == 'ccd':
374  dataId['ccd'] = int(v)
375  dataId['ccdName'] = v
376  elif k == 'amp':
377  dataId['amp'] = int(v)
378  dataId['ampName'] = v
379  elif _keyTypes['sdss'][k] == int:
380  dataId[k] = int(v)
381  else:
382  dataId[k] = v
383  return dataId
def lsst.datarel.datasetScanner._mungeInt (   k,
  v,
  dataId 
)
private
Munger for keys with integer formats.

Definition at line 177 of file datasetScanner.py.

178 def _mungeInt(k, v, dataId):
179  """Munger for keys with integer formats."""
180  kv = dataId.copy()
181  kv[k] = int(v)
182  return kv
183 
def lsst.datarel.datasetScanner._mungeLsstSim (   k,
  v,
  dataId 
)
private

Definition at line 340 of file datasetScanner.py.

341 def _mungeLsstSim(k, v, dataId):
342  dataId = dataId.copy()
343  if k == 'raft':
344  r1, r2 = v
345  dataId['raft'] = r1 + ',' + r2
346  dataId['raftId'] = int(r1) * 5 + int(r2)
347  elif k in ('sensor', 'ccd'):
348  s1, s2 = v
349  dataId['sensor'] = s1 + ',' + s2
350  dataId['sensorNum'] = int(s1) * 3 + int(s2)
351  elif k in ('channel', 'amp'):
352  c1, c2 = v
353  dataId['channel'] = c1 + ',' + c2
354  dataId['channelNum'] = int(c1) * 8 + int(c2)
355  elif k in ('snap', 'exposure'):
356  dataId['snap'] = int(v)
357  elif _keyTypes['lsstsim'][k] == int:
358  dataId[k] = int(v)
359  else:
360  dataId[k] = v
361  return dataId
def lsst.datarel.datasetScanner._mungeSdss (   k,
  v,
  dataId 
)
private

Definition at line 362 of file datasetScanner.py.

363 def _mungeSdss(k, v, dataId):
364  dataId = dataId.copy()
365  if _keyTypes['sdss'][k] == int:
366  dataId[k] = int(v)
367  else:
368  dataId[k] = v
369  return dataId
def lsst.datarel.datasetScanner._mungeStr (   k,
  v,
  dataId 
)
private
Munger for keys with string formats.

Definition at line 171 of file datasetScanner.py.

172 def _mungeStr(k, v, dataId):
173  """Munger for keys with string formats."""
174  kv = dataId.copy()
175  kv[k] = str(v)
176  return kv
def lsst.datarel.datasetScanner.getMapperClass (   camera)
Return the subclass of lsst.daf.persistence.Mapper
to use for the camera with the given name (case-insensitive).

Definition at line 41 of file datasetScanner.py.

41 
42 def getMapperClass(camera):
43  """Return the subclass of lsst.daf.persistence.Mapper
44  to use for the camera with the given name (case-insensitive).
45  """
46  camera = camera.lower()
47  if camera not in _mapperClassName:
48  raise RuntimeError(str.format("{} is not a valid camera name", camera))
49  name = _mapperClassName[camera]
50  try:
51  pieces = name.split('.')
52  cls = reduce(getattr, pieces[1:], __import__('.'.join(pieces[:-1])))
53  return cls
54  except:
55  raise RuntimeError(str.format("Failed to import {}", name))
56 
def lsst.datarel.datasetScanner.parseDataIdRules (   ruleList,
  camera 
)
A rule is a string in the following format:

'key=value1[^value2[^value3...]'

The values may either be strings, or of the form 'int...int'
(e.g. '1..3') which is interpreted as '1^2^3' (inclusive, unlike a python
range). So '0^2..4^7..9' is equivalent to '0^2^3^4^7^8^9'.

This function parses a list of such strings, and returns a dict mapping
keys to sets of legal values.

ruleList:
    List of rule strings
camera:
    Camera the rule list applies to (e.g. 'lsstSim' or 'sdss')

Definition at line 104 of file datasetScanner.py.

105 def parseDataIdRules(ruleList, camera):
106  """A rule is a string in the following format:
107 
108  'key=value1[^value2[^value3...]'
109 
110  The values may either be strings, or of the form 'int...int'
111  (e.g. '1..3') which is interpreted as '1^2^3' (inclusive, unlike a python
112  range). So '0^2..4^7..9' is equivalent to '0^2^3^4^7^8^9'.
113 
114  This function parses a list of such strings, and returns a dict mapping
115  keys to sets of legal values.
116 
117  ruleList:
118  List of rule strings
119  camera:
120  Camera the rule list applies to (e.g. 'lsstSim' or 'sdss')
121  """
122  camera = camera.lower()
123  if camera not in _keyTypes:
124  raise RuntimeError('{} is not a recognized camera name'.format(camera))
125  kvs = {}
126  for rule in ruleList:
127  # process rule for a single key
128  key, _, pattern = rule.partition('=')
129  if key not in _keyTypes[camera]:
130  raise RuntimeError('{} is not a valid dataId key for camera {}'.format(key, camera))
131  if len(pattern) == 0:
132  continue
133  values = set()
134  # compute union of all values or value ranges
135  for p in pattern.split('^'):
136  if _keyTypes[camera][key] == int:
137  # check for range syntax
138  m = re.search(r'^(\d+)\.\.(\d+)$', p)
139  if m:
140  values.update(xrange(int(m.group(1)), int(m.group(2)) + 1))
141  else:
142  values.add(int(p))
143  else:
144  values.add(p)
145  if key in kvs:
146  kvs[key].update(values)
147  else:
148  kvs[key] = values
149  return kvs
150 

Variable Documentation

list lsst.datarel.datasetScanner.__all__
Initial value:
1 = ['getMapperClass',
2  'parseDataIdRules',
3  'HfsScanner',
4  'DatasetScanner',
5  ]

Definition at line 27 of file datasetScanner.py.

dictionary lsst.datarel.datasetScanner._keyTypes

Definition at line 57 of file datasetScanner.py.

dictionary lsst.datarel.datasetScanner._mapperClassName
Initial value:
1 = {
2  'lsstsim': 'lsst.obs.lsstSim.LsstSimMapper',
3  'sdss': 'lsst.obs.sdss.SdssMapper',
4  'cfht': 'lsst.obs.cfht.CfhtMapper',
5 }

Definition at line 34 of file datasetScanner.py.

dictionary lsst.datarel.datasetScanner._mungeFunctions
Initial value:
1 = {
2  'lsstsim': _mungeLsstSim,
3  'sdss': _mungeSdss,
4  'cfht': _mungeCfht,
5 }

Definition at line 384 of file datasetScanner.py.