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
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | List of all members
lsst.meas.base.tests.TransformTestCase Class Reference

Base class for testing measurement transformations. More...

Inheritance diagram for lsst.meas.base.tests.TransformTestCase:
lsst.utils.tests.TestCase lsst.meas.base.tests.CentroidTransformTestCase lsst.meas.base.tests.FluxTransformTestCase

Public Member Functions

def setUp
 
def tearDown
 
def testTransform
 
def testRegistration
 

Public Attributes

 calexp
 

Static Public Attributes

string name = "MeasurementTransformTest"
 
 controlClass = None
 
 algorithmClass = None
 
 transformClass = None
 
tuple flagNames = ("flag",)
 
tuple singleFramePlugins = ()
 
tuple forcedPlugins = ()
 

Private Member Functions

def _populateCatalog
 
def _checkOutput
 
def _runTransform
 
def _checkRegisteredTransform
 

Detailed Description

Base class for testing measurement transformations.

We test both that the transform itself operates successfully (fluxes are converted to magnitudes, flags are propagated properly) and that the transform is registered as the default for the appropriate measurement algorithms.

In the simple case of one-measurement-per-transformation, the developer need not directly write any tests themselves: simply customizing the class variables is all that is required. More complex measurements (e.g. multiple aperture fluxes) require extra effort.

Definition at line 546 of file tests.py.

Member Function Documentation

def lsst.meas.base.tests.TransformTestCase._checkOutput (   self,
  baseNames 
)
private

Definition at line 602 of file tests.py.

603  def _checkOutput(self, baseNames):
604  for inSrc, outSrc in zip(self.inputCat, self.outputCat):
605  for baseName in baseNames:
606  self._compareFieldsInRecords(inSrc, outSrc, baseName)
607  for flagName in self.flagNames:
608  keyName = outSrc.schema.join(baseName, flagName)
609  if keyName in inSrc.schema:
610  self.assertEqual(outSrc.get(keyName), inSrc.get(keyName))
611  else:
612  self.assertFalse(keyName in outSrc.schema)
def lsst.meas.base.tests.TransformTestCase._checkRegisteredTransform (   self,
  registry,
  name 
)
private

Definition at line 643 of file tests.py.

644  def _checkRegisteredTransform(self, registry, name):
645  # If this is a Python-based transform, we can compare directly; if
646  # it's wrapped C++, we need to compare the wrapped class.
647  self.assertEqual(registry[name].PluginClass.getTransformClass(), self.transformClass)
def lsst.meas.base.tests.TransformTestCase._populateCatalog (   self,
  baseNames 
)
private

Definition at line 592 of file tests.py.

593  def _populateCatalog(self, baseNames):
594  records = []
595  for flagValue in (True, False):
596  records.append(self.inputCat.addNew())
597  for baseName in baseNames:
598  for flagName in self.flagNames:
599  if records[-1].schema.join(baseName, flagName) in records[-1].schema:
600  records[-1].set(records[-1].schema.join(baseName, flagName), flagValue)
601  self._setFieldsInRecords(records, baseName)
def lsst.meas.base.tests.TransformTestCase._runTransform (   self,
  doExtend = True 
)
private

Definition at line 613 of file tests.py.

614  def _runTransform(self, doExtend=True):
615  if doExtend:
616  self.outputCat.extend(self.inputCat, mapper=self.mapper)
617  self.transform(self.inputCat, self.outputCat, self.calexp.getWcs(), self.calexp.getCalib())
def lsst.meas.base.tests.TransformTestCase.setUp (   self)

Definition at line 580 of file tests.py.

581  def setUp(self):
583  self.calexp = TestDataset.makeEmptyExposure(bbox)
584  self._setupTransform()
An integer coordinate rectangle.
Definition: Box.h:53
def lsst.meas.base.tests.TransformTestCase.tearDown (   self)

Definition at line 585 of file tests.py.

586  def tearDown(self):
587  del self.calexp
588  del self.inputCat
589  del self.mapper
590  del self.transform
591  del self.outputCat
def lsst.meas.base.tests.TransformTestCase.testRegistration (   self)
Test that the transformation is appropriately registered with the relevant measurement algorithms.

Definition at line 648 of file tests.py.

649  def testRegistration(self):
650  """
651  Test that the transformation is appropriately registered with the relevant measurement algorithms.
652  """
653  for pluginName in self.singleFramePlugins:
654  self._checkRegisteredTransform(lsst.meas.base.SingleFramePlugin.registry, pluginName)
655  for pluginName in self.forcedPlugins:
656  self._checkRegisteredTransform(lsst.meas.base.ForcedPlugin.registry, pluginName)
657 
def lsst.meas.base.tests.TransformTestCase.testTransform (   self,
  baseNames = None 
)
Test the operation of the transformation on a catalog containing random data.

We check that:

* An appropriate exception is raised on an attempt to transform between catalogs with different
  numbers of rows;
* Otherwise, all appropriate conversions are properly appled and that flags have been propagated.

The `baseNames` argument requires some explanation. This should be an iterable of the leading parts of
the field names for each measurement; that is, everything that appears before `_flux`, `_flag`, etc.
In the simple case of a single measurement per plugin, this is simply equal to `self.name` (thus
measurements are stored as `self.name + "_flux"`, etc). More generally, the developer may specify
whatever iterable they require. For example, to handle multiple apertures, we could have
`(self.name + "_0", self.name + "_1", ...)`.

@param[in]  baseNames  Iterable of the initial parts of measurement field names.

Definition at line 618 of file tests.py.

619  def testTransform(self, baseNames=None):
620  """
621  Test the operation of the transformation on a catalog containing random data.
622 
623  We check that:
624 
625  * An appropriate exception is raised on an attempt to transform between catalogs with different
626  numbers of rows;
627  * Otherwise, all appropriate conversions are properly appled and that flags have been propagated.
628 
629  The `baseNames` argument requires some explanation. This should be an iterable of the leading parts of
630  the field names for each measurement; that is, everything that appears before `_flux`, `_flag`, etc.
631  In the simple case of a single measurement per plugin, this is simply equal to `self.name` (thus
632  measurements are stored as `self.name + "_flux"`, etc). More generally, the developer may specify
633  whatever iterable they require. For example, to handle multiple apertures, we could have
634  `(self.name + "_0", self.name + "_1", ...)`.
635 
636  @param[in] baseNames Iterable of the initial parts of measurement field names.
637  """
638  baseNames = baseNames or [self.name]
639  self._populateCatalog(baseNames)
640  self.assertRaises(lsst.pex.exceptions.LengthError, self._runTransform, False)
641  self._runTransform()
642  self._checkOutput(baseNames)

Member Data Documentation

lsst.meas.base.tests.TransformTestCase.algorithmClass = None
static

Definition at line 567 of file tests.py.

lsst.meas.base.tests.TransformTestCase.calexp

Definition at line 582 of file tests.py.

lsst.meas.base.tests.TransformTestCase.controlClass = None
static

Definition at line 566 of file tests.py.

tuple lsst.meas.base.tests.TransformTestCase.flagNames = ("flag",)
static

Definition at line 572 of file tests.py.

tuple lsst.meas.base.tests.TransformTestCase.forcedPlugins = ()
static

Definition at line 578 of file tests.py.

string lsst.meas.base.tests.TransformTestCase.name = "MeasurementTransformTest"
static

Definition at line 563 of file tests.py.

tuple lsst.meas.base.tests.TransformTestCase.singleFramePlugins = ()
static

Definition at line 577 of file tests.py.

lsst.meas.base.tests.TransformTestCase.transformClass = None
static

Definition at line 568 of file tests.py.


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