-
-
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
__contains__ scope? #25
Comments
Sounds good, but we can leave |
cc @cdeil |
For the record: While writing the docs for region containment checks There's some information here what I used this example to play around: import numpy as np
class PixCoord:
def __init__(self, x, y):
self.x = x
self.y = y
def isscalar(self):
return np.isscalar(self.x)
class PixelRegion:
def __init__(self, center, radius):
self.center = center
self.radius = radius
def __contains__(self, coord):
dx = self.center.x - np.array(coord.x)
dy = self.center.y - np.array(coord.y)
d = np.sqrt(dx * dx + dy * dy)
mask = d < self.radius
print(mask)
return mask
c = PixCoord(x=1, y=2)
c2 = PixCoord(x=[1, 2], y=[2, 2])
r = PixelRegion(center=PixCoord(0, 0), radius=3)
print(c in r)
print(c2 in r) The
without a further traceback what happened. So my conclusion is the same one as @joleroi's -- making I'm not sure it's a good idea if having |
At the moment the Region base classes have an abstract method:
__contains__
https://github.com/astropy/regions/blob/master/regions/core/core.py#L195
The docstring suggests that this is supposed to work for a list of
SkyCoords
https://github.com/astropy/regions/blob/master/regions/core/core.py#L197
I don't think this works/is a good idea
I looks like the
in
operator checks for a (non-array) boolean output of__contains__
. This makes sense if you think about statements likeI would suggest changing the API to
regions.contains(coords)
(without the underscores).Do you agree @keflavich @astrofrog @bsipocz ?
The text was updated successfully, but these errors were encountered: