Plotting JWST images#

In this notebook, we will have a taste of the real data of James Webb Space Telescope. We take the images from the UNCOVER survey and plot them using python.

from matplotlib import rcParams, cycler
import matplotlib.pyplot as plt
import numpy as np
import os
import pickle
import astropy

Let’s download the images

Hide code cell source
try:
    import google.colab
    IN_COLAB = True
except:
    IN_COLAB = False

if not IN_COLAB:
    if not os.path.exists("../_static/ObsAstroData/"):
        os.makedirs("../_static/ObsAstroData/")
    os.chdir('../_static/ObsAstroData/')

if os.path.isfile('cutoutRGB_NIRCAM.pkl'):
    print('Data is already there')
else:
    print('Download data')
    !wget https://github.com/AstroJacobLi/ObsAstGreene/raw/main/book/_static/ObsAstroData/cutoutRGB_NIRCAM.pkl

The data has been downloaded to ~/ObsAstroData/ folder if you are using your own computer. If you are using colab, the data is downloaded to the file folder.

Now we open the data using pickle and plot the images.

with open('./cutoutRGB_NIRCAM.pkl', 'rb') as f:
    data = pickle.load(f)
data.keys()
dict_keys(['rIMG', 'rWCS', 'rHDR', 'rfilt', 'gIMG', 'gWCS', 'gHDR', 'gfilt', 'bIMG', 'bWCS', 'bHDR', 'bfilt'])
plt.imshow(np.arcsinh(data['bIMG']))
<matplotlib.image.AxesImage at 0x7fdd50c047c0>
../../_images/a8bf26d6161cdc10a125f5419ac5b8f9dee993a6af05b10805d1544310b84d14.png
plt.imshow(np.log10(data['bIMG'] + 1))
/var/folders/l4/x41n5z4j4q9gypsb58tdh24c0000gn/T/ipykernel_51802/3008184174.py:1: RuntimeWarning: invalid value encountered in log10
  plt.imshow(np.log10(data['bIMG'] + 1))
<matplotlib.image.AxesImage at 0x7fdd720871f0>
../../_images/5b43473190c4ceb903857ce1c1540c4d435a453e21c725ae75d732abe317de15.png
from astropy.visualization import make_lupton_rgb
img_rgb = make_lupton_rgb(data['rIMG'], 0.85 * data['gIMG'], 1.1 * data['bIMG'], Q=10, stretch=5)
plt.imshow(img_rgb, origin='lower')
<matplotlib.image.AxesImage at 0x7fdd00282a90>
../../_images/7885a8e268f26a51b5cf1bf36eaf8820001a685299b3f7bfd6074c7096cc836d.png