The IndexError that is currently caught handles the case when the reference point is outside of the bounding box of the raster, but it doesn't handle the case of when it is outside of the polygon and thus in a masked value of the raster outside of the polygon. That is now handled by the MaskError.
I also changed the reference label to be 255 at those locations because if it's out of bounds it should be considered a "no data" point.
The IndexError that is currently caught handles the case when the reference point is outside of the bounding box of the raster, but it doesn't handle the case of when it is outside of the polygon and thus in a masked value of the raster outside of the polygon. That is now handled by the MaskError.
I also changed the reference label to be 255 at those locations because if it's out of bounds it should be considered a "no data" point.