LSSTApplications  18.1.0
LSSTDataManagementBasePackage
Public Member Functions | Public Attributes | List of all members
lsst.obs.base.mapping.ExposureMapping Class Reference
Inheritance diagram for lsst.obs.base.mapping.ExposureMapping:
lsst.obs.base.mapping.Mapping

Public Member Functions

def __init__ (self, datasetType, policy, registry, root, kwargs)
 
def standardize (self, mapper, item, dataId)
 
def template (self)
 
def keys (self)
 
def map (self, mapper, dataId, write=False)
 
def lookup (self, properties, dataId)
 
def have (self, properties, dataId)
 
def need (self, properties, dataId)
 

Public Attributes

 columns
 
 datasetType
 
 registry
 
 rootStorage
 
 keyDict
 
 python
 
 persistable
 
 storage
 
 level
 
 tables
 
 range
 
 obsTimeName
 
 recipe
 

Detailed Description

ExposureMapping is a Mapping subclass for normal exposures.

Parameters
----------
datasetType : `str`
    Butler dataset type to be mapped.
policy : `daf_persistence.Policy`
    Mapping Policy.
registry : `lsst.obs.base.Registry`
    Registry for metadata lookups
root : `str`
    Path of root directory

Definition at line 359 of file mapping.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.obs.base.mapping.ExposureMapping.__init__ (   self,
  datasetType,
  policy,
  registry,
  root,
  kwargs 
)

Definition at line 374 of file mapping.py.

374  def __init__(self, datasetType, policy, registry, root, **kwargs):
375  Mapping.__init__(self, datasetType, policy, registry, root, **kwargs)
376  self.columns = policy.asArray('columns') if 'columns' in policy else None
377 
def __init__(self, minimum, dataRange, Q)

Member Function Documentation

◆ have()

def lsst.obs.base.mapping.Mapping.have (   self,
  properties,
  dataId 
)
inherited
Returns whether the provided data identifier has all
the properties in the provided list.

Parameters
----------
properties : `list of `str`
    Properties required.
dataId : `dict`
    Dataset identifier.

Returns
-------
bool
    True if all properties are present.

Definition at line 268 of file mapping.py.

268  def have(self, properties, dataId):
269  """Returns whether the provided data identifier has all
270  the properties in the provided list.
271 
272  Parameters
273  ----------
274  properties : `list of `str`
275  Properties required.
276  dataId : `dict`
277  Dataset identifier.
278 
279  Returns
280  -------
281  bool
282  True if all properties are present.
283  """
284  for prop in properties:
285  if prop not in dataId:
286  return False
287  return True
288 

◆ keys()

def lsst.obs.base.mapping.Mapping.keys (   self)
inherited
Return the dict of keys and value types required for this mapping.

Definition at line 132 of file mapping.py.

132  def keys(self):
133  """Return the dict of keys and value types required for this mapping."""
134  return self.keyDict
135 

◆ lookup()

def lsst.obs.base.mapping.Mapping.lookup (   self,
  properties,
  dataId 
)
inherited
Look up properties for in a metadata registry given a partial
dataset identifier.

Parameters
----------
properties : `list` of `str`
    What to look up.
dataId : `dict`
    Dataset identifier

Returns
-------
`list` of `tuple`
    Values of properties.

Definition at line 186 of file mapping.py.

186  def lookup(self, properties, dataId):
187  """Look up properties for in a metadata registry given a partial
188  dataset identifier.
189 
190  Parameters
191  ----------
192  properties : `list` of `str`
193  What to look up.
194  dataId : `dict`
195  Dataset identifier
196 
197  Returns
198  -------
199  `list` of `tuple`
200  Values of properties.
201  """
202  if self.registry is None:
203  raise RuntimeError("No registry for lookup")
204 
205  skyMapKeys = ("tract", "patch")
206 
207  where = []
208  values = []
209 
210  # Prepare to remove skymap entries from properties list. These must
211  # be in the data ID, so we store which ones we're removing and create
212  # an OrderedDict that tells us where to re-insert them. That maps the
213  # name of the property to either its index in the properties list
214  # *after* the skymap ones have been removed (for entries that aren't
215  # skymap ones) or the value from the data ID (for those that are).
216  removed = set()
217  substitutions = OrderedDict()
218  index = 0
219  properties = list(properties) # don't modify the original list
220  for p in properties:
221  if p in skyMapKeys:
222  try:
223  substitutions[p] = dataId[p]
224  removed.add(p)
225  except KeyError:
226  raise RuntimeError(
227  "Cannot look up skymap key '%s'; it must be explicitly included in the data ID" % p
228  )
229  else:
230  substitutions[p] = index
231  index += 1
232  # Can't actually remove while iterating above, so we do it here.
233  for p in removed:
234  properties.remove(p)
235 
236  fastPath = True
237  for p in properties:
238  if p not in ('filter', 'expTime', 'taiObs'):
239  fastPath = False
240  break
241  if fastPath and 'visit' in dataId and "raw" in self.tables:
242  lookupDataId = {'visit': dataId['visit']}
243  result = self.registry.lookup(properties, 'raw_visit', lookupDataId, template=self.template)
244  else:
245  if dataId is not None:
246  for k, v in dataId.items():
247  if self.columns and k not in self.columns:
248  continue
249  if k == self.obsTimeName:
250  continue
251  if k in skyMapKeys:
252  continue
253  where.append((k, '?'))
254  values.append(v)
255  lookupDataId = {k[0]: v for k, v in zip(where, values)}
256  if self.range:
257  # format of self.range is ('?', isBetween-lowKey, isBetween-highKey)
258  # here we transform that to {(lowKey, highKey): value}
259  lookupDataId[(self.range[1], self.range[2])] = dataId[self.obsTimeName]
260  result = self.registry.lookup(properties, self.tables, lookupDataId, template=self.template)
261  if not removed:
262  return result
263  # Iterate over the query results, re-inserting the skymap entries.
264  result = [tuple(v if k in removed else item[v] for k, v in substitutions.items())
265  for item in result]
266  return result
267 
daf::base::PropertySet * set
Definition: fits.cc:884
daf::base::PropertyList * list
Definition: fits.cc:885

◆ map()

def lsst.obs.base.mapping.Mapping.map (   self,
  mapper,
  dataId,
  write = False 
)
inherited
Standard implementation of map function.

Parameters
----------
mapper: `lsst.daf.persistence.Mapper`
    Object to be mapped.
dataId: `dict`
    Dataset identifier.

Returns
-------
lsst.daf.persistence.ButlerLocation
    Location of object that was mapped.

Definition at line 136 of file mapping.py.

136  def map(self, mapper, dataId, write=False):
137  """Standard implementation of map function.
138 
139  Parameters
140  ----------
141  mapper: `lsst.daf.persistence.Mapper`
142  Object to be mapped.
143  dataId: `dict`
144  Dataset identifier.
145 
146  Returns
147  -------
148  lsst.daf.persistence.ButlerLocation
149  Location of object that was mapped.
150  """
151  actualId = self.need(iter(self.keyDict.keys()), dataId)
152  usedDataId = {key: actualId[key] for key in self.keyDict.keys()}
153  path = mapper._mapActualToPath(self.template, actualId)
154  if os.path.isabs(path):
155  raise RuntimeError("Mapped path should not be absolute.")
156  if not write:
157  # This allows mapped files to be compressed, ending in .gz or .fz, without any indication from the
158  # policy that the file should be compressed, easily allowing repositories to contain a combination
159  # of comporessed and not-compressed files.
160  # If needed we can add a policy flag to allow compressed files or not, and perhaps a list of
161  # allowed extensions that may exist at the end of the template.
162  for ext in (None, '.gz', '.fz'):
163  if ext and path.endswith(ext):
164  continue # if the path already ends with the extension
165  extPath = path + ext if ext else path
166  newPath = self.rootStorage.instanceSearch(extPath)
167  if newPath:
168  path = newPath
169  break
170  assert path, "Fully-qualified filename is empty."
171 
172  addFunc = "add_" + self.datasetType # Name of method for additionalData
173  if hasattr(mapper, addFunc):
174  addFunc = getattr(mapper, addFunc)
175  additionalData = addFunc(self.datasetType, actualId)
176  assert isinstance(additionalData, PropertySet), \
177  "Bad type for returned data: %s" (type(additionalData),)
178  else:
179  additionalData = None
180 
181  return ButlerLocation(pythonType=self.python, cppType=self.persistable, storageName=self.storage,
182  locationList=path, dataId=actualId.copy(), mapper=mapper,
183  storage=self.rootStorage, usedDataId=usedDataId, datasetType=self.datasetType,
184  additionalData=additionalData)
185 
table::Key< int > type
Definition: Detector.cc:167

◆ need()

def lsst.obs.base.mapping.Mapping.need (   self,
  properties,
  dataId 
)
inherited
Ensures all properties in the provided list are present in
the data identifier, looking them up as needed.  This is only
possible for the case where the data identifies a single
exposure.

Parameters
----------
properties : `list` of `str`
    Properties required.
dataId : `dict`
    Partial dataset identifier

Returns
-------
`dict`
    Copy of dataset identifier with enhanced values.

Definition at line 289 of file mapping.py.

289  def need(self, properties, dataId):
290  """Ensures all properties in the provided list are present in
291  the data identifier, looking them up as needed. This is only
292  possible for the case where the data identifies a single
293  exposure.
294 
295  Parameters
296  ----------
297  properties : `list` of `str`
298  Properties required.
299  dataId : `dict`
300  Partial dataset identifier
301 
302  Returns
303  -------
304  `dict`
305  Copy of dataset identifier with enhanced values.
306  """
307  newId = dataId.copy()
308  newProps = [] # Properties we don't already have
309  for prop in properties:
310  if prop not in newId:
311  newProps.append(prop)
312  if len(newProps) == 0:
313  return newId
314 
315  lookups = self.lookup(newProps, newId)
316  if len(lookups) != 1:
317  raise NoResults("No unique lookup for %s from %s: %d matches" %
318  (newProps, newId, len(lookups)),
319  self.datasetType, dataId)
320  for i, prop in enumerate(newProps):
321  newId[prop] = lookups[0][i]
322  return newId
323 
324 

◆ standardize()

def lsst.obs.base.mapping.ExposureMapping.standardize (   self,
  mapper,
  item,
  dataId 
)

Definition at line 378 of file mapping.py.

378  def standardize(self, mapper, item, dataId):
379  return mapper._standardizeExposure(self, item, dataId)
380 
381 

◆ template()

def lsst.obs.base.mapping.Mapping.template (   self)
inherited

Definition at line 125 of file mapping.py.

125  def template(self):
126  if self._template: # template must not be an empty string or None
127  return self._template
128  else:
129  raise RuntimeError("Template is not defined for the {} dataset type, ".format(self.datasetType) +
130  "it must be set before it can be used.")
131 
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:168

Member Data Documentation

◆ columns

lsst.obs.base.mapping.ExposureMapping.columns

Definition at line 376 of file mapping.py.

◆ datasetType

lsst.obs.base.mapping.Mapping.datasetType
inherited

Definition at line 88 of file mapping.py.

◆ keyDict

lsst.obs.base.mapping.Mapping.keyDict
inherited

Definition at line 99 of file mapping.py.

◆ level

lsst.obs.base.mapping.Mapping.level
inherited

Definition at line 114 of file mapping.py.

◆ obsTimeName

lsst.obs.base.mapping.Mapping.obsTimeName
inherited

Definition at line 121 of file mapping.py.

◆ persistable

lsst.obs.base.mapping.Mapping.persistable
inherited

Definition at line 111 of file mapping.py.

◆ python

lsst.obs.base.mapping.Mapping.python
inherited

Definition at line 110 of file mapping.py.

◆ range

lsst.obs.base.mapping.Mapping.range
inherited

Definition at line 119 of file mapping.py.

◆ recipe

lsst.obs.base.mapping.Mapping.recipe
inherited

Definition at line 122 of file mapping.py.

◆ registry

lsst.obs.base.mapping.Mapping.registry
inherited

Definition at line 89 of file mapping.py.

◆ rootStorage

lsst.obs.base.mapping.Mapping.rootStorage
inherited

Definition at line 90 of file mapping.py.

◆ storage

lsst.obs.base.mapping.Mapping.storage
inherited

Definition at line 112 of file mapping.py.

◆ tables

lsst.obs.base.mapping.Mapping.tables
inherited

Definition at line 116 of file mapping.py.


The documentation for this class was generated from the following file: