LSST Applications  21.0.0+75b29a8a7f,21.0.0+e70536a077,21.0.0-1-ga51b5d4+62c747d40b,21.0.0-10-gbfb87ad6+3307648ee3,21.0.0-15-gedb9d5423+47cba9fc36,21.0.0-2-g103fe59+fdf0863a2a,21.0.0-2-g1367e85+d38a93257c,21.0.0-2-g45278ab+e70536a077,21.0.0-2-g5242d73+d38a93257c,21.0.0-2-g7f82c8f+e682ffb718,21.0.0-2-g8dde007+d179fbfa6a,21.0.0-2-g8f08a60+9402881886,21.0.0-2-ga326454+e682ffb718,21.0.0-2-ga63a54e+08647d4b1b,21.0.0-2-gde069b7+26c92b3210,21.0.0-2-gecfae73+0445ed2f95,21.0.0-2-gfc62afb+d38a93257c,21.0.0-27-gbbd0d29+ae871e0f33,21.0.0-28-g5fc5e037+feb0e9397b,21.0.0-3-g21c7a62+f4b9c0ff5c,21.0.0-3-g357aad2+57b0bddf0b,21.0.0-3-g4be5c26+d38a93257c,21.0.0-3-g65f322c+3f454acf5d,21.0.0-3-g7d9da8d+75b29a8a7f,21.0.0-3-gaa929c8+9e4ef6332c,21.0.0-3-ge02ed75+4b120a55c4,21.0.0-4-g3300ddd+e70536a077,21.0.0-4-g591bb35+4b120a55c4,21.0.0-4-gc004bbf+4911b9cd27,21.0.0-4-gccdca77+f94adcd104,21.0.0-4-ge8fba5a+2b3a696ff9,21.0.0-5-gb155db7+2c5429117a,21.0.0-5-gdf36809+637e4641ee,21.0.0-6-g00874e7+c9fd7f7160,21.0.0-6-g4e60332+4b120a55c4,21.0.0-7-gc8ca178+40eb9cf840,21.0.0-8-gfbe0b4b+9e4ef6332c,21.0.0-9-g2fd488a+d83b7cd606,w.2021.05
LSST Data Management Base Package
Public Member Functions | Public Attributes | List of all members
lsst.obs.base.gen2to3.translators.TranslatorFactory Class Reference

Public Member Functions

def __init__ (self, Optional[Log] log=None)
 
def __str__ (self)
 
def addRule (self, KeyHandler handler, Optional[str] instrument=None, Optional[str] datasetTypeName=None, Iterable[str] gen2keys=(), bool consume=True)
 
def addGenericInstrumentRules (self, str instrumentName, str calibFilterType="physical_filter", str detectorKey="ccd", str exposureKey="visit")
 
def makeMatching (self, str datasetTypeName, Dict[str, type] gen2keys, Optional[str] instrument=None, Optional[BaseSkyMap] skyMap=None, Optional[str] skyMapName=None)
 

Public Attributes

 log
 

Detailed Description

A class that manages a system of rules for translating Gen2 data IDs
to Gen3 data IDs, and uses these to construct translators for particular
dataset types.

Parameters
----------
log : `lsst.log.Log`, optional
    A logger for diagnostic messages.

Definition at line 234 of file translators.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.obs.base.gen2to3.translators.TranslatorFactory.__init__ (   self,
Optional[Log]   log = None 
)

Definition at line 244 of file translators.py.

244  def __init__(self, log: Optional[Log] = None):
245  # The rules used to match KeyHandlers when constructing a Translator.
246  self._rules: Dict[
247  Optional[str], # instrument name (or None to match any)
248  Dict[
249  Optional[str], # dataset type name (or None to match any)
250  # gen2keys, handler, consume
251  List[Tuple[FrozenSet[str], KeyHandler, bool]]
252  ]
253  ] = {
254  None: {
255  None: []
256  }
257  }
258  self._addDefaultRules()
259  if log is None:
260  log = Log.getLogger("obs.base.gen2to3.TranslatorFactory")
261  self.log = log
262 

Member Function Documentation

◆ __str__()

def lsst.obs.base.gen2to3.translators.TranslatorFactory.__str__ (   self)

Definition at line 263 of file translators.py.

263  def __str__(self):
264  lines = []
265  for instrumentName, nested in self._rules.items():
266  if instrumentName is None:
267  instrumentName = "[any instrument]"
268  for datasetTypeName, rules in nested.items():
269  if datasetTypeName is None:
270  datasetTypeName = "[any dataset type]"
271  lines.append(f"{instrumentName} + {datasetTypeName}:")
272  for gen2keys, handler, consume in rules:
273  consumed = " (consumed)" if consume else ""
274  lines.append(f" {gen2keys}{consumed}: {handler}")
275  return "\n".join(lines)
276 
std::vector< SchemaItem< Flag > > * items

◆ addGenericInstrumentRules()

def lsst.obs.base.gen2to3.translators.TranslatorFactory.addGenericInstrumentRules (   self,
str  instrumentName,
str   calibFilterType = "physical_filter",
str   detectorKey = "ccd",
str   exposureKey = "visit" 
)
Add translation rules that depend on some properties of the
instrument but are otherwise generic.

Parameters
----------
instrument : `str`
    The short (dimension) name of the instrument that conversion is
    going to be run on.
calibFilterType : `str`, optional
    One of ``physical_filter`` or ``band``, indicating which
    of those the gen2 calibRegistry uses as the ``filter`` key.
detectorKey : `str`, optional
    The gen2 key used to identify what in gen3 is `detector`.
exposureKey : `str`, optional
    The gen2 key used to identify what in gen3 is `exposure`.

Definition at line 358 of file translators.py.

361  exposureKey: str = "visit"):
362  """Add translation rules that depend on some properties of the
363  instrument but are otherwise generic.
364 
365  Parameters
366  ----------
367  instrument : `str`
368  The short (dimension) name of the instrument that conversion is
369  going to be run on.
370  calibFilterType : `str`, optional
371  One of ``physical_filter`` or ``band``, indicating which
372  of those the gen2 calibRegistry uses as the ``filter`` key.
373  detectorKey : `str`, optional
374  The gen2 key used to identify what in gen3 is `detector`.
375  exposureKey : `str`, optional
376  The gen2 key used to identify what in gen3 is `exposure`.
377  """
378  # Add instrument to Gen3 data ID if Gen2 contains exposureKey,
379  # detectorKey, "visit", or "calibDate". (Multiple rules may match, so
380  # we'll actually set instrument in the same dict more than once).
381  self.addRule(ConstantKeyHandler("instrument", instrumentName),
382  instrument=instrumentName, gen2keys=(exposureKey,), consume=False)
383  self.addRule(ConstantKeyHandler("instrument", instrumentName),
384  instrument=instrumentName, gen2keys=(detectorKey,), consume=False)
385  self.addRule(ConstantKeyHandler("instrument", instrumentName),
386  instrument=instrumentName, gen2keys=("calibDate",), consume=False)
387  self.addRule(ConstantKeyHandler("instrument", instrumentName),
388  instrument=instrumentName, gen2keys=("visit",), consume=False)
389 
390  # Copy Gen2 exposureKey to Gen3 'exposure' for raw only. Also consume
391  # filter, since that's implied by 'exposure' in Gen3.
392  self.addRule(CopyKeyHandler("exposure", exposureKey),
393  instrument=instrumentName, datasetTypeName="raw", gen2keys=(exposureKey,),
394  consume=(exposureKey, "filter"))
395 
396  # Copy Gen2 'visit' to Gen3 'visit' otherwise. Also consume filter.
397  self.addRule(CopyKeyHandler("visit"), instrument=instrumentName, gen2keys=("visit",),
398  consume=("visit", "filter"))
399 
400  # Copy Gen2 'ccd' to Gen3 'detector;
401  self.addRule(CopyKeyHandler("detector", detectorKey),
402  instrument=instrumentName,
403  gen2keys=(detectorKey,))
404 
405  # Add instrument for transmission curve datasets (transmission_sensor
406  # is already handled by the above rules).
407  self.addRule(ConstantKeyHandler("instrument", instrumentName),
408  instrument=instrumentName, datasetTypeName="transmission_optics")
409  self.addRule(ConstantKeyHandler("instrument", instrumentName),
410  instrument=instrumentName, datasetTypeName="transmission_atmosphere")
411  self.addRule(ConstantKeyHandler("instrument", instrumentName),
412  instrument=instrumentName, datasetTypeName="transmission_filter")
413  self.addRule(CopyKeyHandler("physical_filter", "filter"),
414  instrument=instrumentName, datasetTypeName="transmission_filter")
415 
416  # Add calibration mapping for filter dependent types
417  for calibType in ('flat', 'sky', 'fringe'):
418  self.addRule(CopyKeyHandler(calibFilterType, "filter"),
419  instrument=instrumentName, datasetTypeName=calibType)
420 

◆ addRule()

def lsst.obs.base.gen2to3.translators.TranslatorFactory.addRule (   self,
KeyHandler  handler,
Optional[str]   instrument = None,
Optional[str]   datasetTypeName = None,
Iterable[str]   gen2keys = (),
bool   consume = True 
)
Add a KeyHandler and an associated matching rule.

Parameters
----------
handler : `KeyHandler`
    A KeyHandler instance to add to a Translator when this rule
    matches.
instrument : `str`
    Gen3 instrument name the Gen2 repository must be associated with
    for this rule to match, or None to match any instrument.
datasetTypeName : `str`
    Name of the DatasetType this rule matches, or None to match any
    DatasetType.
gen2Keys : sequence
    Sequence of Gen2 data ID keys that must all be present for this
    rule to match.
consume : `bool` or `tuple`
    If True (default), remove all entries in gen2keys from the set of
    keys being matched to in order to prevent less-specific handlers
    from matching them.
    May also be a `tuple` listing only the keys to consume.

Definition at line 277 of file translators.py.

279  consume: bool = True):
280  """Add a KeyHandler and an associated matching rule.
281 
282  Parameters
283  ----------
284  handler : `KeyHandler`
285  A KeyHandler instance to add to a Translator when this rule
286  matches.
287  instrument : `str`
288  Gen3 instrument name the Gen2 repository must be associated with
289  for this rule to match, or None to match any instrument.
290  datasetTypeName : `str`
291  Name of the DatasetType this rule matches, or None to match any
292  DatasetType.
293  gen2Keys : sequence
294  Sequence of Gen2 data ID keys that must all be present for this
295  rule to match.
296  consume : `bool` or `tuple`
297  If True (default), remove all entries in gen2keys from the set of
298  keys being matched to in order to prevent less-specific handlers
299  from matching them.
300  May also be a `tuple` listing only the keys to consume.
301  """
302  # Ensure consume is always a frozenset, so we can process it uniformly
303  # from here on.
304  if consume is True:
305  consume = frozenset(gen2keys)
306  elif consume:
307  consume = frozenset(consume)
308  else:
309  consume = frozenset()
310  # find the rules for this instrument, or if we haven't seen it before,
311  # add a nested dictionary that matches any DatasetType name and then
312  # append this rule.
313  rulesForInstrument = self._rules.setdefault(instrument, {None: []})
314  rulesForInstrumentAndDatasetType = rulesForInstrument.setdefault(datasetTypeName, [])
315  rulesForInstrumentAndDatasetType.append((frozenset(gen2keys), handler, consume))
316 

◆ makeMatching()

def lsst.obs.base.gen2to3.translators.TranslatorFactory.makeMatching (   self,
str  datasetTypeName,
Dict[str, type gen2keys,
Optional[str]   instrument = None,
Optional[BaseSkyMap]   skyMap = None,
Optional[str]   skyMapName = None 
)
Construct a Translator appropriate for instances of the given
dataset.

Parameters
----------
datasetTypeName : `str`
    Name of the dataset type.
gen2keys: `dict`
    Keys of a Gen2 data ID for this dataset.
instrument: `str`, optional
    Name of the Gen3 instrument dimension for translated data IDs.
skyMap: `~lsst.skymap.BaseSkyMap`, optional
    The skymap instance that defines any tract/patch data IDs.
    `~lsst.skymap.BaseSkyMap` instances.
skyMapName : `str`, optional
    Gen3 SkyMap Dimension name to be associated with any tract or patch
    Dimensions.

Returns
-------
translator : `Translator`
    A translator whose translate() method can be used to transform Gen2
    data IDs to Gen3 dataIds.

Definition at line 421 of file translators.py.

422  skyMap: Optional[BaseSkyMap] = None, skyMapName: Optional[str] = None):
423  """Construct a Translator appropriate for instances of the given
424  dataset.
425 
426  Parameters
427  ----------
428  datasetTypeName : `str`
429  Name of the dataset type.
430  gen2keys: `dict`
431  Keys of a Gen2 data ID for this dataset.
432  instrument: `str`, optional
433  Name of the Gen3 instrument dimension for translated data IDs.
434  skyMap: `~lsst.skymap.BaseSkyMap`, optional
435  The skymap instance that defines any tract/patch data IDs.
436  `~lsst.skymap.BaseSkyMap` instances.
437  skyMapName : `str`, optional
438  Gen3 SkyMap Dimension name to be associated with any tract or patch
439  Dimensions.
440 
441  Returns
442  -------
443  translator : `Translator`
444  A translator whose translate() method can be used to transform Gen2
445  data IDs to Gen3 dataIds.
446  """
447  if instrument is not None:
448  rulesForInstrument = self._rules.get(instrument, {None: []})
449  else:
450  rulesForInstrument = {None: []}
451  rulesForAnyInstrument = self._rules[None]
452  candidateRules = itertools.chain(
453  rulesForInstrument.get(datasetTypeName, []), # this instrument, this DatasetType
454  rulesForInstrument[None], # this instrument, any DatasetType
455  rulesForAnyInstrument.get(datasetTypeName, []), # any instrument, this DatasetType
456  rulesForAnyInstrument[None], # any instrument, any DatasetType
457  )
458  matchedHandlers = []
459  targetKeys = set(gen2keys)
460  self.log.debug("Constructing data ID translator for %s with Gen2 keys %s...",
461  datasetTypeName, gen2keys)
462  for ruleKeys, ruleHandlers, consume in candidateRules:
463  if ruleKeys.issubset(targetKeys):
464  matchedHandlers.append(ruleHandlers)
465  targetKeys -= consume
466  self.log.debug("...matched %d handlers: %s, with %s unmatched.",
467  len(matchedHandlers), matchedHandlers, targetKeys)
468  return Translator(matchedHandlers, skyMap=skyMap, skyMapName=skyMapName,
469  datasetTypeName=datasetTypeName, log=self.log)
470 
471 
daf::base::PropertySet * set
Definition: fits.cc:912

Member Data Documentation

◆ log

lsst.obs.base.gen2to3.translators.TranslatorFactory.log

Definition at line 261 of file translators.py.


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