LSSTApplications  11.0-13-gbb96280,12.1+18,12.1+7,12.1-1-g14f38d3+72,12.1-1-g16c0db7+5,12.1-1-g5961e7a+84,12.1-1-ge22e12b+23,12.1-11-g06625e2+4,12.1-11-g0d7f63b+4,12.1-19-gd507bfc,12.1-2-g7dda0ab+38,12.1-2-gc0bc6ab+81,12.1-21-g6ffe579+2,12.1-21-gbdb6c2a+4,12.1-24-g941c398+5,12.1-3-g57f6835+7,12.1-3-gf0736f3,12.1-37-g3ddd237,12.1-4-gf46015e+5,12.1-5-g06c326c+20,12.1-5-g648ee80+3,12.1-5-gc2189d7+4,12.1-6-ga608fc0+1,12.1-7-g3349e2a+5,12.1-7-gfd75620+9,12.1-9-g577b946+5,12.1-9-gc4df26a+10
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 378 of file datasetScanner.py.

379 def _mungeCfht(k, v, dataId):
380  dataId = dataId.copy()
381  if k == 'ccd':
382  dataId['ccd'] = int(v)
383  dataId['ccdName'] = v
384  elif k == 'amp':
385  dataId['amp'] = int(v)
386  dataId['ampName'] = v
387  elif _keyTypes['sdss'][k] == int:
388  dataId[k] = int(v)
389  else:
390  dataId[k] = v
391  return dataId
def lsst.datarel.datasetScanner._mungeInt (   k,
  v,
  dataId 
)
private
Munger for keys with integer formats.

Definition at line 181 of file datasetScanner.py.

182 def _mungeInt(k, v, dataId):
183  """Munger for keys with integer formats."""
184  kv = dataId.copy()
185  kv[k] = int(v)
186  return kv
187 
def lsst.datarel.datasetScanner._mungeLsstSim (   k,
  v,
  dataId 
)
private

Definition at line 346 of file datasetScanner.py.

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

Definition at line 369 of file datasetScanner.py.

370 def _mungeSdss(k, v, dataId):
371  dataId = dataId.copy()
372  if _keyTypes['sdss'][k] == int:
373  dataId[k] = int(v)
374  else:
375  dataId[k] = v
376  return dataId
377 
def lsst.datarel.datasetScanner._mungeStr (   k,
  v,
  dataId 
)
private
Munger for keys with string formats.

Definition at line 174 of file datasetScanner.py.

175 def _mungeStr(k, v, dataId):
176  """Munger for keys with string formats."""
177  kv = dataId.copy()
178  kv[k] = str(v)
179  return kv
180 
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 42 of file datasetScanner.py.

42 
43 def getMapperClass(camera):
44  """Return the subclass of lsst.daf.persistence.Mapper
45  to use for the camera with the given name (case-insensitive).
46  """
47  camera = camera.lower()
48  if camera not in _mapperClassName:
49  raise RuntimeError(str.format("{} is not a valid camera name", camera))
50  name = _mapperClassName[camera]
51  try:
52  pieces = name.split('.')
53  cls = reduce(getattr, pieces[1:], __import__('.'.join(pieces[:-1])))
54  return cls
55  except:
56  raise RuntimeError(str.format("Failed to import {}", name))
57 
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 105 of file datasetScanner.py.

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

Variable Documentation

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

Definition at line 28 of file datasetScanner.py.

dictionary lsst.datarel.datasetScanner._keyTypes

Definition at line 58 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 35 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 392 of file datasetScanner.py.