How do I easily check if a given RA, Dec is in an exposure from Python?
I have calexp in a repository, and want to check if a given RA, Dec is in that particular image.
@yusra says
“The butler lets you get the wcs and bbox without reading the whole image. Then I usually compare the corners.”
@ctslater says
"exp.getBBox().contains(exp.getWcs().skyToPixel(coord)) is almost there
but [it’s not quite there] because skyToPixel() returns Point2D while exp.getBBox() is Box2I, and they don’t convert automatically"
I suggest you embed your skyToPixel call in a try block: it can raise an exception if the coordinates are a long way off the image.