[AstroPy] Object within region

Miguel Gutiérrez Páez mgutierrez at gmail.com
Mon Jun 13 06:10:23 EDT 2022


Hi Eric,

Thanks for the reply.
Yes, I saw that note, but since I'm only working with RA/DEC coordinates, I
didn't understand why I needed a wcs. But ok, no problem if I can use the
example one.

I've tried to simplify the code and this is the simplest one:

reg=PolygonSkyRegion(SkyCoord([SkyCoord("2h","86d"),SkyCoord("7h","40d"),SkyCoord("5h","8d"),SkyCoord("4h","-5d"),SkyCoord("2h","-12d"),SkyCoord("2h","38d"),SkyCoord("2h","86d")]))
> reg.contains(SkyCoord("21h","57d"),wcs)
>

which returns array([ True]). Checking with stellarium, it should return
false.

My guess is the problem is with the polygon definition, which is quite
irregular. Removing 3th and 4th coordinates makes a similar polygon and it
does work.

Regards

El dom, 12 jun 2022 a las 15:56, Eric Jensen (<ejensen1 at swarthmore.edu>)
escribió:

> Hi Miguel,
>
> One of my questions is why the "contains" method requires a wcs. If my
> only inputs are skycoords in icrs, why is needed to perform wcs
> transformations? This is a concept that I don't fully understand.
>
>
> I think this is answered elsewhere in the docs, here:
> https://astropy-regions.readthedocs.io/en/stable/getting_started.html.
> There it says: “Sky regions are regions that are defined using celestial
> coordinates. Note that these are not defined as regions on the celestial
> sphere, but rather are meant to represent shapes on an image, but simply
> defined using celestial coordinates as opposed to pixel coordinates.”
>
> Given this definition (that regions - even sky regions - always exist in
> the context of some image), then the WCS is needed to be able to convert
> between sky and pixel coords for the associated image.
>
> For your case, where maybe you only care about regions on the celestial
> sphere, it seems like you should be able to make this work using the WCS
> from the sample image they use in the docs.  (Caveat: I’ve never used this,
> so there could be some subtleties I’m missing here.)
>
> If you can provide some sample code, and what results you get vs. what you
> expect to get, we can go from there.
>
> Eric
>
>
> On Jun 12, 2022, at 7:18 AM, Miguel Gutiérrez Páez <mgutierrez at gmail.com>
> wrote:
>
> 
> Hi all,
>
> I'm trying to figure out how to determine if a particular object falls
> within a certain sky region.
> First, please note I'm a complete noob with astropy, so I guess I'm
> probably missing some concept.
>
> I've read examples about regions and sky regions:
> https://astropy-regions.readthedocs.io/en/stable/contains.html
>
> I've been trying some examples by myself but I get some wrong results.
> That is, the script reports an object falls within the region, but after
> checking with stellarium for example, clearly is not.
>
> One of my questions is why the "contains" method requires a wcs. If my
> only inputs are skycoords in icrs, why is needed to perform wcs
> transformations? This is a concept that I don't fully understand.
> The wcs I'm passing to the contains method, is the one described in the
> link above, the mentioned example.
>
> As stated, I'm pretty sure I'm failing due to some missing concepts. Glad
> to hear from your for any clarification.
>
> Thanks in advance.
>
> Regards
>
> PS: if you with I can paste some lines of my code
> _______________________________________________
> AstroPy mailing list
> AstroPy at python.org
> https://mail.python.org/mailman/listinfo/astropy
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at python.org
> https://mail.python.org/mailman/listinfo/astropy
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/astropy/attachments/20220613/e463ee39/attachment.html>


More information about the AstroPy mailing list