Photometry Module

Lecturer: Sudhanshu Barway
Jupyter Notebook Author: Kishalay De & Cameron Hummels

This is a Jupyter notebook lesson taken from the GROWTH Winter School 2018. For other lessons and their accompanying lectures, please see:


Measure photometric fluxes from astronomical ultraviolet, optical, infrared image data.

Key steps

  • Calibrate images to derive relationship between counts and brightness on sky.
  • Use aperture photometry tools to calculate brightness of sources.
  • Use Point Spread Function photometry tools to calculate brightness of sources.

Required dependencies

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).

Python modules

  • python 3
  • astropy
  • numpy
  • matplotlib
  • astroquery

External packages

Let's start by importing a few necessary modules first.

In [1]:
import numpy as np
import as ma
import os
import astropy.units as u
from import ascii
from astropy.coordinates import SkyCoord
from astropy.wcs import WCS
from astropy.stats import sigma_clipped_stats, sigma_clip
import subprocess

Test dependencies

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.

In [2]:
dependencies = ['sextractor', 'psfex']

def test_dependency(dep):
        subprocess.Popen(dep, stderr=subprocess.PIPE)
        print("%s is installed properly. OK" % dep)
        return 1
    except ImportError:
        print("===%s IS NOT YET INSTALLED PROPERLY===" % dep)
        return 0
i = 0
for dep in dependencies:
    i += test_dependency(dep)
print("\n%i out of %i dependencies installed properly." % (i, len(dependencies)))
if i != len(dependencies):
    print("Please correctly install these programs before continuing.")
    print("You are ready to continue.")
sextractor is installed properly. OK
psfex is installed properly. OK

2 out of 2 dependencies installed properly.
You are ready to continue.

Let's plot a reduced image from the previous module.

In [3]:
from import fits
import matplotlib.pyplot as plt
%matplotlib inline
import os

# Move to the data directory for our analysis
imageName = ''
f =
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.imshow(data, vmin=median-3*sigma, vmax=median+3*sigma)