<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Solutions for image visualization
Some exercises make use of code in the notebook. Other exercises will require a GUI interaction. In those cases, one or more images of results are included.
1. matplotlib
Step1:  2. RGB-3-color images
Using astropy and reproject (installable with pip install reproject), follow these instructions in the Astropy documentation to make color RGB images. Compare the second one to Figure 1 of Lupton et al 2004.
Step2:  3. RGB colors of Herschel-SPIRE images
Reproject the 250 um image of W5 in ./data/0259p6031_1342192088_SpirePhoto_L20_PMP250_SPG14.0.fits.gz (extension 1) and the 350 micron image in ./data/0259p6031_1342192088_SpirePhoto_L20_PMP350_SPG14.0.fits.gz onto the 500 micron image in that directory, and try the same 3-color procedures.
Step3:  
<ASSISTANT_TASK:>
Python Code:
import matplotlib.pyplot as plt
from astropy.io import fits
from astropy.wcs import WCS
from astropy.visualization import (MinMaxInterval,
                                  LogStretch,
                                  ImageNormalize)
%matplotlib inline
hdu = fits.open('./data/w5.fits')[0]
wcs = WCS(hdu.header)
hdu2 = fits.open('./data/0259p6031_1342192088_SpirePhoto_L20_PMP350_SPG14.0.fits.gz')[1]
norm = ImageNormalize(hdu.data, interval=MinMaxInterval(),
                      stretch=LogStretch())
fig = plt.figure(figsize=(8,8))
ax = plt.subplot(projection=wcs)
overlay = ax.get_coords_overlay('galactic')
plt.imshow(hdu.data, norm=norm, origin="lower", cmap='Greys_r')
ax.coords['ra'].set_ticks(color='green')
ax.coords['dec'].set_ticks(color='green')
ax.coords['ra'].set_axislabel('Right Ascension')
ax.coords['dec'].set_axislabel('Declination')
ax.coords.grid(color='green', linestyle='solid', alpha=1.0)
overlay['l'].set_ticks(color='cyan')
overlay['b'].set_ticks(color='cyan')
overlay['l'].set_axislabel('Galactic Longitude')
overlay['b'].set_axislabel('Galactic Latitude')
overlay.grid(color='cyan', linestyle='solid', alpha=1.0)
ax.contour(hdu2.data, transform=ax.get_transform(WCS(hdu2.header)),
           levels=[0.7,1.4,3], colors='white');
Explanation: Solutions for image visualization
Some exercises make use of code in the notebook. Other exercises will require a GUI interaction. In those cases, one or more images of results are included.
1. matplotlib: Contours from another image, and secondary axes
Using matplotlib and astropy:
display the file .data/w5.fits as a bitmap with log stretch and min-max scaling
overlay the data in image extension 1 of ./data/0259p6031_1342192088_SpirePhoto_L20_PMP350_SPG14.0.fits.fits.gz as white contours with levels drawn at [0.7, 1.4, 3] image units (Jy/beam)
display coordinate axes and grid (green, alpha=1) in (RA, Dec)  
overlay a coordinate grid (cyan, alpha=1) and axis labels in Galactic longitude and latitude
End of explanation
import numpy as np
from astropy.visualization import make_lupton_rgb
from astropy.io import fits
from reproject import reproject_interp
# Read in the three images downloaded from here:
g = fits.open('http://dr13.sdss.org/sas/dr13/eboss/photoObj/frames/301/1737/5/frame-g-001737-5-0039.fits.bz2')[0]
r = fits.open('http://dr13.sdss.org/sas/dr13/eboss/photoObj/frames/301/1737/5/frame-r-001737-5-0039.fits.bz2')[0]
i = fits.open('http://dr13.sdss.org/sas/dr13/eboss/photoObj/frames/301/1737/5/frame-i-001737-5-0039.fits.bz2')[0]
# remap r and i onto g
r_new, r_mask = reproject_interp(r, g.header)
i_new, i_mask = reproject_interp(i, g.header)
# zero out the unmapped values
i_new[np.logical_not(i_mask)] = 0
r_new[np.logical_not(r_mask)] = 0
# red=i, green=r, blue=g
# make a file with the default scaling
rgb_default = make_lupton_rgb(i_new, r_new, g.data, filename="ngc6976-default.jpeg")
# this scaling is very similar to the one used in Lupton et al. (2004)
rgb = make_lupton_rgb(i_new, r_new, g.data, Q=10, stretch=0.5, filename="ngc6976.jpeg")
Explanation: 2. RGB-3-color images
Using astropy and reproject (installable with pip install reproject), follow these instructions in the Astropy documentation to make color RGB images. Compare the second one to Figure 1 of Lupton et al 2004.
End of explanation
w5_250 = fits.open('./data/0259p6031_1342192088_SpirePhoto_L20_PMP250_SPG14.0.fits.gz')[1]
w5_350 = fits.open('./data/0259p6031_1342192088_SpirePhoto_L20_PMP350_SPG14.0.fits.gz')[1]
w5_500 = fits.open('./data/0259p6031_1342192088_SpirePhoto_L20_PMP500_SPG14.0.fits.gz')[1]
im250, msk250 = reproject_interp(w5_250, w5_500.header)
im350, msk350 = reproject_interp(w5_350, w5_500.header)
# zero out the unmapped values
im250[np.logical_not(msk250)] = 0
im350[np.logical_not(msk350)] = 0
rgb_w5_default = make_lupton_rgb(im250, im350, w5_500.data, filename="w5-default.jpeg")
Explanation: 3. RGB colors of Herschel-SPIRE images
Reproject the 250 um image of W5 in ./data/0259p6031_1342192088_SpirePhoto_L20_PMP250_SPG14.0.fits.gz (extension 1) and the 350 micron image in ./data/0259p6031_1342192088_SpirePhoto_L20_PMP350_SPG14.0.fits.gz onto the 500 micron image in that directory, and try the same 3-color procedures.
End of explanation
rgb_w5 = make_lupton_rgb(im250, im350, w5_500.data, Q=10, stretch=0.5, filename="w5.jpeg")
Explanation: 
End of explanation
<END_TASK>