Skip to content

Commit

Permalink
Fixed comment wording and added missing test to matchPessimistcB.
Browse files Browse the repository at this point in the history
matchPessimisticB.py: Added maxMatchDistArcsec to final cut on output
matches.
  • Loading branch information
morriscb committed Jun 2, 2017
1 parent b15e0a3 commit d58a47c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 35 deletions.
35 changes: 19 additions & 16 deletions python/lsst/meas/astrom/matchPessimisticB.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,17 +402,16 @@ def _doMatch(self, refCat, sourceCat, wcs, refFluxField, numUsableSources,
# the consensus mode of the matcher. If not default to Optimistic
# pattern matcher behavior.
numConsensus = self.config.numPatternConsensus
minRefAndSrcObjectsForConsensus = \
minObjectsForConsensus = \
self.config.numBrightStars + self.config.numPointsForShapeAttempt
if ref_array.shape[0] < self.config.numBrightStars + \
self.config.numPointsForShapeAttempt or \
src_array.shape[0] < self.config.numBrightStars + \
self.config.numPointsForShapeAttempt:
if ref_array.shape[0] < minObjectsForConsensus or \
src_array.shape[0] < minObjectsForConsensus:
numConsensus = 1

self.log.debug("Current tol maxDist: %.4f..." % maxMatchDistArcSec)
self.log.debug("Current shift: %.4f" % maxShiftArcseconds)
self.log.debug("Current rot: %.4f" % self.config.maxRotationDeg)
self.log.debug("Current tol maxDist: %.4f arcsec" %
maxMatchDistArcSec)
self.log.debug("Current shift: %.4f arcsec" %
maxShiftArcseconds)

# Create our matcher object.
pyPPMb = PessimisticPatternMatcherB(ref_array[:, :3], self.log)
Expand Down Expand Up @@ -459,7 +458,7 @@ def _doMatch(self, refCat, sourceCat, wcs, refFluxField, numUsableSources,
match_tolerance.failedPatternList)
)
if try_idx == 0 and \
len(matcher_struct.matches) == 0 and \
len(matcher_struct.match_ids) == 0 and \
match_tolerance.lastMatchedPattern is not None:
# If we found a pattern on a previous match-fit iteration and
# can't find an optimistic match on our first try with the
Expand All @@ -470,7 +469,7 @@ def _doMatch(self, refCat, sourceCat, wcs, refFluxField, numUsableSources,
match_tolerance.failedPatternList.append(
match_tolerance.lastMatchedPattern)
match_tolerance.lastMatchedPattern = None
elif len(matcher_struct.matches) > 0:
elif len(matcher_struct.match_ids) > 0:
# Match found, save a bit a state regarding this pattern
# in the struct and exit.
match_tolerance.maxShift = afwgeom.Angle(matcher_struct.shift,
Expand All @@ -483,7 +482,7 @@ def _doMatch(self, refCat, sourceCat, wcs, refFluxField, numUsableSources,
# the reference and source catalog. For the currrent astrometry solver
# we need to remove as many false positives as possible before sending
# the matches off to the astronomery solver.
distances_arcsec = np.rad2deg(matcher_struct.distances_rad) * 3600
distances_arcsec = np.degrees(matcher_struct.distances_rad) * 3600
# Rather than have a hard cut on the max distance we allow for
# objects we preform a iterative sigma clipping. We input a
# starting point for the clipping based on the largest of the
Expand All @@ -496,13 +495,17 @@ def _doMatch(self, refCat, sourceCat, wcs, refFluxField, numUsableSources,
input_cut=np.max((10 * wcs.pixelScale().asArcseconds(),
maxMatchDistArcSec,
maxShiftArcseconds)))
# We pick the largest of the sigma clipping or 2 pixels. This pevents
print("len distances", len(distances_arcsec))
print("max_dist", distances_arcsec.max())
# We pick the largest of the sigma clipping, the unsofted
# maxMatchDistArcSec or 2 pixels. This pevents
# the AstrometryTask._matchAndFitWCS from overfitting to a small
# number of objects and also allows the WCS fitter to use more
# number of objects and also allows the WCS fitter to bring in more
# matches as the WCS fit improves.
dist_cut_arcsec = np.max(
(2 * wcs.pixelScale().asArcseconds(),
clipped_dist_arcsec))
clipped_dist_arcsec, maxMatchDistArcSec))
print("Dist cut", dist_cut_arcsec, "arcsec")

# A match has been found, return our list of matches and
# return.
Expand All @@ -514,10 +517,10 @@ def _doMatch(self, refCat, sourceCat, wcs, refFluxField, numUsableSources,
match.first = refCat[match_id_pair[1]]
match.second = sourceCat[match_id_pair[0]]
# We compute the true distance along and sphere instead
# and store it as an afw.geom.Angle object. The previous
# and store it in units of arcseconds. The previous
# distances we used were aproximate.
match.distance = match.first.getCoord().angularSeparation(
match.second.getCoord())
match.second.getCoord()).asArcseconds()
matches.append(match)

return pipeBase.Struct(
Expand Down
7 changes: 4 additions & 3 deletions python/lsst/meas/astrom/pessimistic_pattern_matcher_b_3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def _rotation_matrix_chi_sq(flattened_rot_matrix, src_pattern, ref_pattern):
----------
flattened_rot_matrix : float array
A flattened array representing a 3x3 rotation matrix. The array is
flattened to comply with the API of scipy.optimize.leastsq
flattened to comply with the API of scipy.optimize.leastsq. Flattened
elements are [[0, 0], [0, 1], [0, 2], [1, 0]...]
src_patterm : float array of 3 vectors
A array containing N, 3 vectors
ref_pattern : float array of 3 vectors
Expand Down Expand Up @@ -1073,7 +1074,7 @@ def _intermediate_verify(self, src_pattern, ref_pattern, shift_rot_matrix,
Returns
-------
float array
float array or None
Return the fitted shift/rotation matrix if all of the points in our
source pattern are within max_dist_rad of their matched reference
objects. Returns None if this criteria is not satisfied.
Expand Down Expand Up @@ -1232,7 +1233,7 @@ def _match_sources(self, source_array, shift_rot_matrix):

handshake_mask = self._handshake_match(ref_matches, src_matches)
return pipeBase.Struct(
matches=ref_matches[handshake_mask],
match_ids=ref_matches[handshake_mask],
distances_rad=tmp_src_dist[handshake_mask],)

def _handshake_match(self, matches_ref, matches_src):
Expand Down
32 changes: 16 additions & 16 deletions tests/test_PessimisticPatternMatcherB3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ def testMatchPerfect(self):
source_array=self.source_obj_array, n_check=9, n_match=6,
n_agree=2, max_n_patterns=100, max_shift=60., max_rotation=5.0,
max_dist=5., min_matches=30, pattern_skip_array=None)
self.assertEqual(len(match_struct.matches),
self.assertEqual(len(match_struct.match_ids),
len(self.reference_obj_array))
self.assertTrue(
np.all(match_struct.distances < 0.01/3600.0 * __deg_to_rad__))
np.all(match_struct.distances_rad < 0.01/3600.0 * __deg_to_rad__))

def testOptimisticMatch(self):
""" Test the optimistic mode of the pattern matcher. That is
Expand All @@ -137,10 +137,10 @@ def testOptimisticMatch(self):
source_array=self.source_obj_array, n_check=9, n_match=6,
n_agree=1, max_n_patterns=100, max_shift=60., max_rotation=6.0,
max_dist=5., min_matches=30, pattern_skip_array=None)
self.assertEqual(len(match_struct.matches),
self.assertEqual(len(match_struct.match_ids),
len(self.reference_obj_array))
self.assertTrue(
np.all(match_struct.distances < 0.01/3600.0 * __deg_to_rad__))
np.all(match_struct.distances_rad < 0.01/3600.0 * __deg_to_rad__))

def testMatchSkip(self):
""" Test the ablity to skip specified patterns in the matching
Expand All @@ -154,10 +154,10 @@ def testMatchSkip(self):
source_array=self.source_obj_array, n_check=9, n_match=6,
n_agree=2, max_n_patterns=100, max_shift=60., max_rotation=5.0,
max_dist=5., min_matches=30, pattern_skip_array=np.array([0]))
self.assertEqual(len(match_struct.matches),
self.assertEqual(len(match_struct.match_ids),
len(self.reference_obj_array))
self.assertTrue(
np.all(match_struct.distances < 0.01/3600.0 * __deg_to_rad__))
np.all(match_struct.distances_rad < 0.01/3600.0 * __deg_to_rad__))

def testMatchMoreSources(self):
""" Test the case where we have more sources than references
Expand All @@ -171,10 +171,10 @@ def testMatchMoreSources(self):
source_array=self.source_obj_array, n_check=9, n_match=6,
n_agree=2, max_n_patterns=100, max_shift=60.0, max_rotation=5.0,
max_dist=5., min_matches=30, pattern_skip_array=None)
self.assertEqual(len(match_struct.matches),
self.assertEqual(len(match_struct.match_ids),
len(self.reference_obj_array[:500]))
self.assertTrue(
np.all(match_struct.distances < 0.01/3600.0 * __deg_to_rad__))
np.all(match_struct.distances_rad < 0.01/3600.0 * __deg_to_rad__))

def testMatchMoreReferences(self):
""" Test the case where we have more references than sources
Expand All @@ -188,10 +188,10 @@ def testMatchMoreReferences(self):
source_array=self.source_obj_array[:500], n_check=9, n_match=6,
n_agree=2, max_n_patterns=100, max_shift=60., max_rotation=1.0,
max_dist=5., min_matches=30, pattern_skip_array=None)
self.assertEqual(len(match_struct.matches),
self.assertEqual(len(match_struct.match_ids),
len(self.reference_obj_array[:500]))
self.assertTrue(
np.all(match_struct.distances < 0.01/3600.0 * __deg_to_rad__))
np.all(match_struct.distances_rad < 0.01/3600.0 * __deg_to_rad__))

def testShift(self):
""" Test the matcher when a shift is applied to the data.
Expand All @@ -217,10 +217,10 @@ def testShift(self):
n_agree=2, max_n_patterns=100, max_shift=60, max_rotation=5.0,
max_dist=5., min_matches=30, pattern_skip_array=None)

self.assertEqual(len(match_struct.matches),
self.assertEqual(len(match_struct.match_ids),
len(self.reference_obj_array))
self.assertTrue(
np.all(match_struct.distances < 0.01/3600.0 * __deg_to_rad__))
np.all(match_struct.distances_rad < 0.01/3600.0 * __deg_to_rad__))

def testRotation(self):
""" Test the matcher for when a roation is applied to the data.
Expand All @@ -242,10 +242,10 @@ def testRotation(self):
n_agree=2, max_n_patterns=100, max_shift=60, max_rotation=5.0,
max_dist=5., min_matches=30, pattern_skip_array=None)

self.assertEqual(len(match_struct.matches),
self.assertEqual(len(match_struct.match_ids),
len(self.reference_obj_array))
self.assertTrue(
np.all(match_struct.distances < 0.01/3600.0 * __deg_to_rad__))
np.all(match_struct.distances_rad < 0.01/3600.0 * __deg_to_rad__))

def testShiftRotation(self):
""" Test both a shift and rotation being applied to the data.
Expand Down Expand Up @@ -276,10 +276,10 @@ def testShiftRotation(self):
n_agree=2, max_n_patterns=100, max_shift=60., max_rotation=5.0,
max_dist=5., min_matches=30, pattern_skip_array=None)

self.assertEqual(len(match_struct.matches),
self.assertEqual(len(match_struct.match_ids),
len(self.reference_obj_array))
self.assertTrue(
np.all(match_struct.distances < 0.01/3600.0 * __deg_to_rad__))
np.all(match_struct.distances_rad < 0.01/3600.0 * __deg_to_rad__))


if __name__ == '__main__':
Expand Down

0 comments on commit d58a47c

Please sign in to comment.