########################################################
# Started Logging At: 2023-02-19 17:20:26
########################################################
########################################################
# # Started Logging At: 2023-02-19 17:20:26
########################################################
print("test")
get_ipython().run_line_magic('matplotlib', 'inline')
import pylab as pl
import numpy as np
import os
from astropy.utils.data import download_file
from astropy.io import fits
from spectral_cube import SpectralCube
from astropy.visualization import simple_norm
import shutil
from reproject import reproject_from_healpix, reproject_to_healpix

from astropy.wcs import WCS
import matplotlib.pyplot as plt
from astropy.visualization.wcsaxes.frame import EllipticalFrame

from matplotlib.colors import rgb_to_hsv, hsv_to_rgb 

from astropy.convolution import convolve_fft, Gaussian2DKernel, Gaussian1DKernel
import healpy
def h_rot(rgb, rot):
    hsv = rgb_to_hsv(rgb)
    hsv[:,:,0] += rot  # 0.25 = 90/360
    hsv[:,:,0] = hsv[:,:,0] % 1 
    rgb_scaled = hsv_to_rgb(hsv)
    return rgb_scaled

def make_rgb(rgb, basename, hsv_rotation=0, layernames='RGB',
             axlims=None, frame_class=EllipticalFrame):
    plt.figure(figsize=(10,5), dpi=200)
    ax = plt.subplot(1,1,1, projection=WCS(target_header),
                     frame_class=frame_class)
    #ax.coords.grid(color='white')
    ax.coords['glat'].set_ticklabel(visible=False)
    ax.coords['glon'].set_ticklabel(visible=False)
    ax.coords['glat'].set_ticks_visible(False)
    ax.coords['glon'].set_ticks_visible(False)
    for ind, color in zip((0, 1, 2), (layernames)):
        rgbc = np.zeros_like(rgb)
        rgbc[:, :, ind] = rgb[:, :, ind]
        if hsv_rotation != 0:
            rgbc = h_rot(rgbc, hsv_rotation)
        ax.imshow(rgbc)
        pl.savefig(f'{basename}_{color}.png', bbox_inches='tight', transparent=True)
    if hsv_rotation != 0:
        rgb = h_rot(rgb, hsv_rotation)
    ax.imshow(rgb)
    if axlims is not None:
        ax.axis(axlims)
    pl.savefig(f'{basename}_RGB.png', bbox_inches='tight', transparent=True)
target_header_medres = fits.Header.fromstring("""
NAXIS   =                    2
NAXIS1  =                  960
NAXIS2  =                  480
CTYPE1  = 'GLON-MOL'
CRPIX1  =                480.5
CRVAL1  =                  0.0
CDELT1  =              -0.3375
CUNIT1  = 'deg     '
CTYPE2  = 'GLAT-MOL'
CRPIX2  =                240.5
CRVAL2  =                  0.0
CDELT2  =               0.3375
CUNIT2  = 'deg     '
COORDSYS= 'icrs    '
""", sep='\n')
target_header = fits.Header.fromstring("""
NAXIS   =                    2
NAXIS1  =                 1920
NAXIS2  =                  960
CTYPE1  = 'GLON-MOL'
CRPIX1  =                960.5
CRVAL1  =                  0.0
CDELT1  =             -0.16875
CUNIT1  = 'deg     '
CTYPE2  = 'GLAT-MOL'
CRPIX2  =                480.5
CRVAL2  =                  0.0
CDELT2  =              0.16875
CUNIT2  = 'deg     '
COORDSYS= 'icrs    '
""", sep='\n')
def fix_nans(img):
    kernel = Gaussian2DKernel(2)
    sm = convolve_fft(img, kernel)
    img[np.isnan(img)] = sm[np.isnan(img)]
    return img

def fix_rosat_nans(tb):
    kernel = Gaussian1DKernel(1)
    # tb is a 2D array, but we want to convolve in 1D
    sm = convolve_fft(tb, kernel.array[None, :])
    tb[np.isnan(tb)] = sm[np.isnan(tb)]
    return tb
fn_rosat5 = "RASS_SXRB_R5.fits"
if not os.path.exists(fn_rosat5):
    rosat5 = download_file(f"https://www.jb.man.ac.uk/research/cosmos/rosat/{fn_rosat5}")
    shutil.move(rosat5, fn_rosat5)
rosat5 = fits.open(fn_rosat5)
(rosat5[1].data['COUNT_RATE'] == 0).sum()
#[Out]# 2633
pl.imshow(rosat5[1].data['COUNT_RATE'],
          norm=simple_norm(rosat5[1].data['COUNT_RATE'], min_percent=1,
                          max_percent=99, stretch='asinh'))
#[Out]# <matplotlib.image.AxesImage at 0x2b1980f16e80>
rosat5[1].header['COORDSYS']
#[Out]# 'G'
data_rosat5 = rosat5[1].data['COUNT_RATE']
data_rosat5 = fix_rosat_nans(np.where(data_rosat5==0, np.nan, data_rosat5))
pl.imshow(data_rosat5,
          norm=simple_norm(data_rosat5, min_percent=1,
                          max_percent=99, stretch='asinh'))
#[Out]# <matplotlib.image.AxesImage at 0x2b198100bb80>
#img_rosat5, footprint = reproject_from_healpix(fn_rosat5, target_header)
data_rosat5 = rosat5[1].data['COUNT_RATE']
data_rosat5 = fix_rosat_nans(np.where(data_rosat5==0, np.nan, data_rosat5))
img_rosat5, footprint = reproject_from_healpix((data_rosat5.ravel(),
                                                rosat5[1].header["COORDSYS"]),
                                               target_header,
                                               nested=rosat5[1].header["ORDERING"].lower() == "nested"
                                              )
#img_rosat5 = fix_rosat_nans(np.where(img_rosat5==0, np.nan, img_rosat5))
plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header),
                 frame_class=EllipticalFrame,
                )
ax.imshow(img_rosat5, norm=simple_norm(img_rosat5, min_percent=1, max_percent=99.99, stretch='log'))
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
#img_rosat5, footprint = reproject_from_healpix(fn_rosat5, target_header)
data_rosat5 = rosat5[1].data['COUNT_RATE']
data_rosat5 = fix_rosat_nans(np.where(data_rosat5<=0, np.nan, data_rosat5))
img_rosat5, footprint = reproject_from_healpix((data_rosat5.ravel(),
                                                rosat5[1].header["COORDSYS"]),
                                               target_header,
                                               nested=rosat5[1].header["ORDERING"].lower() == "nested"
                                              )
#img_rosat5 = fix_rosat_nans(np.where(img_rosat5==0, np.nan, img_rosat5))
plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header),
                 frame_class=EllipticalFrame,
                )
ax.imshow(img_rosat5, norm=simple_norm(img_rosat5, min_percent=1, max_percent=99.99, stretch='log'))
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
np.min(data_rosat5[data_rosat5>=0])
#[Out]# 0.0
np.min(data_rosat5[data_rosat5>0])
#[Out]# 2.017121e-14
pl.hist(data_rosat5.ravel())
#[Out]# (array([3.14564e+06, 6.10000e+01, 9.00000e+00, 3.00000e+00, 8.00000e+00,
#[Out]#         3.00000e+00, 2.00000e+00, 1.00000e+00, 0.00000e+00, 1.00000e+00]),
#[Out]#  array([-1.5533403e-09,  2.6890088e+04,  5.3780176e+04,  8.0670266e+04,
#[Out]#          1.0756035e+05,  1.3445044e+05,  1.6134053e+05,  1.8823061e+05,
#[Out]#          2.1512070e+05,  2.4201078e+05,  2.6890088e+05], dtype=float32),
#[Out]#  <BarContainer object of 10 artists>)
pl.hist(data_rosat5.ravel(), bins=np.logspace(-14, 6))
#[Out]# (array([1.000000e+00, 2.000000e+00, 4.000000e+00, 4.000000e+00,
#[Out]#         4.000000e+00, 1.000000e+00, 0.000000e+00, 4.000000e+00,
#[Out]#         4.000000e+00, 1.000000e+00, 0.000000e+00, 3.000000e+00,
#[Out]#         3.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00,
#[Out]#         0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00,
#[Out]#         0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00,
#[Out]#         1.000000e+00, 3.000000e+00, 1.000000e+00, 7.000000e+00,
#[Out]#         1.900000e+01, 4.400000e+01, 1.130000e+02, 2.730000e+02,
#[Out]#         7.230000e+02, 1.817000e+03, 4.967000e+03, 1.511600e+04,
#[Out]#         6.568700e+04, 3.409420e+05, 1.500620e+06, 1.012687e+06,
#[Out]#         1.854940e+05, 8.410000e+03, 2.060000e+03, 5.230000e+02,
#[Out]#         2.910000e+02, 7.900000e+01, 1.900000e+01, 5.000000e+00,
#[Out]#         0.000000e+00]),
#[Out]#  array([1.00000000e-14, 2.55954792e-14, 6.55128557e-14, 1.67683294e-13,
#[Out]#         4.29193426e-13, 1.09854114e-12, 2.81176870e-12, 7.19685673e-12,
#[Out]#         1.84206997e-11, 4.71486636e-11, 1.20679264e-10, 3.08884360e-10,
#[Out]#         7.90604321e-10, 2.02358965e-09, 5.17947468e-09, 1.32571137e-08,
#[Out]#         3.39322177e-08, 8.68511374e-08, 2.22299648e-07, 5.68986603e-07,
#[Out]#         1.45634848e-06, 3.72759372e-06, 9.54095476e-06, 2.44205309e-05,
#[Out]#         6.25055193e-05, 1.59985872e-04, 4.09491506e-04, 1.04811313e-03,
#[Out]#         2.68269580e-03, 6.86648845e-03, 1.75751062e-02, 4.49843267e-02,
#[Out]#         1.15139540e-01, 2.94705170e-01, 7.54312006e-01, 1.93069773e+00,
#[Out]#         4.94171336e+00, 1.26485522e+01, 3.23745754e+01, 8.28642773e+01,
#[Out]#         2.12095089e+02, 5.42867544e+02, 1.38949549e+03, 3.55648031e+03,
#[Out]#         9.10298178e+03, 2.32995181e+04, 5.96362332e+04, 1.52641797e+05,
#[Out]#         3.90693994e+05, 1.00000000e+06]),
#[Out]#  <BarContainer object of 49 artists>)
pl.hist(data_rosat5.ravel(), bins=np.logspace(-14, 6), log=True)
#[Out]# (array([1.000000e+00, 2.000000e+00, 4.000000e+00, 4.000000e+00,
#[Out]#         4.000000e+00, 1.000000e+00, 0.000000e+00, 4.000000e+00,
#[Out]#         4.000000e+00, 1.000000e+00, 0.000000e+00, 3.000000e+00,
#[Out]#         3.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00,
#[Out]#         0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00,
#[Out]#         0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00,
#[Out]#         1.000000e+00, 3.000000e+00, 1.000000e+00, 7.000000e+00,
#[Out]#         1.900000e+01, 4.400000e+01, 1.130000e+02, 2.730000e+02,
#[Out]#         7.230000e+02, 1.817000e+03, 4.967000e+03, 1.511600e+04,
#[Out]#         6.568700e+04, 3.409420e+05, 1.500620e+06, 1.012687e+06,
#[Out]#         1.854940e+05, 8.410000e+03, 2.060000e+03, 5.230000e+02,
#[Out]#         2.910000e+02, 7.900000e+01, 1.900000e+01, 5.000000e+00,
#[Out]#         0.000000e+00]),
#[Out]#  array([1.00000000e-14, 2.55954792e-14, 6.55128557e-14, 1.67683294e-13,
#[Out]#         4.29193426e-13, 1.09854114e-12, 2.81176870e-12, 7.19685673e-12,
#[Out]#         1.84206997e-11, 4.71486636e-11, 1.20679264e-10, 3.08884360e-10,
#[Out]#         7.90604321e-10, 2.02358965e-09, 5.17947468e-09, 1.32571137e-08,
#[Out]#         3.39322177e-08, 8.68511374e-08, 2.22299648e-07, 5.68986603e-07,
#[Out]#         1.45634848e-06, 3.72759372e-06, 9.54095476e-06, 2.44205309e-05,
#[Out]#         6.25055193e-05, 1.59985872e-04, 4.09491506e-04, 1.04811313e-03,
#[Out]#         2.68269580e-03, 6.86648845e-03, 1.75751062e-02, 4.49843267e-02,
#[Out]#         1.15139540e-01, 2.94705170e-01, 7.54312006e-01, 1.93069773e+00,
#[Out]#         4.94171336e+00, 1.26485522e+01, 3.23745754e+01, 8.28642773e+01,
#[Out]#         2.12095089e+02, 5.42867544e+02, 1.38949549e+03, 3.55648031e+03,
#[Out]#         9.10298178e+03, 2.32995181e+04, 5.96362332e+04, 1.52641797e+05,
#[Out]#         3.90693994e+05, 1.00000000e+06]),
#[Out]#  <BarContainer object of 49 artists>)
pl.hist(data_rosat5.ravel(), bins=np.logspace(-14, 5), log=True)
#[Out]# (array([1.000000e+00, 1.000000e+00, 3.000000e+00, 6.000000e+00,
#[Out]#         4.000000e+00, 1.000000e+00, 0.000000e+00, 3.000000e+00,
#[Out]#         3.000000e+00, 3.000000e+00, 0.000000e+00, 1.000000e+00,
#[Out]#         3.000000e+00, 2.000000e+00, 0.000000e+00, 0.000000e+00,
#[Out]#         0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00,
#[Out]#         0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00,
#[Out]#         0.000000e+00, 0.000000e+00, 2.000000e+00, 3.000000e+00,
#[Out]#         2.000000e+00, 1.200000e+01, 3.000000e+01, 6.100000e+01,
#[Out]#         1.380000e+02, 3.820000e+02, 8.700000e+02, 2.024000e+03,
#[Out]#         5.799000e+03, 1.664800e+04, 6.976300e+04, 3.339790e+05,
#[Out]#         1.405596e+06, 1.063946e+06, 2.224350e+05, 1.471300e+04,
#[Out]#         2.274000e+03, 7.380000e+02, 3.110000e+02, 1.380000e+02,
#[Out]#         2.100000e+01]),
#[Out]#  array([1.00000000e-14, 2.44205309e-14, 5.96362332e-14, 1.45634848e-13,
#[Out]#         3.55648031e-13, 8.68511374e-13, 2.12095089e-12, 5.17947468e-12,
#[Out]#         1.26485522e-11, 3.08884360e-11, 7.54312006e-11, 1.84206997e-10,
#[Out]#         4.49843267e-10, 1.09854114e-09, 2.68269580e-09, 6.55128557e-09,
#[Out]#         1.59985872e-08, 3.90693994e-08, 9.54095476e-08, 2.32995181e-07,
#[Out]#         5.68986603e-07, 1.38949549e-06, 3.39322177e-06, 8.28642773e-06,
#[Out]#         2.02358965e-05, 4.94171336e-05, 1.20679264e-04, 2.94705170e-04,
#[Out]#         7.19685673e-04, 1.75751062e-03, 4.29193426e-03, 1.04811313e-02,
#[Out]#         2.55954792e-02, 6.25055193e-02, 1.52641797e-01, 3.72759372e-01,
#[Out]#         9.10298178e-01, 2.22299648e+00, 5.42867544e+00, 1.32571137e+01,
#[Out]#         3.23745754e+01, 7.90604321e+01, 1.93069773e+02, 4.71486636e+02,
#[Out]#         1.15139540e+03, 2.81176870e+03, 6.86648845e+03, 1.67683294e+04,
#[Out]#         4.09491506e+04, 1.00000000e+05]),
#[Out]#  <BarContainer object of 49 artists>)
pl.hist(data_rosat5.ravel(), bins=np.logspace(-14, 5), log=True)
pl.loglog();
#img_rosat5, footprint = reproject_from_healpix(fn_rosat5, target_header)
data_rosat5 = rosat5[1].data['COUNT_RATE']
data_rosat5 = fix_rosat_nans(np.where(data_rosat5<=1e-8, np.nan, data_rosat5))
img_rosat5, footprint = reproject_from_healpix((data_rosat5.ravel(),
                                                rosat5[1].header["COORDSYS"]),
                                               target_header,
                                               nested=rosat5[1].header["ORDERING"].lower() == "nested"
                                              )
#img_rosat5 = fix_rosat_nans(np.where(img_rosat5==0, np.nan, img_rosat5))
plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header),
                 frame_class=EllipticalFrame,
                )
ax.imshow(img_rosat5, norm=simple_norm(img_rosat5, min_percent=1, max_percent=99.99, stretch='log'))
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
def fix_nans(img):
    kernel = Gaussian2DKernel(2)
    sm = convolve_fft(img, kernel)
    img[np.isnan(img)] = sm[np.isnan(img)]
    return img

def fix_rosat_nans(tb):
    kernel = Gaussian1DKernel(2)
    # tb is a 2D array, but we want to convolve in 1D
    sm = convolve_fft(tb, kernel.array[None, :])
    tb[np.isnan(tb)] = sm[np.isnan(tb)]
    return tb
#img_rosat5, footprint = reproject_from_healpix(fn_rosat5, target_header)
data_rosat5 = rosat5[1].data['COUNT_RATE']
data_rosat5 = fix_rosat_nans(np.where(data_rosat5<=1e-8, np.nan, data_rosat5))
img_rosat5, footprint = reproject_from_healpix((data_rosat5.ravel(),
                                                rosat5[1].header["COORDSYS"]),
                                               target_header,
                                               nested=rosat5[1].header["ORDERING"].lower() == "nested"
                                              )
#img_rosat5 = fix_rosat_nans(np.where(img_rosat5==0, np.nan, img_rosat5))
plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header),
                 frame_class=EllipticalFrame,
                )
ax.imshow(img_rosat5, norm=simple_norm(img_rosat5, min_percent=1, max_percent=99.99, stretch='log'))
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
def fix_nans(img):
    kernel = Gaussian2DKernel(2)
    sm = convolve_fft(img, kernel)
    img[np.isnan(img)] = sm[np.isnan(img)]
    return img

def fix_rosat_nans(tb):
    kernel = Gaussian1DKernel(3)
    # tb is a 2D array, but we want to convolve in 1D
    sm = convolve_fft(tb, kernel.array[None, :])
    tb[np.isnan(tb)] = sm[np.isnan(tb)]
    return tb
#img_rosat5, footprint = reproject_from_healpix(fn_rosat5, target_header)
data_rosat5 = rosat5[1].data['COUNT_RATE']
data_rosat5 = fix_rosat_nans(np.where(data_rosat5<=1e-8, np.nan, data_rosat5))
img_rosat5, footprint = reproject_from_healpix((data_rosat5.ravel(),
                                                rosat5[1].header["COORDSYS"]),
                                               target_header,
                                               nested=rosat5[1].header["ORDERING"].lower() == "nested"
                                              )
#img_rosat5 = fix_rosat_nans(np.where(img_rosat5==0, np.nan, img_rosat5))
plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header),
                 frame_class=EllipticalFrame,
                )
ax.imshow(img_rosat5, norm=simple_norm(img_rosat5, min_percent=1, max_percent=99.99, stretch='log'))
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
pl.hist(img_rosat5.ravel(), bins=np.logspace(-14, 5), log=True)
pl.loglog();
#img_rosat5, footprint = reproject_from_healpix(fn_rosat5, target_header)
data_rosat5 = rosat5[1].data['COUNT_RATE']
data_rosat5 = fix_rosat_nans(np.where(data_rosat5<=1e-8, np.nan, data_rosat5))
img_rosat5, footprint = reproject_from_healpix((data_rosat5.ravel(),
                                                rosat5[1].header["COORDSYS"]),
                                               target_header,
                                               nested=rosat5[1].header["ORDERING"].lower() == "nested"
                                              )
img_rosat5 = fix_rosat_nans(np.where(img_rosat5<=1e-9, np.nan, img_rosat5))
plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header),
                 frame_class=EllipticalFrame,
                )
ax.imshow(img_rosat5, norm=simple_norm(img_rosat5, min_percent=1, max_percent=99.99, stretch='log'))
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
#img_rosat5, footprint = reproject_from_healpix(fn_rosat5, target_header)
data_rosat5 = rosat5[1].data['COUNT_RATE']
data_rosat5 = fix_rosat_nans(np.where(data_rosat5<=1e-8, np.nan, data_rosat5))
img_rosat5, footprint = reproject_from_healpix((data_rosat5.ravel(),
                                                rosat5[1].header["COORDSYS"]),
                                               target_header,
                                               nested=rosat5[1].header["ORDERING"].lower() == "nested"
                                              )
img_rosat5 = fix_nans(np.where(img_rosat5<=1e-9, np.nan, img_rosat5))
plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header),
                 frame_class=EllipticalFrame,
                )
ax.imshow(img_rosat5, norm=simple_norm(img_rosat5, min_percent=1, max_percent=99.99, stretch='log'))
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
def fix_nans(img):
    kernel = Gaussian2DKernel(2)
    sm = convolve_fft(img, kernel)
    img[np.isnan(img)] = sm[np.isnan(img)]
    return img

def fix_rosat_nans(tb):
    #kernel = Gaussian1DKernel(3)
    kernel = Gaussian2DKernel(1) # convolving in 2D convolves adjacent scans
    # tb is a 2D array, but we want to convolve in 1D
    #sm = convolve_fft(tb, kernel.array[None, :])
    sm = convolve_fft(tb, kernel)
    tb[np.isnan(tb)] = sm[np.isnan(tb)]
    return tb
#img_rosat5, footprint = reproject_from_healpix(fn_rosat5, target_header)
data_rosat5 = rosat5[1].data['COUNT_RATE']
data_rosat5 = fix_rosat_nans(np.where(data_rosat5<=1e-8, np.nan, data_rosat5))
img_rosat5, footprint = reproject_from_healpix((data_rosat5.ravel(),
                                                rosat5[1].header["COORDSYS"]),
                                               target_header,
                                               nested=rosat5[1].header["ORDERING"].lower() == "nested"
                                              )
img_rosat5 = fix_nans(np.where(img_rosat5<=1e-9, np.nan, img_rosat5))
plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header),
                 frame_class=EllipticalFrame,
                )
ax.imshow(img_rosat5, norm=simple_norm(img_rosat5, min_percent=1, max_percent=99.99, stretch='log'))
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=5e1, stretch='log')(img_lfi30),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_hfi143),
                simple_norm(img_synchrotron, min_percent=0.01, max_percent=99.99, log_a=5e1, stretch='log')(img_hfi857)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_Synchro', layernames=('X-Ray', 'Halpha', 'Synchrotron'))
########################################################
# Started Logging At: 2023-02-19 17:28:26
########################################################
########################################################
# # Started Logging At: 2023-02-19 17:28:26
########################################################
print("test")
get_ipython().run_line_magic('matplotlib', 'inline')
import pylab as pl
import numpy as np
import os
from astropy.utils.data import download_file
from astropy.io import fits
from spectral_cube import SpectralCube
from astropy.visualization import simple_norm
import shutil
from reproject import reproject_from_healpix, reproject_to_healpix

from astropy.wcs import WCS
import matplotlib.pyplot as plt
from astropy.visualization.wcsaxes.frame import EllipticalFrame

from matplotlib.colors import rgb_to_hsv, hsv_to_rgb 

from astropy.convolution import convolve_fft, Gaussian2DKernel, Gaussian1DKernel
import healpy
def h_rot(rgb, rot):
    hsv = rgb_to_hsv(rgb)
    hsv[:,:,0] += rot  # 0.25 = 90/360
    hsv[:,:,0] = hsv[:,:,0] % 1 
    rgb_scaled = hsv_to_rgb(hsv)
    return rgb_scaled

def make_rgb(rgb, basename, hsv_rotation=0, layernames='RGB',
             axlims=None, frame_class=EllipticalFrame):
    plt.figure(figsize=(10,5), dpi=200)
    ax = plt.subplot(1,1,1, projection=WCS(target_header),
                     frame_class=frame_class)
    #ax.coords.grid(color='white')
    ax.coords['glat'].set_ticklabel(visible=False)
    ax.coords['glon'].set_ticklabel(visible=False)
    ax.coords['glat'].set_ticks_visible(False)
    ax.coords['glon'].set_ticks_visible(False)
    for ind, color in zip((0, 1, 2), (layernames)):
        rgbc = np.zeros_like(rgb)
        rgbc[:, :, ind] = rgb[:, :, ind]
        if hsv_rotation != 0:
            rgbc = h_rot(rgbc, hsv_rotation)
        ax.imshow(rgbc)
        pl.savefig(f'{basename}_{color}.png', bbox_inches='tight', transparent=True)
    if hsv_rotation != 0:
        rgb = h_rot(rgb, hsv_rotation)
    ax.imshow(rgb)
    if axlims is not None:
        ax.axis(axlims)
    pl.savefig(f'{basename}_RGB.png', bbox_inches='tight', transparent=True)
target_header_medres = fits.Header.fromstring("""
NAXIS   =                    2
NAXIS1  =                  960
NAXIS2  =                  480
CTYPE1  = 'GLON-MOL'
CRPIX1  =                480.5
CRVAL1  =                  0.0
CDELT1  =              -0.3375
CUNIT1  = 'deg     '
CTYPE2  = 'GLAT-MOL'
CRPIX2  =                240.5
CRVAL2  =                  0.0
CDELT2  =               0.3375
CUNIT2  = 'deg     '
COORDSYS= 'icrs    '
""", sep='\n')
target_header = fits.Header.fromstring("""
NAXIS   =                    2
NAXIS1  =                 1920
NAXIS2  =                  960
CTYPE1  = 'GLON-MOL'
CRPIX1  =                960.5
CRVAL1  =                  0.0
CDELT1  =             -0.16875
CUNIT1  = 'deg     '
CTYPE2  = 'GLAT-MOL'
CRPIX2  =                480.5
CRVAL2  =                  0.0
CDELT2  =              0.16875
CUNIT2  = 'deg     '
COORDSYS= 'icrs    '
""", sep='\n')
def fix_nans(img):
    kernel = Gaussian2DKernel(2)
    sm = convolve_fft(img, kernel)
    img[np.isnan(img)] = sm[np.isnan(img)]
    return img

def fix_rosat_nans(tb):
    #kernel = Gaussian1DKernel(3)
    kernel = Gaussian2DKernel(1) # convolving in 2D convolves adjacent scans
    # tb is a 2D array, but we want to convolve in 1D
    #sm = convolve_fft(tb, kernel.array[None, :])
    sm = convolve_fft(tb, kernel)
    tb[np.isnan(tb)] = sm[np.isnan(tb)]
    return tb
fn_rosat5 = "RASS_SXRB_R5.fits"
if not os.path.exists(fn_rosat5):
    rosat5 = download_file(f"https://www.jb.man.ac.uk/research/cosmos/rosat/{fn_rosat5}")
    shutil.move(rosat5, fn_rosat5)
rosat5 = fits.open(fn_rosat5)
rosat5[1].header['COORDSYS']
#[Out]# 'G'
data_rosat5 = rosat5[1].data['COUNT_RATE']
data_rosat5 = fix_rosat_nans(np.where(data_rosat5==0, np.nan, data_rosat5))
pl.hist(data_rosat5.ravel(), bins=np.logspace(-14, 5), log=True)
pl.loglog();
pl.hist(img_rosat5.ravel(), bins=np.logspace(-14, 5), log=True)
pl.loglog();
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=5e1, stretch='log')(img_rosat5),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_synchrotron, min_percent=0.01, max_percent=99.99, log_a=5e1, stretch='log')(img_synchrotron)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_Synchro', layernames=('X-Ray', 'Halpha', 'Synchrotron'))
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=5e1, stretch='log')(img_rosat5),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_ThermalDust, min_percent=0.01, max_percent=99.99, log_a=5e1, stretch='log')(img_ThermalDust)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_Synchro', layernames=('X-Ray', 'Halpha', 'Synchrotron'))
get_ipython().run_line_magic('pwd', '')
#[Out]# '/orange/adamginsburg/cmz/DataSetVisualizations'
get_ipython().run_line_magic('matplotlib', 'inline')
import pylab as pl
import numpy as np
import os
from astropy.utils.data import download_file
from astropy.io import fits
from spectral_cube import SpectralCube
from astropy.visualization import simple_norm
import shutil
from reproject import reproject_from_healpix, reproject_to_healpix

from astropy.wcs import WCS
import matplotlib.pyplot as plt
from astropy.visualization.wcsaxes.frame import EllipticalFrame

from matplotlib.colors import rgb_to_hsv, hsv_to_rgb 

from astropy.convolution import convolve_fft, Gaussian2DKernel, Gaussian1DKernel
import healpy
def h_rot(rgb, rot):
    hsv = rgb_to_hsv(rgb)
    hsv[:,:,0] += rot  # 0.25 = 90/360
    hsv[:,:,0] = hsv[:,:,0] % 1 
    rgb_scaled = hsv_to_rgb(hsv)
    return rgb_scaled

def make_rgb(rgb, basename, hsv_rotation=0, layernames='RGB',
             axlims=None, frame_class=EllipticalFrame):
    plt.figure(figsize=(10,5), dpi=200)
    ax = plt.subplot(1,1,1, projection=WCS(target_header),
                     frame_class=frame_class)
    #ax.coords.grid(color='white')
    ax.coords['glat'].set_ticklabel(visible=False)
    ax.coords['glon'].set_ticklabel(visible=False)
    ax.coords['glat'].set_ticks_visible(False)
    ax.coords['glon'].set_ticks_visible(False)
    for ind, color in zip((0, 1, 2), (layernames)):
        rgbc = np.zeros_like(rgb)
        rgbc[:, :, ind] = rgb[:, :, ind]
        if hsv_rotation != 0:
            rgbc = h_rot(rgbc, hsv_rotation)
        ax.imshow(rgbc)
        pl.savefig(f'{basename}_{color}.png', bbox_inches='tight', transparent=True)
    if hsv_rotation != 0:
        rgb = h_rot(rgb, hsv_rotation)
    ax.imshow(rgb)
    if axlims is not None:
        ax.axis(axlims)
    pl.savefig(f'{basename}_RGB.png', bbox_inches='tight', transparent=True)
target_header_medres = fits.Header.fromstring("""
NAXIS   =                    2
NAXIS1  =                  960
NAXIS2  =                  480
CTYPE1  = 'GLON-MOL'
CRPIX1  =                480.5
CRVAL1  =                  0.0
CDELT1  =              -0.3375
CUNIT1  = 'deg     '
CTYPE2  = 'GLAT-MOL'
CRPIX2  =                240.5
CRVAL2  =                  0.0
CDELT2  =               0.3375
CUNIT2  = 'deg     '
COORDSYS= 'icrs    '
""", sep='\n')
target_header = fits.Header.fromstring("""
NAXIS   =                    2
NAXIS1  =                 1920
NAXIS2  =                  960
CTYPE1  = 'GLON-MOL'
CRPIX1  =                960.5
CRVAL1  =                  0.0
CDELT1  =             -0.16875
CUNIT1  = 'deg     '
CTYPE2  = 'GLAT-MOL'
CRPIX2  =                480.5
CRVAL2  =                  0.0
CDELT2  =              0.16875
CUNIT2  = 'deg     '
COORDSYS= 'icrs    '
""", sep='\n')
def fix_nans(img):
    kernel = Gaussian2DKernel(2)
    sm = convolve_fft(img, kernel)
    img[np.isnan(img)] = sm[np.isnan(img)]
    return img

def fix_rosat_nans(tb):
    #kernel = Gaussian1DKernel(3)
    kernel = Gaussian2DKernel(1) # convolving in 2D convolves adjacent scans
    # tb is a 2D array, but we want to convolve in 1D
    #sm = convolve_fft(tb, kernel.array[None, :])
    sm = convolve_fft(tb, kernel)
    tb[np.isnan(tb)] = sm[np.isnan(tb)]
    return tb
fn_rosat5 = "RASS_SXRB_R5.fits"
if not os.path.exists(fn_rosat5):
    rosat5 = download_file(f"https://www.jb.man.ac.uk/research/cosmos/rosat/{fn_rosat5}")
    shutil.move(rosat5, fn_rosat5)
rosat5 = fits.open(fn_rosat5)
rosat5[1].header['COORDSYS']
#[Out]# 'G'
data_rosat5 = rosat5[1].data['COUNT_RATE']
data_rosat5 = fix_rosat_nans(np.where(data_rosat5==0, np.nan, data_rosat5))
pl.hist(data_rosat5.ravel(), bins=np.logspace(-14, 5), log=True)
pl.loglog();
pl.hist(img_rosat5.ravel(), bins=np.logspace(-14, 5), log=True)
pl.loglog();
#img_rosat5, footprint = reproject_from_healpix(fn_rosat5, target_header)
data_rosat5 = rosat5[1].data['COUNT_RATE']
data_rosat5 = fix_rosat_nans(np.where(data_rosat5<=1e-8, np.nan, data_rosat5))
img_rosat5, footprint = reproject_from_healpix((data_rosat5.ravel(),
                                                rosat5[1].header["COORDSYS"]),
                                               target_header,
                                               nested=rosat5[1].header["ORDERING"].lower() == "nested"
                                              )
img_rosat5 = fix_nans(np.where(img_rosat5<=1e-9, np.nan, img_rosat5))
plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header),
                 frame_class=EllipticalFrame,
                )
ax.imshow(img_rosat5, norm=simple_norm(img_rosat5, min_percent=1, max_percent=99.99, stretch='log'))
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
fn_halpha = "Halpha_map.fits"
if not os.path.exists(fn_halpha):
    halpha = download_file(f"https://lambda.gsfc.nasa.gov/data/foregrounds/fink_halpha/{fn_halpha}")
    shutil.move(halpha, fn_halpha)
halpha = fits.open(fn_halpha)
#img_halpha, footprint = reproject_from_healpix(fn_halpha, target_header)
img_halpha = halpha[0].data
header = halpha[0].header
plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(header),
                 #frame_class=EllipticalFrame,
                )
ax.imshow(img_halpha, norm=simple_norm(img_halpha, min_percent=1, max_percent=99.99, stretch='log'))
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
fn_akari65 = "akari_mollweide_65_1_4096.fits"
if not os.path.exists(fn_akari65):
    akari65 = download_file(f"https://lambda.gsfc.nasa.gov/data/foregrounds/akari/images/{fn_akari65}")
    shutil.move(akari65, fn_akari65)
akari65 = fits.open(fn_akari65)
#img_akari65, footprint = reproject_from_healpix(fn_akari65, target_header)
img_akari65 = fix_nans(np.where(akari65[1].data == 0, np.nan, akari65[1].data))
header = akari65[1].header
plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(header),
                 #frame_class=EllipticalFrame,
                )
ax.imshow(img_akari65, norm=simple_norm(img_akari65, min_percent=1, max_percent=99.99, stretch='log'))
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
fn_akari90 = "akari_mollweide_WideS_1_4096.fits"
if not os.path.exists(fn_akari90):
    akari90 = download_file(f"https://lambda.gsfc.nasa.gov/data/foregrounds/akari/images/{fn_akari90}")
    shutil.move(akari90, fn_akari90)
akari90 = fits.open(fn_akari90)
#img_akari90, footprint = reproject_from_healpix(fn_akari90, target_header)
img_akari90 = fix_nans(np.where(akari90[1].data == 0, np.nan, akari90[1].data))
header = akari90[1].header
plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(header),
                 #frame_class=EllipticalFrame,
                )
ax.imshow(img_akari90, norm=simple_norm(img_akari90, min_percent=1, max_percent=99.99, stretch='log'))
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
fn_akari140 = "akari_mollweide_WideL_1_4096.fits"
if not os.path.exists(fn_akari140):
    akari140 = download_file(f"https://lambda.gsfc.nasa.gov/data/foregrounds/akari/images/{fn_akari140}")
    shutil.move(akari140, fn_akari140)
akari140 = fits.open(fn_akari140)
#img_akari140, footprint = reproject_from_healpix(fn_akari140, target_header)
img_akari140 = fix_nans(np.where(akari140[1].data == 0, np.nan, akari140[1].data))
header = akari140[1].header
plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(header),
                 #frame_class=EllipticalFrame,
                )
ax.imshow(img_akari140, norm=simple_norm(img_akari140, min_percent=1, max_percent=99.99, stretch='log'))
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
fn_akari160 = "akari_mollweide_160_1_4096.fits"
if not os.path.exists(fn_akari160):
    akari160 = download_file(f"https://lambda.gsfc.nasa.gov/data/foregrounds/akari/images/{fn_akari160}")
    shutil.move(akari160, fn_akari160)
akari160 = fits.open(fn_akari160)
#img_akari160, footprint = reproject_from_healpix(fn_akari160, target_header)
img_akari160 = fix_nans(np.where(akari160[1].data == 0, np.nan, akari160[1].data))
header = akari160[1].header
plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(header),
                 #frame_class=EllipticalFrame,
                )
ax.imshow(img_akari160, norm=simple_norm(img_akari160, min_percent=1, max_percent=99.99, stretch='log'))
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
#fn_chipass = "lambda_chipass_HPX_r10.fits"
fn_chipass = "lambda_chipass_mollweide.fits"
if not os.path.exists(fn_chipass):
    chipass = download_file(f"https://lambda.gsfc.nasa.gov/data/foregrounds/chipass/{fn_chipass}")
    shutil.move(chipass, fn_chipass)
chipass = fits.open(fn_chipass)
#img_chipass, footprint = reproject_from_healpix(fn_chipass, target_header)
img_chipass = chipass[1].data
img_chipass[img_chipass <= 0] = chipass[2].data[img_chipass <= 0]
img_chipass[img_chipass <= 0] = np.nan
header = chipass[1].header
plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(header),
                 #frame_class=EllipticalFrame,
                )
ax.imshow(img_chipass, norm=simple_norm(img_chipass, min_percent=1, max_percent=99.99, stretch='asinh'))
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
fn_sve1420 = "STOCKERT+VILLA-ELISA_1420MHz_1_256.fits"
if not os.path.exists(fn_sve1420):
    sve1420 = download_file(f"https://lambda.gsfc.nasa.gov/data/foregrounds/reich_reich/{fn_sve1420}")
    shutil.move(sve1420, fn_sve1420)
sve1420 = fits.open(fn_sve1420)
img_sve1420, footprint = reproject_from_healpix(fn_sve1420, target_header)
plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header),
                 frame_class=EllipticalFrame)
ax.imshow(img_sve1420, norm=simple_norm(img_sve1420, min_percent=1, max_percent=99.99, stretch='log'))
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
fn_lfi30 = 'LFI_SkyMap_030_1024_R2.01_full.fits'
if not os.path.exists(fn_lfi30):
    lfi30 = download_file(f"https://irsa.ipac.caltech.edu/data/Planck/release_2/all-sky-maps/maps/{fn_lfi30}")
    shutil.move(lfi30, fn_lfi30)
lfi30 = fits.open(fn_lfi30)
m30 = healpy.read_map(lfi30)
healpy.mollview(m30, norm=simple_norm(m30, stretch='log'), cbar=False, title='')
img_lfi30, footprint = reproject_from_healpix(fn_lfi_30, target_header)
badinds = np.where(np.isnan(img_lfi30))
img_lfi30 = fix_nans(img_lfi30)
plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header),
                 frame_class=EllipticalFrame)
ax.imshow(img_lfi30, norm=simple_norm(img_lfi30, min_percent=1, max_percent=99.99, stretch='log'))
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
fn_lfi30 = 'LFI_SkyMap_030_1024_R2.01_full.fits'
if not os.path.exists(fn_lfi30):
    lfi30 = download_file(f"https://irsa.ipac.caltech.edu/data/Planck/release_2/all-sky-maps/maps/{fn_lfi30}")
    shutil.move(lfi30, fn_lfi30)
lfi30 = fits.open(fn_lfi30)
m30 = healpy.read_map(lfi30)
healpy.mollview(m30, norm=simple_norm(m30, stretch='log'), cbar=False, title='')
img_lfi30, footprint = reproject_from_healpix(fn_lfi30, target_header)
badinds = np.where(np.isnan(img_lfi30))
img_lfi30 = fix_nans(img_lfi30)
plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header),
                 frame_class=EllipticalFrame)
ax.imshow(img_lfi30, norm=simple_norm(img_lfi30, min_percent=1, max_percent=99.99, stretch='log'))
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
fn_hfi143 = "HFI_SkyMap_143_2048_R2.02_full.fits"
if not os.path.exists(fn_hfi143):
    hfi143 = download_file(f"https://irsa.ipac.caltech.edu/data/Planck/release_2/all-sky-maps/maps/{fn_hfi143}")
    shutil.move(hfi143, fn_hfi143)
hfi143 = fits.open(fn_hfi143)
m143 = healpy.read_map(hfi143)
healpy.mollview(m143, norm=simple_norm(m143, stretch='log'), cbar=False, title='')
img_hfi143, footprint = reproject_from_healpix(fn_hfi143, target_header)
plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header),
                 frame_class=EllipticalFrame)
ax.imshow(img_hfi143, norm=simple_norm(img_hfi143, min_percent=1, max_percent=99.99, stretch='log'))
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
fn_hfi857 = "HFI_SkyMap_857_2048_R2.02_full.fits"
if not os.path.exists(fn_hfi857):
    hfi857 = download_file(f"https://irsa.ipac.caltech.edu/data/Planck/release_2/all-sky-maps/maps/{fn_hfi857}")
    shutil.move(hfi857, fn_hfi857)
hfi857 = fits.open(fn_hfi857)
m857 = healpy.read_map(hfi857)
healpy.mollview(m857, norm=simple_norm(m857, stretch='log'), cbar=False, title='')
img_hfi857, footprint = reproject_from_healpix(fn_hfi857, target_header)
plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header),
                 frame_class=EllipticalFrame)
ax.imshow(img_hfi857, norm=simple_norm(img_hfi857, min_percent=1, max_percent=99.99, stretch='log'))
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
rgb = np.array([simple_norm(img_lfi30,  min_percent=0.01, max_percent=99.90, log_a=5e1, stretch='log')(img_lfi30),
                simple_norm(img_hfi143, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_hfi143),
                simple_norm(img_hfi857, min_percent=0.01, max_percent=99.90, log_a=5e1, stretch='log')(img_hfi857)]).T.swapaxes(0,1)

make_rgb(rgb, 'Planck_RGB_30-143-857')
fn_synchrotron = "COM_CompMap_Synchrotron-commander_0256_R2.00.fits"
if not os.path.exists(fn_synchrotron):
    planck_synchrotron = download_file(f"https://irsa.ipac.caltech.edu/data/Planck/release_2/all-sky-maps/maps/component-maps/foregrounds/{fn_synchrotron}")
    shutil.move(planck_synchrotron, fn_synchrotron)
planck_synchrotron = fits.open(fn_synchrotron)
img_synchrotron, footprint = reproject_from_healpix(fn_synchrotron, target_header)
img_synchrotron = fix_nans(img_synchrotron)
plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header),
                 frame_class=EllipticalFrame)
ax.imshow(img_synchrotron, norm=simple_norm(img_synchrotron, min_percent=1, max_percent=99.99, stretch='log'))
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
fn_freefree = "COM_CompMap_freefree-commander_0256_R2.00.fits"
if not os.path.exists(fn_freefree):
    planck_freefree = download_file(f"https://irsa.ipac.caltech.edu/data/Planck/release_2/all-sky-maps/maps/component-maps/foregrounds/{fn_freefree}")
    shutil.move(planck_freefree, fn_freefree)
planck_freefree = fits.open(fn_freefree)
img_freefree, footprint = reproject_from_healpix(fn_freefree, target_header)
img_freefree = fix_nans(img_freefree)
plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header),
                 frame_class=EllipticalFrame)
ax.imshow(img_freefree, norm=simple_norm(img_freefree, min_percent=1, max_percent=99.99, stretch='log'))
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
fn_CO21 = "COM_CompMap_CO21-commander_2048_R2.00.fits"
if not os.path.exists(fn_CO21):
    planck_CO21 = download_file(f"https://irsa.ipac.caltech.edu/data/Planck/release_2/all-sky-maps/maps/component-maps/foregrounds/{fn_CO21}")
    shutil.move(planck_CO21, fn_CO21)
planck_CO21 = fits.open(fn_CO21)
img_CO21, footprint = reproject_from_healpix(fn_CO21, target_header)
img_CO21 = fix_nans(img_CO21)
plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header),
                 frame_class=EllipticalFrame)
ax.imshow(img_CO21, norm=simple_norm(img_CO21, min_percent=1, max_percent=99.99, stretch='log'))
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
fn_ThermalDust = "COM_CompMap_ThermalDust-commander_2048_R2.00.fits"
if not os.path.exists(fn_ThermalDust):
    planck_ThermalDust = download_file(f"https://irsa.ipac.caltech.edu/data/Planck/release_2/all-sky-maps/maps/component-maps/foregrounds/{fn_ThermalDust}")
    shutil.move(planck_ThermalDust, fn_ThermalDust)
planck_ThermalDust = fits.open(fn_ThermalDust)
mThermalDust = healpy.read_map(planck_ThermalDust)
healpy.mollview(mThermalDust, norm=simple_norm(mThermalDust, stretch='log'), cbar=False, title='')
img_ThermalDust, footprint = reproject_from_healpix(fn_ThermalDust, target_header)
plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header),
                 frame_class=EllipticalFrame)
ax.imshow(img_ThermalDust, norm=simple_norm(img_ThermalDust, min_percent=1, max_percent=99.99, stretch='log'))
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
fn_HI = 'LAB_fullvel.fits'
if not os.path.exists(fn_HI):
    LAB_HI = download_file(f"https://lambda.gsfc.nasa.gov/data/foregrounds/HI/{fn_HI}")
    shutil.move(LAB_HI, fn_HI)
LAB_HI = fits.open(fn_HI)
mLAB_HI = healpy.read_map(LAB_HI)
healpy.mollview(mLAB_HI, norm=simple_norm(mLAB_HI, stretch='asinh'), cbar=False, title='')
fn_HI4PI = 'NHI_HPX.fits'
if not os.path.exists(fn_HI4PI):
    HI4PI = download_file(f"https://lambda.gsfc.nasa.gov/data/foregrounds/HI4PI/{fn_HI4PI}")
    shutil.move(HI4PI, fn_HI4PI)
HI4PI = fits.open(fn_HI4PI)
mHI4PI = healpy.read_map(HI4PI, field=4)
healpy.mollview(mHI4PI, norm=simple_norm(mHI4PI, stretch='asinh'), cbar=False, title='')
healpy.cartview(mHI4PI, norm=simple_norm(mHI4PI, stretch='asinh'), cbar=False, title='',
                notext=True, lonra=[-20,20], latra=[-10,10])
img_HI4PI, footprint = reproject_from_healpix(fn_HI4PI, target_header, field=5)
plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header),
                 frame_class=EllipticalFrame)
ax.imshow(img_HI4PI, norm=simple_norm(img_HI4PI, min_percent=1, max_percent=99.99, stretch='log'))
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
rgb = np.array([simple_norm(img_HI4PI,       min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_HI4PI),
                simple_norm(img_CO21,        min_percent=0.01, max_percent=99.90, log_a=2e1, stretch='log')(img_CO21),
                simple_norm(img_ThermalDust, min_percent=0.01, max_percent=99.90, log_a=5e2, stretch='log')(img_ThermalDust)]).T.swapaxes(0,1)
make_rgb(rgb, 'HI-CO-Dust')
rgb = np.array([simple_norm(img_HI4PI,       min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_HI4PI),
                simple_norm(img_CO21,        min_percent=0.01, max_percent=99.90, log_a=2e1, stretch='log')(img_CO21),
                simple_norm(img_ThermalDust, min_percent=0.01, max_percent=99.90, log_a=5e2, stretch='log')(img_ThermalDust)]).T.swapaxes(0,1)
make_rgb(rgb, 'HI-CO-Dust_m0.25', -0.25, layernames=('HI', 'CO', 'Dust'))
# different colors, overwrites previous
rgb = np.array([simple_norm(img_HI4PI,       min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_HI4PI),
                simple_norm(img_CO21,        min_percent=0.01, max_percent=99.90, log_a=2e1, stretch='log')(img_CO21),
                simple_norm(img_ThermalDust, min_percent=0.01, max_percent=99.90, log_a=5e2, stretch='log')(img_ThermalDust)]).T.swapaxes(0,1)
make_rgb(rgb, 'HI-CO-Dust_m0.35', -0.35, layernames=('HI', 'CO', 'Dust'))
# zoom on lower-left corner
rgb = np.array([simple_norm(img_HI4PI,       min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_HI4PI),
                simple_norm(img_CO21,        min_percent=0.01, max_percent=99.90, log_a=2e1, stretch='log')(img_CO21),
                simple_norm(img_ThermalDust, min_percent=0.01, max_percent=99.90, log_a=5e2, stretch='log')(img_ThermalDust)]).T.swapaxes(0,1)
make_rgb(rgb, 'HI-CO-Dust_m0.35_zoom', -0.35, layernames=('HI', 'CO', 'Dust'),
         axlims=(240, 720, 120, 360), frame_class=None)
# CMZoom
rgb = np.array([simple_norm(img_HI4PI,       min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_HI4PI),
                simple_norm(img_CO21,        min_percent=0.01, max_percent=99.90, log_a=2e1, stretch='log')(img_CO21),
                simple_norm(img_ThermalDust, min_percent=0.01, max_percent=99.90, log_a=5e2, stretch='log')(img_ThermalDust)]).T.swapaxes(0,1)
make_rgb(rgb, 'HI-CO-Dust_m0.35_zoomCMZ', -0.35, layernames=('HI', 'CO', 'Dust'),
         axlims=(240*2, 720*2, 120*2, 360*2), frame_class=None)
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=5e1, stretch='log')(img_rosat5),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_synchrotron, min_percent=0.01, max_percent=99.99, log_a=5e1, stretch='log')(img_synchrotron)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_Synchro', layernames=('X-Ray', 'Halpha', 'Synchrotron'))
img_rosat5.shape, img_halpha.shape, img_synchrotron.shape
#[Out]# ((960, 1920), (4320, 8640), (960, 1920))
#img_halpha, footprint = reproject_from_healpix(fn_halpha, target_header)
# img_halpha = halpha[0].data
# header = halpha[0].header
img_halpha, footprint = reproject.reproject_interp(fn_halpha, target_header)
plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header),
                 frame_class=EllipticalFrame,
                )
ax.imshow(img_halpha, norm=simple_norm(img_halpha, min_percent=1, max_percent=99.99, stretch='log'))
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
import os
from astropy.utils.data import download_file
from astropy.io import fits
from spectral_cube import SpectralCube
from astropy.visualization import simple_norm
import shutil
import reproject
from reproject import reproject_from_healpix, reproject_to_healpix

from astropy.wcs import WCS
import matplotlib.pyplot as plt
from astropy.visualization.wcsaxes.frame import EllipticalFrame

from matplotlib.colors import rgb_to_hsv, hsv_to_rgb 

from astropy.convolution import convolve_fft, Gaussian2DKernel, Gaussian1DKernel
import healpy
# img_halpha = halpha[0].data
# header = halpha[0].header
img_halpha, footprint = reproject.reproject_interp(fn_halpha, target_header)
plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header),
                 frame_class=EllipticalFrame,
                )
ax.imshow(img_halpha, norm=simple_norm(img_halpha, min_percent=1, max_percent=99.99, stretch='log'))
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=5e1, stretch='log')(img_rosat5),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_synchrotron, min_percent=0.01, max_percent=99.99, log_a=5e1, stretch='log')(img_synchrotron)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_Synchro', layernames=('X-Ray', 'Halpha', 'Synchrotron'))
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=5e1, stretch='log')(img_rosat5),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_ThermalDust, min_percent=0.01, max_percent=99.99, log_a=5e1, stretch='log')(img_ThermalDust)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_Synchro', layernames=('X-Ray', 'Halpha', 'Synchrotron'))
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_rosat5),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_ThermalDust, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_ThermalDust)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_Synchro', layernames=('X-Ray', 'Halpha', 'Synchrotron'))
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_rosat5),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_synchrotron, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_synchrotron)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_Synchro', layernames=('X-Ray', 'Halpha', 'Synchrotron'))
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_rosat5),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_ThermalDust, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_ThermalDust)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_Synchro', layernames=('X-Ray', 'Halpha', 'ThermalDust'))
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_rosat5),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_ThermalDust, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_ThermalDust)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_ThermalDust', layernames=('X-Ray', 'Halpha', 'ThermalDust'))
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_rosat5),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_CO, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_CO)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_CO', layernames=('X-Ray', 'Halpha', 'CO'))
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_rosat5),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_freefree, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_freefree)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_freefree', layernames=('X-Ray', 'Halpha', 'freefree'))
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_rosat5),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_HI4PI, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_HI4PI)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_HI4PI', layernames=('X-Ray', 'Halpha', 'HI4PI'))
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_rosat5),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_CO21, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_CO21)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_CO21', layernames=('X-Ray', 'Halpha', 'CO21'))
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_rosat5),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_HI4PI, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_HI4PI)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_HI4PI', layernames=('X-Ray', 'Halpha', 'HI4PI'))
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=5e1, stretch='log')(img_rosat5),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_freefree, min_percent=0.01, max_percent=99.99, log_a=5e1, stretch='log')(img_freefree)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_freefree', layernames=('X-Ray', 'Halpha', 'freefree'))
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=5e1, stretch='log')(img_rosat5),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_CO21, min_percent=0.01, max_percent=99.99, log_a=5e1, stretch='log')(img_CO21)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_CO21', layernames=('X-Ray', 'Halpha', 'CO21'))
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=5e1, stretch='log')(img_rosat5),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_ThermalDust, min_percent=0.01, max_percent=99.99, log_a=5e1, stretch='log')(img_ThermalDust)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_ThermalDust', layernames=('X-Ray', 'Halpha', 'ThermalDust'))
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=5e1, stretch='log')(img_rosat5),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_synchrotron, min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_synchrotron)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_Synchro', layernames=('X-Ray', 'Halpha', 'Synchrotron'))
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=5e1, stretch='log')(img_rosat5),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_HI4PI, min_percent=0.01, max_percent=99.99, log_a=5e1, stretch='log')(img_HI4PI)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_HI4PI', layernames=('X-Ray', 'Halpha', 'HI4PI'))
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=1e2, stretch='log')(img_rosat5),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_freefree, min_percent=0.01, max_percent=99.99, log_a=1e2, stretch='log')(img_freefree)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_freefree', layernames=('X-Ray', 'Halpha', 'freefree'))
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=1e2, stretch='log')(img_rosat5),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_freefree, min_percent=0.01, max_percent=99.99, log_a=1e3, stretch='log')(img_freefree)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_freefree', layernames=('X-Ray', 'Halpha', 'freefree'))
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_rosat5),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_HI4PI, min_percent=0.01, max_percent=99.99, log_a=5e1, stretch='log')(img_HI4PI)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_HI4PI', layernames=('X-Ray', 'Halpha', 'HI4PI'))
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=2e2, stretch='log')(img_rosat5),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_HI4PI, min_percent=0.01, max_percent=99.99, log_a=2e2, stretch='log')(img_HI4PI)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_HI4PI', layernames=('X-Ray', 'Halpha', 'HI4PI'))
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=2e2, stretch='log')(img_rosat5),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_HI4PI, min_percent=0.01, max_percent=99.99, log_a=2e2, stretch='log')(img_HI4PI)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_HI4PI', layernames=('X-Ray', 'Halpha', 'HI4PI'), hsv_rotation=0.25)
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=2e2, stretch='log')(img_rosat5),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_HI4PI, min_percent=0.01, max_percent=99.99, log_a=2e2, stretch='log')(img_HI4PI)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_HI4PI', layernames=('X-Ray', 'Halpha', 'HI4PI'), hsv_rotation=-0.25)
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=2e2, stretch='log')(img_rosat5),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_HI4PI, min_percent=0.01, max_percent=99.99, log_a=2e2, stretch='log')(img_HI4PI)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_HI4PI', layernames=('X-Ray', 'Halpha', 'HI4PI'), hsv_rotation=-0.05)
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=2e2, stretch='log')(img_rosat5),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_HI4PI, min_percent=0.01, max_percent=99.99, log_a=2e2, stretch='log')(img_HI4PI)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_HI4PI', layernames=('X-Ray', 'Halpha', 'HI4PI'))
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=1e2, stretch='log')(img_rosat5),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_freefree, min_percent=0.01, max_percent=99.99, log_a=1e2, stretch='log')(img_freefree)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_freefree', layernames=('X-Ray', 'Halpha', 'freefree'), hsv_rotation=-0.25)
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_rosat5),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_freefree, min_percent=0.01, max_percent=99.99, log_a=1e2, stretch='log')(img_freefree)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_freefree', layernames=('X-Ray', 'Halpha', 'freefree'), hsv_rotation=-0.25)
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=5e1, stretch='log')(img_rosat5),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_CO21, min_percent=0.01, max_percent=99.99, log_a=5e1, stretch='log')(img_CO21)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_CO21', layernames=('X-Ray', 'Halpha', 'CO21'), hsv_rotation=-0.25)
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_rosat5),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_CO21, min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_CO21', layernames=('X-Ray', 'Halpha', 'CO21'), hsv_rotation=-0.25)
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=1e3, stretch='log')(img_rosat5),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_CO21, min_percent=0.01, max_percent=99.999, log_a=3e1, stretch='log')(img_CO21)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_CO21', layernames=('X-Ray', 'Halpha', 'CO21'), hsv_rotation=-0.25)
rgb = np.array([simple_norm(img_rosat5,  min_percent=0.01, max_percent=99.99, log_a=1e3, stretch='log')(img_rosat5),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_CO21, min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRay_Halpha_CO21', layernames=('X-Ray', 'Halpha', 'CO21'), hsv_rotation=-0.25)
xray_synchro = (simple_norm(img_rosat5,  min_percent=0.001, max_percent=99.999, log_a=1e3, stretch='linear')(img_rosat5) +
                simple_norm(img_synchrotron,  min_percent=0.001, max_percent=99.999, log_a=1e3, stretch='linear')(img_synchrotron))
rgb = np.array([simple_norm(xray_synchro,  min_percent=0.01, max_percent=99.99, log_a=1e3, stretch='log')(xray_synchro),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_CO21, min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRaySynchro_Halpha_CO21', layernames=('X-RaySynchro', 'Halpha', 'CO21'), hsv_rotation=-0.25)
xray_synchro = (simple_norm(img_rosat5,  min_percent=0.001, max_percent=99.999, stretch='linear')(img_rosat5) +
                simple_norm(img_synchrotron,  min_percent=0.001, max_percent=99.999, stretch='linear')(img_synchrotron))
rgb = np.array([simple_norm(xray_synchro,  min_percent=0.01, max_percent=99.99, log_a=1e2, stretch='log')(xray_synchro),
                simple_norm(img_halpha, min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_halpha),
                simple_norm(img_CO21, min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21)]).T.swapaxes(0,1)

make_rgb(rgb, 'XRaySynchro_Halpha_CO21', layernames=('X-RaySynchro', 'Halpha', 'CO21'), hsv_rotation=-0.25)
target_header_cmz = fits.Header.fromstring("""
NAXIS   =                    2
NAXIS1  =                 1920
NAXIS2  =                  960
CTYPE1  = 'GLON-MOL'
CRPIX1  =                960.5
CRVAL1  =                  0.0
CDELT1  =                -0.05
CUNIT1  = 'deg     '
CTYPE2  = 'GLAT-MOL'
CRPIX2  =                480.5
CRVAL2  =                  0.0
CDELT2  =                 0.05
CUNIT2  = 'deg     '
COORDSYS= 'icrs    '
""", sep='\n')
img_HI4PI_cmz, footprint = reproject_from_healpix(fn_HI4PI, target_header_cmz, field=5)
img_ThermalDust_cmz, footprint = reproject_from_healpix(fn_ThermalDust, target_header_cmz)
img_CO21_cmz, footprint = reproject_from_healpix(fn_CO21, target_header_cmz)
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)
#[Out]# (240.0, 720.0)
from astropy import units as u
hi_cube_fn = '/orange/adamginsburg/cmz/hi/mcluregriffiths/GC.hi.tb.allgal.fits'
#if os.path.exists("GC.hi.tb.allgal.fits.gz"):
#    hi_cube_fh = fits.open("GC.hi.tb.allgal.fits.gz")
#else:
#    print("Not downloaded.")
#    #hi_cube_fh = download_file("http://www.atnf.csiro.au/research/HI/sgps/SGPS_1/GC.hi.tb.allgal.fits.gz")
hi_cube = SpectralCube.read(hi_cube_fn, use_dask=True)
peak_hi = hi_cube.max(axis=0)
mean_hi = hi_cube.mean(axis=0)
pl.imshow(peak_hi.value)
#[Out]# <matplotlib.image.AxesImage at 0x2b2940c04940>
pl.imshow(mean_hi.value, vmin=0)
#[Out]# <matplotlib.image.AxesImage at 0x2b2942cea580>
if os.path.exists("DHT02_Center_interp.fits"):
    cube_dame12co = SpectralCube.read('DHT02_Center_interp.fits', use_dask=True)
else:
    pass
peak_dameco = cube_dame12co.max(axis=0)
mean_dameco = cube_dame12co.mean(axis=0)
if os.path.exists('GalacticCenterMosaic_downsampled4x_2kms.fits'):
    co_cube = SpectralCube.read('GalacticCenterMosaic_downsampled4x_2kms.fits', use_dask=True)
peak_co = co_cube.max(axis=0)
mean_co = co_cube.mean(axis=0)
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(mean_hi.value, vmin=0, transform=ax.get_transform(hi_cube.wcs.celestial),
          cmap='gray')
#[Out]# <matplotlib.image.AxesImage at 0x2b2942c35ca0>
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(mean_dameco.value, vmin=0, transform=ax.get_transform(cube_dame12co.wcs.celestial),
          cmap='gray')
#[Out]# <matplotlib.image.AxesImage at 0x2b294052f070>
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(peak_co.value,
          norm=simple_norm(peak_co.value, min_percent=0.1, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(co_cube.wcs.celestial),
          cmap='gray')
#[Out]# <matplotlib.image.AxesImage at 0x2b2940a072e0>
atlasgal = fits.open('/orange/adamginsburg/galactic_plane_surveys/atlasgal/MOSAICS/apex_planck.fits')
print(atlasgal[0].data.shape)
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=0.1, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap='gray')
#[Out]# <matplotlib.image.AxesImage at 0x2b29438db5e0>
fn_meerkat = 'MeerKAT_Galactic_Centre_1284MHz-StokesI.fits'
if os.path.exists(fn_meerkat):
    meerkat = download_file(f"https://archive-gw-1.kat.ac.za/public/repository/10.48479/fyst-hj47/data/{fn_meerkat}")
    shutil.move(meerkat, fn_meerkat)
meerkat = fits.open(fn_meerkat)
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(meerkat[0].data,
          norm=simple_norm(meerkat[0].data, min_percent=0.1, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(meerkat[0].header)),
          cmap='gray')
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(meerkat[0].data.squeeze(),
          norm=simple_norm(meerkat[0].data, min_percent=0.1, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(meerkat[0].header).celestial),
          cmap='gray')
#[Out]# <matplotlib.image.AxesImage at 0x2b2943947550>
pl.imshow(meerkat[0].data)
#[Out]# <matplotlib.image.AxesImage at 0x2b2943fa7a60>
ax.imshow(meerkat[0].data.squeeze(),
          norm=simple_norm(meerkat[0].data, min_percent=0.1, max_percent=99.9, stretch='asinh'),
          #transform=ax.get_transform(WCS(meerkat[0].header).celestial),
          cmap='gray')
#[Out]# <matplotlib.image.AxesImage at 0x2b295509c670>
pl.imshow(meerkat[0].data.squeeze(),
          norm=simple_norm(meerkat[0].data, min_percent=0.1, max_percent=99.9, stretch='asinh'),
          #transform=ax.get_transform(WCS(meerkat[0].header).celestial),
          cmap='gray')
#[Out]# <matplotlib.image.AxesImage at 0x2b29550d3910>
pl.imshow(meerkat[0].data.squeeze(),
          norm=simple_norm(meerkat[0].data, min_percent=0.1, max_percent=99.9, stretch='asinh'),
          #transform=ax.get_transform(WCS(meerkat[0].header).celestial),
          cmap='gray')
#[Out]# <matplotlib.image.AxesImage at 0x2b295512a160>
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(meerkat[0].data.squeeze(),
          norm=simple_norm(meerkat[0].data, min_percent=0.1, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(meerkat[0].header).celestial),
          cmap='gray')
#[Out]# <matplotlib.image.AxesImage at 0x2b2957bec100>
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(meerkat[0].data.squeeze(),
          norm=simple_norm(meerkat[0].data, min_percent=0.1, max_percent=99.9, stretch='log'),
          transform=ax.get_transform(WCS(meerkat[0].header).celestial),
          cmap='gray')
#[Out]# <matplotlib.image.AxesImage at 0x2b2957c76100>
meerkat[0].data.shape
#[Out]# (10527, 10121)
meerkat[0].data[0,0]
#[Out]# nan
meerkat[0].header
#[Out]# SIMPLE  =                    T                                                  
#[Out]# BITPIX  =                  -64                                                  
#[Out]# NAXIS   =                    2                                                  
#[Out]# NAXIS1  =                10121                                                  
#[Out]# NAXIS2  =                10527                                                  
#[Out]# EXTEND  =                    T / FITS dataset may contain extensions            
#[Out]# COMMENT   FITS (Flexible Image Transport System) format is defined in 'Astronomy
#[Out]# COMMENT   and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H 
#[Out]# COMMENT   -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-                           
#[Out]# COMMENT   MeerKAT Galactic Centre Survey                                        
#[Out]# COMMENT   South African Radio Astronomy Observatory                             
#[Out]# COMMENT   Total intensity mosaic                                                
#[Out]# COMMENT   Contact: ian.heywood@physics.ox.ac.uk                                 
#[Out]# COMMENT   -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-                           
#[Out]# CTYPE1  = 'RA---TAN'                                                            
#[Out]# CTYPE2  = 'DEC--TAN'                                                            
#[Out]# EQUINOX =                 2000                                                  
#[Out]# CRVAL1  =        266.366790598                                                  
#[Out]# CRVAL2  =       -29.2213778092                                                  
#[Out]# CRPIX1  =               5072.5                                                  
#[Out]# CRPIX2  =               5265.5                                                  
#[Out]# CDELT1  =         -0.000305556                                                  
#[Out]# CDELT2  =          0.000305556                                                  
#[Out]# CTYPE3  = 'FREQ    '                                                            
#[Out]# CRPIX3  =                  1.0                                                  
#[Out]# CRVAL3  =      1283895507.8125                                                  
#[Out]# CDELT3  =          856000000.0                                                  
#[Out]# CUNIT3  = 'Hz      '                                                            
#[Out]# CTYPE4  = 'STOKES  '                                                            
#[Out]# CRPIX4  =                  1.0                                                  
#[Out]# CRVAL4  =                  1.0                                                  
#[Out]# CDELT4  =                  1.0                                                  
#[Out]# CUNIT4  = ''                                                                    
#[Out]# BMAJ    = 0.001111111111111111                                                  
#[Out]# BMIN    = 0.001111111111111111                                                  
#[Out]# BPA     =                  0.0                                                  
#[Out]# TELESCOP= 'MeerKAT '                                                            
#[Out]# BUNIT   = 'JY/BEAM '                                                            
plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(meerkat[0].data.squeeze(),
          norm=simple_norm(meerkat[0].data, min_percent=0.1, max_percent=99.9, stretch='log'),
          transform=ax.get_transform(WCS(meerkat[0].header).celestial),
          cmap='gray')
#[Out]# <matplotlib.image.AxesImage at 0x2b2943f883d0>
plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.set_xlim(840, 1080)
ax.set_ylim(360, 600)

ax.imshow(meerkat[0].data.squeeze(),
          norm=simple_norm(meerkat[0].data, min_percent=0.1, max_percent=99.9, stretch='log'),
          transform=ax.get_transform(WCS(meerkat[0].header).celestial),
          cmap='gray')
#[Out]# <matplotlib.image.AxesImage at 0x2b2957d354f0>
import platform; print(platform.platform())
import sys; print("Python", sys.version)
import astropy; print("astropy", astropy.__version__)
import numpy; print("Numpy", numpy.__version__)
import erfa; print("pyerfa", erfa.__version__)
import scipy; print("Scipy", scipy.__version__)
import matplotlib; print("Matplotlib", matplotlib.__version__)
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

from matplotlib.colors import ListedColormap
cmap = pl.cm.gray
my_cmap = cmap(np.arange(cmap.N))
my_cmap[:,-1] = np.linspace(0, 1, cmap.N)
my_cmap = ListedColormap(my_cmap)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=0.1, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=my_cmap)
#[Out]# <matplotlib.image.AxesImage at 0x2b2957dbc280>
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

from matplotlib.colors import ListedColormap
cmap = pl.cm.gray
my_cmap = cmap(np.arange(cmap.N))
my_cmap[:,-1] = np.linspace(0, 1, cmap.N)
my_cmap = ListedColormap(my_cmap)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=1, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=my_cmap)
#[Out]# <matplotlib.image.AxesImage at 0x2b2957de7340>
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

from matplotlib.colors import ListedColormap
cmap = pl.cm.gray
my_cmap = cmap(np.arange(cmap.N))
my_cmap[:,-1] = np.linspace(0, 1, cmap.N)
my_cmap = ListedColormap(my_cmap)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=5, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=my_cmap)
#[Out]# <matplotlib.image.AxesImage at 0x2b294058de80>
from matplotlib.colors import ListedColormap
cmap = pl.cm.gray
gray_transparent = cmap(np.arange(cmap.N))
gray_transparent[:,-1] = np.linspace(0, 1, cmap.N)
gray_transparent = ListedColormap(gray_transparent)
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(mean_hi.value, vmin=0, transform=ax.get_transform(hi_cube.wcs.celestial),
          cmap=gray_transparent)
#[Out]# <matplotlib.image.AxesImage at 0x2b294083fc40>
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(mean_dameco.value, vmin=0, transform=ax.get_transform(cube_dame12co.wcs.celestial),
          cmap=gray_transparent)
#[Out]# <matplotlib.image.AxesImage at 0x2b29409a40d0>
from matplotlib.colors import ListedColormap
cmap = pl.cm.gray
gray_transparent = cmap(np.arange(cmap.N))
gray_transparent[:,-1] = np.linspace(0, 1, cmap.N)
gray_transparent = ListedColormap(gray_transparent)
cmap = pl.cm.Oranges
orange_transparent = cmap(np.arange(cmap.N))
orange_transparent[:,-1] = np.linspace(0, 1, cmap.N)
orange_transparent = ListedColormap(orange_transparent)
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(mean_hi.value, vmin=0, transform=ax.get_transform(hi_cube.wcs.celestial),
          cmap=orange_transparent)
#[Out]# <matplotlib.image.AxesImage at 0x2b29438f04c0>
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(mean_dameco.value, vmin=0, transform=ax.get_transform(cube_dame12co.wcs.celestial),
          cmap=orange_transparent)
#[Out]# <matplotlib.image.AxesImage at 0x2b29527118e0>
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(peak_co.value,
          norm=simple_norm(peak_co.value, min_percent=0.1, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(co_cube.wcs.celestial),
          cmap=orange_transparent)
#[Out]# <matplotlib.image.AxesImage at 0x2b29527c3ca0>
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=5, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=orange_transparent)
#[Out]# <matplotlib.image.AxesImage at 0x2b295286f730>
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(mean_hi.value,
          transform=ax.get_transform(hi_cube.wcs.celestial),
          norm=simple_norm(mean_hi.value, min_percent=2, max_percent=99.9, stretch='asinh'),
          cmap=orange_transparent)
#[Out]# <matplotlib.image.AxesImage at 0x2b29528ddee0>
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(mean_dameco.value,
          norm=simple_norm(mean_dameco.value, min_percent=2, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(cube_dame12co.wcs.celestial),
          cmap=orange_transparent)
#[Out]# <matplotlib.image.AxesImage at 0x2b295291a220>
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(peak_co.value,
          norm=simple_norm(peak_co.value, min_percent=0.1, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(co_cube.wcs.celestial),
          cmap=orange_transparent)

pl.savefig("HI4PI_CO_Dust_withJCMTCOOrange.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=5, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=gray_transparent)
pl.savefig("HI4PI_CO_Dust_withATLASGALtransparent.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=0.1, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap='gray')

pl.savefig("HI4PI_CO_Dust_withATLASGAL.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=5, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=orange_transparent)
pl.savefig("HI4PI_CO_Dust_withATLASGALOrangetransparent.png", bbox_inches='tight')
from astroquery.vizier import Vizier
from astropy.coordinates import SkyCoord
almaimf_cat = Vizier.get_catalogs('J/A+A/662/A9/objects')[0]
almaimf_crds = SkyCoord(almaimf_cat['RAJ2000'], almaimf_cat['DEJ2000'], frame='fk5', unit=(u.h, u.deg))
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=5, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=orange_transparent)


ax.scatter(crds.galactic.l, crds.galactic.b, marker='*', color='y', transform=ax.get_transform('galactic'))

pl.savefig("HI4PI_CO_Dust_withATLASGALOrangetransparent_ALMA-IMFtargets.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=5, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=orange_transparent)


ax.scatter(almaimf_crds.galactic.l, almaimf_crds.galactic.b, marker='*', color='y', transform=ax.get_transform('galactic'))

pl.savefig("HI4PI_CO_Dust_withATLASGALOrangetransparent_ALMA-IMFtargets.png", bbox_inches='tight')
fn_meerkat = 'MeerKAT_Galactic_Centre_1284MHz-StokesI.fits'
if os.path.exists(fn_meerkat):
    meerkat = download_file(f"https://archive-gw-1.kat.ac.za/public/repository/10.48479/fyst-hj47/data/{fn_meerkat}")
    shutil.move(meerkat, fn_meerkat)
meerkat = fits.open(fn_meerkat)
get_ipython().run_line_magic('ls', 'MeerKAT_Galactic_Centre_1284MHz-StokesI.fits')
os.path.exists(fn_meerkat)
#[Out]# True
fn_meerkat = 'MeerKAT_Galactic_Centre_1284MHz-StokesI.fits'
if not os.path.exists(fn_meerkat):
    meerkat = download_file(f"https://archive-gw-1.kat.ac.za/public/repository/10.48479/fyst-hj47/data/{fn_meerkat}")
    shutil.move(meerkat, fn_meerkat)
meerkat = fits.open(fn_meerkat)
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(meerkat[0].data.squeeze(),
          norm=simple_norm(meerkat[0].data, min_percent=0.1, max_percent=99.9, stretch='log'),
          transform=ax.get_transform(WCS(meerkat[0].header).celestial),
          cmap='gray')
#[Out]# <matplotlib.image.AxesImage at 0x2b2953b9b910>
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=5, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=orange_transparent)


ax.scatter(almaimf_crds.galactic.l, almaimf_crds.galactic.b,
           marker='*', edgecolor='r', facecolor='none', transform=ax.get_transform('galactic'))

pl.savefig("HI4PI_CO_Dust_withATLASGALOrangetransparent_ALMA-IMFtargets.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=5, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=orange_transparent)


ax.scatter(almaimf_crds.galactic.l, almaimf_crds.galactic.b,
           marker='*', edgecolor='purple', facecolor='none', transform=ax.get_transform('galactic'))

pl.savefig("HI4PI_CO_Dust_withATLASGALOrangetransparent_ALMA-IMFtargets.png", bbox_inches='tight')
almaimf_crds.galactic
#[Out]# <SkyCoord (Galactic): (l, b) in deg
#[Out]#     [(  8.67729191, -0.36089691), ( 10.62407462, -0.38390327),
#[Out]#      ( 12.80353831, -0.19975152), (327.29175337, -0.57877471),
#[Out]#      (328.25460991, -0.53160715), (333.60380934, -0.21226415),
#[Out]#      (337.91603971, -0.47685304), (338.92557145,  0.55388661),
#[Out]#      (351.77401332, -0.53754291), (353.40854551, -0.36188772),
#[Out]#      ( 30.81827316, -0.0569235 ), ( 30.70344994, -0.06749385),
#[Out]#      ( 30.71790746, -0.0825418 ), ( 49.48885297, -0.38916025),
#[Out]#      ( 49.48941224, -0.36905059)]>
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=0.1, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap='gray')

pl.savefig("HI4PI_CO_Dust_withATLASGAL.png", bbox_inches='tight')
target_header_innergal = fits.Header.fromstring("""
NAXIS   =                    2
NAXIS1  =                 3840
NAXIS2  =                  960
CTYPE1  = 'GLON-MOL'
CRPIX1  =               1920.5
CRVAL1  =                  0.0
CDELT1  =                -0.05
CUNIT1  = 'deg     '
CTYPE2  = 'GLAT-MOL'
CRPIX2  =                480.5
CRVAL2  =                  0.0
CDELT2  =                 0.05
CUNIT2  = 'deg     '
COORDSYS= 'icrs    '
""", sep='\n')
img_HI4PI_innergal, footprint = reproject_from_healpix(fn_HI4PI, target_header_innergal, field=5)
img_ThermalDust_innergal, footprint = reproject_from_healpix(fn_ThermalDust, target_header_innergal)
img_CO21_innergal, footprint = reproject_from_healpix(fn_CO21, target_header_innergal)
rgb = np.array([simple_norm(img_HI4PI_innergal,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_innergal),
                simple_norm(img_CO21_innergal,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_innergal),
                simple_norm(img_ThermalDust_innergal, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_innergal)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_innergal),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=5, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=orange_transparent)

pl.savefig("HI4PI_CO_Dust_innergal_withATLASGALOrangetransparent.png", bbox_inches='tight')

ax.scatter(almaimf_crds.galactic.l, almaimf_crds.galactic.b,
           marker='*', edgecolor='purple', facecolor='none', transform=ax.get_transform('galactic'))

pl.savefig("HI4PI_CO_Dust_innergal_withATLASGALOrangetransparent_ALMA-IMFtargets.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_HI4PI_innergal,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_innergal),
                simple_norm(img_CO21_innergal,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_innergal),
                simple_norm(img_ThermalDust_innergal, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_innergal)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_innergal),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
#ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=5, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=orange_transparent)

pl.savefig("HI4PI_CO_Dust_innergal_withATLASGALOrangetransparent.png", bbox_inches='tight')

ax.scatter(almaimf_crds.galactic.l, almaimf_crds.galactic.b,
           marker='*', edgecolor='purple', facecolor='none', transform=ax.get_transform('galactic'))

pl.savefig("HI4PI_CO_Dust_innergal_withATLASGALOrangetransparent_ALMA-IMFtargets.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_HI4PI_innergal,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_innergal),
                simple_norm(img_CO21_innergal,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_innergal),
                simple_norm(img_ThermalDust_innergal, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_innergal)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_innergal),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(0, 3840)
ax.set_ylim(120*2, 360*2)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=5, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=orange_transparent)

pl.savefig("HI4PI_CO_Dust_innergal_withATLASGALOrangetransparent.png", bbox_inches='tight')

ax.scatter(almaimf_crds.galactic.l, almaimf_crds.galactic.b,
           marker='*', edgecolor='purple', facecolor='none', transform=ax.get_transform('galactic'))

pl.savefig("HI4PI_CO_Dust_innergal_withATLASGALOrangetransparent_ALMA-IMFtargets.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_HI4PI_innergal,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_innergal),
                simple_norm(img_CO21_innergal,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_innergal),
                simple_norm(img_ThermalDust_innergal, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_innergal)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_innergal),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(540, 3840-540)
ax.set_ylim(0, 960)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=5, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=orange_transparent)

pl.savefig("HI4PI_CO_Dust_innergal_withATLASGALOrangetransparent.png", bbox_inches='tight')

ax.scatter(almaimf_crds.galactic.l, almaimf_crds.galactic.b,
           marker='*', edgecolor='purple', facecolor='none', transform=ax.get_transform('galactic'))

pl.savefig("HI4PI_CO_Dust_innergal_withATLASGALOrangetransparent_ALMA-IMFtargets.png", bbox_inches='tight')
def h_rot(rgb, rot):
    hsv = rgb_to_hsv(rgb)
    hsv[:,:,0] += rot  # 0.25 = 90/360
    hsv[:,:,0] = hsv[:,:,0] % 1 
    rgb_scaled = hsv_to_rgb(hsv)
    return rgb_scaled

def make_rgb(rgb, basename, hsv_rotation=0, layernames='RGB',
             axlims=None, frame_class=EllipticalFrame):
    plt.figure(figsize=(10,5), dpi=200)
    ax = plt.subplot(1,1,1, projection=WCS(target_header),
                     frame_class=frame_class)
    #ax.coords.grid(color='white')
    ax.coords['glat'].set_ticklabel(visible=False)
    ax.coords['glon'].set_ticklabel(visible=False)
    ax.coords['glat'].set_ticks_visible(False)
    ax.coords['glon'].set_ticks_visible(False)
    for ind, color in zip((0, 1, 2), (layernames)):
        rgbc = np.zeros_like(rgb)
        rgbc[:, :, ind] = rgb[:, :, ind]
        if hsv_rotation != 0:
            rgbc = h_rot(rgbc, hsv_rotation)
        ax.imshow(rgbc)
        pl.savefig(f'{basename}_{color}.png', bbox_inches='tight', transparent=True)
    if hsv_rotation != 0:
        rgb = h_rot(rgb, hsv_rotation)
    ax.imshow(rgb)
    if axlims is not None:
        ax.axis(axlims)
    pl.savefig(f'{basename}_RGB.png', bbox_inches='tight', transparent=True)
    return ax
# different colors, overwrites previous
rgb = np.array([simple_norm(img_HI4PI,       min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_HI4PI),
                simple_norm(img_CO21,        min_percent=0.01, max_percent=99.90, log_a=2e1, stretch='log')(img_CO21),
                simple_norm(img_ThermalDust, min_percent=0.01, max_percent=99.90, log_a=5e2, stretch='log')(img_ThermalDust)]).T.swapaxes(0,1)
make_rgb(rgb, 'HI-CO-Dust_m0.35', -0.35, layernames=('HI', 'CO', 'Dust'))
rect = pl.Rectangle(0, 0,
             width=(3840-1080)*target_header_innergal['CDELT1'],
             height=960*target_header_innergal['CDELT2'],
             transform=pl.gca().get_transform('galactic'))
ax.add_artist(rect)
rect = pl.Rectangle((0, 0),
             width=(3840-1080)*target_header_innergal['CDELT1'],
             height=960*target_header_innergal['CDELT2'],
             transform=pl.gca().get_transform('galactic'))
ax.add_artist(rect)
rect = pl.Rectangle((0, 0),
             width=(3840-1080)*target_header_innergal['CDELT1'],
             height=960*target_header_innergal['CDELT2'],
             transform=ax.get_transform('galactic'))
ax.add_artist(rect)
#[Out]# <matplotlib.patches.Rectangle at 0x2b2954297730>
# different colors, overwrites previous
rgb = np.array([simple_norm(img_HI4PI,       min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_HI4PI),
                simple_norm(img_CO21,        min_percent=0.01, max_percent=99.90, log_a=2e1, stretch='log')(img_CO21),
                simple_norm(img_ThermalDust, min_percent=0.01, max_percent=99.90, log_a=5e2, stretch='log')(img_ThermalDust)]).T.swapaxes(0,1)
ax = make_rgb(rgb, 'HI-CO-Dust_m0.35', -0.35, layernames=('HI', 'CO', 'Dust'))
rect = pl.Rectangle((0, 0),
             width=(3840-1080)*target_header_innergal['CDELT1'],
             height=960*target_header_innergal['CDELT2'],
             transform=pl.gca().get_transform('galactic'))
ax.add_artist(rect)
#[Out]# <matplotlib.patches.Rectangle at 0x2b2954184040>
# different colors, overwrites previous
rgb = np.array([simple_norm(img_HI4PI,       min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_HI4PI),
                simple_norm(img_CO21,        min_percent=0.01, max_percent=99.90, log_a=2e1, stretch='log')(img_CO21),
                simple_norm(img_ThermalDust, min_percent=0.01, max_percent=99.90, log_a=5e2, stretch='log')(img_ThermalDust)]).T.swapaxes(0,1)
ax = make_rgb(rgb, 'HI-CO-Dust_m0.35', -0.35, layernames=('HI', 'CO', 'Dust'))
rect = pl.Rectangle(((3840-1080)*target_header_innergal['CDELT1']/2,
                     960*target_header_innergal['CDELT2']/2),
             width=(3840-1080)*target_header_innergal['CDELT1'],
             height=960*target_header_innergal['CDELT2'],
                    facecolor='none',
                    edgecolor='white',
             transform=pl.gca().get_transform('galactic'))
ax.add_artist(rect)

pl.savefig("HI-CO-Dust_m0.35_RGB_innergal_zoombox.png", bbox_inches='tight')
# different colors, overwrites previous
rgb = np.array([simple_norm(img_HI4PI,       min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_HI4PI),
                simple_norm(img_CO21,        min_percent=0.01, max_percent=99.90, log_a=2e1, stretch='log')(img_CO21),
                simple_norm(img_ThermalDust, min_percent=0.01, max_percent=99.90, log_a=5e2, stretch='log')(img_ThermalDust)]).T.swapaxes(0,1)
ax = make_rgb(rgb, 'HI-CO-Dust_m0.35', -0.35, layernames=('HI', 'CO', 'Dust'))
rect = pl.Rectangle(((3840-1080)*target_header_innergal['CDELT1']/2,
                     -960*target_header_innergal['CDELT2']/2),
             width=(3840-1080)*target_header_innergal['CDELT1'],
             height=960*target_header_innergal['CDELT2'],
                    facecolor='none',
                    edgecolor='white',
             transform=pl.gca().get_transform('galactic'))
ax.add_artist(rect)

pl.savefig("HI-CO-Dust_m0.35_RGB_innergal_zoombox.png", bbox_inches='tight')
# different colors, overwrites previous
rgb = np.array([simple_norm(img_HI4PI,       min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_HI4PI),
                simple_norm(img_CO21,        min_percent=0.01, max_percent=99.90, log_a=2e1, stretch='log')(img_CO21),
                simple_norm(img_ThermalDust, min_percent=0.01, max_percent=99.90, log_a=5e2, stretch='log')(img_ThermalDust)]).T.swapaxes(0,1)
ax = make_rgb(rgb, 'HI-CO-Dust_m0.35', -0.35, layernames=('HI', 'CO', 'Dust'))
rect = pl.Rectangle((1080*target_header_innergal['CDELT1'],
                     -960*target_header_innergal['CDELT2']/2),
             width=(3840-1080)*target_header_innergal['CDELT1'],
             height=960*target_header_innergal['CDELT2'],
                    facecolor='none',
                    edgecolor='white',
             transform=pl.gca().get_transform('galactic'))
ax.add_artist(rect)

pl.savefig("HI-CO-Dust_m0.35_RGB_innergal_zoombox.png", bbox_inches='tight')
# different colors, overwrites previous
rgb = np.array([simple_norm(img_HI4PI,       min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_HI4PI),
                simple_norm(img_CO21,        min_percent=0.01, max_percent=99.90, log_a=2e1, stretch='log')(img_CO21),
                simple_norm(img_ThermalDust, min_percent=0.01, max_percent=99.90, log_a=5e2, stretch='log')(img_ThermalDust)]).T.swapaxes(0,1)
ax = make_rgb(rgb, 'HI-CO-Dust_m0.35', -0.35, layernames=('HI', 'CO', 'Dust'))
rect = pl.Rectangle((-1080*target_header_innergal['CDELT1'],
                     -960*target_header_innergal['CDELT2']/2),
             width=(3840-1080)*target_header_innergal['CDELT1'],
             height=960*target_header_innergal['CDELT2'],
                    facecolor='none',
                    edgecolor='white',
             transform=pl.gca().get_transform('galactic'))
ax.add_artist(rect)

pl.savefig("HI-CO-Dust_m0.35_RGB_innergal_zoombox.png", bbox_inches='tight')
# different colors, overwrites previous
rgb = np.array([simple_norm(img_HI4PI,       min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_HI4PI),
                simple_norm(img_CO21,        min_percent=0.01, max_percent=99.90, log_a=2e1, stretch='log')(img_CO21),
                simple_norm(img_ThermalDust, min_percent=0.01, max_percent=99.90, log_a=5e2, stretch='log')(img_ThermalDust)]).T.swapaxes(0,1)
ax = make_rgb(rgb, 'HI-CO-Dust_m0.35', -0.35, layernames=('HI', 'CO', 'Dust'))
rect = pl.Rectangle((-720*target_header_innergal['CDELT1'],
                     -960*target_header_innergal['CDELT2']/2),
             width=(3840-1080)*target_header_innergal['CDELT1'],
             height=960*target_header_innergal['CDELT2'],
                    facecolor='none',
                    edgecolor='white',
             transform=pl.gca().get_transform('galactic'))
ax.add_artist(rect)

pl.savefig("HI-CO-Dust_m0.35_RGB_innergal_zoombox.png", bbox_inches='tight')
ax.bbox
#[Out]# <matplotlib.transforms.TransformedBbox at 0x2b29542af3a0>
ax.bbox.bbox
ax.bbox.bounds
#[Out]# (270.0, 125.0, 1510.0, 755.0)
ax.get_xlim()
#[Out]# (-0.5, 1919.5)
ax.get_xlim()
np.diff(ax.get_xlim())*target_header_innergal['CDELT1']
#[Out]# array([-96.])
import regions
rect = regions.RectangleSkyRegion(coordinates.SkyCoord(0*u.deg, 0*u.deg, frame='galactic'),
             width=(ax.get_xlim()[1] - ax.get_xlim()[0])*target_header_innergal['CDELT1'],
             height=(ax.get_ylim()[1] - ax.get_ylim()[0])*target_header_innergal['CDELT2'],
                                 )
import regions
rect = regions.RectangleSkyRegion(
    coordinates.SkyCoord(0*u.deg, 0*u.deg, frame='galactic'),
    width=(ax.get_xlim()[1] - ax.get_xlim()[0])*target_header_innergal['CDELT1'],
    height=(ax.get_ylim()[1] - ax.get_ylim()[0])*target_header_innergal['CDELT2'],
)
rect
import regions
from astropy import coordinates
rect = regions.RectangleSkyRegion(
    coordinates.SkyCoord(0*u.deg, 0*u.deg, frame='galactic'),
    width=(ax.get_xlim()[1] - ax.get_xlim()[0])*target_header_innergal['CDELT1'],
    height=(ax.get_ylim()[1] - ax.get_ylim()[0])*target_header_innergal['CDELT2'],
)
rect
import regions
from astropy import coordinates
rect = regions.RectangleSkyRegion(
    coordinates.SkyCoord(0*u.deg, 0*u.deg, frame='galactic'),
    width=(ax.get_xlim()[1] - ax.get_xlim()[0])*target_header_innergal['CDELT1']*u.deg,
    height=(ax.get_ylim()[1] - ax.get_ylim()[0])*target_header_innergal['CDELT2']*u.deg,
)
rect
import regions
from astropy import coordinates
rect = regions.RectangleSkyRegion(
    coordinates.SkyCoord(0*u.deg, 0*u.deg, frame='galactic'),
    width=np.abs((ax.get_xlim()[1] - ax.get_xlim()[0])*target_header_innergal['CDELT1'])*u.deg,
    height=(ax.get_ylim()[1] - ax.get_ylim()[0])*target_header_innergal['CDELT2']*u.deg,
)
rect
#[Out]# <RectangleSkyRegion(center=<SkyCoord (Galactic): (l, b) in deg
#[Out]#     (0., 0.)>, width=96.0 deg, height=48.0 deg, angle=0.0 deg)>
rgb = np.array([simple_norm(img_HI4PI_innergal,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_innergal),
                simple_norm(img_CO21_innergal,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_innergal),
                simple_norm(img_ThermalDust_innergal, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_innergal)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_innergal),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(540, 3840-540)
ax.set_ylim(0, 960)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=5, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=orange_transparent)

pl.savefig("HI4PI_CO_Dust_innergal_withATLASGALOrangetransparent.png", bbox_inches='tight')

ax.scatter(almaimf_crds.galactic.l, almaimf_crds.galactic.b,
           marker='*', edgecolor='purple', facecolor='none', transform=ax.get_transform('galactic'))

pl.savefig("HI4PI_CO_Dust_innergal_withATLASGALOrangetransparent_ALMA-IMFtargets.png", bbox_inches='tight')


import regions
from astropy import coordinates
rect = regions.RectangleSkyRegion(
    coordinates.SkyCoord(0*u.deg, 0*u.deg, frame='galactic'),
    width=np.abs((ax.get_xlim()[1] - ax.get_xlim()[0])*target_header_innergal['CDELT1'])*u.deg,
    height=(ax.get_ylim()[1] - ax.get_ylim()[0])*target_header_innergal['CDELT2']*u.deg,
)
# different colors, overwrites previous
rgb = np.array([simple_norm(img_HI4PI,       min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_HI4PI),
                simple_norm(img_CO21,        min_percent=0.01, max_percent=99.90, log_a=2e1, stretch='log')(img_CO21),
                simple_norm(img_ThermalDust, min_percent=0.01, max_percent=99.90, log_a=5e2, stretch='log')(img_ThermalDust)]).T.swapaxes(0,1)
ax = make_rgb(rgb, 'HI-CO-Dust_m0.35', -0.35, layernames=('HI', 'CO', 'Dust'))
prect = rect.to_pixel(ax.get_transform('world'))
prect.plot(ax)
#rect = pl.Rectangle((-720*target_header_innergal['CDELT1'],
#                     -960*target_header_innergal['CDELT2']/2),
#             width=(3840-1080)*target_header_innergal['CDELT1'],
#             height=960*target_header_innergal['CDELT2'],
#                    facecolor='none',
#                    edgecolor='white',
#             transform=pl.gca().get_transform('galactic'))
#ax.add_artist(rect)

pl.savefig("HI-CO-Dust_m0.35_RGB_innergal_zoombox.png", bbox_inches='tight')
ax.wcs
#[Out]# WCS Keywords
#[Out]# 
#[Out]# Number of WCS axes: 2
#[Out]# CTYPE : 'GLON-MOL'  'GLAT-MOL'  
#[Out]# CRVAL : 0.0  0.0  
#[Out]# CRPIX : 960.5  480.5  
#[Out]# PC1_1 PC1_2  : 1.0  0.0  
#[Out]# PC2_1 PC2_2  : 0.0  1.0  
#[Out]# CDELT : -0.16875  0.16875  
#[Out]# NAXIS : 1920  960
# different colors, overwrites previous
rgb = np.array([simple_norm(img_HI4PI,       min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_HI4PI),
                simple_norm(img_CO21,        min_percent=0.01, max_percent=99.90, log_a=2e1, stretch='log')(img_CO21),
                simple_norm(img_ThermalDust, min_percent=0.01, max_percent=99.90, log_a=5e2, stretch='log')(img_ThermalDust)]).T.swapaxes(0,1)
ax = make_rgb(rgb, 'HI-CO-Dust_m0.35', -0.35, layernames=('HI', 'CO', 'Dust'))
prect = rect.to_pixel(ax.wcs)
prect.plot(ax)
#rect = pl.Rectangle((-720*target_header_innergal['CDELT1'],
#                     -960*target_header_innergal['CDELT2']/2),
#             width=(3840-1080)*target_header_innergal['CDELT1'],
#             height=960*target_header_innergal['CDELT2'],
#                    facecolor='none',
#                    edgecolor='white',
#             transform=pl.gca().get_transform('galactic'))
#ax.add_artist(rect)

pl.savefig("HI-CO-Dust_m0.35_RGB_innergal_zoombox.png", bbox_inches='tight')
def h_rot(rgb, rot):
    hsv = rgb_to_hsv(rgb)
    hsv[:,:,0] += rot  # 0.25 = 90/360
    hsv[:,:,0] = hsv[:,:,0] % 1 
    rgb_scaled = hsv_to_rgb(hsv)
    return rgb_scaled

def make_rgb(rgb, basename, hsv_rotation=0, layernames='RGB',
             do_layers=True,
             axlims=None, frame_class=EllipticalFrame):
    plt.figure(figsize=(10,5), dpi=200)
    ax = plt.subplot(1,1,1, projection=WCS(target_header),
                     frame_class=frame_class)
    #ax.coords.grid(color='white')
    ax.coords['glat'].set_ticklabel(visible=False)
    ax.coords['glon'].set_ticklabel(visible=False)
    ax.coords['glat'].set_ticks_visible(False)
    ax.coords['glon'].set_ticks_visible(False)
    if do_layers:
        for ind, color in zip((0, 1, 2), (layernames)):
            rgbc = np.zeros_like(rgb)
            rgbc[:, :, ind] = rgb[:, :, ind]
            if hsv_rotation != 0:
                rgbc = h_rot(rgbc, hsv_rotation)
            ax.imshow(rgbc)
            pl.savefig(f'{basename}_{color}.png', bbox_inches='tight', transparent=True)
    if hsv_rotation != 0:
        rgb = h_rot(rgb, hsv_rotation)
    ax.imshow(rgb)
    if axlims is not None:
        ax.axis(axlims)
    pl.savefig(f'{basename}_RGB.png', bbox_inches='tight', transparent=True)
    return ax
# different colors, overwrites previous
rgb = np.array([simple_norm(img_HI4PI,       min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_HI4PI),
                simple_norm(img_CO21,        min_percent=0.01, max_percent=99.90, log_a=2e1, stretch='log')(img_CO21),
                simple_norm(img_ThermalDust, min_percent=0.01, max_percent=99.90, log_a=5e2, stretch='log')(img_ThermalDust)]).T.swapaxes(0,1)
ax = make_rgb(rgb, 'HI-CO-Dust_m0.35', -0.35, layernames=('HI', 'CO', 'Dust'), do_layers=False)
prect = rect.to_pixel(ax.wcs)
prect.plot(ax=ax)
#rect = pl.Rectangle((-720*target_header_innergal['CDELT1'],
#                     -960*target_header_innergal['CDELT2']/2),
#             width=(3840-1080)*target_header_innergal['CDELT1'],
#             height=960*target_header_innergal['CDELT2'],
#                    facecolor='none',
#                    edgecolor='white',
#             transform=pl.gca().get_transform('galactic'))
#ax.add_artist(rect)

pl.savefig("HI-CO-Dust_m0.35_RGB_innergal_zoombox.png", bbox_inches='tight')
# different colors, overwrites previous
rgb = np.array([simple_norm(img_HI4PI,       min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_HI4PI),
                simple_norm(img_CO21,        min_percent=0.01, max_percent=99.90, log_a=2e1, stretch='log')(img_CO21),
                simple_norm(img_ThermalDust, min_percent=0.01, max_percent=99.90, log_a=5e2, stretch='log')(img_ThermalDust)]).T.swapaxes(0,1)
ax = make_rgb(rgb, 'HI-CO-Dust_m0.35', -0.35, layernames=('HI', 'CO', 'Dust'), do_layers=False)
prect = rect.to_pixel(ax.wcs)
prect.visual['edgecolor'] = 'w'
prect.plot(ax=ax)
#rect = pl.Rectangle((-720*target_header_innergal['CDELT1'],
#                     -960*target_header_innergal['CDELT2']/2),
#             width=(3840-1080)*target_header_innergal['CDELT1'],
#             height=960*target_header_innergal['CDELT2'],
#                    facecolor='none',
#                    edgecolor='white',
#             transform=pl.gca().get_transform('galactic'))
#ax.add_artist(rect)

pl.savefig("HI-CO-Dust_m0.35_RGB_innergal_zoombox.png", bbox_inches='tight')
get_ipython().run_line_magic('pwd', '')
#[Out]# '/orange/adamginsburg/cmz/DataSetVisualizations'
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=5, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=orange_transparent)

cmzrect = regions.RectangleSkyRegion(
    coordinates.SkyCoord(0*u.deg, 0*u.deg, frame='galactic'),
    width=3*u.deg,
    height=2*u.deg,
)
pcmzrect = cmzrect.to_pixel(ax.wcs)
pcmzrect.visual['edgecolor'] = 'w'
pcmzrect.plot(ax=ax)

pl.savefig("HI4PI_CO_Dust_withATLASGALOrangetransparent_cmzbox.png", bbox_inches='tight')
peak_co.wcs
#[Out]# WCS Keywords
#[Out]# 
#[Out]# Number of WCS axes: 2
#[Out]# CTYPE : 'GLON-SFL'  'GLAT-SFL'  
#[Out]# CRVAL : 360.0  0.0  
#[Out]# CRPIX : 568.5  97.854521227825  
#[Out]# PC1_1 PC1_2  : 1.0  0.0  
#[Out]# PC2_1 PC2_2  : 0.0  1.0  
#[Out]# CDELT : -0.010555555436732  0.010555555436732  
#[Out]# NAXIS : 0  0
peak_co.shape
#[Out]# (195, 1137)
peak_hi.shape
#[Out]# (1050, 1050)
hnco_cube = SpectralCube.read("CMZ_3mm_HNCO.fits", use_dask=True)
hnco_cube.shape
#[Out]# (327, 165, 765)
peak_hi.wcs.wcs.cdelt, peak_co.wcs.wcs.cdelt, atlasgal[0].header['CDELT1']
#[Out]# (array([-0.00972222,  0.00972222]),
#[Out]#  array([-0.01055556,  0.01055556]),
#[Out]#  -0.001666667)
img_hi_cmz_hires, footprint = reproject_from_healpix(peak_hi.hdu, target_header_cmz_hires, field=5)
img_agal_cmz, footprint = reproject_from_healpix(atlasgal, target_header_cmz)
img_co_cmz, footprint = reproject_from_healpix(peak_co.hdu, target_header_cmz)
target_header_cmz_hires = fits.Header.fromstring("""
NAXIS   =                    2
NAXIS1  =                 1920
NAXIS2  =                  960
CTYPE1  = 'GLON-CAR'
CRPIX1  =                960.5
CRVAL1  =                  0.0
CDELT1  =                -0.01
CUNIT1  = 'deg     '
CTYPE2  = 'GLAT-CAR'
CRPIX2  =                480.5
CRVAL2  =                  0.0
CDELT2  =                 0.01
CUNIT2  = 'deg     '
COORDSYS= 'icrs    '
""", sep='\n')
img_hi_cmz_hires, footprint = reproject_from_healpix(peak_hi.hdu, target_header_cmz_hires, field=5)
img_agal_cmz, footprint = reproject_from_healpix(atlasgal, target_header_cmz)
img_co_cmz, footprint = reproject_from_healpix(peak_co.hdu, target_header_cmz)
img_hi_cmz_hires, footprint = reproject_from_healpix(peak_hi.hdulist, target_header_cmz_hires, field=5)
img_agal_cmz, footprint = reproject_from_healpix(atlasgal, target_header_cmz)
img_co_cmz, footprint = reproject_from_healpix(peak_co.hdulist, target_header_cmz)
img_hi_cmz_hires, footprint = reproject_from_healpix(fits.HDUList([peak_hi.hdu]), target_header_cmz_hires, field=5)
img_agal_cmz, footprint = reproject_from_healpix(atlasgal, target_header_cmz)
img_co_cmz, footprint = reproject_from_healpix(peak_co.hdulist, target_header_cmz)
img_hi_cmz_hires, footprint = reproject_from_healpix(peak_hi.hdu, target_header_cmz_hires, field=5)
img_agal_cmz, footprint = reproject_from_healpix(atlasgal, target_header_cmz)
img_co_cmz, footprint = reproject_from_healpix(peak_co.hdulist, target_header_cmz)
img_hi_cmz_hires, footprint = reproject_interp(peak_hi.hdu, target_header_cmz_hires, field=5)
img_agal_cmz, footprint = reproject_interp(atlasgal, target_header_cmz)
img_co_cmz, footprint = reproject_interp(peak_co.hdulist, target_header_cmz)
img_hi_cmz_hires, footprint = reproject.reproject_interp(peak_hi.hdu, target_header_cmz_hires, field=5)
img_agal_cmz, footprint = reproject.reproject_interp(atlasgal, target_header_cmz)
img_co_cmz, footprint = reproject.reproject_interp(peak_co.hdulist, target_header_cmz)
img_hi_cmz_hires, footprint = reproject.reproject_interp(peak_hi.hdu, target_header_cmz_hires)
img_agal_cmz, footprint = reproject.reproject_interp(atlasgal, target_header_cmz)
img_co_cmz, footprint = reproject.reproject_interp(peak_co.hdulist, target_header_cmz)
img_hi_cmz_hires, footprint = reproject.reproject_interp(peak_hi.hdu, target_header_cmz_hires)
img_agal_cmz, footprint = reproject.reproject_interp(atlasgal, target_header_cmz)
img_co_cmz, footprint = reproject.reproject_interp(peak_co.hdu, target_header_cmz)
img_hi_cmz_hires, footprint = reproject.reproject_interp(peak_hi.hdu, target_header_cmz_hires)
img_agal_cmz_hires, footprint = reproject.reproject_interp(atlasgal, target_header_cmz)
img_co_cmz_hires, footprint = reproject.reproject_interp(peak_co.hdu, target_header_cmz)
img_hi_cmz_hires, footprint = reproject.reproject_interp(peak_hi.hdu, target_header_cmz_hires)
img_agal_cmz_hires, footprint = reproject.reproject_interp(atlasgal, target_header_cmz_hires)
img_co_cmz_hires, footprint = reproject.reproject_interp(peak_co.hdu, target_header_cmz_hires)
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
target_header_cmz_hires = fits.Header.fromstring("""
NAXIS   =                    2
NAXIS1  =                 1200
NAXIS2  =                  480
CTYPE1  = 'GLON-CAR'
CRPIX1  =                600.5
CRVAL1  =                  0.0
CDELT1  =                -0.01
CUNIT1  = 'deg     '
CTYPE2  = 'GLAT-CAR'
CRPIX2  =                240.5
CRVAL2  =                  0.0
CDELT2  =                 0.01
CUNIT2  = 'deg     '
COORDSYS= 'icrs    '
""", sep='\n')
img_hi_cmz_hires, footprint = reproject.reproject_interp(peak_hi.hdu, target_header_cmz_hires)
img_agal_cmz_hires, footprint = reproject.reproject_interp(atlasgal, target_header_cmz_hires)
img_co_cmz_hires, footprint = reproject.reproject_interp(peak_co.hdu, target_header_cmz_hires)
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100)
ax.set_ylim(100, 380)
#[Out]# (100.0, 380.0)
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100)
ax.set_ylim(120, 360)
#[Out]# (120.0, 360.0)
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100)
ax.set_ylim(140, 340)
#[Out]# (140.0, 340.0)
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=0.01, max_percent=99.99, log_a=5e-1, stretch='log')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=0.01, max_percent=99.99, log_a=1e3, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=0.01, max_percent=99.99, log_a=5e-1, stretch='log')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=0.01, max_percent=99.99, log_a=1e3, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);
img_hi_cmz_hires, footprint = reproject.reproject_interp(peak_hi.hdu, target_header_cmz_hires)
img_agal_cmz_hires, footprint = reproject.reproject_interp(atlasgal, target_header_cmz_hires)
img_co_cmz_hires, footprint = reproject.reproject_interp(mean_co.hdu, target_header_cmz_hires)
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=0.01, max_percent=99.99, log_a=5e-1, stretch='log')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=0.01, max_percent=99.99, log_a=1e3, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=0.01, max_percent=99.99, log_a=5e-1, stretch='asinh')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=0.01, max_percent=99.99, log_a=1e3, stretch='asinh')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);
img_hi_cmz_hires, footprint = reproject.reproject_interp(mean_hi.hdu, target_header_cmz_hires)
img_agal_cmz_hires, footprint = reproject.reproject_interp(atlasgal, target_header_cmz_hires)
img_co_cmz_hires, footprint = reproject.reproject_interp(mean_co.hdu, target_header_cmz_hires)
mean_hi.quicklook()
peak_hi.quicklook()
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=0.01, max_percent=99.99, log_a=5e-1, stretch='lienar')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=0.01, max_percent=99.99, log_a=1e3, stretch='asinh')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=0.01, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=0.01, max_percent=99.99, log_a=1e3, stretch='asinh')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=5, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=0.01, max_percent=99.99, log_a=1e3, stretch='asinh')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=5, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=0.01, max_percent=99.99, log_a=1e3, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=5, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=0.01, max_percent=99.99, log_a=1e0, stretch='log')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=0.01, max_percent=99.99, log_a=1e3, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=5, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=0.01, max_percent=99.99, log_a=1e3, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=5, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=1, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=1e3, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);
img_hi_cmz_hires, footprint = reproject.reproject_interp(mean_hi.hdu, target_header_cmz_hires)
img_agal_cmz_hires, footprint = reproject.reproject_interp(atlasgal, target_header_cmz_hires)
img_co_cmz_hires, footprint = reproject.reproject_interp(mean_co.hdu, target_header_cmz_hires)
for im in (img_hi_cmz_hires, img_agal_cmz_hires, img_co_cmz_hires):
    im[im==0] = np.nan
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=5, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=1, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=1e3, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=1, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=1, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=1e3, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=1, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=1, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e3, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=5, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e3, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);
pl.imshow(img_hi_cmz_hires, norm=simple_norm(img_hi_cmz_hires,   min_percent=5, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires))
pl.imshow(img_hi_cmz_hires, norm=simple_norm(img_hi_cmz_hires,   min_percent=5, max_percent=99.99, log_a=5e-1, stretch='linear'))
#[Out]# <matplotlib.image.AxesImage at 0x2b29576d1a00>
pl.imshow(img_co_cmz_hires, norm=simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh'))
#[Out]# <matplotlib.image.AxesImage at 0x2b29571d06a0>
pl.imshow(img_agal_cmz_hires, norm=simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e3, stretch='log'))
#[Out]# <matplotlib.image.AxesImage at 0x2b2956846280>
pl.imshow(img_agal_cmz_hires, norm=simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e3, stretch='asinh'))
#[Out]# <matplotlib.image.AxesImage at 0x2b29573f5fa0>
pl.imshow(img_hi_cmz_hires, norm=simple_norm(img_hi_cmz_hires,   min_percent=10, max_percent=99.99, log_a=5e-1, stretch='linear'))
#[Out]# <matplotlib.image.AxesImage at 0x2b2953a6d1c0>
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=5, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e3, stretch='asinh')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);
pl.imshow(img_hi_cmz_hires, norm=simple_norm(img_hi_cmz_hires,   min_percent=15, max_percent=99.99, log_a=5e-1, stretch='linear'))
#[Out]# <matplotlib.image.AxesImage at 0x2b2954999a30>
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=15, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e3, stretch='asinh')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=15, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e3, stretch='asinh')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.15  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=15, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e3, stretch='asinh')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.25  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=15, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e3, stretch='asinh')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.0  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e3, stretch='asinh')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.0  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);
pl.imshow(img_hi_cmz_hires, norm=simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=5e-1, stretch='linear'))
#[Out]# <matplotlib.image.AxesImage at 0x2b2957fffca0>
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires)/2,
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e3, stretch='asinh')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.0  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);
img_hi_cmz_hires, footprint = reproject.reproject_interp(mean_hi.hdu, target_header_cmz_hires)
img_agal_cmz_hires, footprint = reproject.reproject_interp(atlasgal, target_header_cmz_hires)
img_meerkat_cmz_hires, footprint = reproject.reproject_interp(meerkat, target_header_cmz_hires)
img_co_cmz_hires, footprint = reproject.reproject_interp(mean_co.hdu, target_header_cmz_hires)
for im in (img_hi_cmz_hires, img_agal_cmz_hires, img_co_cmz_hires):
    im[im==0] = np.nan
img_hi_cmz_hires, footprint = reproject.reproject_interp(mean_hi.hdu, target_header_cmz_hires)
img_agal_cmz_hires, footprint = reproject.reproject_interp(atlasgal, target_header_cmz_hires)
img_meerkat_cmz_hires, footprint = reproject.reproject_interp((meerkat[0].data.squeeze(), WCS(meerkat[0].header).celestial), target_header_cmz_hires)
img_co_cmz_hires, footprint = reproject.reproject_interp(mean_co.hdu, target_header_cmz_hires)
for im in (img_hi_cmz_hires, img_agal_cmz_hires, img_co_cmz_hires):
    im[im==0] = np.nan
pl.imshow(img_meerkat_hires, norm=simple_norm(img_meerkat_hires,   min_percent=1, max_percent=99.99, log_a=5e-1, stretch='log'))
pl.imshow(img_meerkat_cmz_hires, norm=simple_norm(img_meerkat_hires,   min_percent=1, max_percent=99.99, log_a=5e-1, stretch='log'))
pl.imshow(img_meerkat_cmz_hires, norm=simple_norm(img_meerkat_cmz_hires,   min_percent=1, max_percent=99.99, log_a=5e-1, stretch='log'))
#[Out]# <matplotlib.image.AxesImage at 0x2b2957f952b0>
hi_cube.spectral_slab(100*u.km/u.s, 300*u.km/u.s).mean(axis=0).quicklook()
hi_cube.spectral_slab(-300*u.km/u.s, -100*u.km/u.s).mean(axis=0).quicklook()
mean_hi_highv = (hi_cube.spectral_slab(-300*u.km/u.s, -100*u.km/u.s).mean(axis=0) + hi_cube.spectral_slab(100*u.km/u.s, 300*u.km/u.s).mean(axis=0))
img_hi_cmz_hires, footprint = reproject.reproject_interp(mean_hi_highv.hdu, target_header_cmz_hires)
img_agal_cmz_hires, footprint = reproject.reproject_interp(atlasgal, target_header_cmz_hires)
img_meerkat_cmz_hires, footprint = reproject.reproject_interp((meerkat[0].data.squeeze(), WCS(meerkat[0].header).celestial), target_header_cmz_hires)
img_co_cmz_hires, footprint = reproject.reproject_interp(mean_co.hdu, target_header_cmz_hires)
for im in (img_hi_cmz_hires, img_agal_cmz_hires, img_co_cmz_hires):
    im[im==0] = np.nan
pl.imshow(img_meerkat_cmz_hires, norm=simple_norm(img_meerkat_cmz_hires, min_percent=1, max_percent=99.99, log_a=5e-1, stretch='log'))
#[Out]# <matplotlib.image.AxesImage at 0x2b2958966730>
pl.imshow(img_hi_cmz_hires, norm=simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=5e-1, stretch='linear'))
#[Out]# <matplotlib.image.AxesImage at 0x2b29589c3b20>
pl.imshow(img_co_cmz_hires, norm=simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh'))
#[Out]# <matplotlib.image.AxesImage at 0x2b2958a1ebe0>
pl.imshow(img_agal_cmz_hires, norm=simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e3, stretch='asinh'))
#[Out]# <matplotlib.image.AxesImage at 0x2b2958a7aca0>
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires)/2,
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e3, stretch='asinh')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.0  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);
mean_hi.quicklook()
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e3, stretch='asinh')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.0  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e3, stretch='asinh')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e4, stretch='asinh')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);

pl.savefig("HI_CO_Dust_BigCMZ.png", bbox_inches='tight')
pl.imshow(img_agal_cmz_hires, norm=simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e4, stretch='asinh'))
#[Out]# <matplotlib.image.AxesImage at 0x2b2958d2e8b0>
pl.imshow(img_agal_cmz_hires, norm=simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e1, stretch='asinh'))
#[Out]# <matplotlib.image.AxesImage at 0x2b2958d8b970>
pl.imshow(img_agal_cmz_hires, norm=simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e9, stretch='asinh'))
#[Out]# <matplotlib.image.AxesImage at 0x2b2958df8820>
pl.imshow(img_agal_cmz_hires, norm=simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e3, stretch='lpg'))
pl.imshow(img_agal_cmz_hires, norm=simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e3, stretch='log'))
#[Out]# <matplotlib.image.AxesImage at 0x2b2958e568b0>
pl.imshow(img_agal_cmz_hires, norm=simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e2, stretch='log'))
#[Out]# <matplotlib.image.AxesImage at 0x2b2958eb4970>
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e2, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);

pl.savefig("HI_CO_Dust_BigCMZ.png", bbox_inches='tight')
pl.imshow(img_agal_cmz_hires, norm=simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e1, stretch='log'))
#[Out]# <matplotlib.image.AxesImage at 0x2b2958f729a0>
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);

pl.savefig("HI_CO_Dust_BigCMZ.png", bbox_inches='tight')
pl.imshow(img_agal_cmz_hires, norm=simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=5e1, stretch='log'))
#[Out]# <matplotlib.image.AxesImage at 0x2b29590426d0>
pl.imshow(img_agal_cmz_hires, norm=simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=3e1, stretch='log'))
#[Out]# <matplotlib.image.AxesImage at 0x2b295909d790>
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=3e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);

pl.savefig("HI_CO_Dust_BigCMZ.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=2e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);

pl.savefig("HI_CO_Dust_BigCMZ.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);

pl.savefig("HI_CO_Dust_BigCMZ.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += 0#-0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);

pl.savefig("HI_CO_Dust_BigCMZ.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += 0#-0.35  # 0.25 = 90/360
hsv[:,:,0] -= hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);

pl.savefig("HI_CO_Dust_BigCMZ.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += 0#-0.35  # 0.25 = 90/360
#hsv[:,:,0] -= hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);

pl.savefig("HI_CO_Dust_BigCMZ.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += 0#-0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);

pl.savefig("HI_CO_Dust_BigCMZ.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99., log_a=1e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += 0#-0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);

pl.savefig("HI_CO_Dust_BigCMZ.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99., log_a=1e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);

pl.savefig("HI_CO_Dust_BigCMZ.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.5, log_a=1e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);

pl.savefig("HI_CO_Dust_BigCMZ.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.5, log_a=1e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += 0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);

pl.savefig("HI_CO_Dust_BigCMZ.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.5, log_a=1e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += 0.55  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);

pl.savefig("HI_CO_Dust_BigCMZ.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.5, log_a=1e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += 0.45  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);

pl.savefig("HI_CO_Dust_BigCMZ.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=5e-1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.5, log_a=1e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += 0#.45  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);

pl.savefig("HI_CO_Dust_BigCMZ.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=1e1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.5, log_a=1e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += 0#.45  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);

pl.savefig("HI_CO_Dust_BigCMZ.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=1e1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.5, log_a=1e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.15#.45  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);

pl.savefig("HI_CO_Dust_BigCMZ.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=1e1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.5, log_a=1e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.10#.45  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);

pl.savefig("HI_CO_Dust_BigCMZ.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=1e1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.10#.45  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);

pl.savefig("HI_CO_Dust_BigCMZ.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=1e1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.25#.45  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);

pl.savefig("HI_CO_Dust_BigCMZ.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=1e1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35#.45  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);

pl.savefig("HI_CO_Dust_BigCMZ.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=1e1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.9, log_a=1e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.25#.45  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);

pl.savefig("HI_CO_Dust_BigCMZ.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=1e1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=1e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.25#.45  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);

pl.savefig("HI_CO_Dust_BigCMZ.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=1e1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=1e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=1e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35#.45  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);

pl.savefig("HI_CO_Dust_BigCMZ.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=1e1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=2e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=2e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35#.45  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);

pl.savefig("HI_CO_Dust_BigCMZ.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=2e1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=2e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=2e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35#.45  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);

pl.savefig("HI_CO_Dust_BigCMZ.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=4e1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=4e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=4e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35#.45  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);

pl.savefig("HI_CO_Dust_BigCMZ.png", bbox_inches='tight')
target_header_innercmz = fits.Header.fromstring("""
NAXIS   =                    2
NAXIS1  =                 3000
NAXIS2  =                 1000
CTYPE1  = 'GLON-CAR'
CRPIX1  =               1500.5
CRVAL1  =                  0.0
CDELT1  =               -0.001
CUNIT1  = 'deg     '
CTYPE2  = 'GLAT-CAR'
CRPIX2  =                500.5
CRVAL2  =                  0.0
CDELT2  =                0.001
CUNIT2  = 'deg     '
COORDSYS= 'icrs    '
""", sep='\n')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=4e1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=4e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=4e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(np.nan_to_num(rgb))
hsv[:,:,0] += -0.35#.45  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz_hires),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.set_xlim(100, 1100);
ax.set_ylim(140, 340);

pl.savefig("HI_CO_Dust_BigCMZ.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=5, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=orange_transparent)

cmzrect = regions.RectangleSkyRegion(
    coordinates.SkyCoord(0*u.deg, 0*u.deg, frame='galactic'),
    width=12*u.deg,
    height=4.8*u.deg,
)
pcmzrect = cmzrect.to_pixel(ax.wcs)
pcmzrect.visual['edgecolor'] = 'w'
pcmzrect.plot(ax=ax)

pl.savefig("HI4PI_CO_Dust_withATLASGALOrangetransparent_cmzbox.png", bbox_inches='tight')
from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes, inset_axes
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=5, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=orange_transparent)

cmzrect = regions.RectangleSkyRegion(
    coordinates.SkyCoord(0*u.deg, 0*u.deg, frame='galactic'),
    width=12*u.deg,
    height=4.8*u.deg,
)
pcmzrect = cmzrect.to_pixel(ax.wcs)
pcmzrect.visual['edgecolor'] = 'w'
pcmzrect.plot(ax=ax)

rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=4e1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=4e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=4e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(np.nan_to_num(rgb))
hsv[:,:,0] += -0.35#.45  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

axins = inset_axes(ax, **zp['inset_pars'],
                   axes_class=astropy.visualization.wcsaxes.core.WCSAxes,
                   axes_kwargs=dict(wcs=WCS(target_header_cmz_hires))    
axins.imshow(rgb_scaled)
axins.coords['glat'].set_ticklabel(visible=False)
axins.coords['glon'].set_ticklabel(visible=False)
axins.coords['glat'].set_ticks_visible(False)
axins.coords['glon'].set_ticks_visible(False)


pl.savefig("HI4PI_CO_Dust_withATLASGALOrangetransparent_cmzbox_insetzoom.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=5, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=orange_transparent)

cmzrect = regions.RectangleSkyRegion(
    coordinates.SkyCoord(0*u.deg, 0*u.deg, frame='galactic'),
    width=12*u.deg,
    height=4.8*u.deg,
)
pcmzrect = cmzrect.to_pixel(ax.wcs)
pcmzrect.visual['edgecolor'] = 'w'
pcmzrect.plot(ax=ax)

rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=4e1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=4e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=4e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(np.nan_to_num(rgb))
hsv[:,:,0] += -0.35#.45  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

axins = inset_axes(ax, **zp['inset_pars'],
                   axes_class=astropy.visualization.wcsaxes.core.WCSAxes,
                   axes_kwargs=dict(wcs=WCS(target_header_cmz_hires)))
axins.imshow(rgb_scaled)
axins.coords['glat'].set_ticklabel(visible=False)
axins.coords['glon'].set_ticklabel(visible=False)
axins.coords['glat'].set_ticks_visible(False)
axins.coords['glon'].set_ticks_visible(False)


pl.savefig("HI4PI_CO_Dust_withATLASGALOrangetransparent_cmzbox_insetzoom.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=5, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=orange_transparent)

cmzrect = regions.RectangleSkyRegion(
    coordinates.SkyCoord(0*u.deg, 0*u.deg, frame='galactic'),
    width=12*u.deg,
    height=4.8*u.deg,
)
pcmzrect = cmzrect.to_pixel(ax.wcs)
pcmzrect.visual['edgecolor'] = 'w'
pcmzrect.plot(ax=ax)

rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=4e1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=4e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=4e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(np.nan_to_num(rgb))
hsv[:,:,0] += -0.35#.45  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

axins = inset_axes(ax,
                   axes_class=astropy.visualization.wcsaxes.core.WCSAxes,
                   axes_kwargs=dict(wcs=WCS(target_header_cmz_hires)))
axins.imshow(rgb_scaled)
axins.coords['glat'].set_ticklabel(visible=False)
axins.coords['glon'].set_ticklabel(visible=False)
axins.coords['glat'].set_ticks_visible(False)
axins.coords['glon'].set_ticks_visible(False)


pl.savefig("HI4PI_CO_Dust_withATLASGALOrangetransparent_cmzbox_insetzoom.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=5, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=orange_transparent)

cmzrect = regions.RectangleSkyRegion(
    coordinates.SkyCoord(0*u.deg, 0*u.deg, frame='galactic'),
    width=12*u.deg,
    height=4.8*u.deg,
)
pcmzrect = cmzrect.to_pixel(ax.wcs)
pcmzrect.visual['edgecolor'] = 'w'
pcmzrect.plot(ax=ax)

rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=4e1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=4e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=4e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(np.nan_to_num(rgb))
hsv[:,:,0] += -0.35#.45  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

axins = inset_axes(ax,
                   width=2, height=2,
                   axes_class=astropy.visualization.wcsaxes.core.WCSAxes,
                   axes_kwargs=dict(wcs=WCS(target_header_cmz_hires)))
axins.imshow(rgb_scaled)
axins.coords['glat'].set_ticklabel(visible=False)
axins.coords['glon'].set_ticklabel(visible=False)
axins.coords['glat'].set_ticks_visible(False)
axins.coords['glon'].set_ticks_visible(False)


pl.savefig("HI4PI_CO_Dust_withATLASGALOrangetransparent_cmzbox_insetzoom.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(2,1,2, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=5, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=orange_transparent)

cmzrect = regions.RectangleSkyRegion(
    coordinates.SkyCoord(0*u.deg, 0*u.deg, frame='galactic'),
    width=12*u.deg,
    height=4.8*u.deg,
)
pcmzrect = cmzrect.to_pixel(ax.wcs)
pcmzrect.visual['edgecolor'] = 'w'
pcmzrect.plot(ax=ax)

rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=4e1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=4e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=4e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(np.nan_to_num(rgb))
hsv[:,:,0] += -0.35#.45  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

axins = inset_axes(ax,
                   width=8, height=8,
                   bbox_to_anchor=[0, 0.5,],
                   bbox_transform=fig.transFigure,
                   axes_class=astropy.visualization.wcsaxes.core.WCSAxes,
                   axes_kwargs=dict(wcs=WCS(target_header_cmz_hires)))
axins.imshow(rgb_scaled)
axins.coords['glat'].set_ticklabel(visible=False)
axins.coords['glon'].set_ticklabel(visible=False)
axins.coords['glat'].set_ticks_visible(False)
axins.coords['glon'].set_ticks_visible(False)


pl.savefig("HI4PI_CO_Dust_withATLASGALOrangetransparent_cmzbox_insetzoom.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(2,1,2, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=5, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=orange_transparent)

cmzrect = regions.RectangleSkyRegion(
    coordinates.SkyCoord(0*u.deg, 0*u.deg, frame='galactic'),
    width=12*u.deg,
    height=4.8*u.deg,
)
pcmzrect = cmzrect.to_pixel(ax.wcs)
pcmzrect.visual['edgecolor'] = 'w'
pcmzrect.plot(ax=ax)

rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=4e1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=4e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=4e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(np.nan_to_num(rgb))
hsv[:,:,0] += -0.35#.45  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

axins = inset_axes(ax,
                   width=8, height=8,
                   bbox_to_anchor=[0, 0.5,],
                   bbox_transform=fig.transFigure,
                   axes_class=astropy.visualization.wcsaxes.core.WCSAxes,
                   axes_kwargs=dict(wcs=WCS(target_header_cmz_hires)))
axins.imshow(rgb_scaled)
axins.coords['glat'].set_ticklabel(visible=False)
axins.coords['glon'].set_ticklabel(visible=False)
axins.coords['glat'].set_ticks_visible(False)
axins.coords['glon'].set_ticks_visible(False)


pl.savefig("HI4PI_CO_Dust_withATLASGALOrangetransparent_cmzbox_insetzoom.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(2,1,2, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=5, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=orange_transparent)

cmzrect = regions.RectangleSkyRegion(
    coordinates.SkyCoord(0*u.deg, 0*u.deg, frame='galactic'),
    width=12*u.deg,
    height=4.8*u.deg,
)
pcmzrect = cmzrect.to_pixel(ax.wcs)
pcmzrect.visual['edgecolor'] = 'w'
pcmzrect.plot(ax=ax)

rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=4e1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=4e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=4e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(np.nan_to_num(rgb))
hsv[:,:,0] += -0.35#.45  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

axins = inset_axes(ax,
                   width=8, height=8,
                   bbox_to_anchor=[0, 0.5,],
                   bbox_transform=fig.transFigure,
                   loc='lower left',
                   axes_class=astropy.visualization.wcsaxes.core.WCSAxes,
                   axes_kwargs=dict(wcs=WCS(target_header_cmz_hires)))
axins.imshow(rgb_scaled)
axins.coords['glat'].set_ticklabel(visible=False)
axins.coords['glon'].set_ticklabel(visible=False)
axins.coords['glat'].set_ticks_visible(False)
axins.coords['glon'].set_ticks_visible(False)


pl.savefig("HI4PI_CO_Dust_withATLASGALOrangetransparent_cmzbox_insetzoom.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(2,1,2, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=5, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=orange_transparent)

cmzrect = regions.RectangleSkyRegion(
    coordinates.SkyCoord(0*u.deg, 0*u.deg, frame='galactic'),
    width=12*u.deg,
    height=4.8*u.deg,
)
pcmzrect = cmzrect.to_pixel(ax.wcs)
pcmzrect.visual['edgecolor'] = 'w'
pcmzrect.plot(ax=ax)

rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=4e1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=4e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=4e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(np.nan_to_num(rgb))
hsv[:,:,0] += -0.35#.45  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

axins = inset_axes(ax,
                   width=4, height=4,
                   bbox_to_anchor=[0, 0.5,],
                   bbox_transform=fig.transFigure,
                   loc='lower left',
                   axes_class=astropy.visualization.wcsaxes.core.WCSAxes,
                   axes_kwargs=dict(wcs=WCS(target_header_cmz_hires)))
axins.imshow(rgb_scaled)
axins.coords['glat'].set_ticklabel(visible=False)
axins.coords['glon'].set_ticklabel(visible=False)
axins.coords['glat'].set_ticks_visible(False)
axins.coords['glon'].set_ticks_visible(False)


pl.savefig("HI4PI_CO_Dust_withATLASGALOrangetransparent_cmzbox_insetzoom.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(2,1,2, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=5, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=orange_transparent)

cmzrect = regions.RectangleSkyRegion(
    coordinates.SkyCoord(0*u.deg, 0*u.deg, frame='galactic'),
    width=12*u.deg,
    height=4.8*u.deg,
)
pcmzrect = cmzrect.to_pixel(ax.wcs)
pcmzrect.visual['edgecolor'] = 'w'
pcmzrect.plot(ax=ax)

rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=4e1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=4e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=4e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(np.nan_to_num(rgb))
hsv[:,:,0] += -0.35#.45  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

axins = inset_axes(ax,
                   width=4, height=4,
                   bbox_to_anchor=[0, 0.5,],
                   bbox_transform=fig.transFigure,
                   loc='lower center',
                   axes_class=astropy.visualization.wcsaxes.core.WCSAxes,
                   axes_kwargs=dict(wcs=WCS(target_header_cmz_hires)))
axins.imshow(rgb_scaled)
axins.coords['glat'].set_ticklabel(visible=False)
axins.coords['glon'].set_ticklabel(visible=False)
axins.coords['glat'].set_ticks_visible(False)
axins.coords['glon'].set_ticks_visible(False)


pl.savefig("HI4PI_CO_Dust_withATLASGALOrangetransparent_cmzbox_insetzoom.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(2,1,2, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=5, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=orange_transparent)

cmzrect = regions.RectangleSkyRegion(
    coordinates.SkyCoord(0*u.deg, 0*u.deg, frame='galactic'),
    width=12*u.deg,
    height=4.8*u.deg,
)
pcmzrect = cmzrect.to_pixel(ax.wcs)
pcmzrect.visual['edgecolor'] = 'w'
pcmzrect.plot(ax=ax)

rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=4e1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=4e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=4e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(np.nan_to_num(rgb))
hsv[:,:,0] += -0.35#.45  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

axins = inset_axes(ax,
                   width=4, height=4,
                   bbox_to_anchor=[0, 0.5, 1, 0.5],
                   bbox_transform=fig.transFigure,
                   loc='lower center',
                   axes_class=astropy.visualization.wcsaxes.core.WCSAxes,
                   axes_kwargs=dict(wcs=WCS(target_header_cmz_hires)))
axins.imshow(rgb_scaled)
axins.coords['glat'].set_ticklabel(visible=False)
axins.coords['glon'].set_ticklabel(visible=False)
axins.coords['glat'].set_ticks_visible(False)
axins.coords['glon'].set_ticks_visible(False)


pl.savefig("HI4PI_CO_Dust_withATLASGALOrangetransparent_cmzbox_insetzoom.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(2,1,2, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=5, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=orange_transparent)

cmzrect = regions.RectangleSkyRegion(
    coordinates.SkyCoord(0*u.deg, 0*u.deg, frame='galactic'),
    width=12*u.deg,
    height=4.8*u.deg,
)
pcmzrect = cmzrect.to_pixel(ax.wcs)
pcmzrect.visual['edgecolor'] = 'w'
pcmzrect.plot(ax=ax)

rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=4e1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=4e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=4e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(np.nan_to_num(rgb))
hsv[:,:,0] += -0.35#.45  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

axins = inset_axes(ax,
                   width=4, height=4,
                   bbox_to_anchor=[0, 0.25, 1, 0.5],
                   bbox_transform=fig.transFigure,
                   loc='lower center',
                   axes_class=astropy.visualization.wcsaxes.core.WCSAxes,
                   axes_kwargs=dict(wcs=WCS(target_header_cmz_hires)))
axins.imshow(rgb_scaled)
axins.coords['glat'].set_ticklabel(visible=False)
axins.coords['glon'].set_ticklabel(visible=False)
axins.coords['glat'].set_ticks_visible(False)
axins.coords['glon'].set_ticks_visible(False)


pl.savefig("HI4PI_CO_Dust_withATLASGALOrangetransparent_cmzbox_insetzoom.png", bbox_inches='tight')
def mark_inset_generic(axins, parent_ax, data, loc1=1, loc2=3,
                       loc1in=None, loc2in=None, edgecolor='b', zorder1=100, zorder2=100, polyzorder=1):
    bl = axins.wcs.pixel_to_world(0, 0)
    br = axins.wcs.pixel_to_world(data.shape[1], 0)
    tl = axins.wcs.pixel_to_world(0, data.shape[0]) # x,y not y,x
    tr = axins.wcs.pixel_to_world(data.shape[1], data.shape[0]) # x,y not y,x
    
    fig = parent_ax.get_figure()
    
    frame = parent_ax.wcs.wcs.radesys.lower()
    frame = ax.wcs.world_axis_physical_types[0].split(".")[1]
    
    blt = bl.transform_to(frame)
    brt = br.transform_to(frame)
    tlt = tl.transform_to(frame)
    trt = tr.transform_to(frame)
    xys = [parent_ax.wcs.wcs_world2pix([[crd.spherical.lon.deg,
                                         crd.spherical.lat.deg]],0)[0]
           for crd in (trt, tlt, blt, brt, trt)]
    
    markinkwargs = dict(fc='none', ec=edgecolor)
    ppoly = Polygon(xys, fill=False, zorder=polyzorder, **markinkwargs)
    parent_ax.add_patch(ppoly)
    
    corners = parent_ax.transData.inverted().transform(xys)
    
    axcorners = [(1,1), (0,1), (0,0), (1,0)]
    corners = [(crd.spherical.lon.deg, crd.spherical.lat.deg)
               for crd in (trt, tlt, blt, brt)]
    
    if loc1in is None:
        loc1in = loc1
    if loc2in is None:
        loc2in = loc2
    
    con1 = ConnectionPatch(xyA=axcorners[loc1-1], coordsA='axes fraction', axesA=axins,
                           xyB=corners[loc1in-1], coordsB=parent_ax.get_transform('world'), axesB=parent_ax,
                           linestyle='-', color=edgecolor, zorder=zorder1)
    con2 = ConnectionPatch(xyA=axcorners[loc2-1], coordsA='axes fraction', axesA=axins,
                           xyB=corners[loc2in-1], coordsB=parent_ax.get_transform('world'), axesB=parent_ax,
                           linestyle='-', color=edgecolor, zorder=zorder2)    
    fig.add_artist(con1)
    fig.add_artist(con2)
    
    return con1, con2
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(2,1,2, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=5, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=orange_transparent)

cmzrect = regions.RectangleSkyRegion(
    coordinates.SkyCoord(0*u.deg, 0*u.deg, frame='galactic'),
    width=12*u.deg,
    height=4.8*u.deg,
)
pcmzrect = cmzrect.to_pixel(ax.wcs)
pcmzrect.visual['edgecolor'] = 'w'
pcmzrect.plot(ax=ax)

rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=4e1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=4e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=4e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(np.nan_to_num(rgb))
hsv[:,:,0] += -0.35#.45  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

axins = inset_axes(ax,
                   width=4, height=4,
                   bbox_to_anchor=[0, 0.25, 1, 0.5],
                   bbox_transform=fig.transFigure,
                   loc='lower center',
                   axes_class=astropy.visualization.wcsaxes.core.WCSAxes,
                   axes_kwargs=dict(wcs=WCS(target_header_cmz_hires)))
axins.imshow(rgb_scaled)
axins.coords['glat'].set_ticklabel(visible=False)
axins.coords['glon'].set_ticklabel(visible=False)
axins.coords['glat'].set_ticks_visible(False)
axins.coords['glon'].set_ticks_visible(False)

mark_inset_generic(axins, ax, data=img_hi_cmz_hires, loc1=4, edgecolor='w')

pl.savefig("HI4PI_CO_Dust_withATLASGALOrangetransparent_cmzbox_insetzoom.png", bbox_inches='tight')
from mpl_toolkits.axes_grid1.inset_locator import TransformedBbox, BboxPatch, BboxConnector, Path
from matplotlib.transforms import Bbox
from matplotlib.patches import Polygon, PathPatch, ConnectionPatch

def mark_inset_generic(axins, parent_ax, data, loc1=1, loc2=3,
                       loc1in=None, loc2in=None, edgecolor='b', zorder1=100, zorder2=100, polyzorder=1):
    bl = axins.wcs.pixel_to_world(0, 0)
    br = axins.wcs.pixel_to_world(data.shape[1], 0)
    tl = axins.wcs.pixel_to_world(0, data.shape[0]) # x,y not y,x
    tr = axins.wcs.pixel_to_world(data.shape[1], data.shape[0]) # x,y not y,x
    
    fig = parent_ax.get_figure()
    
    frame = parent_ax.wcs.wcs.radesys.lower()
    frame = ax.wcs.world_axis_physical_types[0].split(".")[1]
    
    blt = bl.transform_to(frame)
    brt = br.transform_to(frame)
    tlt = tl.transform_to(frame)
    trt = tr.transform_to(frame)
    xys = [parent_ax.wcs.wcs_world2pix([[crd.spherical.lon.deg,
                                         crd.spherical.lat.deg]],0)[0]
           for crd in (trt, tlt, blt, brt, trt)]
    
    markinkwargs = dict(fc='none', ec=edgecolor)
    ppoly = Polygon(xys, fill=False, zorder=polyzorder, **markinkwargs)
    parent_ax.add_patch(ppoly)
    
    corners = parent_ax.transData.inverted().transform(xys)
    
    axcorners = [(1,1), (0,1), (0,0), (1,0)]
    corners = [(crd.spherical.lon.deg, crd.spherical.lat.deg)
               for crd in (trt, tlt, blt, brt)]
    
    if loc1in is None:
        loc1in = loc1
    if loc2in is None:
        loc2in = loc2
    
    con1 = ConnectionPatch(xyA=axcorners[loc1-1], coordsA='axes fraction', axesA=axins,
                           xyB=corners[loc1in-1], coordsB=parent_ax.get_transform('world'), axesB=parent_ax,
                           linestyle='-', color=edgecolor, zorder=zorder1)
    con2 = ConnectionPatch(xyA=axcorners[loc2-1], coordsA='axes fraction', axesA=axins,
                           xyB=corners[loc2in-1], coordsB=parent_ax.get_transform('world'), axesB=parent_ax,
                           linestyle='-', color=edgecolor, zorder=zorder2)    
    fig.add_artist(con1)
    fig.add_artist(con2)
    
    return con1, con2
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(2,1,2, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=5, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=orange_transparent)

cmzrect = regions.RectangleSkyRegion(
    coordinates.SkyCoord(0*u.deg, 0*u.deg, frame='galactic'),
    width=12*u.deg,
    height=4.8*u.deg,
)
pcmzrect = cmzrect.to_pixel(ax.wcs)
pcmzrect.visual['edgecolor'] = 'w'
pcmzrect.plot(ax=ax)

rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=4e1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=4e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=4e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(np.nan_to_num(rgb))
hsv[:,:,0] += -0.35#.45  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

axins = inset_axes(ax,
                   width=4, height=4,
                   bbox_to_anchor=[0, 0.25, 1, 0.5],
                   bbox_transform=fig.transFigure,
                   loc='lower center',
                   axes_class=astropy.visualization.wcsaxes.core.WCSAxes,
                   axes_kwargs=dict(wcs=WCS(target_header_cmz_hires)))
axins.imshow(rgb_scaled)
axins.coords['glat'].set_ticklabel(visible=False)
axins.coords['glon'].set_ticklabel(visible=False)
axins.coords['glat'].set_ticks_visible(False)
axins.coords['glon'].set_ticks_visible(False)

mark_inset_generic(axins, ax, data=img_hi_cmz_hires, loc1=4, edgecolor='w')

pl.savefig("HI4PI_CO_Dust_withATLASGALOrangetransparent_cmzbox_insetzoom.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(2,1,2, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=5, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=orange_transparent)

#cmzrect = regions.RectangleSkyRegion(
#    coordinates.SkyCoord(0*u.deg, 0*u.deg, frame='galactic'),
#    width=12*u.deg,
#    height=4.8*u.deg,
#)
#pcmzrect = cmzrect.to_pixel(ax.wcs)
#pcmzrect.visual['edgecolor'] = 'w'
#pcmzrect.plot(ax=ax)

rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=4e1, stretch='linear')(img_hi_cmz_hires),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=4e1, stretch='asinh')(img_co_cmz_hires),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=4e1, stretch='log')(img_agal_cmz_hires)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(np.nan_to_num(rgb))
hsv[:,:,0] += -0.35#.45  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

axins = inset_axes(ax,
                   width=4, height=4,
                   bbox_to_anchor=[0, 0.25, 1, 0.5],
                   bbox_transform=fig.transFigure,
                   loc='lower center',
                   axes_class=astropy.visualization.wcsaxes.core.WCSAxes,
                   axes_kwargs=dict(wcs=WCS(target_header_cmz_hires)))
axins.imshow(rgb_scaled)
axins.coords['glat'].set_ticklabel(visible=False)
axins.coords['glon'].set_ticklabel(visible=False)
axins.coords['glat'].set_ticks_visible(False)
axins.coords['glon'].set_ticks_visible(False)

mark_inset_generic(axins, ax, data=img_hi_cmz_hires, loc1=4, edgecolor='w')

pl.savefig("HI4PI_CO_Dust_withATLASGALOrangetransparent_cmzbox_insetzoom.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(2,1,2, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
ax.set_xlim(240*2, 720*2)
ax.set_ylim(120*2, 360*2)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=5, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=orange_transparent)

#cmzrect = regions.RectangleSkyRegion(
#    coordinates.SkyCoord(0*u.deg, 0*u.deg, frame='galactic'),
#    width=12*u.deg,
#    height=4.8*u.deg,
#)
#pcmzrect = cmzrect.to_pixel(ax.wcs)
#pcmzrect.visual['edgecolor'] = 'w'
#pcmzrect.plot(ax=ax)

rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=4e1, stretch='linear')(np.nan_to_num(img_hi_cmz_hires)),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=4e1, stretch='asinh')(np.nan_to_num(img_co_cmz_hires)),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=4e1, stretch='log')(np.nan_to_num(img_agal_cmz_hires))]).T.swapaxes(0,1)
hsv = rgb_to_hsv(np.nan_to_num(rgb))
hsv[:,:,0] += -0.35#.45  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

axins = inset_axes(ax,
                   width=4, height=4,
                   bbox_to_anchor=[0, 0.25, 1, 0.5],
                   bbox_transform=fig.transFigure,
                   loc='lower center',
                   axes_class=astropy.visualization.wcsaxes.core.WCSAxes,
                   axes_kwargs=dict(wcs=WCS(target_header_cmz_hires)))
axins.imshow(rgb_scaled)
axins.coords['glat'].set_ticklabel(visible=False)
axins.coords['glon'].set_ticklabel(visible=False)
axins.coords['glat'].set_ticks_visible(False)
axins.coords['glon'].set_ticks_visible(False)

mark_inset_generic(axins, ax, data=img_hi_cmz_hires, loc1=4, edgecolor='w')

pl.savefig("HI4PI_CO_Dust_withATLASGALOrangetransparent_cmzbox_insetzoom.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(2,1,2, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=5, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=orange_transparent)

#cmzrect = regions.RectangleSkyRegion(
#    coordinates.SkyCoord(0*u.deg, 0*u.deg, frame='galactic'),
#    width=12*u.deg,
#    height=4.8*u.deg,
#)
#pcmzrect = cmzrect.to_pixel(ax.wcs)
#pcmzrect.visual['edgecolor'] = 'w'
#pcmzrect.plot(ax=ax)

rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=4e1, stretch='linear')(np.nan_to_num(img_hi_cmz_hires)),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=4e1, stretch='asinh')(np.nan_to_num(img_co_cmz_hires)),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=4e1, stretch='log')(np.nan_to_num(img_agal_cmz_hires))]).T.swapaxes(0,1)
hsv = rgb_to_hsv(np.nan_to_num(rgb))
hsv[:,:,0] += -0.35#.45  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

axins = inset_axes(ax,
                   width=4, height=4,
                   bbox_to_anchor=[0, 0.25, 1, 0.5],
                   bbox_transform=fig.transFigure,
                   loc='lower center',
                   axes_class=astropy.visualization.wcsaxes.core.WCSAxes,
                   axes_kwargs=dict(wcs=WCS(target_header_cmz_hires)))
axins.imshow(rgb_scaled)
axins.coords['glat'].set_ticklabel(visible=False)
axins.coords['glon'].set_ticklabel(visible=False)
axins.coords['glat'].set_ticks_visible(False)
axins.coords['glon'].set_ticks_visible(False)

mark_inset_generic(axins, ax, data=img_hi_cmz_hires, loc1=4, edgecolor='w')

pl.savefig("HI4PI_CO_Dust_withATLASGALOrangetransparent_cmzbox_insetzoom.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(2,1,2, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
#ax.set_xlim(240*2, 720*2)
ax.set_xlim(0, 1920)
ax.set_ylim(120*2, 360*2)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=5, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=orange_transparent)

#cmzrect = regions.RectangleSkyRegion(
#    coordinates.SkyCoord(0*u.deg, 0*u.deg, frame='galactic'),
#    width=12*u.deg,
#    height=4.8*u.deg,
#)
#pcmzrect = cmzrect.to_pixel(ax.wcs)
#pcmzrect.visual['edgecolor'] = 'w'
#pcmzrect.plot(ax=ax)

rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=4e1, stretch='linear')(np.nan_to_num(img_hi_cmz_hires)),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=4e1, stretch='asinh')(np.nan_to_num(img_co_cmz_hires)),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=4e1, stretch='log')(np.nan_to_num(img_agal_cmz_hires))]).T.swapaxes(0,1)
hsv = rgb_to_hsv(np.nan_to_num(rgb))
hsv[:,:,0] += -0.35#.45  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

axins = inset_axes(ax,
                   width=4, height=4,
                   bbox_to_anchor=[0, 0.25, 1, 0.5],
                   bbox_transform=fig.transFigure,
                   loc='lower center',
                   axes_class=astropy.visualization.wcsaxes.core.WCSAxes,
                   axes_kwargs=dict(wcs=WCS(target_header_cmz_hires)))
axins.imshow(rgb_scaled)
axins.coords['glat'].set_ticklabel(visible=False)
axins.coords['glon'].set_ticklabel(visible=False)
axins.coords['glat'].set_ticks_visible(False)
axins.coords['glon'].set_ticks_visible(False)

mark_inset_generic(axins, ax, data=img_hi_cmz_hires, loc1=4, edgecolor='w')

pl.savefig("HI4PI_CO_Dust_withATLASGALOrangetransparent_cmzbox_insetzoom.png", bbox_inches='tight')
import PIL
import pyavm
rgb = PIL.open('gc_fullres_6.jpg')
avm = pyavm.AVM('gc_fullres_6.jpg')
wwavm = avm.celestial
rgb = PIL.Image.open('gc_fullres_6.jpg')
avm = pyavm.AVM('gc_fullres_6.jpg')
wwavm = avm.celestial
rgb = PIL.Image.open('gc_fullres_6.jpg')
avm = pyavm.AVM.from_image('gc_fullres_6.jpg')
wwavm = avm.wcs
rgb = PIL.Image.open('gc_fullres_6.jpg')
avm = pyavm.AVM.from_image('gc_fullres_6.jpg')
wwavm = avm.to_wcs()
ww = WCS('gc_fullres_6.wcs')
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=4e1, stretch='linear')(np.nan_to_num(img_hi_cmz_hires)),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=4e1, stretch='asinh')(np.nan_to_num(img_co_cmz_hires)),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=4e1, stretch='log')(np.nan_to_num(img_agal_cmz_hires))]).T.swapaxes(0,1)
hsv = rgb_to_hsv(np.nan_to_num(rgb))
hsv[:,:,0] += -0.35
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(2,1,1, projection=WCS(target_header_cmz_hires),)
ax.imshow(rgb_scaled)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)


rgb = PIL.Image.open('gc_fullres_6.jpg')
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

axins = inset_axes(ax,
                   width=4, height=4,
                   bbox_to_anchor=[0, 0.25, 1, 0.5],
                   bbox_transform=fig.transFigure,
                   loc='lower center',
                   axes_class=astropy.visualization.wcsaxes.core.WCSAxes,
                   axes_kwargs=dict(wcs=ww))
axins.imshow(rgb)
axins.coords['glat'].set_ticklabel(visible=False)
axins.coords['glon'].set_ticklabel(visible=False)
axins.coords['glat'].set_ticks_visible(False)
axins.coords['glon'].set_ticks_visible(False)

mark_inset_generic(axins, ax, data=rgb[:,:,0], loc1=4, edgecolor='w')

pl.savefig("HI4PI_CO_Dust_withATLASGALOrangetransparent_cmzbox_insetzoom.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=4e1, stretch='linear')(np.nan_to_num(img_hi_cmz_hires)),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=4e1, stretch='asinh')(np.nan_to_num(img_co_cmz_hires)),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=4e1, stretch='log')(np.nan_to_num(img_agal_cmz_hires))]).T.swapaxes(0,1)
hsv = rgb_to_hsv(np.nan_to_num(rgb))
hsv[:,:,0] += -0.35
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(2,1,1, projection=WCS(target_header_cmz_hires),)
ax.imshow(rgb_scaled)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)


rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

axins = inset_axes(ax,
                   width=4, height=4,
                   bbox_to_anchor=[0, 0.25, 1, 0.5],
                   bbox_transform=fig.transFigure,
                   loc='lower center',
                   axes_class=astropy.visualization.wcsaxes.core.WCSAxes,
                   axes_kwargs=dict(wcs=ww))
axins.imshow(rgb)
axins.coords['glat'].set_ticklabel(visible=False)
axins.coords['glon'].set_ticklabel(visible=False)
axins.coords['glat'].set_ticks_visible(False)
axins.coords['glon'].set_ticks_visible(False)

mark_inset_generic(axins, ax, data=rgb[:,:,0], loc1=4, edgecolor='w')

pl.savefig("HI4PI_CO_Dust_withATLASGALOrangetransparent_cmzbox_insetzoom.png", bbox_inches='tight')
np.array(PIL.Image.open('gc_fullres_6.jpg')).shape
#[Out]# (3295, 6473, 3)
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=4e1, stretch='linear')(np.nan_to_num(img_hi_cmz_hires)),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=4e1, stretch='asinh')(np.nan_to_num(img_co_cmz_hires)),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=4e1, stretch='log')(np.nan_to_num(img_agal_cmz_hires))]).T.swapaxes(0,1)
hsv = rgb_to_hsv(np.nan_to_num(rgb))
hsv[:,:,0] += -0.35
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(2,1,1, projection=WCS(target_header_cmz_hires),)
ax.imshow(rgb_scaled)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)


rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

axins = inset_axes(ax,
                   width=4, height=4,
                   bbox_to_anchor=[0, 0, 1, 0.5],
                   bbox_transform=fig.transFigure,
                   loc='lower center',
                   axes_class=astropy.visualization.wcsaxes.core.WCSAxes,
                   axes_kwargs=dict(wcs=ww))
axins.imshow(rgb)
axins.coords['glat'].set_ticklabel(visible=False)
axins.coords['glon'].set_ticklabel(visible=False)
axins.coords['glat'].set_ticks_visible(False)
axins.coords['glon'].set_ticks_visible(False)

mark_inset_generic(axins, ax, data=rgb[:,:,0], loc2=2, edgecolor='w')

pl.savefig("HI4PI_CO_Dust_withATLASGALOrangetransparent_cmzbox_insetzoom.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=4e1, stretch='linear')(np.nan_to_num(img_hi_cmz_hires)),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=4e1, stretch='asinh')(np.nan_to_num(img_co_cmz_hires)),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=4e1, stretch='log')(np.nan_to_num(img_agal_cmz_hires))]).T.swapaxes(0,1)
hsv = rgb_to_hsv(np.nan_to_num(rgb))
hsv[:,:,0] += -0.35
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(2,1,1, projection=WCS(target_header_cmz_hires),)
ax.imshow(rgb_scaled)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)


rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

axins = inset_axes(ax,
                   width=4, height=4,
                   bbox_to_anchor=[0, 0.5, 1, 0.5],
                   bbox_transform=fig.transFigure,
                   loc='upper center',
                   axes_class=astropy.visualization.wcsaxes.core.WCSAxes,
                   axes_kwargs=dict(wcs=ww))
axins.imshow(rgb[::-1,:,:])
axins.coords['glat'].set_ticklabel(visible=False)
axins.coords['glon'].set_ticklabel(visible=False)
axins.coords['glat'].set_ticks_visible(False)
axins.coords['glon'].set_ticks_visible(False)

mark_inset_generic(axins, ax, data=rgb[:,:,0], loc2=2, edgecolor='w')

pl.savefig("HI4PI_CO_Dust_withATLASGALOrangetransparent_cmzbox_insetzoom.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=4e1, stretch='linear')(np.nan_to_num(img_hi_cmz_hires)),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=4e1, stretch='asinh')(np.nan_to_num(img_co_cmz_hires)),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=4e1, stretch='log')(np.nan_to_num(img_agal_cmz_hires))]).T.swapaxes(0,1)
hsv = rgb_to_hsv(np.nan_to_num(rgb))
hsv[:,:,0] += -0.35
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(2,1,1, projection=WCS(target_header_cmz_hires),)
ax.imshow(rgb_scaled)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)


rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

axins = inset_axes(ax,
                   width=4, height=4,
                   bbox_to_anchor=[0, -0.25, 1, 0.5],
                   bbox_transform=fig.transFigure,
                   loc='upper center',
                   axes_class=astropy.visualization.wcsaxes.core.WCSAxes,
                   axes_kwargs=dict(wcs=ww))
axins.imshow(rgb[::-1,:,:])
axins.coords['glat'].set_ticklabel(visible=False)
axins.coords['glon'].set_ticklabel(visible=False)
axins.coords['glat'].set_ticks_visible(False)
axins.coords['glon'].set_ticks_visible(False)

mark_inset_generic(axins, ax, data=rgb[:,:,0], loc2=2, edgecolor='w')

pl.savefig("HI-CO-Dust_zoominto3color.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_HI4PI_cmz,       min_percent=0.01, max_percent=99.99, log_a=1e1, stretch='log')(img_HI4PI_cmz),
                simple_norm(img_CO21_cmz,        min_percent=0.01, max_percent=99.99, log_a=3e1, stretch='log')(img_CO21_cmz),
                simple_norm(img_ThermalDust_cmz, min_percent=0.01, max_percent=99.99, log_a=5e2, stretch='log')(img_ThermalDust_cmz)]).T.swapaxes(0,1)
hsv = rgb_to_hsv(rgb)
hsv[:,:,0] += -0.35  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(2,1,2, projection=WCS(target_header_cmz),)
                 #frame_class=EllipticalFrame)
ax.imshow(rgb_scaled)
#ax.coords.grid(color='white')
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)
#ax.set_xlim(240*2, 720*2)
ax.set_xlim(0, 1920)
ax.set_ylim(120*2, 360*2)

ax.imshow(atlasgal[0].data,
          norm=simple_norm(atlasgal[0].data, min_percent=5, max_percent=99.9, stretch='asinh'),
          transform=ax.get_transform(WCS(atlasgal[0].header)),
          cmap=orange_transparent)

#cmzrect = regions.RectangleSkyRegion(
#    coordinates.SkyCoord(0*u.deg, 0*u.deg, frame='galactic'),
#    width=12*u.deg,
#    height=4.8*u.deg,
#)
#pcmzrect = cmzrect.to_pixel(ax.wcs)
#pcmzrect.visual['edgecolor'] = 'w'
#pcmzrect.plot(ax=ax)

rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=4e1, stretch='linear')(np.nan_to_num(img_hi_cmz_hires)),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=4e1, stretch='asinh')(np.nan_to_num(img_co_cmz_hires)),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=4e1, stretch='log')(np.nan_to_num(img_agal_cmz_hires))]).T.swapaxes(0,1)
hsv = rgb_to_hsv(np.nan_to_num(rgb))
hsv[:,:,0] += -0.35#.45  # 0.25 = 90/360
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

axins = inset_axes(ax,
                   width=4, height=4,
                   bbox_to_anchor=[0, 0.25, 1, 0.5],
                   bbox_transform=fig.transFigure,
                   loc='lower center',
                   axes_class=astropy.visualization.wcsaxes.core.WCSAxes,
                   axes_kwargs=dict(wcs=WCS(target_header_cmz_hires)))
axins.imshow(rgb_scaled)
axins.coords['glat'].set_ticklabel(visible=False)
axins.coords['glon'].set_ticklabel(visible=False)
axins.coords['glat'].set_ticks_visible(False)
axins.coords['glon'].set_ticks_visible(False)

mark_inset_generic(axins, ax, data=img_hi_cmz_hires, loc1=4, edgecolor='w')

pl.savefig("HI4PI_CO_Dust_withATLASGALOrangetransparent_cmzbox_insetzoom.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=4e1, stretch='linear')(np.nan_to_num(img_hi_cmz_hires)),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=4e1, stretch='asinh')(np.nan_to_num(img_co_cmz_hires)),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=4e1, stretch='log')(np.nan_to_num(img_agal_cmz_hires))]).T.swapaxes(0,1)
hsv = rgb_to_hsv(np.nan_to_num(rgb))
hsv[:,:,0] += -0.35
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(2,1,1, projection=WCS(target_header_cmz_hires),)
ax.imshow(rgb_scaled)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)


rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

axins = inset_axes(ax,
                   width=4, height=4,
                   bbox_to_anchor=[0, -0.05, 1, 0.5],
                   bbox_transform=fig.transFigure,
                   loc='upper center',
                   axes_class=astropy.visualization.wcsaxes.core.WCSAxes,
                   axes_kwargs=dict(wcs=ww))
axins.imshow(rgb[::-1,:,:])
axins.coords['glat'].set_ticklabel(visible=False)
axins.coords['glon'].set_ticklabel(visible=False)
axins.coords['glat'].set_ticks_visible(False)
axins.coords['glon'].set_ticks_visible(False)

mark_inset_generic(axins, ax, data=rgb[:,:,0], loc2=2, edgecolor='w')

pl.savefig("HI-CO-Dust_zoominto3color.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=4e1, stretch='linear')(np.nan_to_num(img_hi_cmz_hires)),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=4e1, stretch='asinh')(np.nan_to_num(img_co_cmz_hires)),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=4e1, stretch='log')(np.nan_to_num(img_agal_cmz_hires))]).T.swapaxes(0,1)
hsv = rgb_to_hsv(np.nan_to_num(rgb))
hsv[:,:,0] += -0.35
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(2,1,1, projection=WCS(target_header_cmz_hires),)
ax.imshow(rgb_scaled)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)


rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

axins = inset_axes(ax,
                   width=4, height=4,
                   bbox_to_anchor=[0, 0, 1, 0.5],
                   bbox_transform=fig.transFigure,
                   loc='upper center',
                   axes_class=astropy.visualization.wcsaxes.core.WCSAxes,
                   axes_kwargs=dict(wcs=ww))
axins.imshow(rgb[::-1,:,:])
axins.coords['glat'].set_ticklabel(visible=False)
axins.coords['glon'].set_ticklabel(visible=False)
axins.coords['glat'].set_ticks_visible(False)
axins.coords['glon'].set_ticks_visible(False)

mark_inset_generic(axins, ax, data=rgb[:,:,0], loc2=2, edgecolor='w')

pl.savefig("HI-CO-Dust_zoominto3color.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=4e1, stretch='linear')(np.nan_to_num(img_hi_cmz_hires)),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=4e1, stretch='asinh')(np.nan_to_num(img_co_cmz_hires)),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=4e1, stretch='log')(np.nan_to_num(img_agal_cmz_hires))]).T.swapaxes(0,1)
hsv = rgb_to_hsv(np.nan_to_num(rgb))
hsv[:,:,0] += -0.35
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(2,1,1, projection=WCS(target_header_cmz_hires),)
ax.imshow(rgb_scaled)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)


rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

axins = inset_axes(ax,
                   width=4, height=4,
                   bbox_to_anchor=[0, 0.2, 1, 0.5],
                   bbox_transform=fig.transFigure,
                   loc='upper center',
                   axes_class=astropy.visualization.wcsaxes.core.WCSAxes,
                   axes_kwargs=dict(wcs=ww))
axins.imshow(rgb[::-1,:,:])
axins.coords['glat'].set_ticklabel(visible=False)
axins.coords['glon'].set_ticklabel(visible=False)
axins.coords['glat'].set_ticks_visible(False)
axins.coords['glon'].set_ticks_visible(False)

mark_inset_generic(axins, ax, data=rgb[:,:,0], loc2=2, edgecolor='w')

pl.savefig("HI-CO-Dust_zoominto3color.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=4e1, stretch='linear')(np.nan_to_num(img_hi_cmz_hires)),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=4e1, stretch='asinh')(np.nan_to_num(img_co_cmz_hires)),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=4e1, stretch='log')(np.nan_to_num(img_agal_cmz_hires))]).T.swapaxes(0,1)
hsv = rgb_to_hsv(np.nan_to_num(rgb))
hsv[:,:,0] += -0.35
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(2,1,1, projection=WCS(target_header_cmz_hires),)
ax.imshow(rgb_scaled)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)


rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

axins = inset_axes(ax,
                   width=4, height=4,
                   bbox_to_anchor=[0.02, 0.2, 1, 0.5],
                   bbox_transform=fig.transFigure,
                   loc='upper center',
                   axes_class=astropy.visualization.wcsaxes.core.WCSAxes,
                   axes_kwargs=dict(wcs=ww))
axins.imshow(rgb[::-1,:,:])
axins.coords['glat'].set_ticklabel(visible=False)
axins.coords['glon'].set_ticklabel(visible=False)
axins.coords['glat'].set_ticks_visible(False)
axins.coords['glon'].set_ticks_visible(False)

mark_inset_generic(axins, ax, data=rgb[:,:,0], loc2=2, edgecolor='w')

pl.savefig("HI-CO-Dust_zoominto3color.png", bbox_inches='tight')
rgb = np.array([simple_norm(img_hi_cmz_hires,   min_percent=25, max_percent=99.99, log_a=4e1, stretch='linear')(np.nan_to_num(img_hi_cmz_hires)),
                simple_norm(img_co_cmz_hires,   min_percent=5, max_percent=99.99, log_a=4e1, stretch='asinh')(np.nan_to_num(img_co_cmz_hires)),
                simple_norm(img_agal_cmz_hires, min_percent=1, max_percent=99.99, log_a=4e1, stretch='log')(np.nan_to_num(img_agal_cmz_hires))]).T.swapaxes(0,1)
hsv = rgb_to_hsv(np.nan_to_num(rgb))
hsv[:,:,0] += -0.35
hsv[:,:,0] = hsv[:,:,0] % 1 
rgb_scaled = hsv_to_rgb(hsv)

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(2,1,1, projection=WCS(target_header_cmz_hires),)
ax.imshow(rgb_scaled)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)


rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

axins = inset_axes(ax,
                   width=4, height=4,
                   bbox_to_anchor=[0.01, 0.2, 1, 0.5],
                   bbox_transform=fig.transFigure,
                   loc='upper center',
                   axes_class=astropy.visualization.wcsaxes.core.WCSAxes,
                   axes_kwargs=dict(wcs=ww))
axins.imshow(rgb[::-1,:,:])
axins.coords['glat'].set_ticklabel(visible=False)
axins.coords['glon'].set_ticklabel(visible=False)
axins.coords['glat'].set_ticks_visible(False)
axins.coords['glon'].set_ticks_visible(False)

mark_inset_generic(axins, ax, data=rgb[:,:,0], loc2=2, edgecolor='w')

pl.savefig("HI-CO-Dust_zoominto3color.png", bbox_inches='tight')
# different colors, overwrites previous
rgb = np.array([simple_norm(img_HI4PI,       min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_HI4PI),
                simple_norm(img_CO21,        min_percent=0.01, max_percent=99.90, log_a=2e1, stretch='log')(img_CO21),
                simple_norm(img_ThermalDust, min_percent=0.01, max_percent=99.90, log_a=5e2, stretch='log')(img_ThermalDust)]).T.swapaxes(0,1)
ax = make_rgb(rgb, 'HI-CO-Dust_m0.35', -0.35, layernames=('HI', 'CO', 'Dust'), do_layers=False)
prect = rect.to_pixel(ax.wcs)
prect.visual['edgecolor'] = 'w'
prect.plot(ax=ax)

pl.savefig("HI-CO-Dust_m0.35_RGB_innergal_zoombox.png", bbox_inches='tight')

ax.text(0, 20, "Galactic Plane")
#[Out]# Text(0, 20, 'Galactic Plane')
# different colors, overwrites previous
rgb = np.array([simple_norm(img_HI4PI,       min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_HI4PI),
                simple_norm(img_CO21,        min_percent=0.01, max_percent=99.90, log_a=2e1, stretch='log')(img_CO21),
                simple_norm(img_ThermalDust, min_percent=0.01, max_percent=99.90, log_a=5e2, stretch='log')(img_ThermalDust)]).T.swapaxes(0,1)
ax = make_rgb(rgb, 'HI-CO-Dust_m0.35', -0.35, layernames=('HI', 'CO', 'Dust'), do_layers=False)
prect = rect.to_pixel(ax.wcs)
prect.visual['edgecolor'] = 'w'
prect.plot(ax=ax)

pl.savefig("HI-CO-Dust_m0.35_RGB_innergal_zoombox.png", bbox_inches='tight')

ax.text(0, 20, "Galactic Plane", transform=ax.get_transform('world'),
        color='w')
#[Out]# Text(0, 20, 'Galactic Plane')
# different colors, overwrites previous
rgb = np.array([simple_norm(img_HI4PI,       min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_HI4PI),
                simple_norm(img_CO21,        min_percent=0.01, max_percent=99.90, log_a=2e1, stretch='log')(img_CO21),
                simple_norm(img_ThermalDust, min_percent=0.01, max_percent=99.90, log_a=5e2, stretch='log')(img_ThermalDust)]).T.swapaxes(0,1)
ax = make_rgb(rgb, 'HI-CO-Dust_m0.35', -0.35, layernames=('HI', 'CO', 'Dust'), do_layers=False)
prect = rect.to_pixel(ax.wcs)
prect.visual['edgecolor'] = 'w'
prect.plot(ax=ax)

pl.savefig("HI-CO-Dust_m0.35_RGB_innergal_zoombox.png", bbox_inches='tight')

ax.text(0, 23, "Galactic Plane", transform=ax.get_transform('world'),
        color='w', horizontalalignment='center')
#[Out]# Text(0, 23, 'Galactic Plane')
# different colors, overwrites previous
rgb = np.array([simple_norm(img_HI4PI,       min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_HI4PI),
                simple_norm(img_CO21,        min_percent=0.01, max_percent=99.90, log_a=2e1, stretch='log')(img_CO21),
                simple_norm(img_ThermalDust, min_percent=0.01, max_percent=99.90, log_a=5e2, stretch='log')(img_ThermalDust)]).T.swapaxes(0,1)
ax = make_rgb(rgb, 'HI-CO-Dust_m0.35', -0.35, layernames=('HI', 'CO', 'Dust'), do_layers=False)
prect = rect.to_pixel(ax.wcs)
prect.visual['edgecolor'] = 'w'
prect.plot(ax=ax)

pl.savefig("HI-CO-Dust_m0.35_RGB_innergal_zoombox.png", bbox_inches='tight')

ax.text(0, 25, "Galactic Plane", transform=ax.get_transform('world'),
        color='w', horizontalalignment='center')

cmzrect = regions.RectangleSkyRegion(
    coordinates.SkyCoord(0*u.deg, 0*u.deg, frame='galactic'),
    width=12*u.deg,
    height=4.8*u.deg,
)
pcmzrect = cmzrect.to_pixel(ax.wcs)
pcmzrect.visual['edgecolor'] = 'w'
pcmzrect.plot(ax=ax)

ax.text(0, 5, "Central Molecular Zone", transform=ax.get_transform('world'),
        color='w', horizontalalignment='center')
#[Out]# Text(0, 5, 'Central Molecular Zone')
# different colors, overwrites previous
rgb = np.array([simple_norm(img_HI4PI,       min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_HI4PI),
                simple_norm(img_CO21,        min_percent=0.01, max_percent=99.90, log_a=2e1, stretch='log')(img_CO21),
                simple_norm(img_ThermalDust, min_percent=0.01, max_percent=99.90, log_a=5e2, stretch='log')(img_ThermalDust)]).T.swapaxes(0,1)
ax = make_rgb(rgb, 'HI-CO-Dust_m0.35', -0.35, layernames=('HI', 'CO', 'Dust'), do_layers=False)
prect = rect.to_pixel(ax.wcs)
prect.visual['edgecolor'] = 'w'
prect.plot(ax=ax)

pl.savefig("HI-CO-Dust_m0.35_RGB_innergal_zoombox.png", bbox_inches='tight')

ax.text(0, 25, "Galactic Plane", transform=ax.get_transform('world'),
        color='w', horizontalalignment='center')

cmzrect = regions.RectangleSkyRegion(
    coordinates.SkyCoord(0*u.deg, 0*u.deg, frame='galactic'),
    width=12*u.deg,
    height=4.8*u.deg,
)
pcmzrect = cmzrect.to_pixel(ax.wcs)
pcmzrect.visual['edgecolor'] = 'w'
pcmzrect.plot(ax=ax)

ax.text(0, 5, "Central Molecular Zone", transform=ax.get_transform('world'),
        color='w', horizontalalignment='center')


orionrect = regions.RectangleSkyRegion(
    coordinates.SkyCoord(209*u.deg, -19*u.deg, frame='galactic'),
    width=5*u.deg,
    height=5*u.deg,
)
porionrect = orionrect.to_pixel(ax.wcs)
porionrect.visual['edgecolor'] = 'w'
porionrect.plot(ax=ax)

ax.text(209, -19, "Orion", transform=ax.get_transform('world'),
        color='w', horizontalalignment='center')
#[Out]# Text(209, -19, 'Orion')
# different colors, overwrites previous
rgb = np.array([simple_norm(img_HI4PI,       min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_HI4PI),
                simple_norm(img_CO21,        min_percent=0.01, max_percent=99.90, log_a=2e1, stretch='log')(img_CO21),
                simple_norm(img_ThermalDust, min_percent=0.01, max_percent=99.90, log_a=5e2, stretch='log')(img_ThermalDust)]).T.swapaxes(0,1)
ax = make_rgb(rgb, 'HI-CO-Dust_m0.35', -0.35, layernames=('HI', 'CO', 'Dust'), do_layers=False)
prect = rect.to_pixel(ax.wcs)
prect.visual['edgecolor'] = 'w'
prect.plot(ax=ax)

pl.savefig("HI-CO-Dust_m0.35_RGB_innergal_zoombox.png", bbox_inches='tight')

ax.text(0, 25, "Galactic Plane", transform=ax.get_transform('world'),
        color='w', horizontalalignment='center')

cmzrect = regions.RectangleSkyRegion(
    coordinates.SkyCoord(0*u.deg, 0*u.deg, frame='galactic'),
    width=12*u.deg,
    height=4.8*u.deg,
)
pcmzrect = cmzrect.to_pixel(ax.wcs)
pcmzrect.visual['edgecolor'] = 'w'
pcmzrect.plot(ax=ax)

ax.text(0, 5, "Central Molecular Zone", transform=ax.get_transform('world'),
        color='w', horizontalalignment='center')


orionrect = regions.RectangleSkyRegion(
    coordinates.SkyCoord(209*u.deg, -19*u.deg, frame='galactic'),
    width=5*u.deg,
    height=5*u.deg,
)
porionrect = orionrect.to_pixel(ax.wcs)
porionrect.visual['edgecolor'] = 'w'
porionrect.plot(ax=ax)

ax.text(209, -15, "Orion", transform=ax.get_transform('world'),
        color='w', horizontalalignment='center')
#[Out]# Text(209, -15, 'Orion')
# different colors, overwrites previous
rgb = np.array([simple_norm(img_HI4PI,       min_percent=0.01, max_percent=99.99, log_a=2e1, stretch='log')(img_HI4PI),
                simple_norm(img_CO21,        min_percent=0.01, max_percent=99.90, log_a=2e1, stretch='log')(img_CO21),
                simple_norm(img_ThermalDust, min_percent=0.01, max_percent=99.90, log_a=5e2, stretch='log')(img_ThermalDust)]).T.swapaxes(0,1)
ax = make_rgb(rgb, 'HI-CO-Dust_m0.35', -0.35, layernames=('HI', 'CO', 'Dust'), do_layers=False)
prect = rect.to_pixel(ax.wcs)
prect.visual['edgecolor'] = 'w'
prect.plot(ax=ax)

pl.savefig("HI-CO-Dust_m0.35_RGB_innergal_zoombox.png", bbox_inches='tight')

ax.text(0, 25, "Galactic Plane", transform=ax.get_transform('world'),
        color='w', horizontalalignment='center')

cmzrect = regions.RectangleSkyRegion(
    coordinates.SkyCoord(0*u.deg, 0*u.deg, frame='galactic'),
    width=12*u.deg,
    height=4.8*u.deg,
)
pcmzrect = cmzrect.to_pixel(ax.wcs)
pcmzrect.visual['edgecolor'] = 'w'
pcmzrect.plot(ax=ax)

ax.text(0, 5, "Central Molecular Zone", transform=ax.get_transform('world'),
        color='w', horizontalalignment='center')


orionrect = regions.RectangleSkyRegion(
    coordinates.SkyCoord(209*u.deg, -19*u.deg, frame='galactic'),
    width=5*u.deg,
    height=5*u.deg,
)
porionrect = orionrect.to_pixel(ax.wcs)
porionrect.visual['edgecolor'] = 'w'
porionrect.plot(ax=ax)

ax.text(209, -15, "Orion", transform=ax.get_transform('world'),
        color='w', horizontalalignment='center')

pl.savefig("HI-CO-Dust_m0.35_RGB_labeled_zones.png", bbox_inches='tight')
rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=ww)
ax.imshow(rgb)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

aces = SpectralCube.read('/orange/adamginsburg/ACES/mosaics/7m_continuum_mosaic.fits')

ax.imshow(aces[0].value, norm=simple_norm(aces[0].value, ), cmap=orange_transparent)



#pl.savefig("gc_fullres_6_small_withACES.png", bbox_inches='tight')
rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=ww)
ax.imshow(rgb)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

aces7m = fits.open('/orange/adamginsburg/ACES/mosaics/7m_continuum_mosaic.fits')
aces7mw = WCS(aces7m[0].header)

ax.imshow(aces7m[0].data, transform=ax.get_transform(aces7mw), norm=simple_norm(aces7m[0].data, ), cmap=orange_transparent)

#pl.savefig("gc_fullres_6_small_withACES.png", bbox_inches='tight')
#[Out]# <matplotlib.image.AxesImage at 0x2b29592f29d0>
rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=ww)
ax.imshow(rgb)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

aces7m = fits.open('/orange/adamginsburg/ACES/mosaics/7m_continuum_mosaic.fits')
aces7mwcs = WCS(aces7m[0].header)

#ax.imshow(aces7m[0].data, transform=ax.get_transform(aces7mwcs),
#          norm=simple_norm(aces7m[0].data, ), cmap=orange_transparent)

#pl.savefig("gc_fullres_6_small_withACES.png", bbox_inches='tight')
rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))[::-1,:,:]
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=ww)
ax.imshow(rgb)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

aces7m = fits.open('/orange/adamginsburg/ACES/mosaics/7m_continuum_mosaic.fits')
aces7mwcs = WCS(aces7m[0].header)

ax.imshow(aces7m[0].data, transform=ax.get_transform(aces7mwcs),
          norm=simple_norm(aces7m[0].data, ), cmap=orange_transparent)

#pl.savefig("gc_fullres_6_small_withACES.png", bbox_inches='tight')
#[Out]# <matplotlib.image.AxesImage at 0x2b29593fd0a0>
rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))[::-1,:,:]
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=ww)
ax.imshow(rgb)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

aces7m = fits.open('/orange/adamginsburg/ACES/mosaics/7m_continuum_mosaic.fits')
aces7mwcs = WCS(aces7m[0].header)
aces7mrepr,_ = reproject.reproject_interp(aces7m, ww, output_footprint=rgb.shape[:2])
ax.imshow(aces7mrepr, 
          norm=simple_norm(aces7mrepr, ), cmap=orange_transparent)

#ax.imshow(aces7m[0].data, transform=ax.get_transform(aces7mwcs),
#          norm=simple_norm(aces7m[0].data, ), cmap=orange_transparent)

#pl.savefig("gc_fullres_6_small_withACES.png", bbox_inches='tight')
rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))[::-1,:,:]
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=ww)
ax.imshow(rgb)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

aces7m = fits.open('/orange/adamginsburg/ACES/mosaics/7m_continuum_mosaic.fits')
aces7mwcs = WCS(aces7m[0].header)
aces7mrepr,_ = reproject.reproject_interp(aces7m, ww, shape_out=rgb.shape[:2])
ax.imshow(aces7mrepr, 
          norm=simple_norm(aces7mrepr, ), cmap=orange_transparent)

#ax.imshow(aces7m[0].data, transform=ax.get_transform(aces7mwcs),
#          norm=simple_norm(aces7m[0].data, ), cmap=orange_transparent)

#pl.savefig("gc_fullres_6_small_withACES.png", bbox_inches='tight')
#[Out]# <matplotlib.image.AxesImage at 0x2b2958c7b970>
rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))[::-1,:,:]
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=ww)
ax.imshow(rgb)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

aces7m = fits.open('/orange/adamginsburg/ACES/mosaics/7m_continuum_mosaic.fits')
aces7mwcs = WCS(aces7m[0].header)
aces7mrepr,_ = reproject.reproject_interp(aces7m, ww, shape_out=rgb.shape[:2])
ax.imshow(aces7mrepr, 
          norm=simple_norm(aces7mrepr, stretch='log'), cmap='gray')

#ax.imshow(aces7m[0].data, transform=ax.get_transform(aces7mwcs),
#          norm=simple_norm(aces7m[0].data, ), cmap=orange_transparent)

#pl.savefig("gc_fullres_6_small_withACES.png", bbox_inches='tight')
#[Out]# <matplotlib.image.AxesImage at 0x2b2958c7b5b0>
rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))[::-1,:,:]
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=ww)
ax.imshow(rgb)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

aces7m = fits.open('/orange/adamginsburg/ACES/mosaics/7m_continuum_mosaic.fits')
aces7mwcs = WCS(aces7m[0].header)
aces7mrepr,_ = reproject.reproject_interp(aces7m, ww, shape_out=rgb.shape[:2])
ax.imshow(aces7mrepr, 
          norm=simple_norm(aces7mrepr, stretch='log', max_percent=99.9, min_percent=2),
          cmap='gray')
# doesn't work...
#ax.imshow(aces7m[0].data, transform=ax.get_transform(aces7mwcs),
#          norm=simple_norm(aces7m[0].data, ), cmap=orange_transparent)

#pl.savefig("gc_fullres_6_small_withACES.png", bbox_inches='tight')
#[Out]# <matplotlib.image.AxesImage at 0x2b29741fc910>
rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))[::-1,:,:]
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=ww)
ax.imshow(rgb)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

aces7m = fits.open('/orange/adamginsburg/ACES/mosaics/7m_continuum_mosaic.fits')
aces7mwcs = WCS(aces7m[0].header)
aces7mrepr,_ = reproject.reproject_interp(aces7m, ww, shape_out=rgb.shape[:2])
ax.imshow(aces7mrepr, 
          norm=simple_norm(aces7mrepr, stretch='log', max_percent=99.96, min_percent=5),
          cmap='gray')
# doesn't work...
#ax.imshow(aces7m[0].data, transform=ax.get_transform(aces7mwcs),
#          norm=simple_norm(aces7m[0].data, ), cmap=orange_transparent)

#pl.savefig("gc_fullres_6_small_withACES.png", bbox_inches='tight')
#[Out]# <matplotlib.image.AxesImage at 0x2b29595593a0>
rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))[::-1,:,:]
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=ww)
ax.imshow(rgb)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

aces7m = fits.open('/orange/adamginsburg/ACES/mosaics/7m_continuum_mosaic.fits')
aces7mwcs = WCS(aces7m[0].header)
aces7mrepr,_ = reproject.reproject_interp(aces7m, ww, shape_out=rgb.shape[:2])
ax.imshow(aces7mrepr, 
          norm=simple_norm(aces7mrepr, stretch='log', max_percent=99.96, min_percent=5),
          cmap=orange_transparent)
# doesn't work...
#ax.imshow(aces7m[0].data, transform=ax.get_transform(aces7mwcs),
#          norm=simple_norm(aces7m[0].data, ), cmap=orange_transparent)

#pl.savefig("gc_fullres_6_small_withACES.png", bbox_inches='tight')
#[Out]# <matplotlib.image.AxesImage at 0x2b297424cd90>
rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))[::-1,:,:]
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=ww)
ax.imshow(rgb)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

aces7m = fits.open('/orange/adamginsburg/ACES/mosaics/7m_continuum_mosaic.fits')
aces7mwcs = WCS(aces7m[0].header)
aces7mrepr,_ = reproject.reproject_interp(aces7m, ww, shape_out=rgb.shape[:2])
ax.imshow(aces7mrepr, 
          norm=simple_norm(aces7mrepr, stretch='log', max_percent=99.96, min_cut=1e-5),
          cmap=orange_transparent)
# doesn't work...
#ax.imshow(aces7m[0].data, transform=ax.get_transform(aces7mwcs),
#          norm=simple_norm(aces7m[0].data, ), cmap=orange_transparent)

#pl.savefig("gc_fullres_6_small_withACES.png", bbox_inches='tight')
#[Out]# <matplotlib.image.AxesImage at 0x2b29740f0af0>
rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))[::-1,:,:]
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=ww)
ax.imshow(rgb)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

aces7m = fits.open('/orange/adamginsburg/ACES/mosaics/7m_continuum_mosaic.fits')
aces7mwcs = WCS(aces7m[0].header)
aces7mrepr,_ = reproject.reproject_interp(aces7m, ww, shape_out=rgb.shape[:2])
aces7mrepr[aces7mrepr < 0] = np.nan
ax.imshow(aces7mrepr, 
          norm=simple_norm(aces7mrepr, stretch='log', max_percent=99.96, min_percent=1),
          cmap=orange_transparent)
# doesn't work...
#ax.imshow(aces7m[0].data, transform=ax.get_transform(aces7mwcs),
#          norm=simple_norm(aces7m[0].data, ), cmap=orange_transparent)

#pl.savefig("gc_fullres_6_small_withACES.png", bbox_inches='tight')
#[Out]# <matplotlib.image.AxesImage at 0x2b2974017cd0>
from astropy.stats import mad_std
mad_std(aces7m[0].data)
#[Out]# nan
from astropy.stats import mad_std
mad_std(aces7m[0].data, ignore_nan=True)
#[Out]# 0.0019418525725530408
rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))[::-1,:,:]
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=ww)
ax.imshow(rgb)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

aces12m = fits.open('/orange/adamginsburg/ACES/mosaics/12m_continuum_mosaic.fits')
aces12mwcs = WCS(aces12m[0].header)
aces12mrepr,_ = reproject.reproject_interp(aces12m, ww, shape_out=rgb.shape[:2])
aces12mrepr[aces12mrepr < 0] = np.nan
ax.imshow(aces12mrepr, 
          norm=simple_norm(aces12mrepr, stretch='log', max_percent=99.96, min_percent=1),
          cmap=orange_transparent)
pl.savefig("gc_fullres_6_small_withACES12m.png", bbox_inches='tight')
pl.imshow(aces12mrepr)
#[Out]# <matplotlib.image.AxesImage at 0x2b297441a940>
pl.imshow(aces12m[0].data)
#[Out]# <matplotlib.image.AxesImage at 0x2b297447ba60>
pl.imshow(aces12m[0].data, norm=simple_norm(aces12m[0].data, stretch='log', min_percent=1, max_percent=99))
pl.colorbar()
#[Out]# <matplotlib.colorbar.Colorbar at 0x2b297450ec10>
pl.imshow(aces12m[0].data, norm=simple_norm(aces12m[0].data, stretch='log', min_percent=6, max_percent=99))
pl.colorbar()
#[Out]# <matplotlib.colorbar.Colorbar at 0x2b2959211070>
pl.imshow(aces12mrepr, norm=simple_norm(aces12mrepr, stretch='log', min_percent=6, max_percent=99))
pl.colorbar()
#[Out]# <matplotlib.colorbar.Colorbar at 0x2b2958bdb5e0>
pl.imshow(aces12mrepr, norm=simple_norm(aces12mrepr, stretch='log',))# min_percent=6, max_percent=99))
pl.colorbar()
#[Out]# <matplotlib.colorbar.Colorbar at 0x2b2958a6ed90>
aces12mrepr[np.isfinite(aces12mrepr)]
#[Out]# array([1.05734143e-04, 2.30151964e-05, 3.94036547e-05, ...,
#[Out]#        3.01893825e-04, 2.15735682e-04, 2.65184245e-04])
pl.hist(aces12mrepr[np.isfinite(aces12mrepr)])
#[Out]# (array([1.406409e+06, 2.200000e+01, 5.000000e+00, 0.000000e+00,
#[Out]#         1.000000e+00, 1.000000e+00, 0.000000e+00, 0.000000e+00,
#[Out]#         1.000000e+00, 1.000000e+00]),
#[Out]#  array([1.25515907e-10, 2.87554229e-01, 5.75108457e-01, 8.62662686e-01,
#[Out]#         1.15021691e+00, 1.43777114e+00, 1.72532537e+00, 2.01287960e+00,
#[Out]#         2.30043383e+00, 2.58798806e+00, 2.87554229e+00]),
#[Out]#  <BarContainer object of 10 artists>)
pl.imshow(aces12mrepr)#, norm=simple_norm(aces12mrepr, stretch='log',))# min_percent=6, max_percent=99))
pl.colorbar()
#[Out]# <matplotlib.colorbar.Colorbar at 0x2b295684ea00>
rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))[::-1,:,:]
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=ww)
ax.imshow(rgb)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

aces12m = fits.open('/orange/adamginsburg/ACES/mosaics/12m_continuum_mosaic.fits')
aces12mwcs = WCS(aces12m[0].header)
aces12mrepr,_ = reproject.reproject_interp(aces12m, ww, shape_out=rgb.shape[:2])
#aces12mrepr[aces12mrepr < 0] = np.nan
ax.imshow(aces12mrepr, 
          norm=simple_norm(aces12mrepr, stretch='log', max_percent=99.96, min_percent=1),
          cmap=orange_transparent)
pl.savefig("gc_fullres_6_small_withACES12m.png", bbox_inches='tight')
pl.imshow(aces12m[0].data, norm=simple_norm(aces12m[0].data, stretch='log', min_percent=6, max_percent=99))
pl.colorbar()
#[Out]# <matplotlib.colorbar.Colorbar at 0x2b2957b49370>
pl.imshow(aces12mrepr)#, norm=simple_norm(aces12mrepr, stretch='log',))# min_percent=6, max_percent=99))
pl.colorbar()
#[Out]# <matplotlib.colorbar.Colorbar at 0x2b2957e8a070>
pl.imshow(aces12mrepr < 0)#, norm=simple_norm(aces12mrepr, stretch='log',))# min_percent=6, max_percent=99))
pl.colorbar()
#[Out]# <matplotlib.colorbar.Colorbar at 0x2b2957a71130>
aces12mrepr < 0
#[Out]# array([[False, False, False, ..., False, False, False],
#[Out]#        [False, False, False, ..., False, False, False],
#[Out]#        [False, False, False, ..., False, False, False],
#[Out]#        ...,
#[Out]#        [False, False, False, ..., False, False, False],
#[Out]#        [False, False, False, ..., False, False, False],
#[Out]#        [False, False, False, ..., False, False, False]])
pl.imshow(aces12mrepr < 0)#, norm=simple_norm(aces12mrepr, stretch='log',))# min_percent=6, max_percent=99))
pl.colorbar()
#[Out]# <matplotlib.colorbar.Colorbar at 0x2b2957a80c70>
pl.clf()
pl.imshow(aces12mrepr < 0)#, norm=simple_norm(aces12mrepr, stretch='log',))# min_percent=6, max_percent=99))
pl.colorbar()
#[Out]# <matplotlib.colorbar.Colorbar at 0x2b29587417f0>
pl.figure(figsize=(20,10))
pl.imshow(aces12mrepr < 0)#, norm=simple_norm(aces12mrepr, stretch='log',))# min_percent=6, max_percent=99))
pl.colorbar()
#[Out]# <matplotlib.colorbar.Colorbar at 0x2b2958f38e80>
pl.figure(figsize=(20,10))
pl.imshow(aces12mrepr[1000:2500,2000:6000] < 0)#, norm=simple_norm(aces12mrepr, stretch='log',))# min_percent=6, max_percent=99))
pl.colorbar()
#[Out]# <matplotlib.colorbar.Colorbar at 0x2b2959929310>
pl.figure(figsize=(20,10))
pl.imshow(aces12mrepr[1000:2500,4000:6000] < 0)#, norm=simple_norm(aces12mrepr, stretch='log',))# min_percent=6, max_percent=99))
pl.colorbar()
#[Out]# <matplotlib.colorbar.Colorbar at 0x2b2973dee4f0>
pl.figure(figsize=(20,10))
pl.imshow(aces12mrepr[1500:1750,5000:1250] < 0)#, norm=simple_norm(aces12mrepr, stretch='log',))# min_percent=6, max_percent=99))
pl.colorbar()
#[Out]# <matplotlib.colorbar.Colorbar at 0x2b2959a3fa00>
pl.figure(figsize=(20,10))
pl.imshow(aces12mrepr[1500:1750,5000:6250] < 0)#, norm=simple_norm(aces12mrepr, stretch='log',))# min_percent=6, max_percent=99))
pl.colorbar()
#[Out]# <matplotlib.colorbar.Colorbar at 0x2b2973f886d0>
pl.figure(figsize=(20,10))
pl.imshow(aces12mrepr[1500:1750,5000:5250] < 0)#, norm=simple_norm(aces12mrepr, stretch='log',))# min_percent=6, max_percent=99))
pl.colorbar()
#[Out]# <matplotlib.colorbar.Colorbar at 0x2b29745979a0>
pl.figure(figsize=(20,10))
pl.imshow(aces12mrepr < 0)#, norm=simple_norm(aces12mrepr, stretch='log',))# min_percent=6, max_percent=99))
pl.colorbar()
#[Out]# <matplotlib.colorbar.Colorbar at 0x2b2959a925e0>
pl.figure(figsize=(20,10))
pl.imshow(aces12mrepr > 0)#, norm=simple_norm(aces12mrepr, stretch='log',))# min_percent=6, max_percent=99))
pl.colorbar()
#[Out]# <matplotlib.colorbar.Colorbar at 0x2b2974629070>
from astropy.stats import mad_std
mad_std(aces7m[0].data, ignore_nan=True)
mad_std(aces12m[0].data, ignore_nan=True)
#[Out]# 0.00015146579420586426
pl.figure(figsize=(20,10))
pl.imshow(aces12mrepr > 1e-4)#, norm=simple_norm(aces12mrepr, stretch='log',))# min_percent=6, max_percent=99))
pl.colorbar()
#[Out]# <matplotlib.colorbar.Colorbar at 0x2b29746d4b50>
pl.figure(figsize=(20,10))
pl.imshow(aces12mrepr > 2e-4)#, norm=simple_norm(aces12mrepr, stretch='log',))# min_percent=6, max_percent=99))
pl.colorbar()
#[Out]# <matplotlib.colorbar.Colorbar at 0x2b297478caf0>
pl.figure(figsize=(20,10))
pl.imshow(aces12mrepr > 3e-4)#, norm=simple_norm(aces12mrepr, stretch='log',))# min_percent=6, max_percent=99))
pl.colorbar()
#[Out]# <matplotlib.colorbar.Colorbar at 0x2b2974841fd0>
rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))[::-1,:,:]
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=ww)
ax.imshow(rgb)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

aces12m = fits.open('/orange/adamginsburg/ACES/mosaics/12m_continuum_mosaic.fits')
aces12mwcs = WCS(aces12m[0].header)
aces12mrepr,_ = reproject.reproject_interp(aces12m, ww, shape_out=rgb.shape[:2])
aces12mrepr[aces12mrepr < 2e-4] = np.nan
ax.imshow(aces12mrepr, 
          norm=simple_norm(aces12mrepr, stretch='log', max_percent=99.96, min_percent=0.01),
          cmap=orange_transparent)
pl.savefig("gc_fullres_6_small_withACES12m.png", bbox_inches='tight')
pl.imshow(aces12m[0].data, norm=simple_norm(aces12m[0].data, stretch='log',             min_percent=None,
            max_percent=None,
            min_cut=-0.0005,
            max_cut=0.005,))
pl.colorbar()
#[Out]# <matplotlib.colorbar.Colorbar at 0x2b29749676a0>
aces12m[0].data[aces12m[0].data < -0.0005] = 0
pl.imshow(aces12m[0].data,
          norm=simple_norm(aces12m[0].data, stretch='log',
                           min_percent=None, max_percent=None,
                           min_cut=-0.0005, max_cut=0.005,),
         origin='lower')
pl.colorbar()
#[Out]# <matplotlib.colorbar.Colorbar at 0x2b2974a29af0>
rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))[::-1,:,:]
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=ww)
ax.imshow(rgb)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

aces12m = fits.open('/orange/adamginsburg/ACES/mosaics/12m_continuum_mosaic.fits')
aces12m[0].data[aces12m[0].data < -0.0005] = 0

aces12mwcs = WCS(aces12m[0].header)
aces12mrepr,_ = reproject.reproject_interp(aces12m, ww, shape_out=rgb.shape[:2])
aces12mrepr[aces12mrepr < 2e-4] = np.nan
ax.imshow(aces12mrepr, 
          norm=simple_norm(aces12mrepr, stretch='log', max_percent=99.96, min_percent=0.01),
          cmap=orange_transparent)
pl.savefig("gc_fullres_6_small_withACES12m.png", bbox_inches='tight')
rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))[::-1,:,:]
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(2,1,2, projection=ww)
ax.imshow(rgb)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

aces7m = fits.open('/orange/adamginsburg/ACES/mosaics/7m_continuum_mosaic.fits')
aces7mwcs = WCS(aces7m[0].header)
aces7mrepr,_ = reproject.reproject_interp(aces7m, ww, shape_out=rgb.shape[:2])
aces7mrepr[aces7mrepr < 0] = np.nan
ax.imshow(aces7mrepr, 
          norm=simple_norm(aces7mrepr, stretch='log', max_percent=99.96, min_percent=1),
          cmap=orange_transparent)

aces12m = fits.open('/orange/adamginsburg/ACES/mosaics/12m_continuum_mosaic.fits')
aces12mwcs = WCS(aces12m[0].header)
aces12m[0].data[aces12m[0].data < -0.0005] = 0

axins = inset_axes(ax,
                   width=4, height=4,
                   bbox_to_anchor=[0.01, 0.5, 1, 0.5],
                   bbox_transform=fig.transFigure,
                   loc='upper center',
                   axes_class=astropy.visualization.wcsaxes.core.WCSAxes,
                   axes_kwargs=dict(wcs=aces12mwcs))
axins.imshow(aces12m[0].data,
             norm=simple_norm(aces12m[0].data, stretch='log',
                              min_percent=None, max_percent=None,
                              min_cut=-0.0005, max_cut=0.005,),
            )

axins.coords['glat'].set_ticklabel(visible=False)
axins.coords['glon'].set_ticklabel(visible=False)
axins.coords['glat'].set_ticks_visible(False)
axins.coords['glon'].set_ticks_visible(False)

mark_inset_generic(axins, ax, data=aces12m[0].data, loc2=2, edgecolor='w')


pl.savefig("gc_fullres_6_small_withACES7m_12minset.png", bbox_inches='tight')
rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))[::-1,:,:]
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=ww)
ax.imshow(rgb)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

aces12m = fits.open('/orange/adamginsburg/ACES/mosaics/12m_continuum_mosaic.fits')
aces12m[0].data[aces12m[0].data < -0.0005] = 0

aces12mwcs = WCS(aces12m[0].header)
aces12mrepr,_ = reproject.reproject_interp(aces12m, ww, shape_out=rgb.shape[:2])
aces12mrepr[aces12mrepr < 2e-4] = np.nan
ax.imshow(aces12mrepr, 
          norm=simple_norm(aces12mrepr, stretch='log', max_percent=99.5, min_percent=0.01),
          cmap=orange_transparent)
pl.savefig("gc_fullres_6_small_withACES12m.png", bbox_inches='tight')
rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))[::-1,:,:]
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(2,1,2, projection=ww)
ax.imshow(rgb)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

aces7m = fits.open('/orange/adamginsburg/ACES/mosaics/7m_continuum_mosaic.fits')
aces7mwcs = WCS(aces7m[0].header)
aces7mrepr,_ = reproject.reproject_interp(aces7m, ww, shape_out=rgb.shape[:2])
aces7mrepr[aces7mrepr < 0] = np.nan
ax.imshow(aces7mrepr, 
          norm=simple_norm(aces7mrepr, stretch='log', max_percent=99.96, min_percent=1),
          cmap=orange_transparent)

aces12m = fits.open('/orange/adamginsburg/ACES/mosaics/12m_continuum_mosaic.fits')
aces12mwcs = WCS(aces12m[0].header)
aces12m[0].data[aces12m[0].data < -0.0005] = 0

axins = inset_axes(ax,
                   width=4, height=4,
                   bbox_to_anchor=[0.01, 0.5, 1, 0.5],
                   bbox_transform=fig.transFigure,
                   loc='upper center',
                   axes_class=astropy.visualization.wcsaxes.core.WCSAxes,
                   axes_kwargs=dict(wcs=aces12mwcs))
axins.imshow(aces12m[0].data,
             norm=simple_norm(aces12m[0].data, stretch='log',
                              min_percent=None, max_percent=None,
                              min_cut=-0.0005, max_cut=0.005,),
             cmap='gray',
            )

axins.coords['glat'].set_ticklabel(visible=False)
axins.coords['glon'].set_ticklabel(visible=False)
axins.coords['glat'].set_ticks_visible(False)
axins.coords['glon'].set_ticks_visible(False)

mark_inset_generic(axins, ax, data=aces12m[0].data, loc1=4, edgecolor='w')


pl.savefig("gc_fullres_6_small_withACES7m_12minset.png", bbox_inches='tight')
pl.imshow(aces12mrepr)#, norm=simple_norm(aces12mrepr, stretch='log',))# min_percent=6, max_percent=99))
pl.colorbar()
#[Out]# <matplotlib.colorbar.Colorbar at 0x2b2974c5f9d0>
pl.imshow(aces12mrepr, origin='lower', norm=simple_norm(aces12mrepr, stretch='log',))# min_percent=6, max_percent=99))
pl.colorbar()
#[Out]# <matplotlib.colorbar.Colorbar at 0x2b2974e3efd0>
rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))[::-1,:,:]
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=ww)
ax.imshow(rgb)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

aces12m = fits.open('/orange/adamginsburg/ACES/mosaics/12m_continuum_mosaic.fits')
aces12m[0].data[aces12m[0].data < -0.0005] = 0

aces12mwcs = WCS(aces12m[0].header)
aces12mrepr,_ = reproject.reproject_interp(aces12m, ww, shape_out=rgb.shape[:2])
aces12mrepr[aces12mrepr < -5e-4] = 0
ax.imshow(aces12mrepr, 
          norm=simple_norm(aces12mrepr, stretch='log', max_percent=99.5, min_percent=0.01),
          cmap=orange_transparent)
pl.savefig("gc_fullres_6_small_withACES12m.png", bbox_inches='tight')
pl.imshow(aces12mrepr, origin='lower', norm=simple_norm(aces12mrepr, stretch='log',))# min_percent=6, max_percent=99))
pl.colorbar()
#[Out]# <matplotlib.colorbar.Colorbar at 0x2b2974f6feb0>
rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))[::-1,:,:]
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(2,1,2, projection=ww)
ax.imshow(rgb)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

aces7m = fits.open('/orange/adamginsburg/ACES/mosaics/7m_continuum_mosaic.fits')
aces7mwcs = WCS(aces7m[0].header)
aces7mrepr,_ = reproject.reproject_interp(aces7m, ww, shape_out=rgb.shape[:2])
aces7mrepr[aces7mrepr < 0] = np.nan
ax.imshow(aces7mrepr, 
          norm=simple_norm(aces7mrepr, stretch='log', max_percent=99.96, min_percent=1),
          cmap=orange_transparent)

aces12m = fits.open('/orange/adamginsburg/ACES/mosaics/12m_continuum_mosaic.fits')
aces12mwcs = WCS(aces12m[0].header)
aces12m[0].data[aces12m[0].data < -0.0005] = 0

axins = inset_axes(ax,
                   width=4, height=4,
                   bbox_to_anchor=[0.01, 0.5, 1, 0.5],
                   bbox_transform=fig.transFigure,
                   loc='upper center',
                   axes_class=astropy.visualization.wcsaxes.core.WCSAxes,
                   axes_kwargs=dict(wcs=aces12mwcs))
axins.imshow(aces12m[0].data,
             norm=simple_norm(aces12m[0].data, stretch='log',
                              min_percent=None, max_percent=None,
                              min_cut=-0.0005, max_cut=0.05,),
             cmap='gray',
            )

axins.coords['glat'].set_ticklabel(visible=False)
axins.coords['glon'].set_ticklabel(visible=False)
axins.coords['glat'].set_ticks_visible(False)
axins.coords['glon'].set_ticks_visible(False)

mark_inset_generic(axins, ax, data=aces12m[0].data, loc1=4, edgecolor='w')


pl.savefig("gc_fullres_6_small_withACES7m_12minset.png", bbox_inches='tight')
pl.imshow(aces12mrepr, origin='lower', norm=simple_norm(aces12mrepr, stretch='log', min_percent=6, max_percent=99))
pl.colorbar()
#[Out]# <matplotlib.colorbar.Colorbar at 0x2b2975110910>
rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))[::-1,:,:]
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=ww)
ax.imshow(rgb)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

aces12m = fits.open('/orange/adamginsburg/ACES/mosaics/12m_continuum_mosaic.fits')
aces12m[0].data[aces12m[0].data < -0.0005] = 0

aces12mwcs = WCS(aces12m[0].header)
aces12mrepr,_ = reproject.reproject_interp(aces12m, ww, shape_out=rgb.shape[:2])
aces12mrepr[aces12mrepr < -5e-4] = 0
ax.imshow(aces12mrepr, 
          norm=simple_norm(aces12mrepr, stretch='log', max_percent=99.5, min_cut=1e-4),
          cmap=orange_transparent)
pl.savefig("gc_fullres_6_small_withACES12m.png", bbox_inches='tight')
rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))[::-1,:,:]
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(2,1,2, projection=ww)
ax.imshow(rgb)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

aces7m = fits.open('/orange/adamginsburg/ACES/mosaics/7m_continuum_mosaic.fits')
aces7mwcs = WCS(aces7m[0].header)
aces7mrepr,_ = reproject.reproject_interp(aces7m, ww, shape_out=rgb.shape[:2])
aces7mrepr[aces7mrepr < 0] = np.nan
ax.imshow(aces7mrepr, 
          norm=simple_norm(aces7mrepr, stretch='log', max_percent=99.96, min_percent=1),
          cmap=orange_transparent)

aces12m = fits.open('/orange/adamginsburg/ACES/mosaics/12m_continuum_mosaic.fits')
aces12mwcs = WCS(aces12m[0].header)
aces12m[0].data[aces12m[0].data < -0.0005] = 0

axins = inset_axes(ax,
                   width=4, height=4,
                   bbox_to_anchor=[0.01, 0.5, 1, 0.5],
                   bbox_transform=fig.transFigure,
                   loc='upper center',
                   axes_class=astropy.visualization.wcsaxes.core.WCSAxes,
                   axes_kwargs=dict(wcs=aces12mwcs))
axins.imshow(aces12m[0].data,
             norm=simple_norm(aces12m[0].data, stretch='log',
                              min_percent=None, max_percent=None,
                              min_cut=-0.0005, max_cut=0.05,),
             cmap='gray',
            )

axins.coords['glat'].set_ticklabel(visible=False)
axins.coords['glon'].set_ticklabel(visible=False)
axins.coords['glat'].set_ticks_visible(False)
axins.coords['glon'].set_ticks_visible(False)

mark_inset_generic(axins, ax, data=aces12m[0].data, loc1=4, edgecolor='y')


pl.savefig("gc_fullres_6_small_withACES7m_12minset.png", bbox_inches='tight')
pl.imshow(aces12mrepr, origin='lower', norm=simple_norm(aces12mrepr, stretch='log', min_cut=1e-4, max_percent=99.5))
pl.colorbar()
#[Out]# <matplotlib.colorbar.Colorbar at 0x2b297531aeb0>
orange_transparent.set_underer
orange_transparent.set_under
#[Out]# <bound method Colormap.set_under of <matplotlib.colors.ListedColormap object at 0x2b29406ff700>>
orange_transparent.get
orange_transparent.get_under()
#[Out]# array([1.        , 0.96078431, 0.92156863, 0.        ])
orange_transparent.get_under()
orange_transparent(0)
#[Out]# (1.0, 0.9607843137254902, 0.9215686274509803, 0.0)
orange_transparent.get_under(), orange_transparent(0)
#[Out]# (array([1.        , 0.96078431, 0.92156863, 0.        ]),
#[Out]#  (1.0, 0.9607843137254902, 0.9215686274509803, 0.0))
orange_transparent.get_under(), orange_transparent(0), orange_transparent(1)
#[Out]# (array([1.        , 0.96078431, 0.92156863, 0.        ]),
#[Out]#  (1.0, 0.9607843137254902, 0.9215686274509803, 0.0),
#[Out]#  (0.9998769703960015,
#[Out]#   0.9589388696655133,
#[Out]#   0.9180007689350249,
#[Out]#   0.00392156862745098))
orange_transparent.get_under(), orange_transparent(0), orange_transparent(256)
#[Out]# (array([1.        , 0.96078431, 0.92156863, 0.        ]),
#[Out]#  (1.0, 0.9607843137254902, 0.9215686274509803, 0.0),
#[Out]#  (0.4980392156862745, 0.15294117647058825, 0.01568627450980392, 1.0))
orange_transparent.get_under(), orange_transparent(0), orange_transparent(256), orange_transparent.get_bad()
#[Out]# (array([1.        , 0.96078431, 0.92156863, 0.        ]),
#[Out]#  (1.0, 0.9607843137254902, 0.9215686274509803, 0.0),
#[Out]#  (0.4980392156862745, 0.15294117647058825, 0.01568627450980392, 1.0),
#[Out]#  array([0., 0., 0., 0.]))
pl.imshow(aces12mrepr, 
          norm=simple_norm(aces12mrepr, stretch='log', max_percent=99.5, min_cut=1e-4),
          cmap=orange_transparent)
#[Out]# <matplotlib.image.AxesImage at 0x2b2975417670>
from matplotlib.colors import ListedColormap
cmap = pl.cm.gray
gray_transparent = cmap(np.arange(cmap.N))
gray_transparent[:,-1] = np.linspace(0, 1, cmap.N)
gray_transparent = ListedColormap(gray_transparent)
cmap = pl.cm.Oranges
orange_transparent = cmap(np.arange(cmap.N))
orange_transparent[:,-1] = np.linspace(0, 1, cmap.N)
orange_transparent = ListedColormap(orange_transparent)

cmap = pl.cm.Oranges_r
orange_transparent_r = cmap(np.arange(cmap.N))
orange_transparent_r[:,-1] = np.linspace(0, 1, cmap.N)
orange_transparent_r = ListedColormap(orange_transparent_r)
pl.imshow(aces12mrepr, 
          norm=simple_norm(aces12mrepr, stretch='log', max_percent=99.5, min_cut=1e-4),
          cmap=orange_transparent_r)
#[Out]# <matplotlib.image.AxesImage at 0x2b2975095e80>
pl.imshow(aces12mrepr, 
          cmap=orange_transparent_r)
#[Out]# <matplotlib.image.AxesImage at 0x2b2974f26ca0>
pl.imshow(aces12mrepr, 
          norm=simple_norm(aces12mrepr, stretch='log', max_percent=99.5, min_cut=-1e-4),
          cmap=orange_transparent_r)
#[Out]# <matplotlib.image.AxesImage at 0x2b2974d11c40>
pl.imshow(aces12mrepr, 
          norm=simple_norm(aces12mrepr, stretch='log', max_percent=99.5, min_cut=1e-3),
          cmap=orange_transparent_r)
#[Out]# <matplotlib.image.AxesImage at 0x2b2974afbdc0>
pl.imshow(aces12mrepr, 
          norm=simple_norm(aces12mrepr, stretch='log', max_percent=99.5, min_cut=1e-5),
          cmap=orange_transparent_r)
#[Out]# <matplotlib.image.AxesImage at 0x2b29748bfd60>
pl.imshow(aces12mrepr, 
          norm=simple_norm(aces12mrepr, stretch='log', max_percent=99.5, min_cut=1e-1),
          cmap=orange_transparent_r)
#[Out]# <matplotlib.image.AxesImage at 0x2b2954031ee0>
pl.imshow(aces12mrepr, 
          norm=simple_norm(aces12mrepr, stretch='log', max_percent=99.5, min_cut=1e-1),
          cmap=orange_transparent_r)
axes12mrepr[1500,3000]
pl.imshow(aces12mrepr, 
          norm=simple_norm(aces12mrepr, stretch='log', max_percent=99.5, min_cut=1e-1),
          cmap=orange_transparent_r)
aces12mrepr[1500,3000]
#[Out]# 0.0001737762841247129
rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))[::-1,:,:]
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=ww)
ax.imshow(rgb)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

aces12m = fits.open('/orange/adamginsburg/ACES/mosaics/12m_continuum_mosaic.fits')
aces12m[0].data[aces12m[0].data < -0.0005] = 0

aces12mwcs = WCS(aces12m[0].header)
aces12mrepr,_ = reproject.reproject_interp(aces12m, ww, shape_out=rgb.shape[:2])
aces12mrepr[aces12mrepr < -5e-4] = 0
aces12mrepr[aces12mrepr < 1e-4] = np.nan
ax.imshow(aces12mrepr, 
          norm=simple_norm(aces12mrepr, stretch='log', max_percent=99.5, min_cut=1e-4),
          cmap=orange_transparent)
pl.savefig("gc_fullres_6_small_withACES12m.png", bbox_inches='tight')
rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))[::-1,:,:]
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

fig = plt.figure(figsize=(10,5), dpi=200)
ax = plt.subplot(1,1,1, projection=ww)
ax.imshow(rgb)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

aces7m = fits.open('/orange/adamginsburg/ACES/mosaics/7m_continuum_mosaic.fits')
aces7mwcs = WCS(aces7m[0].header)
aces7mrepr,_ = reproject.reproject_interp(aces7m, ww, shape_out=rgb.shape[:2])
aces7mrepr[aces7mrepr < 0] = np.nan
ax.imshow(aces7mrepr, 
          norm=simple_norm(aces7mrepr, stretch='log', max_percent=99.96, min_percent=1),
          cmap=orange_transparent)
pl.savefig("gc_fullres_6_small_withACES7m.png", bbox_inches='tight')
pl.imshow(aces12mrepr, 
          norm=simple_norm(aces12mrepr, stretch='log', max_percent=99.5, min_cut=1e-4),
          cmap=orange_transparent_r)
#[Out]# <matplotlib.image.AxesImage at 0x2b2974ebf2e0>
pl.imshow(aces12mrepr, 
          norm=simple_norm(aces12mrepr, stretch='log', max_percent=99.5, min_cut=1e-1),
          cmap=orange_transparent_r)
aces12mrepr[1500,3000]
#[Out]# 0.0001737762841247129
pl.imshow(aces12mrepr, origin='lower', norm=simple_norm(aces12mrepr, stretch='log', min_cut=1e-4, max_percent=99.5))
pl.colorbar()
#[Out]# <matplotlib.colorbar.Colorbar at 0x2b2974cfc370>
rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))[::-1,:,:]
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

fig = plt.figure(figsize=(10,5), dpi=200, frameon=False)
ax = plt.subplot(1,1,1, projection=ww)
ax.imshow(rgb)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

aces7m = fits.open('/orange/adamginsburg/ACES/mosaics/7m_continuum_mosaic.fits')
aces7mwcs = WCS(aces7m[0].header)
aces7mrepr,_ = reproject.reproject_interp(aces7m, ww, shape_out=rgb.shape[:2])
aces7mrepr[aces7mrepr < 0] = np.nan
ax.imshow(aces7mrepr, 
          norm=simple_norm(aces7mrepr, stretch='log', max_percent=99.96, min_percent=1),
          cmap=orange_transparent)
pl.savefig("gc_fullres_6_small_withACES7m.png", bbox_inches='tight')
rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))[::-1,:,:]
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

fig = plt.figure(figsize=(10,5), dpi=200, frameon=False)
ax = plt.subplot(2,1,2, projection=ww)
ax.imshow(rgb)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

aces7m = fits.open('/orange/adamginsburg/ACES/mosaics/7m_continuum_mosaic.fits')
aces7mwcs = WCS(aces7m[0].header)
aces7mrepr,_ = reproject.reproject_interp(aces7m, ww, shape_out=rgb.shape[:2])
aces7mrepr[aces7mrepr < 0] = np.nan
ax.imshow(aces7mrepr, 
          norm=simple_norm(aces7mrepr, stretch='log', max_percent=99.96, min_percent=1),
          cmap=orange_transparent)

aces12m = fits.open('/orange/adamginsburg/ACES/mosaics/12m_continuum_mosaic.fits')
aces12mwcs = WCS(aces12m[0].header)
aces12m[0].data[aces12m[0].data < -0.0005] = 0

axins = inset_axes(ax,
                   width=4, height=4,
                   bbox_to_anchor=[0.01, 0.5, 1, 0.5],
                   bbox_transform=fig.transFigure,
                   loc='upper center',
                   axes_class=astropy.visualization.wcsaxes.core.WCSAxes,
                   axes_kwargs=dict(wcs=aces12mwcs))
axins.imshow(aces12m[0].data,
             norm=simple_norm(aces12m[0].data, stretch='log',
                              min_percent=None, max_percent=None,
                              min_cut=-0.0005, max_cut=0.05,),
             cmap='gray',
            )

axins.coords['glat'].set_ticklabel(visible=False)
axins.coords['glon'].set_ticklabel(visible=False)
axins.coords['glat'].set_ticks_visible(False)
axins.coords['glon'].set_ticks_visible(False)

mark_inset_generic(axins, ax, data=aces12m[0].data, loc1=4, edgecolor='y')


pl.savefig("gc_fullres_6_small_withACES7m_12minset.png", bbox_inches='tight')
rgb = np.array(PIL.Image.open('gc_fullres_6.jpg'))[::-1,:,:]
ww = WCS(fits.Header.fromtextfile('gc_fullres_6.wcs'))

fig = plt.figure(figsize=(10,5), dpi=200, frameon=False)
ax = plt.subplot(1,1,1, projection=ww)
ax.imshow(rgb)
ax.coords['glat'].set_ticklabel(visible=False)
ax.coords['glon'].set_ticklabel(visible=False)
ax.coords['glat'].set_ticks_visible(False)
ax.coords['glon'].set_ticks_visible(False)

aces7m = fits.open('/orange/adamginsburg/ACES/mosaics/7m_continuum_mosaic.fits')
aces7mwcs = WCS(aces7m[0].header)
aces7mrepr,_ = reproject.reproject_interp(aces7m, ww, shape_out=rgb.shape[:2])
aces7mrepr[aces7mrepr < 0] = np.nan
ax.imshow(aces7mrepr, 
          norm=simple_norm(aces7mrepr, stretch='log', max_percent=99.96, min_percent=1),
          cmap=orange_transparent)
pl.savefig("gc_fullres_6_small_withACES7m.png", bbox_inches='tight', pad_inches=0)
glimpsei4 = fits.open('/orange/adamginsburg/cmz/glimpse_data/GLM_00000+0000_mosaic_I4.fits')
img_meerkat_ACES = reproject.reproject_interp(meerkat, aces12m[0].header)
img_glimpse_ACES = reproject.reproject_interp(glimpsei4, aces12m[0].header)
img_meerkat_ACES = reproject.reproject_interp(meerkat, aces12mwcs.celestial, shape_out=aces12m[0].data.shape)
img_glimpse_ACES = reproject.reproject_interp(glimpsei4, aces12mwcs.celestial, shape_out=aces12m[0].data.shape)
img_meerkat_ACES = reproject.reproject_interp((meerkat[0].data.squeeze(), WCS(meerkat[0].header).celestial),
                                              aces12mwcs.celestial, shape_out=aces12m[0].data.shape)
img_glimpse_ACES = reproject.reproject_interp(glimpsei4, aces12mwcs.celestial, shape_out=aces12m[0].data.shape)
rgb = np.array([simple_norm(img_meerkat_ACES,   min_percent=25, max_percent=99.99, log_a=4e1, stretch='linear')(np.nan_to_num(img_meerkat_ACES)),
                simple_norm(aces12m[0].data,   min_percent=5, max_percent=99.99, log_a=4e1, stretch='asinh')(np.nan_to_num(aces12m[0].data)),
                simple_norm(img_glimpse_ACES, min_percent=1, max_percent=99.99, log_a=4e1, stretch='log')(np.nan_to_num(img_glimpse_ACES))]).T.swapaxes(0,1)
pl.imshow(rgb)
rgb.shape
#[Out]# (3295, 6473, 3)
img_meerkat_ACES.shape, img_glimpse_ACES.shape, aces12m[0].data.shape
img_meerkat_ACES,_ = reproject.reproject_interp((meerkat[0].data.squeeze(), WCS(meerkat[0].header).celestial),
                                              aces12mwcs.celestial, shape_out=aces12m[0].data.shape)
img_glimpse_ACES,_ = reproject.reproject_interp(glimpsei4, aces12mwcs.celestial, shape_out=aces12m[0].data.shape)
