Skip to content

Commit

Permalink
switch to use astropy to convert coords
Browse files Browse the repository at this point in the history
  • Loading branch information
henrysky committed Aug 30, 2023
1 parent 782ebfc commit 7ad9395
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 14 additions & 4 deletions mw_plot/mw_plot_matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import astropy.units as u
import astropy.coordinates as apycoords
from galpy.util.coords import radec_to_lb

import pylab as plt
from matplotlib.colors import LinearSegmentedColormap
Expand Down Expand Up @@ -666,11 +665,22 @@ def initialize_mwplot(self, fig=None, ax=None):
# disable ticks if not galactic grid
self.ax.set_yticklabels([])

epoch = "J2000"

def radec_to_lb(ra, dec, degree=False):
if degree is True:
unit = u.deg
else:
unit = u.rad
c = apycoords.SkyCoord(ra * unit, dec * unit, equinox=epoch, frame="icrs")
c = c.transform_to(apycoords.Galactic)
return c.l.to(unit).value, c.b.to(unit).value

if self.radecgrid is True:
for i in [-75, -60, -45, -30, -15, 0, 15, 30, 45, 60, 75]:
ras = np.linspace(0, 360, 360)
des = np.linspace(i, i, 360)
l, b = radec_to_lb(ras, des, degree=True).T
l, b = radec_to_lb(ras, des, degree=True)
l = -(l + 180) % (2 * 180) - 180
if np.max(np.diff(l)) > 100.0:
idx = np.argmax(np.diff(l)) + 1
Expand All @@ -689,7 +699,7 @@ def initialize_mwplot(self, fig=None, ax=None):
for i in [30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330]:
ras = np.linspace(i, i, 360)
des = np.linspace(-75, 75, 360)
l, b = radec_to_lb(ras, des, degree=True).T
l, b = radec_to_lb(ras, des, degree=True)
l = -(l + 180) % (2 * 180) - 180
if np.max(np.diff(l)) > 0.25:
idx = np.argmax(np.diff(l))
Expand Down Expand Up @@ -746,7 +756,7 @@ def ecl_to_lb(elon, elat):
ra[case_1_idx] += np.pi
ra[case_2_idx] += 2 * np.pi
ra[case_3_idx] += 3 * np.pi
l, b = radec_to_lb(ra, dec).T
l, b = radec_to_lb(ra, dec)
l = -(l + np.pi) % (2 * np.pi) - np.pi
return l, b

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
include_package_data=True,
package_data={"mw_plot": ["*.png", "*.jpg"]},
python_requires=">=3.7",
install_requires=["requests", "numpy", "astropy", "matplotlib", "Pillow", "galpy"],
install_requires=["requests", "numpy", "astropy", "matplotlib", "Pillow"],
url="https://github.com/henrysky/milkyway_plot",
project_urls={
"Bug Tracker": "https://github.com/henrysky/milkyway_plot/issues",
Expand Down

0 comments on commit 7ad9395

Please sign in to comment.