2
$\begingroup$

I'm trying to plot celestial equator in galactic coordinates. Here is my code (based on this answer):

import matplotlib.pyplot as plt
import seaborn as sns; sns.set()
import numpy as np

from astropy.coordinates import SkyCoord
from astropy import units as u

ra_all = np.linspace(-180, 180, 100)
dec_0 = np.zeros(100)

# Transform equatorial coordinates to galactic
eq = SkyCoord(ra_all, dec_0, unit=u.deg)
gal = eq.galactic
l_plot, b_plot = gal.l.wrap_at('180d').radian, gal.b.radian


lon = np.linspace(0, 360, 100)
lat = np.zeros(100)

# Transform ecliptic coordinates to galactic
ecl = SkyCoord(lon, lat, unit=u.deg, frame='barycentricmeanecliptic')
ecl_gal = ecl.transform_to('galactic')
l_ecl_gal, b_ecl_gal = ecl_gal.l.wrap_at('180d').radian, ecl_gal.b.radian


plt.figure(figsize=(14,7))
plt.subplot(111, projection='aitoff')

plt.scatter(l_plot, b_plot, s=5, label='Celestial Equator')
plt.scatter(l_ecl_gal, b_ecl_gal, s=5, label='Eclptic')


plt.grid(True)
plt.legend(fontsize=16)

plt.show()

enter image description here

However, the map I drew seems to be flipped left to right compared to the one bellow (taken from here)

enter image description here


Question 1: Why does the result of my implementation appear to be the reverse of the other image? Do I have something wrong, or is this simply an issue of mapping the surface from the inside versus from the outside?

Question 2: What is the best way to change my code to make it draw galactic map in a conventional format?

$\endgroup$
  • 1
    $\begingroup$ I adjusted your wording a little bit to better fit the site. I think this is an interesting question and might have an interesting answer! $\endgroup$ – uhoh Oct 19 at 1:56
  • 4
    $\begingroup$ It’s a “mapping from the inside” issue. As with equatorial coordinates, the longitude coordinate increases to the left (when North is up). See astronomy.stackexchange.com/questions/16339/… $\endgroup$ – Peter Erwin Oct 19 at 3:59
2
$\begingroup$

Ok, community helped me to figure out that I faced the “mapping from the inside” issue (explained here). I'll use this answer to show my final code.

def eq2gal(ra, dec):
    
    '''
    Transforms equatorial coordinates to galactic ones.
    Then prepares them for matplotlib aitoff projection. 
    '''
    
    eq = SkyCoord(ra, dec, unit=u.deg)
    gal = eq.galactic

    # Minus appears because of “mapping from the inside” issue
    l_gal, b_gal = -gal.l.wrap_at('180d').radian, gal.b.radian
    
    return l_gal, b_gal

def ecl2gal(lon_ecl, lat_ecl):
    
    '''
    Transforms ecliptic coordinates to galactic ones.
    Then prepares them for matplotlib aitoff projection.
    '''
    
    ecl = SkyCoord(lon_ecl, lat_ecl, unit=u.deg, frame='barycentricmeanecliptic')
    gal = ecl.transform_to('galactic')

    # Minus appears because of “mapping from the inside” issue
    l_gal, b_gal = -gal.l.wrap_at('180d').radian, gal.b.radian
    
    return l_gal, b_gal

# Equatorial plane
ra_all = np.linspace(-180, 180, 100)
dec_0 = np.zeros(100)

l_eq_gal, b_eq_gal = eq2gal(ra_all, dec_0)

# Ecliptic plane
lon_ecl = np.linspace(0, 360, 100)
lat_ecl = np.zeros(100)

l_ecl_gal, b_ecl_gal = ecl2gal(lon_ecl, lat_ecl)


plt.figure(figsize=(14,7))
plt.subplot(111, projection='aitoff')

plt.scatter(l_eq_gal, b_eq_gal, s=4, marker='v', label='Celestial Equator')
plt.scatter(l_ecl_gal, b_ecl_gal, s=4, marker='^', label='Eclptic')

# Essential thing is to rename ticks to transform them to conventional format
plt.xticks(ticks=np.radians([-150, -120, -90, -60, -30, 0, \
                             30, 60, 90, 120, 150]),
           labels=['150°', '120°', '90°', '60°', '30°', '0°', \
                   '330°', '300°', '270°', '240°', '210°'])


plt.grid(True)
plt.legend(fontsize=16, loc='lower center')

plt.title('Galactic', fontsize='16')

plt.show()

enter image description here

| improve this answer | |
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.