Created
July 30, 2014 07:31
-
-
Save cdeil/c19f2091ada9b6e42e9b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python setup.py test -V -t gammapy/datasets/tests/test_load.py --remote-data | |
running test | |
running build | |
running build_py | |
running build_scripts | |
/Users/deil/Library/Python/2.7/lib/python/site-packages/astropy-0.4rc3.dev9437-py2.7-macosx-10.9-x86_64.egg/astropy/tests/helper.py:30: UserWarning: Module gammapy was already imported from gammapy/__init__.pyc, but /Users/deil/Library/Python/2.7/lib/python/site-packages/gammapy-0.1-py2.7.egg is being added to sys.path | |
import pkg_resources | |
========================================================== test session starts ========================================================== | |
platform darwin -- Python 2.7.8 -- pytest-2.5.1 -- /opt/local/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python | |
cachedir: /private/var/folders/sb/4qv5j4m90pz1rw7m70rj1b1r0000gn/T/gammapy-test-lhkkyp/lib.macosx-10.9-x86_64-2.7/.cache | |
Running tests with Astropy version 0.4rc3.dev9437. | |
Running tests in /private/var/folders/sb/4qv5j4m90pz1rw7m70rj1b1r0000gn/T/gammapy-test-lhkkyp/lib.macosx-10.9-x86_64-2.7/gammapy/datasets/tests/test_load.py. | |
Platform: Darwin-13.3.0-x86_64-i386-64bit | |
Executable: /opt/local/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python | |
Full Python Version: | |
2.7.8 (default, Jul 13 2014, 17:11:32) | |
[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] | |
encodings: sys: ascii, locale: UTF-8, filesystem: utf-8, unicode bits: 15 | |
byteorder: little | |
float info: dig: 15, mant_dig: 15 | |
Numpy: 1.8.1 | |
Scipy: 0.14.0 | |
Matplotlib: 1.3.1 | |
h5py: 2.3.1 | |
Using Astropy options: remote_data. | |
plugins: bench, cache, cov, pep8, rerunfailures, xdist | |
collected 13 items | |
gammapy/datasets/tests/test_load.py:14: test_poisson_stats_image PASSED | |
gammapy/datasets/tests/test_load.py:20: test_poisson_stats_image_direct PASSED | |
gammapy/datasets/tests/test_load.py:27: test_poisson_stats_extra_info PASSED | |
gammapy/datasets/tests/test_load.py:36: TestFermiGalacticCenter.test_filenames PASSED | |
gammapy/datasets/tests/test_load.py:40: TestFermiGalacticCenter.test_psf PASSED | |
gammapy/datasets/tests/test_load.py:45: TestFermiGalacticCenter.test_counts PASSED | |
gammapy/datasets/tests/test_load.py:50: TestFermiGalacticCenter.test_diffuse_model PASSED | |
gammapy/datasets/tests/test_load.py:56: TestFermiGalacticCenter.test_exposure_cube XPASS | |
gammapy/datasets/tests/test_load.py:65: TestFermiVelaRegion.test_filenames PASSED | |
gammapy/datasets/tests/test_load.py:70: TestFermiVelaRegion.test_counts FAILED | |
gammapy/datasets/tests/test_load.py:76: TestFermiVelaRegion.test_background_cube FAILED | |
gammapy/datasets/tests/test_load.py:82: TestFermiVelaRegion.test_exposure_cube FAILED | |
gammapy/datasets/tests/test_load.py:90: test_fetch_fermi_catalog PASSED | |
=============================================================== FAILURES ================================================================ | |
____________________________________________________ TestFermiVelaRegion.test_counts ____________________________________________________ | |
self = <gammapy.datasets.tests.test_load.TestFermiVelaRegion instance at 0x1042e42d8> | |
@remote_data | |
def test_counts(self): | |
> counts = FermiVelaRegion.counts() | |
gammapy/datasets/tests/test_load.py:72: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
@staticmethod | |
def counts(): | |
"""Counts image as `astropy.io.fits.ImageHDU`.""" | |
filename = FermiVelaRegion.filenames()['counts'] | |
> return fits.open(filename)[0] | |
gammapy/datasets/load.py:201: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
name = '/var/folders/sb/4qv5j4m90pz1rw7m70rj1b1r0000gn/T/tmpna45hsastropy_cache/astropy/download/7671c309f1222e98f49c724177107624' | |
mode = 'readonly', memmap = True, save_backup = False, kwargs = {}, conf = <astropy.io.fits.Conf object at 0x103049150> | |
def fitsopen(name, mode='readonly', memmap=None, save_backup=False, **kwargs): | |
"""Factory function to open a FITS file and return an `HDUList` object. | |
Parameters | |
---------- | |
name : file path, file object or file-like object | |
File to be opened. | |
mode : str | |
Open mode, 'readonly' (default), 'update', 'append', 'denywrite', or | |
'ostream'. | |
If ``name`` is a file object that is already opened, ``mode`` must | |
match the mode the file was opened with, readonly (rb), update (rb+), | |
append (ab+), ostream (w), denywrite (rb)). | |
memmap : bool | |
Is memory mapping to be used? | |
save_backup : bool | |
If the file was opened in update or append mode, this ensures that a | |
backup of the original file is saved before any changes are flushed. | |
The backup has the same name as the original file with ".bak" appended. | |
If "file.bak" already exists then "file.bak.1" is used, and so on. | |
kwargs : dict | |
optional keyword arguments, possible values are: | |
- **uint** : bool | |
Interpret signed integer data where ``BZERO`` is the | |
central value and ``BSCALE == 1`` as unsigned integer | |
data. For example, ``int16`` data with ``BZERO = 32768`` | |
and ``BSCALE = 1`` would be treated as ``uint16`` data. | |
Note, for backward compatibility, the kwarg **uint16** may | |
be used instead. The kwarg was renamed when support was | |
added for integers of any size. | |
- **ignore_missing_end** : bool | |
Do not issue an exception when opening a file that is | |
missing an ``END`` card in the last header. | |
- **checksum** : bool, str | |
If `True`, verifies that both ``DATASUM`` and | |
``CHECKSUM`` card values (when present in the HDU header) | |
match the header and data of all HDU's in the file. Updates to a | |
file that already has a checksum will preserve and update the | |
existing checksums unless this argument is given a value of | |
'remove', in which case the CHECKSUM and DATASUM values are not | |
checked, and are removed when saving changes to the file. | |
- **disable_image_compression** : bool | |
If `True`, treates compressed image HDU's like normal | |
binary table HDU's. | |
- **do_not_scale_image_data** : bool | |
If `True`, image data is not scaled using BSCALE/BZERO values | |
when read. | |
- **ignore_blank** : bool | |
If `True`, the BLANK keyword is ignored if present. | |
- **scale_back** : bool | |
If `True`, when saving changes to a file that contained scaled | |
image data, restore the data to the original type and reapply the | |
original BSCALE/BZERO values. This could lead to loss of accuracy | |
if scaling back to integer values after performing floating point | |
operations on the data. | |
Returns | |
------- | |
hdulist : an `HDUList` object | |
`HDUList` containing all of the header data units in the | |
file. | |
""" | |
if memmap is None: | |
from .. import conf | |
memmap = conf.use_memmap | |
if 'uint16' in kwargs and 'uint' not in kwargs: | |
kwargs['uint'] = kwargs['uint16'] | |
del kwargs['uint16'] | |
if not name: | |
raise ValueError('Empty filename: %s' % repr(name)) | |
> return HDUList.fromfile(name, mode, memmap, save_backup, **kwargs) | |
/Users/deil/Library/Python/2.7/lib/python/site-packages/astropy-0.4rc3.dev9437-py2.7-macosx-10.9-x86_64.egg/astropy/io/fits/hdu/hdulist.py:119: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
cls = <class 'astropy.io.fits.hdu.hdulist.HDUList'> | |
fileobj = '/var/folders/sb/4qv5j4m90pz1rw7m70rj1b1r0000gn/T/tmpna45hsastropy_cache/astropy/download/7671c309f1222e98f49c724177107624' | |
mode = 'readonly', memmap = True, save_backup = False, kwargs = {} | |
@classmethod | |
def fromfile(cls, fileobj, mode=None, memmap=False, | |
save_backup=False, **kwargs): | |
""" | |
Creates an `HDUList` instance from a file-like object. | |
The actual implementation of ``fitsopen()``, and generally shouldn't | |
be used directly. Use :func:`open` instead (and see its | |
documentation for details of the parameters accepted by this method). | |
""" | |
return cls._readfrom(fileobj=fileobj, mode=mode, memmap=memmap, | |
> save_backup=save_backup, **kwargs) | |
/Users/deil/Library/Python/2.7/lib/python/site-packages/astropy-0.4rc3.dev9437-py2.7-macosx-10.9-x86_64.egg/astropy/io/fits/hdu/hdulist.py:251: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
cls = <class 'astropy.io.fits.hdu.hdulist.HDUList'> | |
fileobj = '/var/folders/sb/4qv5j4m90pz1rw7m70rj1b1r0000gn/T/tmpna45hsastropy_cache/astropy/download/7671c309f1222e98f49c724177107624' | |
data = None, mode = 'readonly', memmap = True, save_backup = False, kwargs = {} | |
ffo = <astropy.io.fits.file._File <open file u'/var/folders/sb/4qv5j4m90pz1rw7m70rj1.../astropy/download/7671c309f1222e98f49c724177107624', mode 'rb' at 0x1042b5300>> | |
hdulist = [], saved_compression_enabled = True | |
@classmethod | |
def _readfrom(cls, fileobj=None, data=None, mode=None, | |
memmap=False, save_backup=False, **kwargs): | |
""" | |
Provides the implementations from HDUList.fromfile and | |
HDUList.fromstring, both of which wrap this method, as their | |
implementations are largely the same. | |
""" | |
if fileobj is not None: | |
if not isinstance(fileobj, _File): | |
# instantiate a FITS file object (ffo) | |
ffo = _File(fileobj, mode=mode, memmap=memmap) | |
else: | |
ffo = fileobj | |
# The pyfits mode is determined by the _File initializer if the | |
# supplied mode was None | |
mode = ffo.mode | |
hdulist = cls(file=ffo) | |
else: | |
if mode is None: | |
# The default mode | |
mode = 'readonly' | |
hdulist = cls() | |
# This method is currently only called from HDUList.fromstring and | |
# HDUList.fromfile. If fileobj is None then this must be the | |
# fromstring case; the data type of ``data`` will be checked in the | |
# _BaseHDU.fromstring call. | |
hdulist._save_backup = save_backup | |
saved_compression_enabled = compressed.COMPRESSION_ENABLED | |
try: | |
if ('disable_image_compression' in kwargs and | |
kwargs['disable_image_compression']): | |
compressed.COMPRESSION_ENABLED = False | |
# read all HDUs | |
while True: | |
try: | |
if fileobj is not None: | |
if ffo.writeonly: | |
# Output stream--not interested in reading/parsing | |
# the HDUs--just writing to the output file | |
return hdulist | |
try: | |
> hdu = _BaseHDU.readfrom(ffo, **kwargs) | |
/Users/deil/Library/Python/2.7/lib/python/site-packages/astropy-0.4rc3.dev9437-py2.7-macosx-10.9-x86_64.egg/astropy/io/fits/hdu/hdulist.py:805: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
cls = <class 'astropy.io.fits.hdu.base._BaseHDU'> | |
fileobj = <astropy.io.fits.file._File <open file u'/var/folders/sb/4qv5j4m90pz1rw7m70rj1.../astropy/download/7671c309f1222e98f49c724177107624', mode 'rb' at 0x1042b5300>> | |
checksum = False, ignore_missing_end = False, kwargs = {} | |
@classmethod | |
def readfrom(cls, fileobj, checksum=False, ignore_missing_end=False, | |
**kwargs): | |
""" | |
Read the HDU from a file. Normally an HDU should be opened with | |
:func:`open` which reads the entire HDU list in a FITS file. But this | |
method is still provided for symmetry with :func:`writeto`. | |
Parameters | |
---------- | |
fileobj : file object or file-like object | |
Input FITS file. The file's seek pointer is assumed to be at the | |
beginning of the HDU. | |
checksum : bool | |
If `True`, verifies that both ``DATASUM`` and ``CHECKSUM`` card | |
values (when present in the HDU header) match the header and data | |
of all HDU's in the file. | |
ignore_missing_end : bool | |
Do not issue an exception when opening a file that is missing an | |
``END`` card in the last header. | |
""" | |
# TODO: Figure out a way to make it possible for the _File | |
# constructor to be a noop if the argument is already a _File | |
if not isinstance(fileobj, _File): | |
fileobj = _File(fileobj) | |
hdu = cls._readfrom_internal(fileobj, checksum=checksum, | |
ignore_missing_end=ignore_missing_end, | |
> **kwargs) | |
/Users/deil/Library/Python/2.7/lib/python/site-packages/astropy-0.4rc3.dev9437-py2.7-macosx-10.9-x86_64.egg/astropy/io/fits/hdu/base.py:379: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
cls = <class 'astropy.io.fits.hdu.base._BaseHDU'> | |
data = <astropy.io.fits.file._File <open file u'/var/folders/sb/4qv5j4m90pz1rw7m70rj1.../astropy/download/7671c309f1222e98f49c724177107624', mode 'rb' at 0x1042b5300>> | |
header = None, checksum = False, ignore_missing_end = False, kwargs = {}, hdu_buffer = None, hdu_fileobj = None, header_offset = 0 | |
from_file = True | |
@classmethod | |
def _readfrom_internal(cls, data, header=None, checksum=False, | |
ignore_missing_end=False, **kwargs): | |
""" | |
Provides the bulk of the internal implementation for readfrom and | |
fromstring. | |
For some special cases, supports using a header that was already | |
created, and just using the input data for the actual array data. | |
""" | |
hdu_buffer = None | |
hdu_fileobj = None | |
header_offset = 0 | |
if isinstance(data, _File): | |
from_file = True | |
if header is None: | |
header_offset = data.tell() | |
> header = Header.fromfile(data, endcard=not ignore_missing_end) | |
/Users/deil/Library/Python/2.7/lib/python/site-packages/astropy-0.4rc3.dev9437-py2.7-macosx-10.9-x86_64.egg/astropy/io/fits/hdu/base.py:439: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
cls = <class 'astropy.io.fits.header.Header'> | |
fileobj = <astropy.io.fits.file._File <open file u'/var/folders/sb/4qv5j4m90pz1rw7m70rj1.../astropy/download/7671c309f1222e98f49c724177107624', mode 'rb' at 0x1042b5300>> | |
sep = '', endcard = True, padding = True | |
@classmethod | |
def fromfile(cls, fileobj, sep='', endcard=True, padding=True): | |
""" | |
Similar to :meth:`Header.fromstring`, but reads the header string from | |
a given file-like object or filename. | |
Parameters | |
---------- | |
fileobj : str, file-like | |
A filename or an open file-like object from which a FITS header is | |
to be read. For open file handles the file pointer must be at the | |
beginning of the header. | |
sep : str, optional | |
The string separating cards from each other, such as a newline. By | |
default there is no card separator (as is the case in a raw FITS | |
file). | |
endcard : bool, optional | |
If True (the default) the header must end with an END card in order | |
to be considered valid. If an END card is not found an | |
`~.exceptions.IOError` is raised. | |
padding : bool, optional | |
If True (the default) the header will be required to be padded out | |
to a multiple of 2880, the FITS header block size. Otherwise any | |
padding, or lack thereof, is ignored. | |
Returns | |
------- | |
header | |
A new `Header` instance. | |
""" | |
close_file = False | |
if isinstance(fileobj, string_types): | |
# Open in text mode by default to support newline handling; if a | |
# binary-mode file object is passed in, the user is on their own | |
# with respect to newline handling | |
fileobj = open(fileobj, 'r') | |
close_file = True | |
try: | |
is_binary = fileobj_is_binary(fileobj) | |
def block_iter(nbytes): | |
while True: | |
data = fileobj.read(nbytes) | |
if data: | |
yield data | |
else: | |
break | |
return cls._from_blocks(block_iter, is_binary, sep, endcard, | |
> padding)[1] | |
/Users/deil/Library/Python/2.7/lib/python/site-packages/astropy-0.4rc3.dev9437-py2.7-macosx-10.9-x86_64.egg/astropy/io/fits/header.py:462: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
cls = <class 'astropy.io.fits.header.Header'>, block_iter = <function block_iter at 0x104323398>, is_binary = True, sep = '' | |
endcard = True, padding = True | |
@classmethod | |
def _from_blocks(cls, block_iter, is_binary, sep, endcard, padding): | |
""" | |
The meat of `Header.fromfile`; in a separate method so that | |
`Header.fromfile` itself is just responsible for wrapping file | |
handling. Also used by `_BaseHDU.fromstring`. | |
``block_iter`` should be a callable which, given a block size n | |
(typically 2880 bytes as used by the FITS standard) returns an iterator | |
of byte strings of that block size. | |
``is_binary`` specifies whether the returned blocks are bytes or text | |
Returns both the entire header *string*, and the `Header` object | |
returned by Header.fromstring on that string. | |
""" | |
actual_block_size = _block_size(sep) | |
clen = Card.length + len(sep) | |
blocks = block_iter(actual_block_size) | |
# Read the first header block. | |
try: | |
block = next(blocks) | |
except StopIteration: | |
raise EOFError() | |
if not is_binary: | |
# TODO: There needs to be error handling at *this* level for | |
# non-ASCII characters; maybe at this stage decoding latin-1 might | |
# be safer | |
block = encode_ascii(block) | |
read_blocks = [] | |
is_eof = False | |
end_found = False | |
# continue reading header blocks until END card or EOF is reached | |
while True: | |
# find the END card | |
end_found, block = cls._find_end_card(block, clen) | |
read_blocks.append(decode_ascii(block)) | |
if end_found: | |
break | |
try: | |
block = next(blocks) | |
except StopIteration: | |
is_eof = True | |
break | |
if not block: | |
is_eof = True | |
break | |
if not is_binary: | |
block = encode_ascii(block) | |
if not end_found and is_eof and endcard: | |
# TODO: Pass this error to validation framework as an ERROR, | |
# rather than raising an exception | |
> raise IOError('Header missing END card.') | |
E IOError: Header missing END card. | |
/Users/deil/Library/Python/2.7/lib/python/site-packages/astropy-0.4rc3.dev9437-py2.7-macosx-10.9-x86_64.egg/astropy/io/fits/header.py:531: IOError | |
_______________________________________________ TestFermiVelaRegion.test_background_cube ________________________________________________ | |
self = <gammapy.datasets.tests.test_load.TestFermiVelaRegion instance at 0x104610248> | |
@remote_data | |
def test_background_cube(self): | |
> background = FermiVelaRegion.background_cube() | |
gammapy/datasets/tests/test_load.py:78: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
@staticmethod | |
def background_cube(): | |
"""Predicted background counts spectral cube, based on the Fermi Diffuse model. | |
Returns | |
------- | |
spectral_cube : `~gammapy.spectral_cube.GammaSpectralCube` | |
Diffuse model spectral cube | |
""" | |
filename = FermiVelaRegion.filenames()['background_cube'] | |
> return fits.open(filename)[0] | |
gammapy/datasets/load.py:213: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
name = '/var/folders/sb/4qv5j4m90pz1rw7m70rj1b1r0000gn/T/tmpna45hsastropy_cache/astropy/download/b856f8f907ea3a897d109bcee42bf7e0' | |
mode = 'readonly', memmap = True, save_backup = False, kwargs = {}, conf = <astropy.io.fits.Conf object at 0x103049150> | |
def fitsopen(name, mode='readonly', memmap=None, save_backup=False, **kwargs): | |
"""Factory function to open a FITS file and return an `HDUList` object. | |
Parameters | |
---------- | |
name : file path, file object or file-like object | |
File to be opened. | |
mode : str | |
Open mode, 'readonly' (default), 'update', 'append', 'denywrite', or | |
'ostream'. | |
If ``name`` is a file object that is already opened, ``mode`` must | |
match the mode the file was opened with, readonly (rb), update (rb+), | |
append (ab+), ostream (w), denywrite (rb)). | |
memmap : bool | |
Is memory mapping to be used? | |
save_backup : bool | |
If the file was opened in update or append mode, this ensures that a | |
backup of the original file is saved before any changes are flushed. | |
The backup has the same name as the original file with ".bak" appended. | |
If "file.bak" already exists then "file.bak.1" is used, and so on. | |
kwargs : dict | |
optional keyword arguments, possible values are: | |
- **uint** : bool | |
Interpret signed integer data where ``BZERO`` is the | |
central value and ``BSCALE == 1`` as unsigned integer | |
data. For example, ``int16`` data with ``BZERO = 32768`` | |
and ``BSCALE = 1`` would be treated as ``uint16`` data. | |
Note, for backward compatibility, the kwarg **uint16** may | |
be used instead. The kwarg was renamed when support was | |
added for integers of any size. | |
- **ignore_missing_end** : bool | |
Do not issue an exception when opening a file that is | |
missing an ``END`` card in the last header. | |
- **checksum** : bool, str | |
If `True`, verifies that both ``DATASUM`` and | |
``CHECKSUM`` card values (when present in the HDU header) | |
match the header and data of all HDU's in the file. Updates to a | |
file that already has a checksum will preserve and update the | |
existing checksums unless this argument is given a value of | |
'remove', in which case the CHECKSUM and DATASUM values are not | |
checked, and are removed when saving changes to the file. | |
- **disable_image_compression** : bool | |
If `True`, treates compressed image HDU's like normal | |
binary table HDU's. | |
- **do_not_scale_image_data** : bool | |
If `True`, image data is not scaled using BSCALE/BZERO values | |
when read. | |
- **ignore_blank** : bool | |
If `True`, the BLANK keyword is ignored if present. | |
- **scale_back** : bool | |
If `True`, when saving changes to a file that contained scaled | |
image data, restore the data to the original type and reapply the | |
original BSCALE/BZERO values. This could lead to loss of accuracy | |
if scaling back to integer values after performing floating point | |
operations on the data. | |
Returns | |
------- | |
hdulist : an `HDUList` object | |
`HDUList` containing all of the header data units in the | |
file. | |
""" | |
if memmap is None: | |
from .. import conf | |
memmap = conf.use_memmap | |
if 'uint16' in kwargs and 'uint' not in kwargs: | |
kwargs['uint'] = kwargs['uint16'] | |
del kwargs['uint16'] | |
if not name: | |
raise ValueError('Empty filename: %s' % repr(name)) | |
> return HDUList.fromfile(name, mode, memmap, save_backup, **kwargs) | |
/Users/deil/Library/Python/2.7/lib/python/site-packages/astropy-0.4rc3.dev9437-py2.7-macosx-10.9-x86_64.egg/astropy/io/fits/hdu/hdulist.py:119: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
cls = <class 'astropy.io.fits.hdu.hdulist.HDUList'> | |
fileobj = '/var/folders/sb/4qv5j4m90pz1rw7m70rj1b1r0000gn/T/tmpna45hsastropy_cache/astropy/download/b856f8f907ea3a897d109bcee42bf7e0' | |
mode = 'readonly', memmap = True, save_backup = False, kwargs = {} | |
@classmethod | |
def fromfile(cls, fileobj, mode=None, memmap=False, | |
save_backup=False, **kwargs): | |
""" | |
Creates an `HDUList` instance from a file-like object. | |
The actual implementation of ``fitsopen()``, and generally shouldn't | |
be used directly. Use :func:`open` instead (and see its | |
documentation for details of the parameters accepted by this method). | |
""" | |
return cls._readfrom(fileobj=fileobj, mode=mode, memmap=memmap, | |
> save_backup=save_backup, **kwargs) | |
/Users/deil/Library/Python/2.7/lib/python/site-packages/astropy-0.4rc3.dev9437-py2.7-macosx-10.9-x86_64.egg/astropy/io/fits/hdu/hdulist.py:251: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
cls = <class 'astropy.io.fits.hdu.hdulist.HDUList'> | |
fileobj = '/var/folders/sb/4qv5j4m90pz1rw7m70rj1b1r0000gn/T/tmpna45hsastropy_cache/astropy/download/b856f8f907ea3a897d109bcee42bf7e0' | |
data = None, mode = 'readonly', memmap = True, save_backup = False, kwargs = {} | |
ffo = <astropy.io.fits.file._File <open file u'/var/folders/sb/4qv5j4m90pz1rw7m70rj1.../astropy/download/b856f8f907ea3a897d109bcee42bf7e0', mode 'rb' at 0x1042b54b0>> | |
hdulist = [], saved_compression_enabled = True | |
@classmethod | |
def _readfrom(cls, fileobj=None, data=None, mode=None, | |
memmap=False, save_backup=False, **kwargs): | |
""" | |
Provides the implementations from HDUList.fromfile and | |
HDUList.fromstring, both of which wrap this method, as their | |
implementations are largely the same. | |
""" | |
if fileobj is not None: | |
if not isinstance(fileobj, _File): | |
# instantiate a FITS file object (ffo) | |
ffo = _File(fileobj, mode=mode, memmap=memmap) | |
else: | |
ffo = fileobj | |
# The pyfits mode is determined by the _File initializer if the | |
# supplied mode was None | |
mode = ffo.mode | |
hdulist = cls(file=ffo) | |
else: | |
if mode is None: | |
# The default mode | |
mode = 'readonly' | |
hdulist = cls() | |
# This method is currently only called from HDUList.fromstring and | |
# HDUList.fromfile. If fileobj is None then this must be the | |
# fromstring case; the data type of ``data`` will be checked in the | |
# _BaseHDU.fromstring call. | |
hdulist._save_backup = save_backup | |
saved_compression_enabled = compressed.COMPRESSION_ENABLED | |
try: | |
if ('disable_image_compression' in kwargs and | |
kwargs['disable_image_compression']): | |
compressed.COMPRESSION_ENABLED = False | |
# read all HDUs | |
while True: | |
try: | |
if fileobj is not None: | |
if ffo.writeonly: | |
# Output stream--not interested in reading/parsing | |
# the HDUs--just writing to the output file | |
return hdulist | |
try: | |
> hdu = _BaseHDU.readfrom(ffo, **kwargs) | |
/Users/deil/Library/Python/2.7/lib/python/site-packages/astropy-0.4rc3.dev9437-py2.7-macosx-10.9-x86_64.egg/astropy/io/fits/hdu/hdulist.py:805: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
cls = <class 'astropy.io.fits.hdu.base._BaseHDU'> | |
fileobj = <astropy.io.fits.file._File <open file u'/var/folders/sb/4qv5j4m90pz1rw7m70rj1.../astropy/download/b856f8f907ea3a897d109bcee42bf7e0', mode 'rb' at 0x1042b54b0>> | |
checksum = False, ignore_missing_end = False, kwargs = {} | |
@classmethod | |
def readfrom(cls, fileobj, checksum=False, ignore_missing_end=False, | |
**kwargs): | |
""" | |
Read the HDU from a file. Normally an HDU should be opened with | |
:func:`open` which reads the entire HDU list in a FITS file. But this | |
method is still provided for symmetry with :func:`writeto`. | |
Parameters | |
---------- | |
fileobj : file object or file-like object | |
Input FITS file. The file's seek pointer is assumed to be at the | |
beginning of the HDU. | |
checksum : bool | |
If `True`, verifies that both ``DATASUM`` and ``CHECKSUM`` card | |
values (when present in the HDU header) match the header and data | |
of all HDU's in the file. | |
ignore_missing_end : bool | |
Do not issue an exception when opening a file that is missing an | |
``END`` card in the last header. | |
""" | |
# TODO: Figure out a way to make it possible for the _File | |
# constructor to be a noop if the argument is already a _File | |
if not isinstance(fileobj, _File): | |
fileobj = _File(fileobj) | |
hdu = cls._readfrom_internal(fileobj, checksum=checksum, | |
ignore_missing_end=ignore_missing_end, | |
> **kwargs) | |
/Users/deil/Library/Python/2.7/lib/python/site-packages/astropy-0.4rc3.dev9437-py2.7-macosx-10.9-x86_64.egg/astropy/io/fits/hdu/base.py:379: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
cls = <class 'astropy.io.fits.hdu.base._BaseHDU'> | |
data = <astropy.io.fits.file._File <open file u'/var/folders/sb/4qv5j4m90pz1rw7m70rj1.../astropy/download/b856f8f907ea3a897d109bcee42bf7e0', mode 'rb' at 0x1042b54b0>> | |
header = None, checksum = False, ignore_missing_end = False, kwargs = {}, hdu_buffer = None, hdu_fileobj = None, header_offset = 0 | |
from_file = True | |
@classmethod | |
def _readfrom_internal(cls, data, header=None, checksum=False, | |
ignore_missing_end=False, **kwargs): | |
""" | |
Provides the bulk of the internal implementation for readfrom and | |
fromstring. | |
For some special cases, supports using a header that was already | |
created, and just using the input data for the actual array data. | |
""" | |
hdu_buffer = None | |
hdu_fileobj = None | |
header_offset = 0 | |
if isinstance(data, _File): | |
from_file = True | |
if header is None: | |
header_offset = data.tell() | |
> header = Header.fromfile(data, endcard=not ignore_missing_end) | |
/Users/deil/Library/Python/2.7/lib/python/site-packages/astropy-0.4rc3.dev9437-py2.7-macosx-10.9-x86_64.egg/astropy/io/fits/hdu/base.py:439: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
cls = <class 'astropy.io.fits.header.Header'> | |
fileobj = <astropy.io.fits.file._File <open file u'/var/folders/sb/4qv5j4m90pz1rw7m70rj1.../astropy/download/b856f8f907ea3a897d109bcee42bf7e0', mode 'rb' at 0x1042b54b0>> | |
sep = '', endcard = True, padding = True | |
@classmethod | |
def fromfile(cls, fileobj, sep='', endcard=True, padding=True): | |
""" | |
Similar to :meth:`Header.fromstring`, but reads the header string from | |
a given file-like object or filename. | |
Parameters | |
---------- | |
fileobj : str, file-like | |
A filename or an open file-like object from which a FITS header is | |
to be read. For open file handles the file pointer must be at the | |
beginning of the header. | |
sep : str, optional | |
The string separating cards from each other, such as a newline. By | |
default there is no card separator (as is the case in a raw FITS | |
file). | |
endcard : bool, optional | |
If True (the default) the header must end with an END card in order | |
to be considered valid. If an END card is not found an | |
`~.exceptions.IOError` is raised. | |
padding : bool, optional | |
If True (the default) the header will be required to be padded out | |
to a multiple of 2880, the FITS header block size. Otherwise any | |
padding, or lack thereof, is ignored. | |
Returns | |
------- | |
header | |
A new `Header` instance. | |
""" | |
close_file = False | |
if isinstance(fileobj, string_types): | |
# Open in text mode by default to support newline handling; if a | |
# binary-mode file object is passed in, the user is on their own | |
# with respect to newline handling | |
fileobj = open(fileobj, 'r') | |
close_file = True | |
try: | |
is_binary = fileobj_is_binary(fileobj) | |
def block_iter(nbytes): | |
while True: | |
data = fileobj.read(nbytes) | |
if data: | |
yield data | |
else: | |
break | |
return cls._from_blocks(block_iter, is_binary, sep, endcard, | |
> padding)[1] | |
/Users/deil/Library/Python/2.7/lib/python/site-packages/astropy-0.4rc3.dev9437-py2.7-macosx-10.9-x86_64.egg/astropy/io/fits/header.py:462: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
cls = <class 'astropy.io.fits.header.Header'>, block_iter = <function block_iter at 0x105a85cf8>, is_binary = True, sep = '' | |
endcard = True, padding = True | |
@classmethod | |
def _from_blocks(cls, block_iter, is_binary, sep, endcard, padding): | |
""" | |
The meat of `Header.fromfile`; in a separate method so that | |
`Header.fromfile` itself is just responsible for wrapping file | |
handling. Also used by `_BaseHDU.fromstring`. | |
``block_iter`` should be a callable which, given a block size n | |
(typically 2880 bytes as used by the FITS standard) returns an iterator | |
of byte strings of that block size. | |
``is_binary`` specifies whether the returned blocks are bytes or text | |
Returns both the entire header *string*, and the `Header` object | |
returned by Header.fromstring on that string. | |
""" | |
actual_block_size = _block_size(sep) | |
clen = Card.length + len(sep) | |
blocks = block_iter(actual_block_size) | |
# Read the first header block. | |
try: | |
block = next(blocks) | |
except StopIteration: | |
raise EOFError() | |
if not is_binary: | |
# TODO: There needs to be error handling at *this* level for | |
# non-ASCII characters; maybe at this stage decoding latin-1 might | |
# be safer | |
block = encode_ascii(block) | |
read_blocks = [] | |
is_eof = False | |
end_found = False | |
# continue reading header blocks until END card or EOF is reached | |
while True: | |
# find the END card | |
end_found, block = cls._find_end_card(block, clen) | |
read_blocks.append(decode_ascii(block)) | |
if end_found: | |
break | |
try: | |
block = next(blocks) | |
except StopIteration: | |
is_eof = True | |
break | |
if not block: | |
is_eof = True | |
break | |
if not is_binary: | |
block = encode_ascii(block) | |
if not end_found and is_eof and endcard: | |
# TODO: Pass this error to validation framework as an ERROR, | |
# rather than raising an exception | |
> raise IOError('Header missing END card.') | |
E IOError: Header missing END card. | |
/Users/deil/Library/Python/2.7/lib/python/site-packages/astropy-0.4rc3.dev9437-py2.7-macosx-10.9-x86_64.egg/astropy/io/fits/header.py:531: IOError | |
________________________________________________ TestFermiVelaRegion.test_exposure_cube _________________________________________________ | |
self = <gammapy.datasets.tests.test_load.TestFermiVelaRegion instance at 0x105d2a7e8> | |
@remote_data | |
def test_exposure_cube(self): | |
> exposure_cube = FermiVelaRegion.exposure_cube() | |
gammapy/datasets/tests/test_load.py:84: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
@staticmethod | |
def exposure_cube(): | |
"""Exposure cube. | |
Returns | |
------- | |
spectral_cube : `~gammapy.spectral_cube.GammaSpectralCube` | |
Exposure cube | |
""" | |
filename = FermiVelaRegion.filenames()['exposure_cube'] | |
> return GammaSpectralCube.read(filename) | |
gammapy/datasets/load.py:225: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
filename = '/var/folders/sb/4qv5j4m90pz1rw7m70rj1b1r0000gn/T/tmpna45hsastropy_cache/astropy/download/042f15bfd69d3d3153427aeb62d52f8f' | |
@staticmethod | |
def read(filename): | |
"""Read spectral cube from FITS file. | |
Parameters | |
---------- | |
filename : str | |
File name | |
Returns | |
------- | |
spectral_cube : `GammaSpectralCube` | |
Spectral cube | |
""" | |
> data = fits.getdata(filename) | |
gammapy/spectral_cube/core.py:136: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
filename = '/var/folders/sb/4qv5j4m90pz1rw7m70rj1b1r0000gn/T/tmpna45hsastropy_cache/astropy/download/042f15bfd69d3d3153427aeb62d52f8f' | |
args = (), kwargs = {}, mode = 'readonly', closed = False, header = None, lower = None, upper = None, view = None | |
def getdata(filename, *args, **kwargs): | |
""" | |
Get the data from an extension of a FITS file (and optionally the | |
header). | |
Parameters | |
---------- | |
filename : file path, file object, or file like object | |
File to get data from. If opened, mode must be one of the | |
following rb, rb+, or ab+. | |
ext | |
The rest of the arguments are for extension specification. | |
They are flexible and are best illustrated by examples. | |
No extra arguments implies the primary header:: | |
getdata('in.fits') | |
By extension number:: | |
getdata('in.fits', 0) # the primary header | |
getdata('in.fits', 2) # the second extension | |
getdata('in.fits', ext=2) # the second extension | |
By name, i.e., ``EXTNAME`` value (if unique):: | |
getdata('in.fits', 'sci') | |
getdata('in.fits', extname='sci') # equivalent | |
Note ``EXTNAME`` values are not case sensitive | |
By combination of ``EXTNAME`` and EXTVER`` as separate | |
arguments or as a tuple:: | |
getdata('in.fits', 'sci', 2) # EXTNAME='SCI' & EXTVER=2 | |
getdata('in.fits', extname='sci', extver=2) # equivalent | |
getdata('in.fits', ('sci', 2)) # equivalent | |
Ambiguous or conflicting specifications will raise an exception:: | |
getdata('in.fits', ext=('sci',1), extname='err', extver=2) | |
header : bool, optional | |
If `True`, return the data and the header of the specified HDU as a | |
tuple. | |
lower, upper : bool, optional | |
If ``lower`` or ``upper`` are `True`, the field names in the | |
returned data object will be converted to lower or upper case, | |
respectively. | |
view : ndarray, optional | |
When given, the data will be returned wrapped in the given ndarray | |
subclass by calling:: | |
data.view(view) | |
kwargs | |
Any additional keyword arguments to be passed to | |
`astropy.io.fits.open`. | |
Returns | |
------- | |
array : array, record array or groups data object | |
Type depends on the type of the extension being referenced. | |
If the optional keyword ``header`` is set to `True`, this | |
function will return a (``data``, ``header``) tuple. | |
""" | |
mode, closed = _get_file_mode(filename) | |
header = kwargs.pop('header', None) | |
lower = kwargs.pop('lower', None) | |
upper = kwargs.pop('upper', None) | |
view = kwargs.pop('view', None) | |
> hdulist, extidx = _getext(filename, mode, *args, **kwargs) | |
/Users/deil/Library/Python/2.7/lib/python/site-packages/astropy-0.4rc3.dev9437-py2.7-macosx-10.9-x86_64.egg/astropy/io/fits/convenience.py:187: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
filename = '/var/folders/sb/4qv5j4m90pz1rw7m70rj1b1r0000gn/T/tmpna45hsastropy_cache/astropy/download/042f15bfd69d3d3153427aeb62d52f8f' | |
mode = 'readonly', args = (), kwargs = {}, ext = 0, extname = None, extver = None | |
err_msg = "Redundant/conflicting extension arguments(s): {'ext': None, 'args': (), 'extver': None, 'extname': None}" | |
def _getext(filename, mode, *args, **kwargs): | |
""" | |
Open the input file, return the `HDUList` and the extension. | |
This supports several different styles of extension selection. See the | |
:func:`getdata()` documentation for the different possibilities. | |
""" | |
ext = kwargs.pop('ext', None) | |
extname = kwargs.pop('extname', None) | |
extver = kwargs.pop('extver', None) | |
err_msg = ('Redundant/conflicting extension arguments(s): %s' % | |
({'args': args, 'ext': ext, 'extname': extname, | |
'extver': extver},)) | |
# This code would be much simpler if just one way of specifying an | |
# extension were picked. But now we need to support all possible ways for | |
# the time being. | |
if len(args) == 1: | |
# Must be either an extension number, an extension name, or an | |
# (extname, extver) tuple | |
if _is_int(args[0]) or (isinstance(ext, tuple) and len(ext) == 2): | |
if ext is not None or extname is not None or extver is not None: | |
raise TypeError(err_msg) | |
ext = args[0] | |
elif isinstance(args[0], string_types): | |
# The first arg is an extension name; it could still be valid | |
# to provide an extver kwarg | |
if ext is not None or extname is not None: | |
raise TypeError(err_msg) | |
extname = args[0] | |
else: | |
# Take whatever we have as the ext argument; we'll validate it | |
# below | |
ext = args[0] | |
elif len(args) == 2: | |
# Must be an extname and extver | |
if ext is not None or extname is not None or extver is not None: | |
raise TypeError(err_msg) | |
extname = args[0] | |
extver = args[1] | |
elif len(args) > 2: | |
raise TypeError('Too many positional arguments.') | |
if (ext is not None and | |
not (_is_int(ext) or | |
(isinstance(ext, tuple) and len(ext) == 2 and | |
isinstance(ext[0], string_types) and _is_int(ext[1])))): | |
raise ValueError( | |
'The ext keyword must be either an extension number ' | |
'(zero-indexed) or a (extname, extver) tuple.') | |
if extname is not None and not isinstance(extname, string_types): | |
raise ValueError('The extname argument must be a string.') | |
if extver is not None and not _is_int(extver): | |
raise ValueError('The extver argument must be an integer.') | |
if ext is None and extname is None and extver is None: | |
ext = 0 | |
elif ext is not None and (extname is not None or extver is not None): | |
raise TypeError(err_msg) | |
elif extname: | |
if extver: | |
ext = (extname, extver) | |
else: | |
ext = (extname, 1) | |
elif extver and extname is None: | |
raise TypeError('extver alone cannot specify an extension.') | |
> hdulist = fitsopen(filename, mode=mode, **kwargs) | |
/Users/deil/Library/Python/2.7/lib/python/site-packages/astropy-0.4rc3.dev9437-py2.7-macosx-10.9-x86_64.egg/astropy/io/fits/convenience.py:753: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
name = '/var/folders/sb/4qv5j4m90pz1rw7m70rj1b1r0000gn/T/tmpna45hsastropy_cache/astropy/download/042f15bfd69d3d3153427aeb62d52f8f' | |
mode = 'readonly', memmap = True, save_backup = False, kwargs = {}, conf = <astropy.io.fits.Conf object at 0x103049150> | |
def fitsopen(name, mode='readonly', memmap=None, save_backup=False, **kwargs): | |
"""Factory function to open a FITS file and return an `HDUList` object. | |
Parameters | |
---------- | |
name : file path, file object or file-like object | |
File to be opened. | |
mode : str | |
Open mode, 'readonly' (default), 'update', 'append', 'denywrite', or | |
'ostream'. | |
If ``name`` is a file object that is already opened, ``mode`` must | |
match the mode the file was opened with, readonly (rb), update (rb+), | |
append (ab+), ostream (w), denywrite (rb)). | |
memmap : bool | |
Is memory mapping to be used? | |
save_backup : bool | |
If the file was opened in update or append mode, this ensures that a | |
backup of the original file is saved before any changes are flushed. | |
The backup has the same name as the original file with ".bak" appended. | |
If "file.bak" already exists then "file.bak.1" is used, and so on. | |
kwargs : dict | |
optional keyword arguments, possible values are: | |
- **uint** : bool | |
Interpret signed integer data where ``BZERO`` is the | |
central value and ``BSCALE == 1`` as unsigned integer | |
data. For example, ``int16`` data with ``BZERO = 32768`` | |
and ``BSCALE = 1`` would be treated as ``uint16`` data. | |
Note, for backward compatibility, the kwarg **uint16** may | |
be used instead. The kwarg was renamed when support was | |
added for integers of any size. | |
- **ignore_missing_end** : bool | |
Do not issue an exception when opening a file that is | |
missing an ``END`` card in the last header. | |
- **checksum** : bool, str | |
If `True`, verifies that both ``DATASUM`` and | |
``CHECKSUM`` card values (when present in the HDU header) | |
match the header and data of all HDU's in the file. Updates to a | |
file that already has a checksum will preserve and update the | |
existing checksums unless this argument is given a value of | |
'remove', in which case the CHECKSUM and DATASUM values are not | |
checked, and are removed when saving changes to the file. | |
- **disable_image_compression** : bool | |
If `True`, treates compressed image HDU's like normal | |
binary table HDU's. | |
- **do_not_scale_image_data** : bool | |
If `True`, image data is not scaled using BSCALE/BZERO values | |
when read. | |
- **ignore_blank** : bool | |
If `True`, the BLANK keyword is ignored if present. | |
- **scale_back** : bool | |
If `True`, when saving changes to a file that contained scaled | |
image data, restore the data to the original type and reapply the | |
original BSCALE/BZERO values. This could lead to loss of accuracy | |
if scaling back to integer values after performing floating point | |
operations on the data. | |
Returns | |
------- | |
hdulist : an `HDUList` object | |
`HDUList` containing all of the header data units in the | |
file. | |
""" | |
if memmap is None: | |
from .. import conf | |
memmap = conf.use_memmap | |
if 'uint16' in kwargs and 'uint' not in kwargs: | |
kwargs['uint'] = kwargs['uint16'] | |
del kwargs['uint16'] | |
if not name: | |
raise ValueError('Empty filename: %s' % repr(name)) | |
> return HDUList.fromfile(name, mode, memmap, save_backup, **kwargs) | |
/Users/deil/Library/Python/2.7/lib/python/site-packages/astropy-0.4rc3.dev9437-py2.7-macosx-10.9-x86_64.egg/astropy/io/fits/hdu/hdulist.py:119: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
cls = <class 'astropy.io.fits.hdu.hdulist.HDUList'> | |
fileobj = '/var/folders/sb/4qv5j4m90pz1rw7m70rj1b1r0000gn/T/tmpna45hsastropy_cache/astropy/download/042f15bfd69d3d3153427aeb62d52f8f' | |
mode = 'readonly', memmap = True, save_backup = False, kwargs = {} | |
@classmethod | |
def fromfile(cls, fileobj, mode=None, memmap=False, | |
save_backup=False, **kwargs): | |
""" | |
Creates an `HDUList` instance from a file-like object. | |
The actual implementation of ``fitsopen()``, and generally shouldn't | |
be used directly. Use :func:`open` instead (and see its | |
documentation for details of the parameters accepted by this method). | |
""" | |
return cls._readfrom(fileobj=fileobj, mode=mode, memmap=memmap, | |
> save_backup=save_backup, **kwargs) | |
/Users/deil/Library/Python/2.7/lib/python/site-packages/astropy-0.4rc3.dev9437-py2.7-macosx-10.9-x86_64.egg/astropy/io/fits/hdu/hdulist.py:251: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
cls = <class 'astropy.io.fits.hdu.hdulist.HDUList'> | |
fileobj = '/var/folders/sb/4qv5j4m90pz1rw7m70rj1b1r0000gn/T/tmpna45hsastropy_cache/astropy/download/042f15bfd69d3d3153427aeb62d52f8f' | |
data = None, mode = 'readonly', memmap = True, save_backup = False, kwargs = {} | |
ffo = <astropy.io.fits.file._File <open file u'/var/folders/sb/4qv5j4m90pz1rw7m70rj1.../astropy/download/042f15bfd69d3d3153427aeb62d52f8f', mode 'rb' at 0x1042b5420>> | |
hdulist = [], saved_compression_enabled = True | |
@classmethod | |
def _readfrom(cls, fileobj=None, data=None, mode=None, | |
memmap=False, save_backup=False, **kwargs): | |
""" | |
Provides the implementations from HDUList.fromfile and | |
HDUList.fromstring, both of which wrap this method, as their | |
implementations are largely the same. | |
""" | |
if fileobj is not None: | |
if not isinstance(fileobj, _File): | |
# instantiate a FITS file object (ffo) | |
ffo = _File(fileobj, mode=mode, memmap=memmap) | |
else: | |
ffo = fileobj | |
# The pyfits mode is determined by the _File initializer if the | |
# supplied mode was None | |
mode = ffo.mode | |
hdulist = cls(file=ffo) | |
else: | |
if mode is None: | |
# The default mode | |
mode = 'readonly' | |
hdulist = cls() | |
# This method is currently only called from HDUList.fromstring and | |
# HDUList.fromfile. If fileobj is None then this must be the | |
# fromstring case; the data type of ``data`` will be checked in the | |
# _BaseHDU.fromstring call. | |
hdulist._save_backup = save_backup | |
saved_compression_enabled = compressed.COMPRESSION_ENABLED | |
try: | |
if ('disable_image_compression' in kwargs and | |
kwargs['disable_image_compression']): | |
compressed.COMPRESSION_ENABLED = False | |
# read all HDUs | |
while True: | |
try: | |
if fileobj is not None: | |
if ffo.writeonly: | |
# Output stream--not interested in reading/parsing | |
# the HDUs--just writing to the output file | |
return hdulist | |
try: | |
> hdu = _BaseHDU.readfrom(ffo, **kwargs) | |
/Users/deil/Library/Python/2.7/lib/python/site-packages/astropy-0.4rc3.dev9437-py2.7-macosx-10.9-x86_64.egg/astropy/io/fits/hdu/hdulist.py:805: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
cls = <class 'astropy.io.fits.hdu.base._BaseHDU'> | |
fileobj = <astropy.io.fits.file._File <open file u'/var/folders/sb/4qv5j4m90pz1rw7m70rj1.../astropy/download/042f15bfd69d3d3153427aeb62d52f8f', mode 'rb' at 0x1042b5420>> | |
checksum = False, ignore_missing_end = False, kwargs = {} | |
@classmethod | |
def readfrom(cls, fileobj, checksum=False, ignore_missing_end=False, | |
**kwargs): | |
""" | |
Read the HDU from a file. Normally an HDU should be opened with | |
:func:`open` which reads the entire HDU list in a FITS file. But this | |
method is still provided for symmetry with :func:`writeto`. | |
Parameters | |
---------- | |
fileobj : file object or file-like object | |
Input FITS file. The file's seek pointer is assumed to be at the | |
beginning of the HDU. | |
checksum : bool | |
If `True`, verifies that both ``DATASUM`` and ``CHECKSUM`` card | |
values (when present in the HDU header) match the header and data | |
of all HDU's in the file. | |
ignore_missing_end : bool | |
Do not issue an exception when opening a file that is missing an | |
``END`` card in the last header. | |
""" | |
# TODO: Figure out a way to make it possible for the _File | |
# constructor to be a noop if the argument is already a _File | |
if not isinstance(fileobj, _File): | |
fileobj = _File(fileobj) | |
hdu = cls._readfrom_internal(fileobj, checksum=checksum, | |
ignore_missing_end=ignore_missing_end, | |
> **kwargs) | |
/Users/deil/Library/Python/2.7/lib/python/site-packages/astropy-0.4rc3.dev9437-py2.7-macosx-10.9-x86_64.egg/astropy/io/fits/hdu/base.py:379: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
cls = <class 'astropy.io.fits.hdu.base._BaseHDU'> | |
data = <astropy.io.fits.file._File <open file u'/var/folders/sb/4qv5j4m90pz1rw7m70rj1.../astropy/download/042f15bfd69d3d3153427aeb62d52f8f', mode 'rb' at 0x1042b5420>> | |
header = None, checksum = False, ignore_missing_end = False, kwargs = {}, hdu_buffer = None, hdu_fileobj = None, header_offset = 0 | |
from_file = True | |
@classmethod | |
def _readfrom_internal(cls, data, header=None, checksum=False, | |
ignore_missing_end=False, **kwargs): | |
""" | |
Provides the bulk of the internal implementation for readfrom and | |
fromstring. | |
For some special cases, supports using a header that was already | |
created, and just using the input data for the actual array data. | |
""" | |
hdu_buffer = None | |
hdu_fileobj = None | |
header_offset = 0 | |
if isinstance(data, _File): | |
from_file = True | |
if header is None: | |
header_offset = data.tell() | |
> header = Header.fromfile(data, endcard=not ignore_missing_end) | |
/Users/deil/Library/Python/2.7/lib/python/site-packages/astropy-0.4rc3.dev9437-py2.7-macosx-10.9-x86_64.egg/astropy/io/fits/hdu/base.py:439: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
cls = <class 'astropy.io.fits.header.Header'> | |
fileobj = <astropy.io.fits.file._File <open file u'/var/folders/sb/4qv5j4m90pz1rw7m70rj1.../astropy/download/042f15bfd69d3d3153427aeb62d52f8f', mode 'rb' at 0x1042b5420>> | |
sep = '', endcard = True, padding = True | |
@classmethod | |
def fromfile(cls, fileobj, sep='', endcard=True, padding=True): | |
""" | |
Similar to :meth:`Header.fromstring`, but reads the header string from | |
a given file-like object or filename. | |
Parameters | |
---------- | |
fileobj : str, file-like | |
A filename or an open file-like object from which a FITS header is | |
to be read. For open file handles the file pointer must be at the | |
beginning of the header. | |
sep : str, optional | |
The string separating cards from each other, such as a newline. By | |
default there is no card separator (as is the case in a raw FITS | |
file). | |
endcard : bool, optional | |
If True (the default) the header must end with an END card in order | |
to be considered valid. If an END card is not found an | |
`~.exceptions.IOError` is raised. | |
padding : bool, optional | |
If True (the default) the header will be required to be padded out | |
to a multiple of 2880, the FITS header block size. Otherwise any | |
padding, or lack thereof, is ignored. | |
Returns | |
------- | |
header | |
A new `Header` instance. | |
""" | |
close_file = False | |
if isinstance(fileobj, string_types): | |
# Open in text mode by default to support newline handling; if a | |
# binary-mode file object is passed in, the user is on their own | |
# with respect to newline handling | |
fileobj = open(fileobj, 'r') | |
close_file = True | |
try: | |
is_binary = fileobj_is_binary(fileobj) | |
def block_iter(nbytes): | |
while True: | |
data = fileobj.read(nbytes) | |
if data: | |
yield data | |
else: | |
break | |
return cls._from_blocks(block_iter, is_binary, sep, endcard, | |
> padding)[1] | |
/Users/deil/Library/Python/2.7/lib/python/site-packages/astropy-0.4rc3.dev9437-py2.7-macosx-10.9-x86_64.egg/astropy/io/fits/header.py:462: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
cls = <class 'astropy.io.fits.header.Header'>, block_iter = <function block_iter at 0x1042e7140>, is_binary = True, sep = '' | |
endcard = True, padding = True | |
@classmethod | |
def _from_blocks(cls, block_iter, is_binary, sep, endcard, padding): | |
""" | |
The meat of `Header.fromfile`; in a separate method so that | |
`Header.fromfile` itself is just responsible for wrapping file | |
handling. Also used by `_BaseHDU.fromstring`. | |
``block_iter`` should be a callable which, given a block size n | |
(typically 2880 bytes as used by the FITS standard) returns an iterator | |
of byte strings of that block size. | |
``is_binary`` specifies whether the returned blocks are bytes or text | |
Returns both the entire header *string*, and the `Header` object | |
returned by Header.fromstring on that string. | |
""" | |
actual_block_size = _block_size(sep) | |
clen = Card.length + len(sep) | |
blocks = block_iter(actual_block_size) | |
# Read the first header block. | |
try: | |
block = next(blocks) | |
except StopIteration: | |
raise EOFError() | |
if not is_binary: | |
# TODO: There needs to be error handling at *this* level for | |
# non-ASCII characters; maybe at this stage decoding latin-1 might | |
# be safer | |
block = encode_ascii(block) | |
read_blocks = [] | |
is_eof = False | |
end_found = False | |
# continue reading header blocks until END card or EOF is reached | |
while True: | |
# find the END card | |
end_found, block = cls._find_end_card(block, clen) | |
read_blocks.append(decode_ascii(block)) | |
if end_found: | |
break | |
try: | |
block = next(blocks) | |
except StopIteration: | |
is_eof = True | |
break | |
if not block: | |
is_eof = True | |
break | |
if not is_binary: | |
block = encode_ascii(block) | |
if not end_found and is_eof and endcard: | |
# TODO: Pass this error to validation framework as an ERROR, | |
# rather than raising an exception | |
> raise IOError('Header missing END card.') | |
E IOError: Header missing END card. | |
/Users/deil/Library/Python/2.7/lib/python/site-packages/astropy-0.4rc3.dev9437-py2.7-macosx-10.9-x86_64.egg/astropy/io/fits/header.py:531: IOError | |
============================================ 3 failed, 9 passed, 1 xpassed in 10.18 seconds ============================================= |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment