Step 1: Download
Download one of four data sets.
Each data set is of a different astronomical object. For this assignment, you only need to manipulate one of them. For each object, there are multiple images taken in different filters. These images have already been processed to remove camera features and cosmic rays.
Save the files from one data set in your class folder. Notice that the files end with *.gz. They've been compressed to use less storage space. To unpack them, in your Terminal type:
gunzip filename.gz
Step 2: Display the Hubble images in ds9
For a reminder on using ds9, click here.
Open ds9 and load a file (file -> open).
Play with the zoom and scale until you are able to see your object.
You can change the contrast with your mouse (Mac users, press command while dragging your mouse on the image).
You can estimate average pixel value by moving your mouse around the image and watch how the number next to ‘Value’ in the upper right of ds9 changes.
from astropy.io import fits
hdulist = fits.open('CTD_CT5/data1/hlsp_heritage_hst_wfpc2_arp194_f450w_drz.fits')
hdulist.info()
Filename: CTD_CT5/data1/hlsp_heritage_hst_wfpc2_arp194_f450w_drz.fits No. Name Type Cards Dimensions Format 0 PRIMARY PrimaryHDU 1295 (4200, 2800) float32
hdu = hdulist[0]
hdu.header['TELESCOP']
'HST'
%matplotlib inline
import matplotlib.pyplot as plt
import pylab
plt.figure(figsize=(18,16))
plt.imshow(hdu.data, origin='lower',vmin=-0.00001,vmax=0.005)
<matplotlib.image.AxesImage at 0xdac0cc0>
Step 4: Read your Hubble images into Python.
In your IPython Console within Spyder, make sure you're in the same directory as where your Hubble images are. Then type:
ls
import astropy
import pyfits
im1 = pyfits.getdata('myimage.fits')
The data are loaded into a numpy array. To see the pixel values type:
im1
To see various math options you can do to this array, type:
im1 <<hit the space bar and then press tab>>
Or google 'Python math'
One option listed was to determine the minimum value of the array/image.To do this, type:
im1.min()
Questions:
What is the minimum and maximum pixel value in your image?
What is the mean value of the full image?
Step 5: Display your image in Python.
Type:
plt.close()
fig=plt.figure()
plt.imshow(im1)
Remember, your figure may be hiding behind your Spyder window.
The figure probably doesn't look very good. Unlike in ds9, you cannot dynamically change the contrast or zoom in/out. How annoying! Someone should write a python tool to do this.
You can manually set the min/max value displayed to improve how this looks.
plt.imshow?
This lists various options. One of the options it lists is to set vmin/vmax. Type:
plt.imshow(im1,vmin=-0.00001,vmax=0.005)
This may take a little while for the figure to pop up. Be patient.
Note: First try values that are close to the min/max values you found above. Then use trial and error to find an ideal contrast level.)
Step 6: Read the image header information.
In addition to the image data itself, each *.fits file contains ‘header’ information which is the metadata attached to each image. The header usually includes what telescope and camera the image was taken with, observing conditions, coordinates of the object, etc.
To read the header file, type:
hdr1 = pyfits.getheader(‘myimage.fits’)
print hdr1
Scroll up the screen to see all of the header info. To pick out certain pieces of the header, you need know the relevant keyword. For example, to find out what telescope this image was taken with type:
print hdr1['TELESCOP']
Keywords include targname, ra_targ, dec_targ, and exptime.
Questions:
What is the exposure time and filter used for each of your images?
Based on the target name and coordinates (Ra/Dec), what is your astronomical object?
Step 7: Create a multi-color image using 3 of the images from your data set.
Follow these instructions. You will need img_scale.py to scale your image.
Note: adjust the minimum and maximum values within the code to reflect the best contrast setting for each filter and with the final multicolor image in mind.
Hubble Site has created a remarkable inventory and contains color versions for each of of the four datasets. Look up your object and compare your work. Do not be discouraged if your work isn't quite as pretty-- this is a difficult artform! This is a great skill for public talks and press releases.
Congratulations! You've completed Computational Project #4 (CT-4).