[AstroPy] Object within region

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


Hi Eric,

Thanks again for your help.
I'm not sure I fully get the point. I'm referring to absolute coordinates,
not points (ie, countries) which I have to figure out their coordinates. I
have a set of 7 coordinates and want to know if another one falls into the
corresponding polygon. I understand your example, but I'm not
resolving/transforming between celestial objects and coordinates. In any
case, I agree that wcs could be involved and affect the results. So, as
suspected, it's mainly an usability issue from my side. But please, since
no image is involved in this process, do you know how to define/use/create
the wcs I need?

Miguel

El lun, 13 jun 2022 a las 15:48, Eric Jensen (<ejensen1 at swarthmore.edu>)
escribió:

> Hi Miguel,
>
> Thanks for the example code.  To see what’s going on with your example, it
> might be helpful to think about a corresponding example with a world map:
>
> If I draw a polygon with vertices in the United Kingdom, Spain, Turkey,
> and Poland, is any point in North America inside that polygon?
>
> Your immediate answer is probably “no”, but the real answer is, “it
> depends on the map.”  If the world map is projected so that Europe is at or
> near the center of the map, then the answer is no.  But if the map is
> projected so that the center is in the Pacific Ocean, then it’s possible to
> have the UK and Spain on the far right-hand side of the map, and Turkey and
> Poland on the far left.  So a polygon with those four vertices, *if each
> edge stays on the map*, will indeed included parts of North America.
>
> That’s why the WCS is needed - it tells the routine how your map (image)
> is oriented, i.e. what coordinates are in the center, and what coordinates
> are nearer the edges.  When you look at Stellarium, presumably you are
> orienting your view of the sky so that your point of interest is somewhere
> near the center of your view.   But the WCS that you’re giving to the
> regions routine probably isn’t centered in that same way, so it may be that
> the polygon has some edges that have to go the “long way” (equivalent to a
> line from Spain to Turkey that cuts across North America) in order to stay
> on the map.
>
> Hope this helps,
>
> Eric
>
>
> On Jun 13, 2022, at 6:10 AM, Miguel Gutiérrez Páez <mgutierrez at gmail.com>
> wrote:
>
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/astropy/attachments/20220613/2b48f4b3/attachment.html>


More information about the AstroPy mailing list