/usr/lib/python3/dist-packages/photutils/datasets/load.py is in python3-photutils 0.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | # Licensed under a 3-clause BSD style license - see LICENSE.rst
"""
Load example datasets.
"""
from __future__ import (absolute_import, division, print_function,
unicode_literals)
try:
# python >= 3
from urllib.error import HTTPError, URLError
except ImportError:
# python 2
from urllib2 import HTTPError, URLError
from astropy.io import fits
from astropy.table import Table
from astropy.utils.data import get_pkg_data_filename, download_file
__all__ = ['get_path', 'load_spitzer_image', 'load_spitzer_catalog',
'load_irac_psf', 'load_fermi_image', 'load_star_image']
def get_path(filename, location='local', cache=True, show_progress=False):
"""
Get path (location on your disk) for a given file.
Parameters
----------
filename : str
File name in the local or remote data folder.
location : {'local', 'remote', 'photutils-datasets'}
File location. ``'local'`` means bundled with ``photutils``.
``'remote'`` means the astropy data server (or the
photutils-datasets repo as a backup) or the Astropy cache on
your machine. ``'photutils-datasets'`` means the
photutils-datasets repo or the Astropy cache on your machine.
cache : bool, optional
Whether to cache the contents of remote URLs. Default is
`True`.
show_progress : bool, optional
Whether to display a progress bar during the download (default
is `False`).
Returns
-------
path : str
Path (location on your disk) of the file.
Examples
--------
>>> from astropy.io import fits
>>> from photutils import datasets
>>> hdulist = fits.open(datasets.get_path('fermi_counts.fits.gz'))
"""
datasets_url = ('https://github.com/astropy/photutils-datasets/raw/'
'master/data/{0}'.format(filename))
if location == 'local':
path = get_pkg_data_filename('data/' + filename)
elif location == 'remote': # pragma: no cover
try:
url = 'https://data.astropy.org/photometry/{0}'.format(filename)
path = download_file(url, cache=cache,
show_progress=show_progress)
except (URLError, HTTPError): # timeout or not found
path = download_file(datasets_url, cache=cache,
show_progress=show_progress)
elif location == 'photutils-datasets': # pragma: no cover
path = download_file(datasets_url, cache=cache,
show_progress=show_progress)
else:
raise ValueError('Invalid location: {0}'.format(location))
return path
def load_spitzer_image(show_progress=False): # pragma: no cover
"""
Load a 4.5 micron Spitzer image.
The catalog for this image is returned by
:func:`load_spitzer_catalog`.
Parameters
----------
show_progress : bool, optional
Whether to display a progress bar during the download (default
is `False`).
Returns
-------
hdu : `~astropy.io.fits.ImageHDU`
The 4.5 micron Spitzer image in a FITS image HDU.
See Also
--------
load_spitzer_catalog
Examples
--------
.. plot::
:include-source:
from photutils import datasets
hdu = datasets.load_spitzer_image()
plt.imshow(hdu.data, origin='lower', vmax=50)
"""
path = get_path('spitzer_example_image.fits', location='remote',
show_progress=show_progress)
hdu = fits.open(path)[0]
return hdu
def load_spitzer_catalog(show_progress=False): # pragma: no cover
"""
Load a 4.5 micron Spitzer catalog.
The image from which this catalog was derived is returned by
:func:`load_spitzer_image`.
Parameters
----------
show_progress : bool, optional
Whether to display a progress bar during the download (default
is `False`).
Returns
-------
catalog : `~astropy.table.Table`
The catalog of sources.
See Also
--------
load_spitzer_image
Examples
--------
.. plot::
:include-source:
from photutils import datasets
catalog = datasets.load_spitzer_catalog()
plt.scatter(catalog['l'], catalog['b'])
plt.xlabel('Galactic l')
plt.ylabel('Galactic b')
plt.xlim(18.39, 18.05)
plt.ylim(0.13, 0.30)
"""
path = get_path('spitzer_example_catalog.xml', location='remote',
show_progress=show_progress)
table = Table.read(path)
return table
def load_irac_psf(channel, show_progress=False): # pragma: no cover
"""
Load a Spitzer IRAC PSF image.
Parameters
----------
channel : int (1-4)
The IRAC channel number:
* Channel 1: 3.6 microns
* Channel 2: 4.5 microns
* Channel 3: 5.8 microns
* Channel 4: 8.0 microns
show_progress : bool, optional
Whether to display a progress bar during the download (default
is `False`).
Returns
-------
hdu : `~astropy.io.fits.ImageHDU`
The IRAC PSF in a FITS image HDU.
Examples
--------
.. plot::
:include-source:
from astropy.visualization import LogStretch, ImageNormalize
from photutils.datasets import load_irac_psf
hdu1 = load_irac_psf(1)
hdu2 = load_irac_psf(2)
hdu3 = load_irac_psf(3)
hdu4 = load_irac_psf(4)
norm = ImageNormalize(hdu1.data, stretch=LogStretch())
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)
ax1.imshow(hdu1.data, origin='lower', interpolation='nearest',
norm=norm)
ax1.set_title('IRAC Ch1 PSF')
ax2.imshow(hdu2.data, origin='lower', interpolation='nearest',
norm=norm)
ax2.set_title('IRAC Ch2 PSF')
ax3.imshow(hdu3.data, origin='lower', interpolation='nearest',
norm=norm)
ax3.set_title('IRAC Ch3 PSF')
ax4.imshow(hdu4.data, origin='lower', interpolation='nearest',
norm=norm)
ax4.set_title('IRAC Ch4 PSF')
plt.tight_layout()
plt.show()
"""
channel = int(channel)
if channel < 1 or channel > 4:
raise ValueError('channel must be 1, 2, 3, or 4')
fn = 'irac_ch{0}_flight.fits'.format(channel)
path = get_path(fn, location='remote', show_progress=show_progress)
hdu = fits.open(path)[0]
return hdu
def load_fermi_image(show_progress=False):
"""
Load a Fermi counts image for the Galactic center region.
Parameters
----------
show_progress : bool, optional
Whether to display a progress bar during the download (default
is `False`).
Returns
-------
hdu : `~astropy.io.fits.ImageHDU`
A FITS image HDU.
Examples
--------
.. plot::
:include-source:
from photutils import datasets
hdu = datasets.load_fermi_image()
plt.imshow(hdu.data, vmax=10, origin='lower', interpolation='nearest')
"""
path = get_path('fermi_counts.fits.gz', location='local',
show_progress=show_progress)
hdu = fits.open(path)[1]
return hdu
def load_star_image(show_progress=False): # pragma: no cover
"""
Load an optical image of stars.
This is an image of M67 from photographic data obtained as part of
the National Geographic Society - Palomar Observatory Sky Survey
(NGS-POSS). The image was digitized from the POSS-I Red plates as
part of the Digitized Sky Survey produced at the Space Telescope
Science Institute.
Parameters
----------
show_progress : bool, optional
Whether to display a progress bar during the download (default
is `False`).
Returns
-------
hdu : `~astropy.io.fits.ImageHDU`
The M67 image in a FITS image HDU.
Examples
--------
.. plot::
:include-source:
from photutils import datasets
hdu = datasets.load_star_image()
plt.imshow(hdu.data, origin='lower', interpolation='nearest')
"""
path = get_path('M6707HH.fits', location='remote',
show_progress=show_progress)
hdu = fits.open(path)[0]
return hdu
|