From simon at sconseil.fr Thu Jun 2 16:18:47 2022 From: simon at sconseil.fr (Simon Conseil) Date: Thu, 02 Jun 2022 22:18:47 +0200 Subject: [AstroPy] ANN: astropy 5.1 released Message-ID: Dear colleagues, We are very happy to announce the v5.1 release of astropy, a core Python package for Astronomy: http://www.astropy.org The astropy core package is a community-driven Python package intended to contain much of the core functionality and common tools needed for astronomy and astrophysics. It is part of the Astropy Project, which aims to foster an ecosystem of interoperable astronomy packages for Python. New and improved major functionality in this release includes: - Updates to cosmology - doppler_redshift() equivalency - Specifying data types when reading ASCII tables - Structured Columns - New model fitters have been added - Allow time conversions without predictive Earth rotation data (IERS- A) - Uncertainty classes can be transformed into each other - Schechter1D Model In addition, hundreds of smaller improvements and fixes have been made. An overview of the changes is provided at: http://docs.astropy.org/en/stable/whatsnew/5.1.html Instructions for installing astropy are provided on our website, and extensive documentation can be found at: http://docs.astropy.org If you usually use pip/vanilla Python, you can do: pip install astropy --upgrade If you make use of the Anaconda Python Distribution, soon you will be able update to Astropy v5.1 with: conda update astropy Or if you cannot wait for Anaconda to update their default version, you can use the conda-forge channel: conda update -c conda-forge astropy Please report any issues, or request new features via our GitHub repository: https://github.com/astropy/astropy/issues Over 400 people have contributed code to the core astropy package so far, and you can find out more about the team here: https://www.astropy.org/team.html If you use astropy directly for your work, or as a dependency to another package, please remember to acknowledge it by citing the appropriate Astropy paper. For the most up-to-date suggestions, see the acknowledgement page, but as of this release the recommendation is: This research made use of Astropy, a community-developed core Python package for Astronomy (Astropy Collaboration, 2018). We hope that you enjoy using astropy as much as we enjoyed developing it! Simon Conseil v5.1 Release Coordinator on behalf of The Astropy Project From mgutierrez at gmail.com Sun Jun 12 07:17:24 2022 From: mgutierrez at gmail.com (=?UTF-8?Q?Miguel_Guti=C3=A9rrez_P=C3=A1ez?=) Date: Sun, 12 Jun 2022 13:17:24 +0200 Subject: [AstroPy] Object within region Message-ID: 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: From ejensen1 at swarthmore.edu Sun Jun 12 09:56:46 2022 From: ejensen1 at swarthmore.edu (Eric Jensen) Date: Sun, 12 Jun 2022 09:56:46 -0400 Subject: [AstroPy] Object within region In-Reply-To: References: Message-ID: <81A319FD-D045-43CA-8D3D-65288EE8E8C7@swarthmore.edu> 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 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: From mgutierrez at gmail.com Mon Jun 13 06:10:23 2022 From: mgutierrez at gmail.com (=?UTF-8?Q?Miguel_Guti=C3=A9rrez_P=C3=A1ez?=) Date: Mon, 13 Jun 2022 12:10:23 +0200 Subject: [AstroPy] Object within region In-Reply-To: <81A319FD-D045-43CA-8D3D-65288EE8E8C7@swarthmore.edu> References: <81A319FD-D045-43CA-8D3D-65288EE8E8C7@swarthmore.edu> Message-ID: 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 () 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 > 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: From ejensen1 at swarthmore.edu Mon Jun 13 09:48:02 2022 From: ejensen1 at swarthmore.edu (Eric Jensen) Date: Mon, 13 Jun 2022 09:48:02 -0400 Subject: [AstroPy] Object within region In-Reply-To: References: <81A319FD-D045-43CA-8D3D-65288EE8E8C7@swarthmore.edu> Message-ID: <0A58DF94-600F-48EF-9A07-6293DFA123FA@swarthmore.edu> 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 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 (>) 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 > 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: From mgutierrez at gmail.com Mon Jun 13 10:40:29 2022 From: mgutierrez at gmail.com (=?UTF-8?Q?Miguel_Guti=C3=A9rrez_P=C3=A1ez?=) Date: Mon, 13 Jun 2022 16:40:29 +0200 Subject: [AstroPy] Object within region In-Reply-To: <0A58DF94-600F-48EF-9A07-6293DFA123FA@swarthmore.edu> References: <81A319FD-D045-43CA-8D3D-65288EE8E8C7@swarthmore.edu> <0A58DF94-600F-48EF-9A07-6293DFA123FA@swarthmore.edu> Message-ID: 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 () 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 > 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 () > 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 >> 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: From ejensen1 at swarthmore.edu Mon Jun 13 11:44:56 2022 From: ejensen1 at swarthmore.edu (Eric L. N. Jensen) Date: Mon, 13 Jun 2022 11:44:56 -0400 Subject: [AstroPy] Object within region In-Reply-To: References: <81A319FD-D045-43CA-8D3D-65288EE8E8C7@swarthmore.edu> <0A58DF94-600F-48EF-9A07-6293DFA123FA@swarthmore.edu> Message-ID: Hi Miguel, Maybe another way to say it that the regions code only deals with polygons drawn on flat maps of the sky, not with polygons on the actual, spherical sky. So to make a flat map (of the surface of the Earth or of the sky) you have to make some choices, most notably about where the center of the map is going to be. (The same is true in Stellarium, btw - to view the sky on your flat computer screen, you have to choose which point in the sky is going to be at the center of your current view.) Yet another way to say the same thing is that, while routines for both SkyRegion and PixelRegion exist, I think the underlying calculations are always done as a PixelRegion. (I?m not 100% sure that?s true, but that seems consistent with how it?s described in the documentation.) > 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. It doesn?t matter whether or not you have a specific object in mind - a coordinate gives you a spot on the map. Lat/long gives you a point on the Earth, whether there is a city/country there or not. RA/Dec gives you a point on the sky, whether there is a star there or not. And either one can be (and indeed, has to be) transformed to an x,y coordinate to give you a position on a flat map. To get a WCS that is behaving more like what you expect, i.e. where the point you are considering is at or near the center of your map, I would try something like this: import astropy.wcs as wcs from astropy.wcs import WCS import numpy as np from regions import PolygonSkyRegion from astropy.coordinates import SkyCoord # Create a new WCS with two axes: w = wcs.WCS(naxis=2) # Use RA and Dec as coords w.wcs.ctype = ["RA---AIT", "DEC--AIT"] # Set the pixel size to be whatever you want; # units are degrees, so 1/60 is 1 arcminute. pix_size = 1/60. w.wcs.cdelt = np.array([pix_size, pix_size]) # How many pixels in x and y, given that we # want to span the whole sky: width_x = 360/pix_size width_y = 180/pix_size # Set the key reference pixel to be at the center pixel # of the image: w.wcs.crpix = [int(width_x/2), int(width_y/2)] # Choose your coordinates of interest - replace this with # the RA and Dec of the point you're interested in testing, so # it will be at the center of the image: myra = 21 * 15 # degrees, not hours mydec = 57 # degrees # Put that as the RA and Dec of the WCS reference pixel w.wcs.crval = [myra, mydec] 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"),w) reg.contains(SkyCoord(myra, mydec, unit="deg"),w) (prints ?False?) Note that if you want to test other points on the sky, you will need to change the ?crval? in the wcs object again. You don?t have to recreate the whole wcs, just change that one value. So a cycle that looks like this: myra = 21 * 15 # degrees, not hours mydec = 57 # degrees # Put that as the RA and Dec of the WCS reference pixel w.wcs.crval = [myra, mydec] reg.contains(SkyCoord(myra, mydec, unit="deg"),w) with different values of myra and mydec would allow you to test a bunch of points again the same region. Eric > On Jun 13, 2022, at 10:40 AM, Miguel Guti?rrez P?ez wrote: > > 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 (>) 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 > 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 (>) 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 > 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: From mgutierrez at gmail.com Mon Jun 13 12:05:46 2022 From: mgutierrez at gmail.com (=?UTF-8?Q?Miguel_Guti=C3=A9rrez_P=C3=A1ez?=) Date: Mon, 13 Jun 2022 18:05:46 +0200 Subject: [AstroPy] Object within region In-Reply-To: References: <81A319FD-D045-43CA-8D3D-65288EE8E8C7@swarthmore.edu> <0A58DF94-600F-48EF-9A07-6293DFA123FA@swarthmore.edu> Message-ID: Hi Eric, Maybe another way to say it that the regions code only deals with polygons > drawn on flat maps of the sky, not with polygons on the actual, spherical > sky. > Yes, you are right. I forgot again that essential detail. Makes sense. I've tried the code you pasted and works perfectly. My script shows now much more consistent results. I need some time and reading to understand what really means. No problem I will, sure. Thanks for your help and kind support. Have a nice day. Miguel El lun, 13 jun 2022 a las 17:45, Eric L. N. Jensen () escribi?: > Hi Miguel, > > Maybe another way to say it that the regions code only deals with polygons > drawn on flat maps of the sky, not with polygons on the actual, spherical > sky. So to make a flat map (of the surface of the Earth or of the sky) you > have to make some choices, most notably about where the center of the map > is going to be. (The same is true in Stellarium, btw - to view the sky on > your flat computer screen, you have to choose which point in the sky is > going to be at the center of your current view.) > > Yet another way to say the same thing is that, while routines for both > SkyRegion and PixelRegion exist, I think the underlying calculations are > always done as a PixelRegion. (I?m not 100% sure that?s true, but that > seems consistent with how it?s described in the documentation.) > > 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. > > > It doesn?t matter whether or not you have a specific object in mind - a > coordinate gives you a spot on the map. Lat/long gives you a point on the > Earth, whether there is a city/country there or not. RA/Dec gives you a > point on the sky, whether there is a star there or not. And either one can > be (and indeed, has to be) transformed to an x,y coordinate to give you a > position on a flat map. > > To get a WCS that is behaving more like what you expect, i.e. where the > point you are considering is at or near the center of your map, I would try > something like this: > > import astropy.wcs as wcs > from astropy.wcs import WCS > import numpy as np > > from regions import PolygonSkyRegion > from astropy.coordinates import SkyCoord > > # Create a new WCS with two axes: > w = wcs.WCS(naxis=2) > # Use RA and Dec as coords > w.wcs.ctype = ["RA---AIT", "DEC--AIT"] > # Set the pixel size to be whatever you want; > # units are degrees, so 1/60 is 1 arcminute. > pix_size = 1/60. > w.wcs.cdelt = np.array([pix_size, pix_size]) > # How many pixels in x and y, given that we > # want to span the whole sky: > width_x = 360/pix_size > width_y = 180/pix_size > # Set the key reference pixel to be at the center pixel > # of the image: > w.wcs.crpix = [int(width_x/2), int(width_y/2)] > # Choose your coordinates of interest - replace this with > # the RA and Dec of the point you're interested in testing, so > # it will be at the center of the image: > myra = 21 * 15 # degrees, not hours > mydec = 57 # degrees > # Put that as the RA and Dec of the WCS reference pixel > w.wcs.crval = [myra, mydec] > > > 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"),w) > reg.contains(SkyCoord(myra, mydec, unit="deg"),w) > > (prints ?False?) > > Note that if you want to test other points on the sky, you will need to > change the ?crval? in the wcs object again. You don?t have to recreate the > whole wcs, just change that one value. So a cycle that looks like this: > > myra = 21 * 15 # degrees, not hours > mydec = 57 # degrees > # Put that as the RA and Dec of the WCS reference pixel > w.wcs.crval = [myra, mydec] > reg.contains(SkyCoord(myra, mydec, unit="deg"),w) > > with different values of myra and mydec would allow you to test a bunch of > points again the same region. > > Eric > > On Jun 13, 2022, at 10:40 AM, Miguel Guti?rrez P?ez > wrote: > > 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 () > 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 >> 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 () >> 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 >>> 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 > > > _______________________________________________ > AstroPy mailing list > AstroPy at python.org > https://mail.python.org/mailman/listinfo/astropy > -------------- next part -------------- An HTML attachment was scrubbed... URL: