{"action":"created","issue":{"url":"https://api.github.com/repos/astropy/astropy/issues/7377","repository_url":"https://api.github.com/repos/astropy/astropy","labels_url":"https://api.github.com/repos/astropy/astropy/issues/7377/labels{/name}","comments_url":"https://api.github.com/repos/astropy/astropy/issues/7377/comments","events_url":"https://api.github.com/repos/astropy/astropy/issues/7377/events","html_url":"https://github.com/astropy/astropy/issues/7377","id":314317716,"number":7377,"title":"converting  galactic cartesian SkyCoord to spherical and also to ecliptical","user":{"login":"richardgmcmahon","id":2388403,"avatar_url":"https://avatars3.githubusercontent.com/u/2388403?v=4","gravatar_id":"","url":"https://api.github.com/users/richardgmcmahon","html_url":"https://github.com/richardgmcmahon","followers_url":"https://api.github.com/users/richardgmcmahon/followers","following_url":"https://api.github.com/users/richardgmcmahon/following{/other_user}","gists_url":"https://api.github.com/users/richardgmcmahon/gists{/gist_id}","starred_url":"https://api.github.com/users/richardgmcmahon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/richardgmcmahon/subscriptions","organizations_url":"https://api.github.com/users/richardgmcmahon/orgs","repos_url":"https://api.github.com/users/richardgmcmahon/repos","events_url":"https://api.github.com/users/richardgmcmahon/events{/privacy}","received_events_url":"https://api.github.com/users/richardgmcmahon/received_events","type":"User","site_admin":false},"labels":[{"id":3345090,"url":"https://api.github.com/repos/astropy/astropy/labels/Docs","name":"Docs","color":"02d7e1","default":false},{"id":35762381,"url":"https://api.github.com/repos/astropy/astropy/labels/Effort-low","name":"Effort-low","color":"fef2c0","default":false},{"id":145666575,"url":"https://api.github.com/repos/astropy/astropy/labels/Enhancement","name":"Enhancement","color":"fad8c7","default":false},{"id":113315579,"url":"https://api.github.com/repos/astropy/astropy/labels/Package-novice","name":"Package-novice","color":"bfe5bf","default":false},{"id":21499868,"url":"https://api.github.com/repos/astropy/astropy/labels/coordinates","name":"coordinates","color":"c7def8","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-04-14T10:19:07Z","updated_at":"2018-05-01T19:31:45Z","closed_at":null,"author_association":"NONE","body":"![plot_galactic_radec](https://user-images.githubusercontent.com/2388403/38767278-287409fa-3fd6-11e8-87a1-af7f5d1bbe5f.png)\r\nPlotting random data in Aitoff projection: plotting galactic coordindates\r\n\r\nI am strugglig with converting a SkyCoord in galactic cartesian to galactic spherical\r\n\r\nI want to create a set of  example plots in equatotal, galactic and ecliptic cordinates that are \r\nnot just a random set of uniform points. I have started from the this example:\r\n\r\nExample 1: Plotting random data in Aitoff projection\r\n\r\nhttp://docs.astropy.org/en/stable/coordinates/skycoord.html#example-2-plotting-star-positions-in-bulge-and-disk\r\n\r\nThis creates a SkyCoord using u, v, w \r\n\r\ncoords_disk = SkyCoord(disk,\r\n                     representation='cartesian',\r\n                     frame='galactic')\r\n\r\nI have stuggled with getting galactic cords in long, lat or l, b from this. The u, v, w, cartesian form is being used to that a simple disk and bulge distribution can be created using np.random.multivariate_normal\r\n\r\nprint(coords_disk)\r\n<SkyCoord (Galactic): (u, v, w) in rad\r\n\r\nprint(coords_disk.u) works\r\n\r\nprint(cords_disk.l) or .lon gives an error as expected\r\n\r\nSo I tried changing the representation:\r\n\r\ncoords_disk.representation = 'spherical'\r\nprint(coords_disk)\r\n<SkyCoord (Galactic): (l, b, distance) in (deg, deg, rad)\r\nprint(coords_disk.l) work.\r\n\r\nIs there a way to convert the SkyCoord from cartesian to sperical since that would be more \r\nconvenient since I want to also plot ecliptic cordinates.\r\n\r\nI have been able to this:\r\n\r\ncoords_disk.representation = 'spherical'\r\ncoords_bulge.representation = 'spherical'\r\n\r\n\r\nl_disk_rad = coords_disk.l.wrap_at(180 * u.deg).radian\r\nb_disk_rad = coords_disk.b.radian\r\n\r\nl_bulge_rad = coords_bulge.galactic.l.wrap_at(180 * u.deg).radian\r\nb_bulge_rad = coords_bulge.galactic.b.radian\r\n\r\n\r\n![plot_galactic_galactic](https://user-images.githubusercontent.com/2388403/38767337-2dc90bb6-3fd7-11e8-8cac-225ce4274c86.png)\r\n\r\nHow do I get ecliptic?\r\n\r\nOK, maybe I have answered my own question:\r\n\r\nfrom astropy.coordinates import BarycentricTrueEcliptic\r\ncoords_disk_ecliptic = coords_disk.transform_to(BarycentricTrueEcliptic)\r\n\r\nl_disk_rad = coords_disk_ecliptic.lon.wrap_at(180 * u.deg).radian\r\nb_disk_rad = coords_disk_ecliptic.lat.radian\r\n\r\n\r\n\r\n "},"comment":{"url":"https://api.github.com/repos/astropy/astropy/issues/comments/385765811","html_url":"https://github.com/astropy/astropy/issues/7377#issuecomment-385765811","issue_url":"https://api.github.com/repos/astropy/astropy/issues/7377","id":385765811,"user":{"login":"lfulmer","id":22732420,"avatar_url":"https://avatars3.githubusercontent.com/u/22732420?v=4","gravatar_id":"","url":"https://api.github.com/users/lfulmer","html_url":"https://github.com/lfulmer","followers_url":"https://api.github.com/users/lfulmer/followers","following_url":"https://api.github.com/users/lfulmer/following{/other_user}","gists_url":"https://api.github.com/users/lfulmer/gists{/gist_id}","starred_url":"https://api.github.com/users/lfulmer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lfulmer/subscriptions","organizations_url":"https://api.github.com/users/lfulmer/orgs","repos_url":"https://api.github.com/users/lfulmer/repos","events_url":"https://api.github.com/users/lfulmer/events{/privacy}","received_events_url":"https://api.github.com/users/lfulmer/received_events","type":"User","site_admin":false},"created_at":"2018-05-01T19:31:44Z","updated_at":"2018-05-01T19:31:44Z","author_association":"NONE","body":"It looks like this can be closed @adrn ."}}
{"actor":{"display_login":"lfulmer"}}