-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DM-30993: Implement reference catalog culling for astrometry in SFM #410
base: main
Are you sure you want to change the base?
Conversation
6cdd9e9
to
781935d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a concern about how coordinates are handled in the new CullFromMaskedRegion
. I have a few different suggestions in the comments, depending on the desired behavior.
bbox = exposure.getBBox() | ||
xMax = bbox.getMaxX() | ||
yMax = bbox.getMaxY() | ||
# If reference object nominally lies outside the detector, consider | ||
# it to be at the edge (and thus obeys those mask planes). | ||
xRefList = [int(min(max(0, xRef), xMax)) for xRef in xRefList] | ||
yRefList = [int(min(max(0, yRef), yMax)) for yRef in yRefList] | ||
badMaskNames = [] | ||
maskPlaneDict = exposure.getMask().getMaskPlaneDict() | ||
for badName in self.badMaskNames: | ||
if badName in maskPlaneDict: | ||
badMaskNames.append(badName) | ||
bitmask = exposure.mask.getPlaneBitMask(badMaskNames) | ||
toKeep = ((exposure.mask.array & bitmask) == 0) | ||
selected = toKeep[yRefList, xRefList] # x & y flipped for numpy arrays |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will break if the bbox has a non-zero XY0.
Possible alternative:
xRefList = catalog[self.xColName]
yRefList = catalog[self.yColName]
bbox = exposure.getBBox()
badMaskNames = []
maskPlaneDict = exposure.getMask().getMaskPlaneDict()
for badName in self.badMaskNames:
if badName in maskPlaneDict:
badMaskNames.append(badName)
bitmask = exposure.mask.getPlaneBitMask(badMaskNames)
selected = np.array([(exposure.mask[xv, yv] & bitmask) == 0 for xv, yv in zip(xRefList, yRefList)])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the other hand, the above will break if any of the catalog sources are outside the image. That is easy to fix with an extra isInBbox = bbox.contains(xRefList, yRefList)
and using that to throw out sources.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternately, to keep the current behavior where off-image sources are moved to the edge of the image for the check, I would suggest:
x0, y0 = exposure.getXY0()
xMax, yMax = exposure.getDimensions()
xRefList = [int(min(max(0, xRef - x0), xMax)) for xRef in xRefList]
yRefList = [int(min(max(0, yRef - y0), yMax)) for yRef in yRefList]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UPDATED: my first version was wrong. This is what I have now and I've added what I think works as a test of a non (0, 0) XY0 exposure in the unittest.
Another nice catch, thanks! I do want to keep the current (battle-tested) behavior, so I'm going with this one, but it has to slightly modify it to:
x0, y0 = exposure.getXY0()
xMax, yMax = exposure.getDimensions()
xRefList = [int(min(max(0, xRef - x0), xMax - 1)) for xRef in xRefList]
yRefList = [int(min(max(0, yRef - y0), yMax - 1)) for yRef in yRefList]
Let me know if this looks wrong to you...
ed032ca
to
2cba7de
Compare
2cba7de
to
a7ec3c3
Compare
No description provided.