Skip to content

Commit

Permalink
Merge branch 'master' into astropy
Browse files Browse the repository at this point in the history
This brings in all changes to trunk for PyFITS v3.3.0 between
8d2a54d3ef93e356a0d20a71924cff7ab8c87426 (SVN r2391) and
2ab1b36e8135beb37bcc53859985a52a82a0d880 (SVN r2796).  These are all the
changes from that period that were not also ported as bugfixes to the
3.2.x branch.

Conflicts:
	.coveragerc
	.travis.yml
	README.txt
	astropy/io/fits/card.py
	astropy/io/fits/column.py
	astropy/io/fits/core.py
	astropy/io/fits/fitsrec.py
	astropy/io/fits/hdu/base.py
	astropy/io/fits/hdu/compressed.py
	astropy/io/fits/header.py
	astropy/io/fits/tests/test_diff.py
	astropy/io/fits/tests/test_header.py
	astropy/io/fits/tests/test_image.py
	astropy/io/fits/tests/test_table.py
	astropy/io/fits/util.py
	docs/io/fits/appendix/header_transition.rst
	docs/io/fits/appendix/history.rst
	docs/io/fits/users_guide/users_headers.rst
	docs/io/fits/users_guide/users_tutorial.rst
	docs/io/fits/users_guide/users_verification.rst
	docs/source/conf.py
	docs/source/developers_guide/developers_guide.rst
	lib/pyfits/_release.py
	lib/pyfits/tests/test_checksum.py
	setup.cfg
	setup.py
	tox.ini

Conflicts:

	astropy/io/fits/__init__.py
	astropy/io/fits/card.py
	astropy/io/fits/column.py
	astropy/io/fits/convenience.py
	astropy/io/fits/core.py
	astropy/io/fits/diff.py
	astropy/io/fits/file.py
	astropy/io/fits/fitsrec.py
	astropy/io/fits/hdu/__init__.py
	astropy/io/fits/hdu/base.py
	astropy/io/fits/hdu/compressed.py
	astropy/io/fits/hdu/groups.py
	astropy/io/fits/hdu/hdulist.py
	astropy/io/fits/hdu/image.py
	astropy/io/fits/hdu/nonstandard.py
	astropy/io/fits/hdu/streaming.py
	astropy/io/fits/hdu/table.py
	astropy/io/fits/header.py
	astropy/io/fits/py3compat.py
	astropy/io/fits/scripts/fitscheck.py
	astropy/io/fits/scripts/fitsdiff.py
	astropy/io/fits/tests/test_checksum.py
	astropy/io/fits/tests/test_core.py
	astropy/io/fits/tests/test_diff.py
	astropy/io/fits/tests/test_division.py
	astropy/io/fits/tests/test_groups.py
	astropy/io/fits/tests/test_hdulist.py
	astropy/io/fits/tests/test_header.py
	astropy/io/fits/tests/test_image.py
	astropy/io/fits/tests/test_nonstandard.py
	astropy/io/fits/tests/test_structured.py
	astropy/io/fits/tests/test_table.py
	astropy/io/fits/tests/test_uint.py
	astropy/io/fits/tests/test_util.py
	astropy/io/fits/tests/util.py
	astropy/io/fits/util.py
	astropy/io/fits/verify.py
	docs/io/fits/api/hdus.rst
	docs/io/fits/usage/headers.rst
	docs/io/fits/usage/table.rst
	docs/io/fits/usage/unfamiliar.rst
	docs/io/fits/usage/verification.rst
	docs/io/fits/users_guide/users_tutorial.rst
  • Loading branch information
embray committed Jun 4, 2014
1 parent b85bb65 commit 9a388e2
Show file tree
Hide file tree
Showing 41 changed files with 1,974 additions and 1,185 deletions.
66 changes: 45 additions & 21 deletions astropy/io/fits/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .verify import _Verify, _ErrList, VerifyError, VerifyWarning

from . import conf
from ...extern.six import string_types, integer_types, text_type
from ...extern.six import string_types, integer_types, text_type, binary_type
from ...extern.six.moves import xrange
from ...utils import deprecated
from ...utils.exceptions import AstropyUserWarning, AstropyDeprecationWarning
Expand Down Expand Up @@ -517,7 +517,8 @@ def keyword(self, keyword):
# also displayed
warnings.warn(
'Keyword name %r is greater than 8 characters or '
'contains spaces; a HIERARCH card will be created.' %
'contains characters not allowed by the FITS '
'standard; a HIERARCH card will be created.' %
keyword, VerifyWarning)
else:
raise ValueError('Illegal keyword name: %r.' % keyword)
Expand Down Expand Up @@ -564,24 +565,23 @@ def value(self, value):
if oldvalue is None:
oldvalue = ''

if not isinstance(value, (string_types, integer_types, float, complex,
bool, Undefined, np.floating, np.integer,
np.complexfloating, np.bool_)):
if not isinstance(value, string_types + integer_types +
(float, complex, bool, Undefined, np.floating,
np.integer, np.complexfloating, np.bool_)):
raise ValueError('Illegal value: %r.' % value)

if isinstance(value, float) and (np.isnan(value) or np.isinf(value)):
raise ValueError(
"Floating point %r values are not allowed in FITS headers." %
value)

if isinstance(value, text_type):
elif isinstance(value, text_type):
m = self._ascii_text_re.match(value)
if not m:
raise ValueError(
'FITS header values must contain standard printable ASCII '
'characters; %r contains characters not representable in '
'ASCII or non-printable characters.' % value)
elif isinstance(value, bytes):
elif isinstance(value, binary_type):
# Allow str, but only if they can be decoded to ASCII text; note
# this is not even allowed on Python 3 since the `bytes` type is
# not included in `six.string_types`. Presently we simply don't
Expand Down Expand Up @@ -768,6 +768,27 @@ def image(self):
self._image = self._format_image()
return self._image

@property
def is_blank(self):
"""
`True` if the card is completely blank--that is, it has no keyword,
value, or comment. It appears in the header as 80 spaces.
Returns `False` otherwise.
"""

if not self._verified:
# The card image has not been parsed yet; compare directly with the
# string representation of a blank card
return self._image == BLANK_CARD

# If the keyword, value, and comment are all empty (for self.value
# explicitly check that it is a string value, since a blank value is
# returned as '')
return (not self.keyword and
(isinstance(self.value, string_types) and not self.value) and
not self.comment)

@property
@deprecated('0.1', alternative='the `.image` attribute')
def cardimage(self):
Expand Down Expand Up @@ -946,9 +967,6 @@ def _parse_keyword(self):

keyword_upper = keyword_upper[:val_ind_idx]

if keyword_upper != keyword:
self._modified = True

return keyword_upper
elif (keyword_upper == 'HIERARCH' and self._image[8] == ' ' and
HIERARCH_VALUE_INDICATOR in self._image):
Expand Down Expand Up @@ -1316,18 +1334,24 @@ def _verify(self, option='warn'):
self._hierarch):
pass
else:
if self._image:
# PyFITS will auto-uppercase any standard keyword, so lowercase
# keywords can only occur if they came from the wild
keyword = self._split()[0]
if keyword != keyword.upper():
# Keyword should be uppercase unless it's a HIERARCH card
errs.append(self.run_option(
option,
err_text='Card keyword %r is not upper case.' %
keyword,
fix_text=fix_text,
fix=self._fix_keyword))

keyword = self.keyword
if self.field_specifier:
keyword = keyword.split('.', 1)[0]

if keyword != keyword.upper():
# Keyword should be uppercase unless it's a HIERARCH card
errs.append(self.run_option(
option,
err_text='Card keyword %r is not upper case.' % keyword,
fix_text=fix_text,
fix=self._fix_keyword))
elif not self._keywd_FSC_RE.match(keyword):
if not self._keywd_FSC_RE.match(keyword):
errs.append(self.run_option(
option,
err_text='Illegal keyword name %s' % repr(keyword),
Expand All @@ -1351,7 +1375,7 @@ def _verify(self, option='warn'):
errs.append(self.run_option(
option,
err_text='Card %r is not FITS standard (invalid value '
'string: %s).' % (self.keyword, valuecomment),
'string: %r).' % (self.keyword, valuecomment),
fix_text=fix_text,
fix=self._fix_value))

Expand Down Expand Up @@ -1379,7 +1403,7 @@ def _itersubcards(self):

ncards = len(self._image) // Card.length

for idx in xrange(0, Card.length * ncards, Card.length):
for idx in range(0, Card.length * ncards, Card.length):
card = Card.fromstring(self._image[idx:idx + Card.length])
if idx > 0 and card.keyword.upper() != 'CONTINUE':
raise VerifyError(
Expand Down
Loading

0 comments on commit 9a388e2

Please sign in to comment.