Lecturer: Sudhanshu Barway
Jupyter Notebook Author: Kishalay De & Cameron Hummels
This is a Jupyter notebook lesson taken from the GROWTH Summer School 2019. For other lessons and their accompanying lectures, please see: http://growth.caltech.edu/growth-school-2019.html
Measure photometric fluxes from astronomical ultraviolet, optical, infrared image data.
See GROWTH school webpage for detailed instructions on how to install these modules and packages. Nominally, you should be able to install the python modules with pip install <module>
. The external astromatic packages are easiest installed using package managers (e.g., rpm
, apt-get
).
Let's start by importing a few necessary modules first.
import numpy as np
import numpy.ma as ma
import os
import astropy.units as u
from astropy.io import ascii
from astropy.coordinates import SkyCoord
from astropy.wcs import WCS
from astropy.stats import sigma_clipped_stats, sigma_clip
import subprocess
In order for this jupyter notebook to function correctly, we must have some external software installed, as described above. The following step assures that these are installed properly before getting to the rest of the content of this lesson.
def test_dependency(dep, alternate_name=None):
"""
Test external dependency by trying to run it as a subprocess
"""
try:
subprocess.check_output(dep, stderr=subprocess.PIPE, shell=True)
print("%s is installed properly as %s. OK" % (dep, dep))
return 1
except subprocess.CalledProcessError:
try:
subprocess.check_output(alternate_name, stderr=subprocess.PIPE, shell=True)
print("%s is installed properly as %s. OK" % (dep, alternate_name))
return 1
except subprocess.CalledProcessError:
print("===%s/%s IS NOT YET INSTALLED PROPERLY===" % (dep, alternate_name))
return 0
dependencies = [('sextractor', 'sex'), ('psfex', 'PSFEx')]
i = 0
for dep_name1, dep_name2 in dependencies:
i += test_dependency(dep_name1, dep_name2)
print("%i out of %i external dependencies installed properly.\n" % (i, len(dependencies)))
if i != len(dependencies):
print("Please correctly install these programs before continuing by following the instructions in README.md.")
else:
print("You are ready to continue.")
sextractor is installed properly as sextractor. OK psfex is installed properly as psfex. OK 2 out of 2 external dependencies installed properly. You are ready to continue.
Let's plot a reduced image from the previous module.
from astropy.io import fits
import matplotlib.pyplot as plt
%matplotlib inline
import os
# Move to the data directory for our analysis
os.chdir('data')
imageName = 'aC0_20181013-174714-557.wcs.fits.proc.cr.fits'
f = fits.open(imageName)
data = f[0].data #This is the image array
header = f[0].header
#Compute some image statistics for scaling the image plot
mean, median, sigma = sigma_clipped_stats(data)
#plot the image with some reasonable scale
plt.figure(figsize=(10,10))
plt.imshow(data, vmin=median-3*sigma, vmax=median+3*sigma)
plt.show()