def plotThem(bMid, y, fStr, yMin=None):
    y0 = numpy.array(y)
    if yMin != None:
        t0 = numpy.where(y <= yMin)[0]
        y0[t0] = yMin
    simplePlot.plot(numpy.log10(bMid), numpy.log10(y0), f=fStr)
def plotThem(bMid, y, fStr, yMin=None):
    y0 = numpy.array(y)
    if yMin != None:
        t0 = numpy.where(y <= yMin)[0]
        y0[t0] = yMin
    simplePlot.plot(numpy.log10(bMid), numpy.log10(y0), f=fStr)
                        trimTypes != sSMType])
t2 = numpy.where(t1)[0]
bestRefTrimXOffset, bestRefTrimYOffset, t1, t2 = \
                 matchTrimToDet.searchTrimDetMatch(
    refxs[t0], refys[t0], trimxs[t2], trimys[t2])
print 'Found match dx: %5.2f, dy: %5.2f pix' % (
    bestRefTrimXOffset, bestRefTrimYOffset)
offrefxsTrim = refxs + bestRefTrimXOffset
offrefysTrim = refys + bestRefTrimYOffset

# Now recalculate for the final pixDist and trimToRef
refPixDistsTrim, trimToRef, t0, t1 = matchTrimToDet.matchTrimToDet(
    offrefxsTrim, offrefysTrim, trimxs, trimys)

simplePlot.clear()
simplePlot.plot(trimxs, trimys, f='ko')
simplePlot.oplot(offrefxsTrim, offrefysTrim, f='r.')
simplePlot.clear()
simplePlot.plot(refMags, trimMags[trimToRef], f='ko')


## Apparently matching ref directly to image doesn't work well
#print 'Matching ref catalog to image detection.'
#t0 = numpy.where(refMags < refMagThresh)[0]
#t1 = pyCommon.arrayAnd([trimMags < trimMagThresh, trimTypes != galaxyType,
#                        trimTypes != sSMType])
#t2 = numpy.where(nCts > minCtsBrightThresh)[0]
#bestRefDetXOffset, bestRefDetYOffset, t1, t2 = \
#                 matchTrimToDet.searchTrimDetMatch(
#    refxs[t0], refys[t0], detxs[t2], detys[t2])
#print 'Found match dx: %5.2f, dy: %5.2f pix' % (
    [trimMags < trimMagThresh, trimTypes != galaxyType, trimTypes != sSMType])
t2 = numpy.where(t1)[0]
bestRefTrimXOffset, bestRefTrimYOffset, t1, t2 = \
                 matchTrimToDet.searchTrimDetMatch(
    refxs[t0], refys[t0], trimxs[t2], trimys[t2])
print 'Found match dx: %5.2f, dy: %5.2f pix' % (bestRefTrimXOffset,
                                                bestRefTrimYOffset)
offrefxsTrim = refxs + bestRefTrimXOffset
offrefysTrim = refys + bestRefTrimYOffset

# Now recalculate for the final pixDist and trimToRef
refPixDistsTrim, trimToRef, t0, t1 = matchTrimToDet.matchTrimToDet(
    offrefxsTrim, offrefysTrim, trimxs, trimys)

simplePlot.clear()
simplePlot.plot(trimxs, trimys, f='ko')
simplePlot.oplot(offrefxsTrim, offrefysTrim, f='r.')
simplePlot.clear()
simplePlot.plot(refMags, trimMags[trimToRef], f='ko')

## Apparently matching ref directly to image doesn't work well
#print 'Matching ref catalog to image detection.'
#t0 = numpy.where(refMags < refMagThresh)[0]
#t1 = pyCommon.arrayAnd([trimMags < trimMagThresh, trimTypes != galaxyType,
#                        trimTypes != sSMType])
#t2 = numpy.where(nCts > minCtsBrightThresh)[0]
#bestRefDetXOffset, bestRefDetYOffset, t1, t2 = \
#                 matchTrimToDet.searchTrimDetMatch(
#    refxs[t0], refys[t0], detxs[t2], detys[t2])
#print 'Found match dx: %5.2f, dy: %5.2f pix' % (
#    bestRefTrimXOffset, bestRefTrimYOffset)