Skip to content

Commit

Permalink
Update DonutDetector after review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbkalmbach committed Mar 12, 2021
1 parent f687571 commit 7dd864f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
47 changes: 23 additions & 24 deletions python/lsst/ts/wep/DonutDetector.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@


class DonutDetector(object):

"""
Class to detect donuts directly from an out of focus image
by convolution with a template image.
Expand All @@ -39,19 +38,18 @@ class DonutDetector(object):
def detectDonuts(
self, expArray, template, blendRadius, peakThreshold=0.95, dbscanEps=5
):

"""
Detect and categorize donut sources as blended/unblended
Parameters
-------
expArray: numpy ndarray
The input image data
template: numpy ndarray
Donut template appropriate for the image
expArray: numpy.ndarray
The input image data.
template: numpy.ndarray
Donut template appropriate for the image.
blendRadius: float
Minimum distance in pixels two donut centers need to
be apart in order to be tagged as unblended
be apart in order to be tagged as unblended.
peakThreshold: float, optional
This value is a specifies a number between 0 and 1 that is
the fraction of the highest pixel value in the convolved image.
Expand All @@ -65,7 +63,7 @@ def detectDonuts(
Returns
-------
pandas dataframe
pandas.DataFrame
Dataframe identifying donut positions and if they
are blended with other donuts. If blended also identfies
which donuts are blended with which.
Expand All @@ -86,28 +84,27 @@ def detectDonuts(
donutDf = pd.DataFrame(
np.array([centroidX, centroidY]).T, columns=["x_center", "y_center"]
)
donutDf = self.labelUnblended(donutDf, blendRadius)
donutDf = self.identifyBlendedDonuts(donutDf, blendRadius)

return donutDf

def labelUnblended(self, donutDf, blendRadius):

def identifyBlendedDonuts(self, donutDf, blendRadius):
"""
Label donuts as blended/unblended if the centroids are within
the blendRadius number of pixels.
Parameters
----------
donutDf: pandas dataframe
donutDf: pandas.DataFrame
Dataframe identifying donut positions with labels
'x_center' and 'y_center'.
blendRadius: float
Minimum distance in pixels two donut centers need to
be apart in order to be tagged as unblended
be apart in order to be tagged as unblended.
Returns
-------
pandas dataframe
pandas.DataFrame
Dataframe identifying donut positions and if they
are blended with other donuts. If blended also identfies
which donuts are blended with which.
Expand All @@ -130,21 +127,23 @@ def labelUnblended(self, donutDf, blendRadius):
donutDf["blended"] = False
donutDf.loc[blendedCenters, "blended"] = True
donutDf["blended_with"] = None
for i, j in blendedPairs:
if donutDf.loc[i, "blended_with"] is None:
donutDf.at[i, "blended_with"] = []
if donutDf.loc[j, "blended_with"] is None:
donutDf.at[j, "blended_with"] = []
donutDf.loc[i, "blended_with"].append(j)
donutDf.loc[j, "blended_with"].append(i)
for donutOne, donutTwo in blendedPairs:
if donutDf.loc[donutOne, "blended_with"] is None:
donutDf.at[donutOne, "blended_with"] = []
if donutDf.loc[donutTwo, "blended_with"] is None:
donutDf.at[donutTwo, "blended_with"] = []
donutDf.loc[donutOne, "blended_with"].append(donutTwo)
donutDf.loc[donutTwo, "blended_with"].append(donutOne)

# Count the number of other donuts overlapping
# each donut
donutDf["num_blended_neighbors"] = 0
for i in range(len(donutDf)):
if donutDf["blended_with"].iloc[i] is None:
for donutIdx in range(len(donutDf)):
if donutDf["blended_with"].iloc[donutIdx] is None:
continue

donutDf.at[i, "num_blended_neighbors"] = len(donutDf["blended_with"].loc[i])
donutDf.at[donutIdx, "num_blended_neighbors"] = len(
donutDf["blended_with"].loc[donutIdx]
)

return donutDf
4 changes: 2 additions & 2 deletions tests/test_donutDetector.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ def _makeData(self, imgSize, templateSize, donutSep):

return template, blendedImg

def testLabelUnblended(self):
def testIdentifyBlendedDonuts(self):

testDataFrame = pd.DataFrame()
testDataFrame["x_center"] = [50.0, 100.0, 120.0]
testDataFrame["y_center"] = [100.0, 100.0, 100.0]

labeledDf = self.donutDetector.labelUnblended(testDataFrame, 30.0)
labeledDf = self.donutDetector.identifyBlendedDonuts(testDataFrame, 30.0)

self.assertCountEqual(
labeledDf.columns,
Expand Down

0 comments on commit 7dd864f

Please sign in to comment.