-
-
Notifications
You must be signed in to change notification settings - Fork 54
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
Fix BoundingBox from_float() upper bounds #103
Conversation
@larrybradley - Thanks! Some suggestions:
|
@cdeil Yes, this fixes a literal edge case. It's a guarantee modulo possible float-point errors. If I worry a bit about make Example: >>> from regions import BoundingBox
>>> BoundingBox(ixmin=1, ixmax=10, iymin=2, iymax=20)
BoundingBox(ixmin=1, ixmax=10, iymin=2, iymax=20)
>>> BoundingBox._from_float(xmin=1, xmax=10, ymin=2, ymax=20)
BoundingBox(ixmin=1, ixmax=11, iymin=2, iymax=21) That could be very confusing even though the difference is explained in the documentation. If you want to make it public, perhaps |
@larrybradley - I see your point. I'd still like to have it publicly available, because calling private methods from other parts of the package (see https://github.com/astropy/regions/search?utf8=%E2%9C%93&q=_from_float) or other Python packages (like Gammapy) is bad. And if it's private, it doesn't show up in the docs, and I can't link to a docs URL to point it out to people. Concerning method name (or even relocating to somewhere completely else), I don't have a suggestion. If you agree to the change to make it public, maybe you can come up with something? |
@cdeil I don't have a good name. @astrofrog? |
One option I was thinking about was to always go via regions.RectanglePixelRegion which does support floats, and then access it's But I don't actually think it's a good suggestion. There's several other possible solutions: allow float in bounding box init, and add a method or attribute that goes to int index. Or have a separate class for float bounding boxes. Or mostly keep as-is and try to find a good name. I don't know which of these options would be best here, or have a suggestion for a good name. Let's wait and see if someone comes up with a good suggestion. |
What about |
@sosey - Thanks for the suggestion! Personally I would prefer @larrybradley - Unless others chime in, could you please make the call here on naming and then merge this? (I'd like to make the regions 0.2 release) |
@cdeil I made |
aa103ae
to
7b0c6e8
Compare
7b0c6e8
to
a981b69
Compare
@cdeil - I've merged this as it was all green. Now regions should be ready for 0.2. |
@larrybradley - Thanks! |
This is yet another fix for
BoundingBox.from_float()
. In the case where the upper bound is at the pixel edge (e.g. xmax=2.5), the code was effectively rounding up and then adding 1. In those cases, the bounding box upper bound is too large by one pixel.In other words, the lower and upper bounds were treating x.5 pixel inputs the same (rounding the same way). But because these represent boundaries, we want them to "round inward".
Example:
New:
Old: