"""Downloads the FITS files that are used in image testing and for building documentation.


"""

from astropy.utils.data import download_file
from astropy.io import fits


def msx_hdu(cache=True):
    filename = download_file("http://astrofrog.github.io/wcsaxes-datasets/msx.fits", cache=cache)
    return fits.open(filename)[0]


def rosat_hdu(cache=True):
    filename = download_file("http://astrofrog.github.io/wcsaxes-datasets/rosat.fits", cache=cache)
    return fits.open(filename)[0]


def twoMASS_k_hdu(cache=True):
    filename = download_file("http://astrofrog.github.io/wcsaxes-datasets/2MASS_k.fits", cache=cache)
    return fits.open(filename)[0]


def l1448_co_hdu(cache=True):
    filename = download_file("http://astrofrog.github.io/wcsaxes-datasets/L1448_13CO_subset.fits", cache=cache)
    return fits.open(filename)[0]


def bolocam_hdu(cache=True):
    filename = download_file("http://astrofrog.github.io/wcsaxes-datasets/bolocam_v2.0.fits", cache=cache)
    return fits.open(filename)[0]

@@ -84,18 +84,16 @@
 tation.%0A
-%0A%0A
 %22%22%22%0A%0Afro
@@ -167,117 +167,137 @@
 ts%0A%0A
-%0Adef msx_hdu(cache=True):%0A    filename = download_file(%22http://astrofrog.github.io/wcsaxes-datasets/msx.fits%22
+URL = 'http://astrofrog.github.io/wcsaxes-datasets/'%0A%0A%0Adef get_hdu(filename, cache=True):%0A    path = download_file(URL + filename
 , ca
@@ -324,32 +324,28 @@
 n fits.open(
-filename
+path
 )%5B0%5D%0A%0A%0Adef r
@@ -343,21 +343,19 @@
 %5D%0A%0A%0Adef 
-rosat
+msx
 _hdu(cac
@@ -372,89 +372,33 @@
     
-filename = download_file(%22http://astrofrog.github.io/wcsaxes-datasets/rosat
+return get_hdu('msx
 .fits
-%22
+'
 , ca
@@ -412,149 +412,136 @@
 he)%0A
-    return fits.open(filename)%5B0%5D%0A%0A%0Adef twoMASS_k_hdu(cache=True):%0A    filename = download_file(%22http://astrofrog.github.io/wcsaxes-datasets/
+%0A%0Adef rosat_hdu(cache=True):%0A    return get_hdu('rosat.fits', cache=cache)%0A%0A%0Adef twoMASS_k_hdu(cache=True):%0A    return get_hdu('
 2MAS
@@ -544,25 +544,25 @@
 2MASS_k.fits
-%22
+'
 , cache=cach
@@ -568,42 +568,8 @@
 he)%0A
-    return fits.open(filename)%5B0%5D%0A
 %0A%0Ade
@@ -604,78 +604,24 @@
     
-filename = download_file(%22http://astrofrog.github.io/wcsaxes-datasets/
+return get_hdu('
 L144
@@ -634,25 +634,25 @@
 _subset.fits
-%22
+'
 , cache=cach
@@ -658,42 +658,8 @@
 he)%0A
-    return fits.open(filename)%5B0%5D%0A
 %0A%0Ade
@@ -693,78 +693,24 @@
     
-filename = download_file(%22http://astrofrog.github.io/wcsaxes-datasets/
+return get_hdu('
 bolo
@@ -722,17 +722,17 @@
 2.0.fits
-%22
+'
 , cache=
@@ -742,38 +742,4 @@
 he)%0A
-    return fits.open(filename)%5B0%5D%0A

Simplify datasets functions a bit