diff -Nru stsci.tools-3.4.11/debian/changelog stsci.tools-3.4.12/debian/changelog --- stsci.tools-3.4.11/debian/changelog 2017-12-20 07:49:59.000000000 +0000 +++ stsci.tools-3.4.12/debian/changelog 2018-02-15 07:54:36.000000000 +0000 @@ -1,3 +1,12 @@ +stsci.tools (3.4.12-1) unstable; urgency=medium + + * Update VCS URLs to salsa.d.o + * New upstream version 3.4.12. Rediff patches + * Push Standards-Version to 4.1.3. No changes needed. + * Use a fake relic package for version info + + -- Ole Streicher Thu, 15 Feb 2018 08:54:36 +0100 + stsci.tools (3.4.11-1) unstable; urgency=low * Initial release. (Closes: #884598) diff -Nru stsci.tools-3.4.11/debian/clean stsci.tools-3.4.12/debian/clean --- stsci.tools-3.4.11/debian/clean 2017-12-18 16:31:09.000000000 +0000 +++ stsci.tools-3.4.12/debian/clean 2018-02-15 07:54:36.000000000 +0000 @@ -1,2 +1,3 @@ lib/stsci/tools/version.py lib/stsci.tools.egg-info/ +lib/stsci/tools/version.py diff -Nru stsci.tools-3.4.11/debian/control stsci.tools-3.4.12/debian/control --- stsci.tools-3.4.11/debian/control 2017-12-20 07:49:59.000000000 +0000 +++ stsci.tools-3.4.12/debian/control 2018-02-15 07:54:36.000000000 +0000 @@ -7,22 +7,28 @@ dh-python, python-all (>= 2.6.6-3~), python-d2to1 (>= 0.2.9~), + python-dateutil, + python-debian, python-nose, python-numpy, + python-pytest-runner, python-setuptools, python-stsci.distutils, python3-all (>= 3.1.2-6~), python3-d2to1 (>= 0.2.9~), + python3-dateutil, + python3-debian, python3-nose, python3-numpy, + python3-pytest-runner, python3-setuptools, python3-stsci.distutils X-Python-Version: >= 2.5 X-Python3-Version: >= 3.0 -Standards-Version: 4.1.2 +Standards-Version: 4.1.3 Homepage: https://pypi.python.org/pypi/stsci.tools -Vcs-Git: https://anonscm.debian.org/git/debian-astro/packages/stsci.tools.git -Vcs-Browser: https://anonscm.debian.org/cgit/debian-astro/packages/stsci.tools.git +Vcs-Git: https://salsa.debian.org/debian-astro-team/stsci.tools.git +Vcs-Browser: https://salsa.debian.org/debian-astro-team/stsci.tools Package: python-stsci.tools Architecture: all @@ -31,7 +37,7 @@ This package provides a selection of tools for FITS and WCS handling, image handling, and data analysis, used by other STScI packages. . - This is the Python 2 version. + This is the Python 2 legacy version. Package: python3-stsci.tools Architecture: all diff -Nru stsci.tools-3.4.11/debian/patches/Allow-reproducible-builds.patch stsci.tools-3.4.12/debian/patches/Allow-reproducible-builds.patch --- stsci.tools-3.4.11/debian/patches/Allow-reproducible-builds.patch 2017-12-20 07:49:59.000000000 +0000 +++ stsci.tools-3.4.12/debian/patches/Allow-reproducible-builds.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,24 +0,0 @@ -From: Ole Streicher -Date: Sun, 17 Dec 2017 14:19:57 +0100 -Subject: Allow reproducible builds - ---- - lib/stsci/tools/stsci_distutils_hack.py | 5 ++++- - 1 file changed, 4 insertions(+), 1 deletion(-) - -diff --git a/lib/stsci/tools/stsci_distutils_hack.py b/lib/stsci/tools/stsci_distutils_hack.py -index 8051fb5..22d7eb3 100644 ---- a/lib/stsci/tools/stsci_distutils_hack.py -+++ b/lib/stsci/tools/stsci_distutils_hack.py -@@ -296,7 +296,10 @@ def __get_full_info__(path): - def __set_setup_date__( path="./", fname='svn_version.py') : - import datetime - file = os.path.join(path,fname) -- d = datetime.datetime.now() -+ if 'SOURCE_DATE_EPOCH' in os.environ: -+ d = datetime.datetime.utcfromtimestamp((int(os.environ.get('SOURCE_DATE_EPOCH')))) -+ else: -+ d = datetime.datetime.now() - l = [ ] - try : - # we don't expect this to fail ever, but it might diff -Nru stsci.tools-3.4.11/debian/patches/Don-t-install-scripts.patch stsci.tools-3.4.12/debian/patches/Don-t-install-scripts.patch --- stsci.tools-3.4.11/debian/patches/Don-t-install-scripts.patch 2017-12-20 07:49:59.000000000 +0000 +++ stsci.tools-3.4.12/debian/patches/Don-t-install-scripts.patch 2018-02-15 07:54:36.000000000 +0000 @@ -1,23 +1,21 @@ From: Ole Streicher -Date: Sun, 17 Dec 2017 14:16:38 +0100 +Date: Thu, 15 Feb 2018 09:08:22 +0100 Subject: Don't install scripts --- - setup.cfg | 4 ---- - 1 file changed, 4 deletions(-) + setup.py | 2 -- + 1 file changed, 2 deletions(-) -diff --git a/setup.cfg b/setup.cfg -index 1d4d1d7..e7fb32e 100644 ---- a/setup.cfg -+++ b/setup.cfg -@@ -27,10 +27,6 @@ packages = - stsci.tools.tests - package_data = - stsci.tools.tests = *.fits --scripts = -- scripts/convertwaiveredfits -- scripts/stscidocs -- scripts/convertlog - - [nosetests] - exclude = .*(testutil|tester) +diff --git a/setup.py b/setup.py +index 01d938c..a878bd1 100755 +--- a/setup.py ++++ b/setup.py +@@ -58,8 +58,6 @@ setup( + }, + entry_points = { + 'console_scripts': [ +- 'convertwaiveredfits=stsci.tools.convertwaiveredfits:main', +- 'convertlog=stsci.tools.convertlog:main' + ], + }, + ) diff -Nru stsci.tools-3.4.11/debian/patches/series stsci.tools-3.4.12/debian/patches/series --- stsci.tools-3.4.11/debian/patches/series 2017-12-20 07:49:59.000000000 +0000 +++ stsci.tools-3.4.12/debian/patches/series 2018-02-15 07:54:36.000000000 +0000 @@ -1,4 +1,4 @@ Don-t-install-scripts.patch -Allow-reproducible-builds.patch Fix-path-for-Python-3.patch Don-t-check-for-login.cl-in-.iraf-for-userIrafHome.patch +Use-a-fake-relic-package-for-version-info.patch diff -Nru stsci.tools-3.4.11/debian/patches/Use-a-fake-relic-package-for-version-info.patch stsci.tools-3.4.12/debian/patches/Use-a-fake-relic-package-for-version-info.patch --- stsci.tools-3.4.11/debian/patches/Use-a-fake-relic-package-for-version-info.patch 1970-01-01 00:00:00.000000000 +0000 +++ stsci.tools-3.4.12/debian/patches/Use-a-fake-relic-package-for-version-info.patch 2018-02-15 07:54:36.000000000 +0000 @@ -0,0 +1,81 @@ +From: Ole Streicher +Date: Sun, 6 Nov 2016 10:24:07 +0100 +Subject: Use a fake relic package for version info + +The original package depends on a git repository, which is not there +when we build the package from a tarball. So, we take the opportunity +to take the version info from the Debian changelog. + +This requires the "python(3)-debian" package as build dependency. +--- + relic/__init__.py | 1 + + relic/release.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 53 insertions(+) + create mode 100644 relic/__init__.py + create mode 100644 relic/release.py + +diff --git a/relic/__init__.py b/relic/__init__.py +new file mode 100644 +index 0000000..8b13789 +--- /dev/null ++++ b/relic/__init__.py +@@ -0,0 +1 @@ ++ +diff --git a/relic/release.py b/relic/release.py +new file mode 100644 +index 0000000..bf442e7 +--- /dev/null ++++ b/relic/release.py +@@ -0,0 +1,52 @@ ++from collections import namedtuple ++import datetime ++import dateutil.parser ++import os ++from debian import changelog ++ ++template = """ ++__all__ = [ ++ '__version__', ++ '__version_short__', ++ '__version_long__', ++ '__version_post__', ++ '__version_commit__', ++ '__version_date__', ++ '__version_dirty__', ++ '__build_date__', ++ '__build_status__' ++] ++__version__ = '{pep386}' ++__version_short__ = '{short}' ++__version_long__ = '{long}' ++__version_post__ = '' ++__version_commit__ = '' ++__version_date__ = '{date}' ++__version_dirty__ = {dirty} ++__build_date__ = '{build_date}' ++__build_time__ = '{build_time}' ++__build_status__ = 'release' if not __version_dirty__ else 'development' ++""" ++ ++def get_info(): ++ DebVersion = namedtuple('DebVersion', ['pep386', 'short', 'long', ++ 'date', 'dirty']) ++ with open('debian/changelog') as cl_file: ++ cl = changelog.Changelog(cl_file) ++ return DebVersion(pep386=cl.upstream_version, ++ short=cl.upstream_version, ++ long=cl.version, ++ date=dateutil.parser.parse(cl.date), ++ dirty=(cl.distributions=='UNRELEASED')) ++ ++def write_template(info, module_path, filename='version.py'): ++ path = os.path.join(module_path, filename) ++ with open(path, 'w+') as f: ++ output = template.format(pep386=info.pep386, ++ short=info.short, ++ long=info.long, ++ date=info.date, ++ build_date=info.date.date(), ++ build_time=info.date.time(), ++ dirty=info.dirty) ++ f.write(output) diff -Nru stsci.tools-3.4.11/lib/stsci/tools/bitmask.py stsci.tools-3.4.12/lib/stsci/tools/bitmask.py --- stsci.tools-3.4.11/lib/stsci/tools/bitmask.py 2017-12-18 16:20:37.000000000 +0000 +++ stsci.tools-3.4.12/lib/stsci/tools/bitmask.py 2018-02-15 01:51:12.000000000 +0000 @@ -8,14 +8,14 @@ """ -import numpy as np +import sys import warnings import six +import numpy as np from astropy.utils import deprecated - -__version__ = '1.0.0' -__vdate__ = '16-March-2017' +__version__ = '1.1.1' +__vdate__ = '30-January-2018' __author__ = 'Mihai Cara' @@ -41,6 +41,22 @@ # and string comma- (or '+') separated lists of bit flags). # 5. Added 'is_bit_flag()' function to check if an integer number has # only one bit set (i.e., that it is a power of 2). +# 1.1.0 (29-January-2018) - Multiple enhancements: +# 1. Added support for long type in Python 2.7 in +# `interpret_bit_flags()` and `bitfield_to_boolean_mask()`. +# 2. `interpret_bit_flags()` now always returns `int` (or `int` or `long` +# in Python 2.7). Previously when input was of integer-like type +# (i.e., `numpy.uint64`), it was not converted to Python `int`. +# 3. `bitfield_to_boolean_mask()` will no longer crash when +# `ignore_flags` argument contains bit flags beyond what the type of +# the argument `bitfield` can hold. +# 1.1.1 (30-January-2018) - Improved filtering of high bits in flags. +# +INT_TYPE = (int, long,) if sys.version_info < (3,) else (int,) +MAX_UINT_TYPE = np.maximum_sctype(np.uint) +SUPPORTED_FLAGS = int(np.bitwise_not( + 0, dtype=MAX_UINT_TYPE, casting='unsafe' +)) def is_bit_flag(n): @@ -68,7 +84,7 @@ def _is_int(n): return ( - (isinstance(n, int) and not isinstance(n, bool)) or + (isinstance(n, INT_TYPE) and not isinstance(n, bool)) or (isinstance(n, np.generic) and np.issubdtype(n, np.integer)) ) @@ -136,7 +152,7 @@ allow_non_flags = False if _is_int(bit_flags): - return (~int(bit_flags) if flip_bits else bit_flags) + return (~int(bit_flags) if flip_bits else int(bit_flags)) elif bit_flags is None: if has_flip_bits: @@ -409,7 +425,12 @@ mask = np.zeros_like(bitfield, dtype=dtype) return mask - ignore_mask = np.bitwise_not(bitfield.dtype.type(ignore_mask)) + # filter out bits beyond the maximum supported by the data type: + ignore_mask = ignore_mask & SUPPORTED_FLAGS + + # invert the "ignore" mask: + ignore_mask = np.bitwise_not(ignore_mask, dtype=bitfield.dtype, + casting='unsafe') mask = np.empty_like(bitfield, dtype=np.bool_) np.bitwise_and(bitfield, ignore_mask, out=mask, casting='unsafe') @@ -503,7 +524,7 @@ @deprecated(since='3.4.6', message='', name='bitmask2mask', - alternative='flags_to_boolean_mask') + alternative='bitfield_to_boolean_mask') def bitmask2mask(bitmask, ignore_bits, good_mask_value=1, dtype=np.bool_): """ bitmask2mask(bitmask, ignore_bits, good_mask_value=1, dtype=numpy.bool\_) diff -Nru stsci.tools-3.4.11/lib/stsci/tools/capable.py stsci.tools-3.4.12/lib/stsci/tools/capable.py --- stsci.tools-3.4.11/lib/stsci/tools/capable.py 2017-12-18 16:20:37.000000000 +0000 +++ stsci.tools-3.4.12/lib/stsci/tools/capable.py 2018-02-15 01:51:12.000000000 +0000 @@ -10,7 +10,7 @@ import os, sys PY3K = sys.version_info[0] > 2 -descrip = "basic capabilities file, last edited: 4 Jan 2017" +descrip = "basic capabilities file, last edited: 28 Dec 2017" def is_darwin_and_x(): """ Convenience function. Returns True if is an X11-linked Python/tkinter diff -Nru stsci.tools-3.4.11/lib/stsci/tools/convertgeis.py stsci.tools-3.4.12/lib/stsci/tools/convertgeis.py --- stsci.tools-3.4.11/lib/stsci/tools/convertgeis.py 2017-12-18 16:19:42.000000000 +0000 +++ stsci.tools-3.4.12/lib/stsci/tools/convertgeis.py 2018-02-15 01:51:12.000000000 +0000 @@ -219,7 +219,7 @@ _shape = _naxis[1:] _shape.reverse() - _code = fits.hdu.ImageHDU.NumCode[_bitpix] + _code = fits.BITPIX2DTYPE[_bitpix] _bscale = phdr.get('BSCALE', 1) _bzero = phdr.get('BZERO', 0) diff -Nru stsci.tools-3.4.11/lib/stsci/tools/convertwaiveredfits.py stsci.tools-3.4.12/lib/stsci/tools/convertwaiveredfits.py --- stsci.tools-3.4.11/lib/stsci/tools/convertwaiveredfits.py 2017-12-18 16:19:42.000000000 +0000 +++ stsci.tools-3.4.12/lib/stsci/tools/convertwaiveredfits.py 2018-02-15 01:51:12.000000000 +0000 @@ -3,18 +3,16 @@ # $Id$ """ - convertwaiveredfits: Convert a waivered FITS file to various other formats. +Convert a waivered FITS file to various other formats. - :License: http://www.stsci.edu/resources/software_hardware/pyraf/LICENSE +Syntax for the command line:: - :Syntax From the command line: + convertwaiveredfits.py [-hm] [-o ,...] FILE ... - convertwaiveredfits.py [-hm] [-o ,...] FILE ... +Convert the waivered FITS files (wFITS) to various formats. +The default conversion format is multi-extension FITS (MEF). - Convert the waivered FITS files (FILEs) to various formats. - The default conversion format is multi-extension FITS. - - :Options: +Options:: -h, --help print this help message and exit @@ -31,119 +29,89 @@ character of the base name changed to `h` in multi-extension FITS format - Examples - ======== - Conversion of a WFPC2 waivered FITS file obtained from the HST archive:: - - convertwaiveredfits u9zh010bm_c0f.fits - - This will convert the waivered FITS file `u9zh010bm_c0f.fits` - to multi-extension FITS format and generate the output file - `u9zh010bm_c0h.fits`. - - - Conversion of multiple FITS files can be done using:: - - convertwaiveredfits -o out1.fits,out2.fits - u9zh010bm_c0f.fits u9zh010bm_c1f.fits - - This will convert the waivered FITS files u9zh010bm_c0f.fits - and u9zh010bm_c1f.fits to multi-extension FITS format and - generate the output files out1.fits and out2.fits - - - :Python Syntax: You can run this code interactively from within Python using the syntax: - - >>> from stsci.tools import convertwaiveredfits - >>> fobj = convertwaiveredfits.convertwaiveredfits(waiveredObject, - >>> outputFileName=None, - >>> forceFileOutput=False, - >>> convertTo='multiExtension', - >>> verbose=False) - - The returned object `fobj` is a PyFITS object using the multi-extension FITS format. - - - Parameters - ========== - waiveredObject: obj - input object representing a waivered FITS - file; either a astropy.io.fits.HDUList object, a file - object, or a file specification - - outputFileName : string - file specification for the output file - Default: None - do not generate an output file - - forceFileOutput: boolean - force the generation of an output file when - the outputFileName parameter is None; the - output file specification will be the same as - the input file specification with the last - character of the base name replaced with the - character `h` in multi-extension FITS format. - - Default: False - - convertTo: string - target conversion type - Default: 'multiExtension' - - verbose: boolean - provide verbose output - Default: False - - Returns - ======= - hduList - fits.HDUList (PyFITS multi-extension FITS object) containing converted output - - Examples - ======== - >>> import convertwaiveredfits - >>> hdulist = convertwaiveredfits.convertwaiveredfits('u9zh010bm_c0f.fits', - forceFileOutput=True) - - this will convert the waivered FITS file u9zh010bm_c0f.fits - to multi-extension FITS format and write the output to the - file u9zh010bm_c0h.fits; the returned HDUList is in - multi-extension FITS format - +For example, conversion of a WFPC2 waivered FITS file obtained +from the MAST archive:: - >>> import convertwaiveredfits - >>> inFile = open('u9zh010bm_c0f.fits',mode='rb') - >>> hdulist = convertwaiveredfits.convertwaiveredfits(inFile, - 'out.fits') + convertwaiveredfits u9zh010bm_c0f.fits - this will convert the waivered FITS file u9zh010bm_c0f.fits - to multi-extension FITS format and write the output to the - file out.fits; the returned HDUList is in multi-extension - FITS format - - >>> from astropy.io import fits - >>> import convertwaiveredfits - >>> inHdul = fits.open('u9zh010bm_c0f.fits') - >>> hdulist = convertwaiveredfits.convertwaiveredfits(inHdul) - - this will convert the waivered FITS file u9zh010bm_c0f.fits - to multi-extension FITS format; no output file is generated; - the returned HDUList is in multi-extension format - -__version__ = "1.0 (31 January, 2008)" +This will convert the waivered FITS file ``u9zh010bm_c0f.fits`` +to multi-extension FITS format and generate the output file +``u9zh010bm_c0h.fits``. + +Conversion of multiple FITS files can be done using:: + + convertwaiveredfits -o out1.fits,out2.fits u9zh010bm_c0f.fits u9zh010bm_c1f.fits + +This will convert the waivered FITS files ``u9zh010bm_c0f.fits`` +and ``u9zh010bm_c1f.fits`` to multi-extension FITS format and +generate the output files ``out1.fits`` and ``out2.fits``. + +Parameters +========== +waiveredObject: obj + input object representing a waivered FITS + file; either a ``astropy.io.fits.HDUList`` object, a file + object, or a file specification. + +outputFileName : string + file specification for the output file. + Default: `None` - do not generate an output file + +forceFileOutput: boolean + force the generation of an output file when + the ``outputFileName`` parameter is `None`; the + output file specification will be the same as + the input file specification with the last + character of the base name replaced with the + character ``h`` in multi-extension FITS format. + + Default: False + +convertTo: string + target conversion type. + Default: 'multiExtension' + +verbose: boolean + provide verbose output. + Default: `False` + +Returns +======= +hduList : fits.HDUList + ``astropy.io.fits`` multi-extension FITS object containing converted output + +Examples +======== + +>>> import convertwaiveredfits +>>> hdulist = convertwaiveredfits.convertwaiveredfits( +... 'u9zh010bm_c0f.fits', forceFileOutput=True) + +This will convert the waivered FITS file ``u9zh010bm_c0f.fits`` +to multi-extension FITS format and write the output to the +file ``u9zh010bm_c0h.fits``; the returned ``HDUList`` is in +multi-extension FITS format. + +>>> import convertwaiveredfits +>>> with open('u9zh010bm_c0f.fits', mode='rb') as inFile: +... hdulist = convertwaiveredfits.convertwaiveredfits(inFile, 'out.fits') + +This will convert the waivered FITS file ``u9zh010bm_c0f.fits`` +to multi-extension FITS format and write the output to the +file ``out.fits``; the returned ``HDUList`` is in multi-extension +FITS format. + +>>> from astropy.io import fits +>>> import convertwaiveredfits +>>> with fits.open('u9zh010bm_c0f.fits') as inHdul: +... hdulist = convertwaiveredfits.convertwaiveredfits(inHdul) + +This will convert the waivered FITS file ``u9zh010bm_c0f.fits`` +to multi-extension FITS format; no output file is generated; +the returned ``HDUList`` is in multi-extension format. """ - -# Developed by Science Software Branch, STScI, USA. - -from __future__ import division, print_function # confidence high - -__version__ = "1.1 (15 June, 2015)" - -import sys -if sys.version_info[0] < 3: - string_types = basestring -else: - string_types = str +from __future__ import division, print_function # confidence high # # ----------------------------------------------------------------------------- @@ -156,8 +124,16 @@ from astropy.io import fits from distutils.version import LooseVersion +if sys.version_info[0] < 3: + string_types = basestring +else: + string_types = str + ASTROPY_VER_GE13 = LooseVersion(astropy.__version__) >= LooseVersion('1.3') +__version__ = "1.1 (15 June, 2015)" + + # # ----------------------------------------------------------------------------- # Function definitions @@ -176,6 +152,7 @@ print("usage: convertwaiveredfits.py [-hmv] [-o , ...] FILE ...") + def _processCommandLineArgs(): """ Get the command line arguments diff -Nru stsci.tools-3.4.11/lib/stsci/tools/fileutil.py stsci.tools-3.4.12/lib/stsci/tools/fileutil.py --- stsci.tools-3.4.11/lib/stsci/tools/fileutil.py 2017-12-18 16:20:37.000000000 +0000 +++ stsci.tools-3.4.12/lib/stsci/tools/fileutil.py 2018-02-15 01:51:12.000000000 +0000 @@ -35,7 +35,7 @@ updateKeyword(filename, key, value) - openImage(filename,mode='readonly',memmap=0,fitsname=None) + openImage(filename,mode='readonly',memmap=False,fitsname=None) Opens file and returns PyFITS object. It will work on both FITS and GEIS formatted images. @@ -674,7 +674,7 @@ return _fitsname -def openImage(filename, mode='readonly', memmap=0, writefits=True, +def openImage(filename, mode='readonly', memmap=False, writefits=True, clobber=True, fitsname=None): """ Opens file and returns PyFITS object. Works on both FITS and GEIS @@ -693,16 +693,16 @@ name of input file mode: str mode for opening file based on PyFITS `mode` parameter values - memmap: int - switch for using memory mapping, 0 for no, 1 for yes + memmap: bool + switch for using memory mapping, `False` for no, `True` for yes writefits: bool - if True, will write out GEIS as multi-extension FITS + if `True`, will write out GEIS as multi-extension FITS and return handle to that opened GEIS-derived MEF file clobber: bool overwrite previously written out GEIS-derived MEF file fitsname: str name to use for GEIS-derived MEF file, - if None and writefits==True, will use 'buildFITSName()' to generate one + if None and writefits==`True`, will use 'buildFITSName()' to generate one """ from stwcs import updatewcs diff -Nru stsci.tools-3.4.11/lib/stsci/tools/__init__.py stsci.tools-3.4.12/lib/stsci/tools/__init__.py --- stsci.tools-3.4.11/lib/stsci/tools/__init__.py 2017-12-18 16:19:42.000000000 +0000 +++ stsci.tools-3.4.12/lib/stsci/tools/__init__.py 2018-02-15 01:51:12.000000000 +0000 @@ -1,9 +1,5 @@ from __future__ import division # confidence high - from .version import * -import stsci.tools.tester -def test(*args,**kwds): - stsci.tools.tester.test(modname=__name__, *args, **kwds) - +__vdate__ = __version_date__ diff -Nru stsci.tools-3.4.11/lib/stsci/tools/readgeis.py stsci.tools-3.4.12/lib/stsci/tools/readgeis.py --- stsci.tools-3.4.11/lib/stsci/tools/readgeis.py 2017-12-18 16:19:42.000000000 +0000 +++ stsci.tools-3.4.12/lib/stsci/tools/readgeis.py 2018-02-15 01:51:12.000000000 +0000 @@ -202,7 +202,7 @@ _shape = _naxis[1:] _shape.reverse() - _code = fits.hdu.ImageHDU.NumCode[_bitpix] + _code = fits.BITPIX2DTYPE[_bitpix] _bscale = phdr.get('BSCALE', 1) _bzero = phdr.get('BZERO', 0) if phdr['DATATYPE'][:10] == 'UNSIGNED*2': diff -Nru stsci.tools-3.4.11/lib/stsci/tools/stpyfits.py stsci.tools-3.4.12/lib/stsci/tools/stpyfits.py --- stsci.tools-3.4.11/lib/stsci/tools/stpyfits.py 2017-12-18 16:19:42.000000000 +0000 +++ stsci.tools-3.4.12/lib/stsci/tools/stpyfits.py 2018-02-15 01:51:12.000000000 +0000 @@ -12,15 +12,19 @@ import sys import numpy as np +import astropy from astropy.io import fits # A few imports for backward compatibility; in the earlier stpyfits these were # overridden, but with fits's new extension system it's not necessary from astropy.io.fits.util import _is_int from astropy.utils import lazyproperty +from distutils.version import LooseVersion PY3K = sys.version_info[0] > 2 +ASTROPY_VER_GE20 = LooseVersion(astropy.__version__) >= LooseVersion('2.0') + +STPYFITS_ENABLED = False # Not threadsafe TODO: (should it be?) -STPYFITS_ENABLED = False # Not threadsafe TODO: (should it be?) # Register the extension classes; simply importing stpyfits does not # automatically enable it. Instead, it can be enabled/disabled using these @@ -51,7 +55,8 @@ # BUG: Forcefully disable lazy loading. # Lazy loading breaks ability to initialize ConstantValueHDUs # TODO: Investigate the cause upstream (astropy.io.fits) - kwargs['lazy_load_hdus'] = False + if 'write' not in func.__name__: + kwargs['lazy_load_hdus'] = False retval = func(*args, **kwargs) finally: # Only disable stpyfits if it wasn't already enabled @@ -150,7 +155,7 @@ @lazyproperty def data(self): if ('PIXVALUE' in self._header and 'NPIX1' not in self._header and - self._header['NAXIS'] > 0): + self._header['NAXIS'] > 0): bitpix = self._header['BITPIX'] dims = self.shape @@ -231,13 +236,12 @@ naxis = header.get('NAXIS', 0) return (super(_ConstantValueImageBaseHDU, cls).match_header(header) and - (isinstance(pixvalue, float) or _is_int(pixvalue)) and - naxis == 0) - + (isinstance(pixvalue, float) or _is_int(pixvalue)) and + naxis == 0) def update_header(self): if (not self._modified and not self._header._modified and - (self._has_data and self.shape == self.data.shape)): + (self._has_data and self.shape == self.data.shape)): # Not likely that anything needs updating return @@ -285,15 +289,20 @@ def _summary(self): summ = super(_ConstantValueImageBaseHDU, self)._summary() - return (summ[0], summ[1].replace('ConstantValue', '')) + summ[2:] + if ASTROPY_VER_GE20: + outsumm = ((summ[0], summ[1], + summ[2].replace('ConstantValue', '')) + summ[3:]) + else: + outsumm = ((summ[0], + summ[1].replace('ConstantValue', '')) + summ[2:]) + return outsumm def _writedata_internal(self, fileobj): if 'PIXVALUE' in self._header: # This is a Constant Value Data Array, so no data is written return 0 else: - return super(_ConstantValueImageBaseHDU, self).\ - _writedata_internal(fileobj) + return super(_ConstantValueImageBaseHDU, self)._writedata_internal(fileobj) def _check_constant_value_data(self, data): """Verify that the HDU's data is a constant value array.""" @@ -304,7 +313,6 @@ return None - class ConstantValuePrimaryHDU(_ConstantValueImageBaseHDU, fits.hdu.PrimaryHDU): """Primary HDUs with constant value arrays.""" @@ -315,7 +323,7 @@ # Import the rest of the astropy.io.fits module -from astropy.io.fits import * +from astropy.io.fits import * # noqa # For backward-compatibility with older code that thinks PrimaryHDU and # ImageHDU should support the ConstantValue features diff -Nru stsci.tools-3.4.11/lib/stsci/tools/stsci_distutils_hack.py stsci.tools-3.4.12/lib/stsci/tools/stsci_distutils_hack.py --- stsci.tools-3.4.11/lib/stsci/tools/stsci_distutils_hack.py 2017-12-18 16:19:42.000000000 +0000 +++ stsci.tools-3.4.12/lib/stsci/tools/stsci_distutils_hack.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,372 +0,0 @@ -# -# $HeadURL$ -# $Rev$ -# -# Implements setup.py code common to many of our packages. -# -# The new standard stsci module setup.py is just -# -# import stsci.tools.stsci_distutils_hack -# stsci.tools.stsci_distutils_hack.run( pytools_version = "XX" ) -# -# where XX is the version of stsci.tools you expect for the install to work -# - -from __future__ import division, print_function # confidence high - -""" -Special handling for stsci_python package installation. - -stsci_python is distributed as a single package, but it contains -packages that are also distributed separately. When we use this -module to install our package, we can use the exact same definition -file to control the setup.py of the individual package _and_ the -setup.py of stsci_python. - -This module also preserves revision control data in the installed -or distributed files. - -If you are not a developer at STScI, this module is probably not of -much interest to you. - -""" - -__docformat__ = 'restructuredtext' - - -######## ######## ######## ######## ######## ######## ######## ######## -# -# actually perform the install -# -# NOTE: This is not used to install stsci.tools itself! - -import sys - -def run( pytools_version = None ) : - """ - Perform a stsci_python install based on the information in defsetup.py - - * gather our subversion revision number and the install time - - * perform the install - - usage: - - import stsci.tools.stsci_distutils_hack - stsci.tools.stsci_distutils_hack.run(pytools_version = "3.1") - - """ - - if not hasattr(sys, 'version_info') or sys.version_info < (2,3,0,'alpha',0): - raise SystemExit("Python 2.3 or later required.") - - if pytools_version : - # Only try to import stsci.tools if we are asked to check for a version. - # - # ( We may have been extracted from stsci.tools and bundled with a package. - # In that case, we do not want to risk finding some _other_ stsci.tools - # and comparing that version. ) - import stsci.tools - - # bug: should use distutils version comparator to perform ">" comparisons - if ( stsci.tools.__version__ != pytools_version ) : - print("wrong version of stsci.tools!") - print("have "+str(stsci.tools.__version__)) - print("want "+str(pytools_version)) - sys.exit(1) - - # look for include files that common linux distributions leave out - check_requirements() - - from distutils.core import setup - from defsetup import setupargs, pkg - - if "version" in sys.argv : - sys.exit(0) - - # If they have multiple packages, we have to allow them to give a list. - # That is the unusual case, so we let them give a string if they have a single - # package. - if isinstance(pkg,str) : - pkg = [ pkg ] - - # If they have multiple packages, they have to specify package_dir. Otherwise, - # we can create one for them. - if not 'package_dir' in setupargs : - setupargs['package_dir'] = { pkg[0] : 'lib' } - - - for x in setupargs['package_dir'] : - x = setupargs['package_dir'][x] - # collect our subversion information - __set_svn_version__( x ) - - # save the date when we last ran setup.py - __set_setup_date__( x ) - - if "version" in sys.argv : - sys.exit(0) - - return setup( - name = pkg[0], - packages = pkg, - **setupargs - ) - - - -######## ######## ######## ######## ######## ######## ######## ######## -# -# This part fixes install_data to put data files in the same directory -# with the python library files, which is where our packages want -# them. -# -# This is essentially "smart_install_data" as used in the old -# setup.py files, except that it also understands wildcards -# and os-specific paths. This means the module author can -# ask for data files with -# "data/generic/*" -# instead of -# glob.glob(os.path.join('data', 'generic', '*')) - - -import os -import glob - -import distutils.util - -import distutils.command.install_data - -o = distutils.command.install_data.install_data - -# same trick as smart_install_data used: save the old run() method and -# insert our own run method ahead of it - -o.old_run = o.run - -def new_run ( self ) : - """ - Hack for distutils to cause install_data to be in the same directory - as the python library files. Our packages expect this. - """ - - # We want our data files in the directory with the library files - install_cmd = self.get_finalized_command('install') - self.install_dir = getattr(install_cmd, 'install_lib') - - - # self.data_files is a list of - # ( destination_directory, [ source_file, source_file, source_file ] ) - # - # We want to do wildcard expansion on all the file names. - # - l = [ ] - for f in self.data_files : - ( dest_dir, files ) = f - fl = [ ] - for ff in files : - ff = distutils.util.convert_path(ff) - ff = glob.glob(ff) - fl.extend(ff) - dest_dir = distutils.util.convert_path(dest_dir) - l.append( ( dest_dir, fl ) ) - self.data_files = l - - # now use the original run() function to finish - return distutils.command.install_data.install_data.old_run(self) - -o.run = new_run - - -######## ######## ######## ######## ######## ######## ######## ######## -# -# Function to collect svn version information - used to be stsci_python/version.py -# with multiple copies in the system. -# -import os.path -import re - -# -# This is the entry point. All you need to do is call this function from your -# setup.py according to the example above. It will create a file called -# lib/svn_version.py ; After that, you can -# -# # find out what subversion information applies to yourpackage -# import yourpackage.svn_version -# print yourpackage.svn_version.__svn_version__ -# print yourpackage.svn_version.__full_svn_info__ -# - -def __set_svn_version__(directory="./", fname='svn_version.py' ) : - # - # directory is both the directory where the version information will be stored - # (in the file fname) and the directory that we will run svn info on to - # get a version number. - # - # I think the default of ./ is probably useless at this point. - # - # fname is the name of the file to store the version information in. Never change - # this. - # - - info = None - rev = __get_svn_rev__(directory) - version_file = os.path.join(directory,fname) - - # if we are unable to determine the revision, we default to leaving the - # revision file unchanged. Otherwise, we fill it in with whatever - # we have - - if rev is None: - if os.path.exists(version_file) : - return - revision = 'Unable to determine SVN revision' - else: - if ( rev == 'exported' or rev == 'unknown' ) and os.path.exists(version_file) : - return - revision = str(rev) - - info = __get_full_info__(directory) - - # now we can write the version information - - f = open(version_file,'w') - f.write("__svn_version__ = %s\n" % repr(revision)) - - # info will be a multi-line string. We are not using repr(info) - # for readability; the output of "svn info" can not contain ''' - # unless you are doing something bad. - f.write("\n__full_svn_info__ = '''\n%s'''\n\n" % info) - f.close() - - -def __get_svn_rev__(path): - m = None - try: - # with popen3, stderr goes into a pipe where we ignore it, - # This means the user does not see errors. - cmd = 'svnversion '+path - (sin, sout, serr) = os.popen3(cmd) - - # pick up the first line of output - m=sout.read().strip() - - # if it looks like valid svnversion output, return it - if m == 'exported' : - return m - if re.match('^[0-9][0-9:]*[A-Z]*$',m) : - return m - - # if we get here, it was not valid - that probably means - # an error of some kind. - except: - pass - - return None - -def __get_full_info__(path): - info = None - try: - # with popen3, stderr goes into a pipe where we ignore it, - # This means the user does not see errors. - (sin, sout, serr) = os.popen3('svn info %s' % path) - - # pick up all the lines of output - info = [l.strip() for l in sout.readlines()] - - # if no output, there was an error and we don't know anything - if len(info) == 0 : - return "unknown" - - # there was output, so join it all together - return '\n'.join(info) - - except: - pass - - return "unknown" - -######## ######## ######## ######## ######## ######## ######## ######## -# -# note when we last ran setup.py -- what we really want is when the -# software was installed, but we can use the time we ran setup.py as -# a proxy for that. -# - -def __set_setup_date__( path="./", fname='svn_version.py') : - import datetime - file = os.path.join(path,fname) - d = datetime.datetime.now() - l = [ ] - try : - # we don't expect this to fail ever, but it might - f = open(file,"r") - for line in f : - if line.find("# setupdate") < 0 : - l.append(line) - f.close() - except IOError : - pass - f=open(file,"w") - for line in l : - f.write(line) - - f.write("%s # setupdate\n" % "import datetime") - f.write("%s # setupdate\n" % ("setupdate = "+repr(d))) - f.close() - - -######## ######## ######## ######## ######## ######## ######## ######## -# -# - -def check_requirements() : - - import distutils.sysconfig - - dev_pkg_missing =0 - numpy_missing = 0 - - d = distutils.sysconfig.get_python_inc( plat_specific=0 ) - if not os.path.exists( d + '/Python.h') : - print("ERROR: Python development files are missing from "+d) - dev_pkg_missing=1 - - d = distutils.sysconfig.get_python_inc( plat_specific=1 ) - if not os.path.exists( d + '/pyconfig.h') : - print("ERROR: Python development files are missing from "+d) - dev_pkg_missing=1 - - try : - import numpy - except ImportError: - numpy_missing = 1 - - if not numpy_missing : - d = numpy.get_include() - if not os.path.exists( d + '/numpy/arrayobject.h') : - print("ERROR: Numpy development files are missing from "+d) - dev_pkg_missing=1 - - # print explanations for whatever problems there are - if numpy_missing: - print(""" -This installation requires the numpy package. You may find it in -your operating system distribution, or you may find it at -http://numpy.scipy.org -""") - - if dev_pkg_missing : - print(""" -Many OS distributions separate Python and Numpy into user and -developer packages. You need both packages to complete this install, -but this machine appears to be missing one of the developer packages. -The package names are different on different systems, but usually -the necessary package is named somethng like 'python-dev' or -'python-devel' (or 'numpy-dev' or 'numpy-devel', for numpy). - -""") - - if numpy_missing or dev_pkg_missing : - import sys - sys.exit(0) diff -Nru stsci.tools-3.4.11/lib/stsci/tools/swapgeis.py stsci.tools-3.4.12/lib/stsci/tools/swapgeis.py --- stsci.tools-3.4.11/lib/stsci/tools/swapgeis.py 2017-12-18 16:19:42.000000000 +0000 +++ stsci.tools-3.4.12/lib/stsci/tools/swapgeis.py 2018-02-15 01:51:12.000000000 +0000 @@ -210,7 +210,7 @@ _shape = _naxis[1:] _shape.reverse() - _code = fits.hdu.ImageHDU.NumCode[_bitpix] + _code = fits.BITPIX2DTYPE[_bitpix] _bscale = phdr.get('BSCALE', 1) _bzero = phdr.get('BZERO', 0) if phdr['DATATYPE'][:10] == 'UNSIGNED*2': @@ -377,7 +377,7 @@ _shape = _naxis[1:] _shape.reverse() - _code = fits.hdu.ImageHDU.NumCode[_bitpix] + _code = fits.BITPIX2DTYPE[_bitpix] _bscale = phdr.get('BSCALE', 1) _bzero = phdr.get('BZERO', 0) if phdr['DATATYPE'][:10] == 'UNSIGNED*2': diff -Nru stsci.tools-3.4.11/lib/stsci/tools/tests/test_bitmask.py stsci.tools-3.4.12/lib/stsci/tools/tests/test_bitmask.py --- stsci.tools-3.4.11/lib/stsci/tools/tests/test_bitmask.py 1970-01-01 00:00:00.000000000 +0000 +++ stsci.tools-3.4.12/lib/stsci/tools/tests/test_bitmask.py 2018-02-15 01:51:12.000000000 +0000 @@ -0,0 +1,184 @@ +""" +A module containing unit tests for the `bitmask` modue. + +:Authors: Mihai Cara (contact: help@stsci.edu) + +""" +from __future__ import (absolute_import, division, unicode_literals, + print_function) + +import warnings +import numpy as np +import pytest + +from stsci.tools import bitmask + +MAX_INT_TYPE = np.maximum_sctype(np.int) +MAX_UINT_TYPE = np.maximum_sctype(np.uint) +MAX_UINT_FLAG = np.left_shift( + MAX_UINT_TYPE(1), + MAX_UINT_TYPE(np.iinfo(MAX_UINT_TYPE).bits - 1) +) +MAX_INT_FLAG = np.left_shift( + MAX_INT_TYPE(1), + MAX_INT_TYPE(np.iinfo(MAX_INT_TYPE).bits - 2) +) +SUPER_LARGE_FLAG = 1 << np.iinfo(MAX_UINT_TYPE).bits +EXTREME_TEST_DATA = np.array([ + 0, 1, 1 + 1 << 2, MAX_INT_FLAG, ~0, MAX_INT_TYPE(MAX_UINT_FLAG), + 1 + MAX_INT_TYPE(MAX_UINT_FLAG) +], dtype=MAX_INT_TYPE) + + +@pytest.mark.parametrize('flag', [0, -1]) +def test_nonpositive_not_a_bit_flag(flag): + assert not bitmask.is_bit_flag(n=flag) + + +@pytest.mark.parametrize('flag', [ + 1, MAX_UINT_FLAG, int(MAX_UINT_FLAG), SUPER_LARGE_FLAG +]) +def test_is_bit_flag(flag): + assert bitmask.is_bit_flag(n=flag) + + +@pytest.mark.parametrize('number', [0, 1, MAX_UINT_FLAG, SUPER_LARGE_FLAG]) +def test_is_int(number): + assert bitmask._is_int(number) + + +@pytest.mark.parametrize('number', ['1', True, 1.0]) +def test_nonint_is_not_an_int(number): + assert not bitmask._is_int(number) + + +@pytest.mark.parametrize('flag,flip,expected', [ + (3, None, 3), + (3, True, -4), + (3, False, 3), + ([1, 2], False, 3), + ([1, 2], True, -4) +]) +def test_interpret_valid_int_bit_flags(flag, flip, expected): + assert( + bitmask.interpret_bit_flags(bit_flags=flag, flip_bits=flip) == expected + ) + + +@pytest.mark.parametrize('flag', [None, ' ', 'None', 'Indef']) +def test_interpret_none_bit_flags_as_None(flag): + assert bitmask.interpret_bit_flags(bit_flags=flag) is None + + +@pytest.mark.parametrize('flag,expected', [ + ('1', 1), + ('~-1', ~(-1)), + ('~1', ~1), + ('1,2', 3), + ('1+2', 3), + ('(1,2)', 3), + ('(1+2)', 3), + ('~1,2', ~3), + ('~1+2', ~3), + ('~(1,2)', ~3), + ('~(1+2)', ~3) +]) +def test_interpret_valid_str_bit_flags(flag, expected): + assert( + bitmask.interpret_bit_flags(bit_flags=flag) == expected + ) + + +@pytest.mark.parametrize('flag,flip', [ + (None, True), + (' ', True), + ('None', True), + ('Indef', True), + (None, False), + (' ', False), + ('None', False), + ('Indef', False), + ('1', True), + ('1', False) +]) +def test_interpret_None_or_str_and_flip_incompatibility(flag, flip): + with pytest.raises(TypeError): + bitmask.interpret_bit_flags(bit_flags=flag, flip_bits=flip) + + +@pytest.mark.parametrize('flag', [True, 1.0, [1.0], object]) +def test_interpret_wrong_flag_type(flag): + with pytest.raises(TypeError): + bitmask.interpret_bit_flags(bit_flags=flag) + + +@pytest.mark.parametrize('flag', ['SOMETHING', '1.0,2,3']) +def test_interpret_wrong_string_int_format(flag): + with pytest.raises(ValueError): + bitmask.interpret_bit_flags(bit_flags=flag) + + +def test_interpret_duplicate_flag_warning(): + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter("always") + assert bitmask.interpret_bit_flags([2, 4, 4]) == 6 + assert len(w) + assert issubclass(w[-1].category, UserWarning) + assert "Duplicate" in str(w[-1].message) + + +@pytest.mark.parametrize('flag', [[1, 2, 3], '1, 2, 3']) +def test_interpret_non_flag(flag): + with pytest.raises(ValueError): + bitmask.interpret_bit_flags(bit_flags=flag) + + +def test_interpret_allow_single_value_str_nonflags(): + assert bitmask.interpret_bit_flags(bit_flags=str(3)) == 3 + + +@pytest.mark.parametrize('flag', [ + '~', + '( )', + '(~1,2)', + '~(1,2', + '1,~2', + '1,(2,4)', + '1,2+4', + '1+4,2' +]) +def test_interpret_bad_str_syntax(flag): + with pytest.raises(ValueError): + bitmask.interpret_bit_flags(bit_flags=flag) + + +def test_bitfield_must_be_integer_check(): + with pytest.raises(TypeError): + bitmask.bitfield_to_boolean_mask(1.0, 1) + + +@pytest.mark.parametrize('data,flags,flip,goodval,dtype,ref', [ + (EXTREME_TEST_DATA, None, None, True, np.bool_, + EXTREME_TEST_DATA.size * [1]), + (EXTREME_TEST_DATA, None, None, False, np.bool_, + EXTREME_TEST_DATA.size * [0]), + (EXTREME_TEST_DATA, [1, MAX_UINT_FLAG], False, True, np.bool_, + [1, 1, 0, 0, 0, 1, 1]), + (EXTREME_TEST_DATA, None, None, True, np.bool_, + EXTREME_TEST_DATA.size * [1]), + (EXTREME_TEST_DATA, [1, MAX_UINT_FLAG], False, False, np.bool_, + [0, 0, 1, 1, 1, 0, 0]), + (EXTREME_TEST_DATA, [1, MAX_UINT_FLAG], True, True, np.int8, + [1, 0, 1, 1, 0, 0, 0]) +]) +def test_bitfield_to_boolean_mask(data, flags, flip, goodval, dtype, ref): + mask = bitmask.bitfield_to_boolean_mask( + bitfield=data, + ignore_flags=flags, + flip_bits=flip, + good_mask_value=goodval, + dtype=dtype + ) + + assert(mask.dtype == dtype) + assert np.all(mask == ref) diff -Nru stsci.tools-3.4.11/lib/stsci/tools/tests/test_stpyfits.py stsci.tools-3.4.12/lib/stsci/tools/tests/test_stpyfits.py --- stsci.tools-3.4.11/lib/stsci/tools/tests/test_stpyfits.py 1970-01-01 00:00:00.000000000 +0000 +++ stsci.tools-3.4.12/lib/stsci/tools/tests/test_stpyfits.py 2018-02-15 01:51:12.000000000 +0000 @@ -0,0 +1,755 @@ +#!/usr/bin/env python +from __future__ import division # confidence high + +import os +import tempfile + +import astropy +import numpy as np +import pytest +from astropy.io import fits +from astropy.io.fits.tests import FitsTestCase +from distutils.version import LooseVersion + +import stsci.tools.stpyfits as stpyfits + +ASTROPY_VER_GE13 = LooseVersion(astropy.__version__) >= LooseVersion('1.3') +ASTROPY_VER_GE20 = LooseVersion(astropy.__version__) >= LooseVersion('2.0') + + +class TestStpyfitsFunctions(FitsTestCase): + def setup(self): + self.data_dir = os.path.dirname(__file__) + self.temp_dir = tempfile.mkdtemp(prefix='stpyfits-test-') + + if ASTROPY_VER_GE13: + self.writekwargs = {'overwrite': True} + else: + self.writekwargs = {'clobber': True} + + def test_InfoConvienceFunction(self): + """Test the info convience function in both the fits and stpyfits + namespace.""" + + if ASTROPY_VER_GE20: + ans1 = [(0, 'PRIMARY', 1, 'PrimaryHDU', 215, (), '', ''), + (1, 'SCI', 1, 'ImageHDU', 141, (62, 44), 'int16 (rescales to uint16)', ''), + (2, 'ERR', 1, 'ImageHDU', 71, (62, 44), 'int16', ''), + (3, 'DQ', 1, 'ImageHDU', 71, (62, 44), 'int16', ''), + (4, 'SCI', 2, 'ImageHDU', 141, (62, 44), 'int16 (rescales to uint16)', ''), + (5, 'ERR', 2, 'ImageHDU', 71, (62, 44), 'int16', ''), + (6, 'DQ', 2, 'ImageHDU', 71, (62, 44), 'int16', '')] + ans2 = [(0, 'PRIMARY', 1, 'PrimaryHDU', 215, (), '', ''), + (1, 'SCI', 1, 'ImageHDU', 141, (62, 44), 'int16 (rescales to uint16)', ''), + (2, 'ERR', 1, 'ImageHDU', 71, (), '', ''), + (3, 'DQ', 1, 'ImageHDU', 71, (), '', ''), + (4, 'SCI', 2, 'ImageHDU', 141, (62, 44), 'int16 (rescales to uint16)', ''), + (5, 'ERR', 2, 'ImageHDU', 71, (), '', ''), + (6, 'DQ', 2, 'ImageHDU', 71, (), '', '')] + ans3 = [(0, 'PRIMARY', 1, 'PrimaryHDU', 7, (10, 10), 'int32', '')] + ans4 = [(0, 'PRIMARY', 1, 'PrimaryHDU', 7, (), '', '')] + else: + ans1 = [(0, 'PRIMARY', 'PrimaryHDU', 215, (), '', ''), + (1, 'SCI', 'ImageHDU', 141, (62, 44), 'int16 (rescales to uint16)', ''), + (2, 'ERR', 'ImageHDU', 71, (62, 44), 'int16', ''), + (3, 'DQ', 'ImageHDU', 71, (62, 44), 'int16', ''), + (4, 'SCI', 'ImageHDU', 141, (62, 44), 'int16 (rescales to uint16)', ''), + (5, 'ERR', 'ImageHDU', 71, (62, 44), 'int16', ''), + (6, 'DQ', 'ImageHDU', 71, (62, 44), 'int16', '')] + ans2 = [(0, 'PRIMARY', 'PrimaryHDU', 215, (), '', ''), + (1, 'SCI', 'ImageHDU', 141, (62, 44), 'int16 (rescales to uint16)', ''), + (2, 'ERR', 'ImageHDU', 71, (), '', ''), + (3, 'DQ', 'ImageHDU', 71, (), '', ''), + (4, 'SCI', 'ImageHDU', 141, (62, 44), 'int16 (rescales to uint16)', ''), + (5, 'ERR', 'ImageHDU', 71, (), '', ''), + (6, 'DQ', 'ImageHDU', 71, (), '', '')] + ans3 = [(0, 'PRIMARY', 'PrimaryHDU', 7, (10, 10), 'int32', '')] + ans4 = [(0, 'PRIMARY', 'PrimaryHDU', 7, (), '', '')] + + assert stpyfits.info(self.data('o4sp040b0_raw.fits'), output=False) == ans1 + assert fits.info(self.data('o4sp040b0_raw.fits'), output=False) == ans2 + + assert stpyfits.info(self.data('cdva2.fits'), output=False) == ans3 + assert fits.info(self.data('cdva2.fits'), output=False) == ans4 + + def test_OpenConvienceFunction(self): + """Test the open convience function in both the fits and stpyfits + namespace.""" + + hdul = stpyfits.open(self.data('cdva2.fits')) + hdul1 = fits.open(self.data('cdva2.fits')) + + assert hdul[0].header['NAXIS'] == 2 + assert hdul1[0].header['NAXIS'] == 0 + assert hdul[0].header['NAXIS1'] == 10 + assert hdul[0].header['NAXIS2'] == 10 + + for k in ('NAXIS1', 'NAXIS2'): + with pytest.raises(KeyError): + hdul1[0].header[k] + for k in ('NPIX1', 'NPIX2'): + with pytest.raises(KeyError): + hdul[0].header[k] + + assert hdul1[0].header['NPIX1'] == 10 + assert hdul1[0].header['NPIX2'] == 10 + + assert (hdul[0].data == np.ones((10, 10), dtype=np.int32)).all() + + assert hdul1[0].data is None + + hdul.close() + hdul1.close() + + @pytest.mark.parametrize(['filename', 'ext', 'naxis1', 'naxis2'], + [('cdva2.fits', None, 10, 10), + ('o4sp040b0_raw.fits', 2, 62, 44)]) + def test_GetHeaderConvienceFunction(self, filename, ext, naxis1, naxis2): + """Test the getheader convience function in both the fits and + stpyfits namespace.""" + + if ext is None: + hd = stpyfits.getheader(self.data(filename)) + hd1 = fits.getheader(self.data(filename)) + else: + hd = stpyfits.getheader(self.data(filename), ext) + hd1 = fits.getheader(self.data(filename), ext) + + assert hd['NAXIS'] == 2 + assert hd1['NAXIS'] == 0 + assert hd['NAXIS1'] == naxis1 + assert hd['NAXIS2'] == naxis2 + + for k in ('NAXIS1', 'NAXIS2'): + with pytest.raises(KeyError): + hd1[k] + for k in ('NPIX1', 'NPIX2'): + with pytest.raises(KeyError): + hd[k] + + assert hd1['NPIX1'] == naxis1 + assert hd1['NPIX2'] == naxis2 + + def test_GetDataConvienceFunction(self): + """Test the getdata convience function in both the fits and + stpyfits namespace.""" + + d = stpyfits.getdata(self.data('cdva2.fits')) + assert (d == np.ones((10, 10), dtype=np.int32)).all() + with pytest.raises(IndexError): + fits.getdata(self.data('cdva2.fits')) + + def test_GetValConvienceFunction(self): + """Test the getval convience function in both the fits and + stpyfits namespace.""" + + val = stpyfits.getval(self.data('cdva2.fits'), 'NAXIS', 0) + val1 = fits.getval(self.data('cdva2.fits'), 'NAXIS', 0) + assert val == 2 + assert val1 == 0 + + def test_writetoConvienceFunction(self): + """Test the writeto convience function in both the fits and stpyfits + namespace.""" + + hdul = stpyfits.open(self.data('cdva2.fits')) + hdul1 = fits.open(self.data('cdva2.fits')) + + header = hdul[0].header.copy() + header['NAXIS'] = 0 + + stpyfits.writeto(self.temp('new.fits'), hdul[0].data, header, + **self.writekwargs) + fits.writeto(self.temp('new1.fits'), hdul1[0].data, hdul1[0].header, + **self.writekwargs) + + hdul.close() + hdul1.close() + + info1 = fits.info(self.temp('new.fits'), output=False) + info2 = stpyfits.info(self.temp('new.fits'), output=False) + info3 = fits.info(self.temp('new1.fits'), output=False) + info4 = stpyfits.info(self.temp('new1.fits'), output=False) + + if ASTROPY_VER_GE20: + ans1 = [(0, 'PRIMARY', 1, 'PrimaryHDU', 6, (), '', '')] + ans2 = [(0, 'PRIMARY', 1, 'PrimaryHDU', 6, (10, 10), 'int32', '')] + ans3 = [(0, 'PRIMARY', 1, 'PrimaryHDU', 6, (), '', '')] + ans4 = [(0, 'PRIMARY', 1, 'PrimaryHDU', 6, (10, 10), 'uint8', '')] + else: + ans1 = [(0, 'PRIMARY', 'PrimaryHDU', 6, (), '', '')] + ans2 = [(0, 'PRIMARY', 'PrimaryHDU', 6, (10, 10), 'int32', '')] + ans3 = [(0, 'PRIMARY', 'PrimaryHDU', 6, (), '', '')] + ans4 = [(0, 'PRIMARY', 'PrimaryHDU', 6, (10, 10), 'uint8', '')] + + assert info1 == ans1 + assert info2 == ans2 + assert info3 == ans3 + assert info4 == ans4 + + def test_appendConvienceFunction(self): + """Test the append convience function in both the fits and stpyfits + namespace.""" + + hdul = stpyfits.open(self.data('cdva2.fits')) + hdul1 = fits.open(self.data('cdva2.fits')) + + stpyfits.writeto(self.temp('new.fits'), hdul[0].data, hdul[0].header, + **self.writekwargs) + fits.writeto(self.temp('new1.fits'), hdul1[0].data, hdul1[0].header, + **self.writekwargs) + + hdu = stpyfits.ImageHDU() + hdu1 = fits.ImageHDU() + + hdu.data = hdul[0].data + hdu1.data = hdul1[0].data + hdu.header.set('BITPIX', 32) + hdu1.header.set('BITPIX', 32) + hdu.header.set('NAXIS', 2) + hdu.header.set('NAXIS1', 10, 'length of constant array axis 1', + after='NAXIS') + hdu.header.set('NAXIS2', 10, 'length of constant array axis 2', + after='NAXIS1') + hdu.header.set('PIXVALUE', 1, 'Constant pixel value', after='GCOUNT') + hdu1.header.set('PIXVALUE', 1, 'Constant pixel value', after='GCOUNT') + hdu1.header.set('NPIX1', 10, 'length of constant array axis 1', + after='GCOUNT') + hdu1.header.set('NPIX2', 10, 'length of constant array axis 2', + after='NPIX1') + stpyfits.append(self.temp('new.fits'), hdu.data, hdu.header) + fits.append(self.temp('new1.fits'), hdu1.data, hdu1.header) + + if ASTROPY_VER_GE20: + ans1 = [(0, 'PRIMARY', 1, 'PrimaryHDU', 7, (10, 10), 'int32', ''), + (1, '', 1, 'ImageHDU', 8, (10, 10), 'int32', '')] + ans2 = [(0, 'PRIMARY', 1, 'PrimaryHDU', 7, (10, 10), 'uint8', ''), + (1, '', 1, 'ImageHDU', 8, (10, 10), 'uint8', '')] + ans3 = [(0, 'PRIMARY', 1, 'PrimaryHDU', 7, (10, 10), 'int32', ''), + (1, '', 1, 'ImageHDU', 8, (10, 10), 'int32', '')] + ans4 = [(0, 'PRIMARY', 1, 'PrimaryHDU', 7, (), '', ''), + (1, '', 1, 'ImageHDU', 8, (), '', '')] + else: + ans1 = [(0, 'PRIMARY', 'PrimaryHDU', 7, (10, 10), 'int32', ''), + (1, '', 'ImageHDU', 8, (10, 10), 'int32', '')] + ans2 = [(0, 'PRIMARY', 'PrimaryHDU', 7, (10, 10), 'uint8', ''), + (1, '', 'ImageHDU', 8, (10, 10), 'uint8', '')] + ans3 = [(0, 'PRIMARY', 'PrimaryHDU', 7, (10, 10), 'int32', ''), + (1, '', 'ImageHDU', 8, (10, 10), 'int32', '')] + ans4 = [(0, 'PRIMARY', 'PrimaryHDU', 7, (), '', ''), + (1, '', 'ImageHDU', 8, (), '', '')] + + assert stpyfits.info(self.temp('new.fits'), output=False) == ans1 + assert stpyfits.info(self.temp('new1.fits'), output=False) == ans2 + assert fits.info(self.temp('new.fits'), output=False) == ans3 + assert fits.info(self.temp('new1.fits'), output=False) == ans4 + + hdul5 = stpyfits.open(self.temp('new.fits')) + hdul6 = fits.open(self.temp('new1.fits')) + + assert hdul5[1].header['NAXIS'] == 2 + assert hdul6[1].header['NAXIS'] == 0 + assert hdul5[1].header['NAXIS1'] == 10 + assert hdul5[1].header['NAXIS2'] == 10 + + for k in ('NPIX1', 'NPIX2'): + with pytest.raises(KeyError): + hdul5[1].header[k] + for k in ('NAXIS1', 'NAXIS2'): + with pytest.raises(KeyError): + hdul6[1].header[k] + + assert hdul6[1].header['NPIX1'] == 10 + assert hdul6[1].header['NPIX2'] == 10 + assert (hdul5[1].data == np.ones((10, 10), dtype=np.int32)).all() + assert hdul6[1].data is None + + hdul5.close() + hdul6.close() + hdul.close() + hdul1.close() + + def test_updateConvienceFunction(self): + """Test the update convience function in both the fits and stpyfits + namespace.""" + + hdul = stpyfits.open(self.data('cdva2.fits')) + hdul1 = fits.open(self.data('cdva2.fits')) + + header = hdul[0].header.copy() + header['NAXIS'] = 0 + + stpyfits.writeto(self.temp('new.fits'), hdul[0].data, header, + **self.writekwargs) + + hdu = stpyfits.ImageHDU() + hdu1 = fits.ImageHDU() + + hdu.data = hdul[0].data + hdu1.data = hdul1[0].data + hdu.header.set('BITPIX', 32) + hdu1.header.set('BITPIX', 32) + hdu.header.set('NAXIS', 0) + hdu.header.set('PIXVALUE', 1, 'Constant pixel value', after='GCOUNT') + hdu1.header.set('PIXVALUE', 1, 'Constant pixel value', after='GCOUNT') + hdu.header.set('NPIX1', 10, 'length of constant array axis 1', + after='GCOUNT') + hdu.header.set('NPIX2', 10, 'length of constant array axis 2', + after='NPIX1') + stpyfits.append(self.temp('new.fits'), hdu.data, hdu.header) + + d = np.zeros_like(hdu.data) + + stpyfits.update(self.temp('new.fits'), d, hdu.header, 1) + + if ASTROPY_VER_GE20: + ans1 = [(0, 'PRIMARY', 1, 'PrimaryHDU', 7, (), '', ''), + (1, '', 1, 'ImageHDU', 8, (), '', '')] + ans2 = [(0, 'PRIMARY', 1, 'PrimaryHDU', 7, (10, 10), 'int32', ''), + (1, '', 1, 'ImageHDU', 8, (10, 10), 'int32', '')] + else: + ans1 = [(0, 'PRIMARY', 'PrimaryHDU', 7, (), '', ''), + (1, '', 'ImageHDU', 8, (), '', '')] + ans2 = [(0, 'PRIMARY', 'PrimaryHDU', 7, (10, 10), 'int32', ''), + (1, '', 'ImageHDU', 8, (10, 10), 'int32', '')] + + assert fits.info(self.temp('new.fits'), output=False) == ans1 + assert stpyfits.info(self.temp('new.fits'), output=False) == ans2 + + hdul7 = stpyfits.open(self.temp('new.fits')) + assert hdul7[1].header['NAXIS'] == 2 + assert hdul7[1].header['NAXIS1'] == 10 + assert hdul7[1].header['NAXIS2'] == 10 + assert hdul7[1].header['PIXVALUE'] == 0 + + for k in ('NPIX1', 'NPIX2'): + with pytest.raises(KeyError): + hdul7[1].header[k] + + assert (hdul7[1].data == np.zeros((10, 10), dtype=np.int32)).all() + + hdul8 = fits.open(self.temp('new.fits')) + assert hdul8[1].header['NAXIS'] == 0 + assert hdul8[1].header['NPIX1'] == 10 + assert hdul8[1].header['NPIX2'] == 10 + assert hdul8[1].header['PIXVALUE'] == 0 + + for k in ('NAXIS1', 'NAXIS2'): + with pytest.raises(KeyError): + hdul8[1].header[k] + + assert hdul8[1].data is None + + hdul7.close() + hdul8.close() + hdul.close() + hdul1.close() + + def test_ImageHDUConstructor(self): + """Test the ImageHDU constructor in both the fits and stpyfits + namespace.""" + + hdu = stpyfits.ImageHDU() + assert isinstance(hdu, stpyfits.ConstantValueImageHDU) + assert isinstance(hdu, fits.ImageHDU) + + def test_PrimaryHDUConstructor(self): + """Test the PrimaryHDU constructor in both the fits and stpyfits + namespace. Although stpyfits does not reimplement the + constructor, it does add _ConstantValueImageBaseHDU to the + inheritance hierarchy of fits.PrimaryHDU when accessed through the + stpyfits namespace. This method tests that that inheritance is + working""" + + n = np.ones(10) + + hdu = stpyfits.PrimaryHDU(n) + hdu.header.set('PIXVALUE', 1.0, 'Constant pixel value', after='EXTEND') + hdu.header.set('NAXIS', 0) + + stpyfits.writeto(self.temp('new.fits'), hdu.data, hdu.header, + **self.writekwargs) + + hdul = stpyfits.open(self.temp('new.fits')) + hdul1 = fits.open(self.temp('new.fits')) + + assert hdul[0].header['NAXIS'] == 1 + assert hdul[0].header['NAXIS1'] == 10 + assert hdul[0].header['PIXVALUE'] == 1.0 + + with pytest.raises(KeyError): + hdul[0].header['NPIX1'] + + assert (hdul[0].data == np.ones(10, dtype=np.float32)).all() + + assert hdul1[0].header['NAXIS'] == 0 + assert hdul1[0].header['NPIX1'] == 10 + assert hdul1[0].header['PIXVALUE'] == 1.0 + + with pytest.raises(KeyError): + hdul1[0].header['NAXIS1'] + + assert hdul1[0].data is None + + hdul.close() + hdul1.close() + + def test_HDUListWritetoMethod(self): + """Test the writeto method of HDUList in both the fits and stpyfits + namespace.""" + + hdu = stpyfits.PrimaryHDU() + hdu1 = stpyfits.ImageHDU() + hdu.data = np.zeros((10, 10), dtype=np.int32) + hdu1.data = hdu.data + 2 + hdu.header.set('BITPIX', 32) + hdu1.header.set('BITPIX', 32) + hdu.header.set('NAXIS', 2) + hdu.header.set('NAXIS1', 10, 'length of constant array axis 1', + after='NAXIS') + hdu.header.set('NAXIS2', 10, 'length of constant array axis 2', + after='NAXIS1') + hdu.header.set('PIXVALUE', 0, 'Constant pixel value') + hdu1.header.set('PIXVALUE', 2, 'Constant pixel value', after='GCOUNT') + hdu1.header.set('NAXIS', 2) + hdu1.header.set('NAXIS1', 10, 'length of constant array axis 1', + after='NAXIS') + hdu1.header.set('NAXIS2', 10, 'length of constant array axis 2', + after='NAXIS1') + hdul = stpyfits.HDUList([hdu, hdu1]) + + hdul.writeto(self.temp('new.fits'), **self.writekwargs) + + if ASTROPY_VER_GE20: + ans1 = [(0, 'PRIMARY', 1, 'PrimaryHDU', 7, (10, 10), 'int32', ''), + (1, '', 1, 'ImageHDU', 8, (10, 10), 'int32', '')] + ans2 = [(0, 'PRIMARY', 1, 'PrimaryHDU', 7, (), '', ''), + (1, '', 1, 'ImageHDU', 8, (), '', '')] + else: + ans1 = [(0, 'PRIMARY', 'PrimaryHDU', 7, (10, 10), 'int32', ''), + (1, '', 'ImageHDU', 8, (10, 10), 'int32', '')] + ans2 = [(0, 'PRIMARY', 'PrimaryHDU', 7, (), '', ''), + (1, '', 'ImageHDU', 8, (), '', '')] + + assert stpyfits.info(self.temp('new.fits'), output=False) == ans1 + assert fits.info(self.temp('new.fits'), output=False) == ans2 + + hdul1 = stpyfits.open(self.temp('new.fits')) + hdul2 = fits.open(self.temp('new.fits')) + + assert hdul1[0].header['NAXIS'] == 2 + assert hdul1[0].header['NAXIS1'] == 10 + assert hdul1[0].header['NAXIS2'] == 10 + assert hdul1[0].header['PIXVALUE'] == 0 + + assert (hdul1[0].data == np.zeros((10, 10), dtype=np.int32)).all() + + assert hdul1[1].header['NAXIS'] == 2 + assert hdul1[1].header['NAXIS1'] == 10 + assert hdul1[1].header['NAXIS2'] == 10 + assert hdul1[1].header['PIXVALUE'] == 2 + + assert (hdul1[1].data == (np.zeros((10, 10), dtype=np.int32) + 2)).all() + + assert hdul2[0].header['NAXIS'] == 0 + assert hdul2[0].header['NPIX1'] == 10 + assert hdul2[0].header['NPIX2'] == 10 + assert hdul2[0].header['PIXVALUE'] == 0 + + for i in range(2): + for k in ('NPIX1', 'NPIX2'): + with pytest.raises(KeyError): + hdul1[i].header[k] + for k in ('NAXIS1', 'NAXIS2'): + with pytest.raises(KeyError): + hdul2[i].header[k] + + assert hdul2[0].data is None + + assert hdul2[1].header['NAXIS'] == 0 + assert hdul2[1].header['NPIX1'] == 10 + assert hdul2[1].header['NPIX2'] == 10 + assert hdul2[1].header['PIXVALUE'] == 2 + + hdul1.close() + hdul2.close() + + def test_HDUList_getitem_Method(self): + """Test the __getitem__ method of st_HDUList in the stpyfits + namespace.""" + + n = np.ones(10) + + hdu = stpyfits.PrimaryHDU(n) + hdu.header.set('PIXVALUE', 1., 'constant pixel value', after='EXTEND') + + hdu.writeto(self.temp('new.fits'), **self.writekwargs) + + hdul = stpyfits.open(self.temp('new.fits')) + hdul1 = fits.open(self.temp('new.fits')) + + hdu = hdul[0] + hdu1 = hdul1[0] + + assert hdu.header['NAXIS'] == 1 + assert hdu.header['NAXIS1'] == 10 + assert hdu.header['PIXVALUE'] == 1.0 + + with pytest.raises(KeyError): + hdu.header['NPIX1'] + + assert (hdu.data == np.ones(10, dtype=np.float32)).all() + assert hdu1.header['NAXIS'] == 0 + assert hdu1.header['NPIX1'] == 10 + assert hdu1.header['PIXVALUE'] == 1.0 + + with pytest.raises(KeyError): + hdu1.header['NAXIS1'] + + assert hdu1.data is None + + hdul.close() + hdul1.close() + + def test_HDUListFlushMethod(self): + """Test the flush method of HDUList in both the fits and stpyfits + namespace.""" + + hdu = stpyfits.PrimaryHDU() + hdu1 = stpyfits.ImageHDU() + hdu.data = np.zeros((10, 10), dtype=np.int32) + hdu1.data = hdu.data + 2 + hdu.header.set('BITPIX', 32) + hdu1.header.set('BITPIX', 32) + hdu.header.set('NAXIS', 2) + hdu.header.set('NAXIS1', 10, 'length of constant array axis 1', + after='NAXIS') + hdu.header.set('NAXIS2', 10, 'length of constant array axis 2', + after='NAXIS1') + hdu.header.set('PIXVALUE', 0, 'Constant pixel value') + hdu1.header.set('PIXVALUE', 2, 'Constant pixel value', after='GCOUNT') + hdu1.header.set('NAXIS', 2) + hdu1.header.set('NAXIS1', 10, 'length of constant array axis 1', + after='NAXIS') + hdu1.header.set('NAXIS2', 10, 'length of constant array axis 2', + after='NAXIS1') + hdul = stpyfits.HDUList([hdu, hdu1]) + + hdul.writeto(self.temp('new.fits'), **self.writekwargs) + + hdul = stpyfits.open(self.temp('new.fits'), 'update') + hdul[0].data = np.zeros(10, dtype=np.int32) + 3 + hdul.flush() + hdul.close() + + if ASTROPY_VER_GE20: + ans1 = [(0, 'PRIMARY', 1, 'PrimaryHDU', 6, (10,), 'int32', ''), + (1, '', 1, 'ImageHDU', 8, (10, 10), 'int32', '')] + ans2 = [(0, 'PRIMARY', 1, 'PrimaryHDU', 6, (), '', ''), + (1, '', 1, 'ImageHDU', 8, (), '', '')] + ans3 = [(0, 'PRIMARY', 1, 'PrimaryHDU', 6, (15,), 'int32', ''), + (1, '', 1, 'ImageHDU', 8, (10, 10), 'int32', '')] + ans4 = [(0, 'PRIMARY', 1, 'PrimaryHDU', 6, (), '', ''), + (1, '', 1, 'ImageHDU', 8, (), '', '')] + else: + ans1 = [(0, 'PRIMARY', 'PrimaryHDU', 6, (10,), 'int32', ''), + (1, '', 'ImageHDU', 8, (10, 10), 'int32', '')] + ans2 = [(0, 'PRIMARY', 'PrimaryHDU', 6, (), '', ''), + (1, '', 'ImageHDU', 8, (), '', '')] + ans3 = [(0, 'PRIMARY', 'PrimaryHDU', 6, (15,), 'int32', ''), + (1, '', 'ImageHDU', 8, (10, 10), 'int32', '')] + ans4 = [(0, 'PRIMARY', 'PrimaryHDU', 6, (), '', ''), + (1, '', 'ImageHDU', 8, (), '', '')] + + assert stpyfits.info(self.temp('new.fits'), output=False) == ans1 + assert fits.info(self.temp('new.fits'), output=False) == ans2 + + hdul1 = stpyfits.open(self.temp('new.fits')) + hdul2 = fits.open(self.temp('new.fits')) + + assert hdul1[0].header['NAXIS'] == 1 + assert hdul1[0].header['NAXIS1'] == 10 + assert hdul1[0].header['PIXVALUE'] == 3 + + with pytest.raises(KeyError): + hdul1[0].header['NPIX1'] + + assert (hdul1[0].data == (np.zeros(10, dtype=np.int32) + 3)).all() + + assert hdul2[0].header['NAXIS'] == 0 + assert hdul2[0].header['NPIX1'] == 10 + assert hdul2[0].header['PIXVALUE'] == 3 + + with pytest.raises(KeyError): + hdul2[0].header['NAXIS1'] + + assert hdul2[0].data is None + + hdul1.close() + hdul2.close() + + hdul3 = stpyfits.open(self.temp('new.fits'), 'update') + hdul3[0].data = np.zeros(15, dtype=np.int32) + 4 + hdul3.close() # Note that close calls flush + + assert stpyfits.info(self.temp('new.fits'), output=False) == ans3 + assert fits.info(self.temp('new.fits'), output=False) == ans4 + + hdul1 = stpyfits.open(self.temp('new.fits')) + hdul2 = fits.open(self.temp('new.fits')) + + assert hdul1[0].header['NAXIS'] == 1 + assert hdul1[0].header['NAXIS1'] == 15 + assert hdul1[0].header['PIXVALUE'] == 4 + + with pytest.raises(KeyError): + hdul1[0].header['NPIX1'] + + assert (hdul1[0].data == (np.zeros(15, dtype=np.int32) + 4)).all() + + assert hdul2[0].header['NAXIS'] == 0 + assert hdul2[0].header['NPIX1'] == 15 + assert hdul2[0].header['PIXVALUE'] == 4 + + with pytest.raises(KeyError): + hdul2[0].header['NAXIS1'] + + assert hdul2[0].data is None + + hdul1.close() + hdul2.close() + + def test_ImageBaseHDU_getattr_Method(self): + """Test the __getattr__ method of ImageBaseHDU in both the fits + and stpyfits namespace.""" + + hdul = stpyfits.open(self.data('cdva2.fits')) + hdul1 = fits.open(self.data('cdva2.fits')) + + hdu = hdul[0] + hdu1 = hdul1[0] + + assert (hdu.data == np.ones((10, 10), dtype=np.int32)).all() + assert hdu1.data is None + + hdul.close() + hdul1.close() + + def test_ImageBaseHDUWriteToMethod(self): + """Test the writeto method of _ConstantValueImageBaseHDU in the + stpyfits namespace.""" + + n = np.ones(10) + + hdu = stpyfits.PrimaryHDU(n) + hdu.header.set('PIXVALUE', 1., 'constant pixel value', after='EXTEND') + + hdu.writeto(self.temp('new.fits'), **self.writekwargs) + + hdul = stpyfits.open(self.temp('new.fits')) + hdul1 = fits.open(self.temp('new.fits')) + + assert hdul[0].header['NAXIS'] == 1 + assert hdul[0].header['NAXIS1'] == 10 + assert hdul[0].header['PIXVALUE'] == 1.0 + + with pytest.raises(KeyError): + hdul[0].header['NPIX1'] + + assert (hdul[0].data == np.ones(10, dtype=np.float32)).all() + + assert hdul1[0].header['NAXIS'] == 0 + assert hdul1[0].header['NPIX1'] == 10 + assert hdul1[0].header['PIXVALUE'] == 1.0 + + with pytest.raises(KeyError): + hdul1[0].header['NAXIS1'] + + assert hdul1[0].data is None + + hdul.close() + hdul1.close() + + def test_StrayPixvalue(self): + """Regression test for #885 + (https://svn.stsci.edu/trac/ssb/stsci_python/ticket/885) + + Tests that HDUs containing a non-zero NAXIS as well as a PIXVALUE + keyword in their header are not treated as constant value HDUs. + """ + + data = np.arange(100).reshape((10, 10)) + phdu = fits.PrimaryHDU(data=data) + hdu = fits.ImageHDU(data=data) + + phdu.header['PIXVALUE'] = 10 + hdu.header['PIXVALUE'] = 10 + + hdul = fits.HDUList([phdu, hdu]) + hdul.writeto(self.temp('test.fits')) + + with stpyfits.open(self.temp('test.fits')) as h: + assert not isinstance(h[0], stpyfits.ConstantValuePrimaryHDU) + assert not isinstance(h[1], stpyfits.ConstantValueImageHDU) + assert (h[0].data == data).all() + assert (h[1].data == data).all() + + def test_DimensionlessConstantValueArray(self): + """Tests a case that was reported where an HDU can be a constant + value HDU (it has a PIXVALUE and NAXIS=0) but NPIX1 = NPIX2 = 0 as + well. + """ + + hdu = stpyfits.PrimaryHDU() + hdu.header['NAXIS'] = 0 + hdu.header['BITPIX'] = 16 + hdu.header['NPIX1'] = 0 + hdu.header['NPIX2'] = 0 + hdu.header['PIXVALUE'] = 0 + + hdu.writeto(self.temp('test.fits')) + + with stpyfits.open(self.temp('test.fits')) as h: + assert h[0].data is None + h.writeto(self.temp('test2.fits')) + + def test_DeconvertConstantArray(self): + """When a constant value array's data is overridden with non- + constant data, test that when saving the file it removes + all constant value array keywords and is treated as a normal image + HDU. + """ + + data = np.ones((100, 100)) + hdu = stpyfits.PrimaryHDU(data=data) + hdu.header['PIXVALUE'] = 1 + hdu.writeto(self.temp('test.fits')) + + with stpyfits.open(self.temp('test.fits'), mode='update') as h: + assert h[0].header['PIXVALUE'] == 1 + h[0].data[20:80, 20:80] = 2 + + with fits.open(self.temp('test.fits')) as h: + assert 'PIXVALUE' not in h[0].header + assert 'NPIX1' not in h[0].header + assert 'NPIX2' not in h[0].header + assert h[0].header.count('NAXIS') == 1 + assert h[0].header['NAXIS'] == 2 + assert h[0].header['NAXIS1'] == 100 + assert h[0].header['NAXIS2'] == 100 + assert h[0].data.max() == 2 + assert h[0].data.min() == 1 + + def test_GetvalExtensionHDU(self): + """Regression test for an issue that came up with the fact that + ImageHDU has a different argument signature from PrimaryHDU. + """ + + data = np.ones((100, 100)) + hdu = stpyfits.ImageHDU(data=data) + hdu.header['PIXVALUE'] = 1 + hdu.header['FOO'] = 'test' + hdul = stpyfits.HDUList([stpyfits.PrimaryHDU(), hdu]) + hdul.writeto(self.temp('test.fits')) + + assert stpyfits.getval(self.temp('test.fits'), 'FOO', ext=1) == 'test' diff -Nru stsci.tools-3.4.11/lib/stsci/tools/tests/testStpyfits.py stsci.tools-3.4.12/lib/stsci/tools/tests/testStpyfits.py --- stsci.tools-3.4.11/lib/stsci/tools/tests/testStpyfits.py 2017-12-18 16:19:42.000000000 +0000 +++ stsci.tools-3.4.12/lib/stsci/tools/tests/testStpyfits.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,746 +0,0 @@ -#!/usr/bin/env python -from __future__ import division # confidence high - -import os -import tempfile - -import numpy as np -from distutils.version import LooseVersion - -from nose.tools import assert_true, assert_false, assert_equal, assert_raises - -import stsci.tools.stpyfits as stpyfits -#import pyfits -import astropy -from astropy.io import fits -#from pyfits.tests import PyfitsTestCase -from astropy.io.fits.tests import FitsTestCase - -ASTROPY_VER_GE13 = LooseVersion(astropy.__version__) >= LooseVersion('1.3') - -class TestStpyfitsFunctions(FitsTestCase): - def setup(self): - self.data_dir = os.path.dirname(__file__) - self.temp_dir = tempfile.mkdtemp(prefix='stpyfits-test-') - - def testInfoConvienceFunction(self): - """Test the info convience function in both the fits and stpyfits - namespace.""" - - assert_equal( - stpyfits.info(self.data('o4sp040b0_raw.fits'), output=False), - [(0, 'PRIMARY', 'PrimaryHDU', 215, (), '', ''), - (1, 'SCI', 'ImageHDU', 141, (62, 44), 'int16', ''), - (2, 'ERR', 'ImageHDU', 71, (62, 44), 'int16', ''), - (3, 'DQ', 'ImageHDU', 71, (62, 44), 'int16', ''), - (4, 'SCI', 'ImageHDU', 141, (62, 44), 'int16', ''), - (5, 'ERR', 'ImageHDU', 71, (62, 44), 'int16', ''), - (6, 'DQ', 'ImageHDU', 71, (62, 44), 'int16', '')]) - - - assert_equal( - fits.info(self.data('o4sp040b0_raw.fits'), output=False), - [(0, 'PRIMARY', 'PrimaryHDU', 215, (), '', ''), - (1, 'SCI', 'ImageHDU', 141, (62, 44), 'int16', ''), - (2, 'ERR', 'ImageHDU', 71, (), '', ''), - (3, 'DQ', 'ImageHDU', 71, (), '', ''), - (4, 'SCI', 'ImageHDU', 141, (62, 44), 'int16', ''), - (5, 'ERR', 'ImageHDU', 71, (), '', ''), - (6, 'DQ', 'ImageHDU', 71, (), '', '')]) - - assert_equal( - stpyfits.info(self.data('cdva2.fits'), output=False), - [(0, 'PRIMARY', 'PrimaryHDU', 7, (10, 10), 'int32', '')]) - - assert_equal( - fits.info(self.data('cdva2.fits'), output=False), - [(0, 'PRIMARY', 'PrimaryHDU', 7, (), '', '')]) - - - def testOpenConvienceFunction(self): - """Test the open convience function in both the fits and stpyfits - namespace.""" - - hdul = stpyfits.open(self.data('cdva2.fits')) - hdul1 = fits.open(self.data('cdva2.fits')) - - assert_equal(hdul[0].header['NAXIS'], 2) - assert_equal(hdul1[0].header['NAXIS'], 0) - assert_equal(hdul[0].header['NAXIS1'], 10) - assert_equal(hdul[0].header['NAXIS2'], 10) - - assert_raises(KeyError, lambda: hdul1[0].header['NAXIS1']) - assert_raises(KeyError, lambda: hdul1[0].header['NAXIS2']) - assert_raises(KeyError, lambda: hdul[0].header['NPIX1']) - assert_raises(KeyError, lambda: hdul[0].header['NPIX2']) - - assert_equal(hdul1[0].header['NPIX1'], 10) - assert_equal(hdul1[0].header['NPIX2'], 10) - - assert_true((hdul[0].data == np.ones((10, 10), dtype=np.int32)).all()) - - assert_equal(hdul1[0].data, None) - - hdul.close() - hdul1.close() - - def testGetHeaderConvienceFunction(self): - """Test the getheader convience function in both the fits and - stpyfits namespace.""" - - hd = stpyfits.getheader(self.data('cdva2.fits')) - hd1 = fits.getheader(self.data('cdva2.fits')) - - assert_equal(hd['NAXIS'], 2) - assert_equal(hd1['NAXIS'], 0) - assert_equal(hd['NAXIS1'], 10) - assert_equal(hd['NAXIS2'], 10) - - assert_raises(KeyError, lambda: hd1['NAXIS1']) - assert_raises(KeyError, lambda: hd1['NAXIS2']) - assert_raises(KeyError, lambda: hd['NPIX1']) - assert_raises(KeyError, lambda: hd['NPIX2']) - - assert_equal(hd1['NPIX1'], 10) - assert_equal(hd1['NPIX2'], 10) - - hd = stpyfits.getheader(self.data('o4sp040b0_raw.fits'), 2) - hd1 = fits.getheader(self.data('o4sp040b0_raw.fits'), 2) - - assert_equal(hd['NAXIS'], 2) - assert_equal(hd1['NAXIS'], 0) - assert_equal(hd['NAXIS1'], 62) - assert_equal(hd['NAXIS2'], 44) - - assert_raises(KeyError, lambda: hd1['NAXIS1']) - assert_raises(KeyError, lambda: hd1['NAXIS2']) - assert_raises(KeyError, lambda: hd['NPIX1']) - assert_raises(KeyError, lambda: hd['NPIX2']) - - assert_equal(hd1['NPIX1'], 62) - assert_equal(hd1['NPIX2'], 44) - - def testGetDataConvienceFunction(self): - """Test the getdata convience function in both the fits and - stpyfits namespace.""" - - d = stpyfits.getdata(self.data('cdva2.fits')) - assert_true((d == np.ones((10, 10), dtype=np.int32)).all()) - - assert_raises(IndexError, fits.getdata, self.data('cdva2.fits')) - - def testGetValConvienceFunction(self): - """Test the getval convience function in both the fits and - stpyfits namespace.""" - - val = stpyfits.getval(self.data('cdva2.fits'), 'NAXIS', 0) - val1 = fits.getval(self.data('cdva2.fits'), 'NAXIS', 0) - assert_equal(val, 2) - assert_equal(val1, 0) - - def testwritetoConvienceFunction(self): - """Test the writeto convience function in both the fits and stpyfits - namespace.""" - - hdul = stpyfits.open(self.data('cdva2.fits')) - hdul1 = fits.open(self.data('cdva2.fits')) - - header = hdul[0].header.copy() - header['NAXIS'] = 0 - - if ASTROPY_VER_GE13: - stpyfits.writeto(self.temp('new.fits'), hdul[0].data, header, - overwrite=True) - else: - stpyfits.writeto(self.temp('new.fits'), hdul[0].data, header, - clobber=True) - - if ASTROPY_VER_GE13: - fits.writeto(self.temp('new1.fits'), hdul1[0].data, - hdul1[0].header, overwrite=True) - else: - fits.writeto(self.temp('new1.fits'), hdul1[0].data, - hdul1[0].header, clobber=True) - - hdul.close() - hdul1.close() - - info1 = fits.info(self.temp('new.fits'), output=False) - info2 = stpyfits.info(self.temp('new.fits'), output=False) - info3 = fits.info(self.temp('new1.fits'), output=False) - info4 = stpyfits.info(self.temp('new1.fits'), output=False) - - assert_equal(info1, [(0, 'PRIMARY', 'PrimaryHDU', 6, (), '', '')]) - assert_equal(info2, - [(0, 'PRIMARY', 'PrimaryHDU', 6, (10, 10), 'int32', '')]) - assert_equal(info3, [(0, 'PRIMARY', 'PrimaryHDU', 6, (), '', '')]) - assert_equal(info4, - [(0, 'PRIMARY', 'PrimaryHDU', 6, (10, 10), 'uint8', '')]) - - def testappendConvienceFunction(self): - """Test the append convience function in both the fits and stpyfits - namespace.""" - - hdul = stpyfits.open(self.data('cdva2.fits')) - hdul1 = fits.open(self.data('cdva2.fits')) - - if ASTROPY_VER_GE13: - stpyfits.writeto(self.temp('new.fits'), hdul[0].data, - hdul[0].header, overwrite=True) - else: - stpyfits.writeto(self.temp('new.fits'), hdul[0].data, - hdul[0].header, clobber=True) - - if ASTROPY_VER_GE13: - fits.writeto(self.temp('new1.fits'), hdul1[0].data, - hdul1[0].header, overwrite=True) - else: - fits.writeto(self.temp('new1.fits'), hdul1[0].data, - hdul1[0].header, clobber=True) - - hdu = stpyfits.ImageHDU() - hdu1 = fits.ImageHDU() - - hdu.data = hdul[0].data - hdu1.data = hdul1[0].data - hdu.header.set('BITPIX', 32) - hdu1.header.set('BITPIX', 32) - hdu.header.set('NAXIS', 2) - hdu.header.set('NAXIS1', 10, 'length of constant array axis 1', - after='NAXIS') - hdu.header.set('NAXIS2', 10, 'length of constant array axis 2', - after='NAXIS1') - hdu.header.set('PIXVALUE', 1, 'Constant pixel value', after='GCOUNT') - hdu1.header.set('PIXVALUE', 1, 'Constant pixel value', after='GCOUNT') - hdu1.header.set('NPIX1', 10, 'length of constant array axis 1', - after='GCOUNT') - hdu1.header.set('NPIX2', 10, 'length of constant array axis 2', - after='NPIX1') - stpyfits.append(self.temp('new.fits'), hdu.data, hdu.header) - fits.append(self.temp('new1.fits'), hdu1.data, hdu1.header) - - assert_equal(stpyfits.info(self.temp('new.fits'), output=False), - [(0, 'PRIMARY', 'PrimaryHDU', 7, (10, 10), 'int32', ''), - (1, '', 'ImageHDU', 8, (10, 10), 'int32', '')]) - assert_equal(stpyfits.info(self.temp('new1.fits'), output=False), - [(0, 'PRIMARY', 'PrimaryHDU', 7, (10, 10), 'uint8', ''), - (1, '', 'ImageHDU', 8, (10, 10), 'uint8', '')]) - assert_equal(fits.info(self.temp('new.fits'), output=False), - [(0, 'PRIMARY', 'PrimaryHDU', 7, (10, 10), 'int32', ''), - (1, '', 'ImageHDU', 8, (10, 10), 'int32', '')]) - assert_equal(fits.info(self.temp('new1.fits'), output=False), - [(0, 'PRIMARY', 'PrimaryHDU', 7, (), '', ''), - (1, '', 'ImageHDU', 8, (), '', '')]) - - hdul5 = stpyfits.open(self.temp('new.fits')) - hdul6 = fits.open(self.temp('new1.fits')) - assert_equal(hdul5[1].header['NAXIS'], 2) - assert_equal(hdul6[1].header['NAXIS'], 0) - assert_equal(hdul5[1].header['NAXIS1'], 10) - assert_equal(hdul5[1].header['NAXIS2'], 10) - - assert_raises(KeyError, lambda: hdul6[1].header['NAXIS1']) - assert_raises(KeyError, lambda: hdul6[1].header['NAXIS2']) - assert_raises(KeyError, lambda: hdul5[1].header['NPIX1']) - assert_raises(KeyError, lambda: hdul5[1].header['NPIX2']) - - assert_equal(hdul6[1].header['NPIX1'], 10) - assert_equal(hdul6[1].header['NPIX2'], 10) - - assert_true((hdul5[1].data == np.ones((10, 10), dtype=np.int32)).all()) - - assert_equal(hdul6[1].data, None) - - hdul5.close() - hdul6.close() - hdul.close() - hdul1.close() - - def testupdateConvienceFunction(self): - """Test the update convience function in both the fits and stpyfits - namespace.""" - - hdul = stpyfits.open(self.data('cdva2.fits')) - hdul1 = fits.open(self.data('cdva2.fits')) - - header = hdul[0].header.copy() - header['NAXIS'] = 0 - - if ASTROPY_VER_GE13: - stpyfits.writeto(self.temp('new.fits'), hdul[0].data, - header, overwrite=True) - else: - stpyfits.writeto(self.temp('new.fits'), hdul[0].data, - header, clobber=True) - - - hdu = stpyfits.ImageHDU() - hdu1 = fits.ImageHDU() - - hdu.data = hdul[0].data - hdu1.data = hdul1[0].data - hdu.header.set('BITPIX', 32) - hdu1.header.set('BITPIX', 32) - hdu.header.set('NAXIS', 0) - hdu.header.set('PIXVALUE', 1, 'Constant pixel value', after='GCOUNT') - hdu1.header.set('PIXVALUE', 1, 'Constant pixel value', after='GCOUNT') - hdu.header.set('NPIX1', 10, 'length of constant array axis 1', - after='GCOUNT') - hdu.header.set('NPIX2', 10, 'length of constant array axis 2', - after='NPIX1') - stpyfits.append(self.temp('new.fits'), hdu.data, hdu.header) - - d = hdu.data * 0 - - stpyfits.update(self.temp('new.fits'), d, hdu.header, 1) - - assert_equal(fits.info(self.temp('new.fits'), output=False), - [(0, 'PRIMARY', 'PrimaryHDU', 7, (), '', ''), - (1, '', 'ImageHDU', 8, (), '', '')]) - assert_equal(stpyfits.info(self.temp('new.fits'), output=False), - [(0, 'PRIMARY', 'PrimaryHDU', 7, (10, 10), 'int32', ''), - (1, '', 'ImageHDU', 8, (10, 10), 'int32', '')]) - - hdul7 = stpyfits.open(self.temp('new.fits')) - assert_equal(hdul7[1].header['NAXIS'], 2) - assert_equal(hdul7[1].header['NAXIS1'], 10) - assert_equal(hdul7[1].header['NAXIS2'], 10) - assert_equal(hdul7[1].header['PIXVALUE'], 0) - - assert_raises(KeyError, lambda: hdul7[1].header['NPIX1']) - assert_raises(KeyError, lambda: hdul7[1].header['NPIX2']) - - assert_true((hdul7[1].data == - np.zeros((10, 10), dtype=np.int32)).all()) - - hdul8 = fits.open(self.temp('new.fits')) - assert_equal(hdul8[1].header['NAXIS'], 0) - assert_equal(hdul8[1].header['NPIX1'], 10) - assert_equal(hdul8[1].header['NPIX2'], 10) - assert_equal(hdul8[1].header['PIXVALUE'], 0) - - assert_raises(KeyError, lambda: hdul8[1].header['NAXIS1']) - assert_raises(KeyError, lambda: hdul8[1].header['NAXIS2']) - - assert_equal(hdul8[1].data, None) - - hdul7.close() - hdul8.close() - hdul.close() - hdul1.close() - - def testImageHDUConstructor(self): - """Test the ImageHDU constructor in both the fits and stpyfits - namespace.""" - - hdu = stpyfits.ImageHDU() - assert_true(isinstance(hdu, stpyfits.ConstantValueImageHDU)) - hdu1 = fits.ImageHDU() - assert_true(isinstance(hdu, fits.ImageHDU)) - - def testPrimaryHDUConstructor(self): - """Test the PrimaryHDU constructor in both the fits and stpyfits - namespace. Although stpyfits does not reimplement the - constructor, it does add _ConstantValueImageBaseHDU to the - inheritance hierarchy of fits.PrimaryHDU when accessed through the - stpyfits namespace. This method tests that that inheritance is - working""" - - n = np.zeros(10) - n = n + 1 - - hdu = stpyfits.PrimaryHDU(n) - hdu.header.set('PIXVALUE', 1.0, 'Constant pixel value', after='EXTEND') - hdu.header.set('NAXIS', 0) - - if ASTROPY_VER_GE13: - stpyfits.writeto(self.temp('new.fits'), hdu.data, hdu.header, - overwrite=True) - else: - stpyfits.writeto(self.temp('new.fits'), hdu.data, hdu.header, - clobber=True) - - hdul = stpyfits.open(self.temp('new.fits')) - hdul1 = fits.open(self.temp('new.fits')) - - assert_equal(hdul[0].header['NAXIS'], 1) - assert_equal(hdul[0].header['NAXIS1'], 10) - assert_equal(hdul[0].header['PIXVALUE'], 1.0) - - assert_raises(KeyError, lambda: hdul[0].header['NPIX1']) - - assert_true((hdul[0].data == np.ones(10, dtype=np.float32)).all()) - - assert_equal(hdul1[0].header['NAXIS'], 0) - assert_equal(hdul1[0].header['NPIX1'], 10) - assert_equal(hdul1[0].header['PIXVALUE'], 1.0) - - assert_raises(KeyError, lambda: hdul1[0].header['NAXIS1']) - - assert_equal(hdul1[0].data, None) - - hdul.close() - hdul1.close() - - def testHDUListWritetoMethod(self): - """Test the writeto method of HDUList in both the fits and stpyfits - namespace.""" - - hdu = stpyfits.PrimaryHDU() - hdu1 = stpyfits.ImageHDU() - hdu.data = np.zeros((10, 10), dtype=np.int32) - hdu1.data = hdu.data + 2 - hdu.header.set('BITPIX', 32) - hdu1.header.set('BITPIX', 32) - hdu.header.set('NAXIS', 2) - hdu.header.set('NAXIS1', 10, 'length of constant array axis 1', - after='NAXIS') - hdu.header.set('NAXIS2', 10, 'length of constant array axis 2', - after='NAXIS1') - hdu.header.set('PIXVALUE', 0, 'Constant pixel value') - hdu1.header.set('PIXVALUE', 2, 'Constant pixel value', after='GCOUNT') - hdu1.header.set('NAXIS', 2) - hdu1.header.set('NAXIS1', 10, 'length of constant array axis 1', - after='NAXIS') - hdu1.header.set('NAXIS2', 10, 'length of constant array axis 2', - after='NAXIS1') - hdul = stpyfits.HDUList([hdu,hdu1]) - if ASTROPY_VER_GE13: - hdul.writeto(self.temp('new.fits'), overwrite=True) - else: - hdul.writeto(self.temp('new.fits'), clobber=True) - - assert_equal(stpyfits.info(self.temp('new.fits'), output=False), - [(0, 'PRIMARY', 'PrimaryHDU', 7, (10, 10), 'int32', ''), - (1, '', 'ImageHDU', 8, (10, 10), 'int32', '')]) - - assert_equal(fits.info(self.temp('new.fits'), output=False), - [(0, 'PRIMARY', 'PrimaryHDU', 7, (), '', ''), - (1, '', 'ImageHDU', 8, (), '', '')]) - - hdul1 = stpyfits.open(self.temp('new.fits')) - hdul2 = fits.open(self.temp('new.fits')) - - assert_equal(hdul1[0].header['NAXIS'], 2) - assert_equal(hdul1[0].header['NAXIS1'], 10) - assert_equal(hdul1[0].header['NAXIS2'], 10) - assert_equal(hdul1[0].header['PIXVALUE'], 0) - - assert_raises(KeyError, lambda: hdul1[0].header['NPIX1']) - assert_raises(KeyError, lambda: hdul1[0].header['NPIX2']) - - assert_true((hdul1[0].data == - np.zeros((10, 10), dtype=np.int32)).all()) - - assert_equal(hdul1[1].header['NAXIS'], 2) - assert_equal(hdul1[1].header['NAXIS1'], 10) - assert_equal(hdul1[1].header['NAXIS2'], 10) - assert_equal(hdul1[1].header['PIXVALUE'], 2) - - assert_raises(KeyError, lambda: hdul1[1].header['NPIX1']) - assert_raises(KeyError, lambda: hdul1[1].header['NPIX2']) - - assert_true((hdul1[1].data == - (np.zeros((10, 10), dtype=np.int32) + 2)).all()) - - assert_equal(hdul2[0].header['NAXIS'], 0) - assert_equal(hdul2[0].header['NPIX1'], 10) - assert_equal(hdul2[0].header['NPIX2'], 10) - assert_equal(hdul2[0].header['PIXVALUE'], 0) - - assert_raises(KeyError, lambda: hdul2[0].header['NAXIS1']) - assert_raises(KeyError, lambda: hdul2[0].header['NAXIS2']) - - assert_equal(hdul2[0].data, None) - - assert_equal(hdul2[1].header['NAXIS'], 0) - assert_equal(hdul2[1].header['NPIX1'], 10) - assert_equal(hdul2[1].header['NPIX2'], 10) - assert_equal(hdul2[1].header['PIXVALUE'], 2) - - assert_raises(KeyError, lambda: hdul2[1].header['NAXIS1']) - assert_raises(KeyError, lambda: hdul2[1].header['NAXIS2']) - - hdul1.close() - hdul2.close() - - def testHDUList__getitem__Method(self): - """Test the __getitem__ method of st_HDUList in the stpyfits - namespace.""" - - n = np.zeros(10) - n = n + 1 - - hdu = stpyfits.PrimaryHDU(n) - hdu.header.set('PIXVALUE', 1., 'constant pixel value', after='EXTEND') - - if ASTROPY_VER_GE13: - hdu.writeto(self.temp('new.fits'), overwrite=True) - else: - hdu.writeto(self.temp('new.fits'), clobber=True) - - hdul = stpyfits.open(self.temp('new.fits')) - hdul1 = fits.open(self.temp('new.fits')) - - hdu = hdul[0] - hdu1 = hdul1[0] - - assert_equal(hdu.header['NAXIS'], 1) - assert_equal(hdu.header['NAXIS1'], 10) - assert_equal(hdu.header['PIXVALUE'], 1.0) - - assert_raises(KeyError, lambda: hdu.header['NPIX1']) - - assert_true((hdu.data == np.ones(10, dtype=np.float32)).all()) - assert_equal(hdu1.header['NAXIS'], 0) - assert_equal(hdu1.header['NPIX1'], 10) - assert_equal(hdu1.header['PIXVALUE'], 1.0) - - assert_raises(KeyError, lambda: hdu1.header['NAXIS1']) - - assert_equal(hdu1.data, None) - - hdul.close() - hdul1.close() - - def testHDUListFlushMethod(self): - """Test the flush method of HDUList in both the fits and stpyfits - namespace.""" - - hdu = stpyfits.PrimaryHDU() - hdu1 = stpyfits.ImageHDU() - hdu.data = np.zeros((10, 10), dtype=np.int32) - hdu1.data = hdu.data + 2 - hdu.header.set('BITPIX', 32) - hdu1.header.set('BITPIX', 32) - hdu.header.set('NAXIS', 2) - hdu.header.set('NAXIS1', 10, 'length of constant array axis 1', - after='NAXIS') - hdu.header.set('NAXIS2', 10, 'length of constant array axis 2', - after='NAXIS1') - hdu.header.set('PIXVALUE', 0, 'Constant pixel value') - hdu1.header.set('PIXVALUE', 2, 'Constant pixel value', after='GCOUNT') - hdu1.header.set('NAXIS', 2) - hdu1.header.set('NAXIS1', 10, 'length of constant array axis 1', - after='NAXIS') - hdu1.header.set('NAXIS2', 10, 'length of constant array axis 2', - after='NAXIS1') - hdul = stpyfits.HDUList([hdu, hdu1]) - if ASTROPY_VER_GE13: - hdul.writeto(self.temp('new.fits'), overwrite=True) - else: - hdul.writeto(self.temp('new.fits'), clobber=True) - - hdul = stpyfits.open(self.temp('new.fits'), 'update') - d = np.arange(10, dtype=np.int32) - d = d * 0 - d = d + 3 - hdul[0].data = d - hdul.flush() - hdul.close() - - assert_equal(stpyfits.info(self.temp('new.fits'), output=False), - [(0, 'PRIMARY', 'PrimaryHDU', 6, (10,), 'int32', ''), - (1, '', 'ImageHDU', 8, (10, 10), 'int32', '')]) - assert_equal(fits.info(self.temp('new.fits'), output=False), - [(0, 'PRIMARY', 'PrimaryHDU', 6, (), '', ''), - (1, '', 'ImageHDU', 8, (), '', '')]) - - hdul1 = stpyfits.open(self.temp('new.fits')) - hdul2 = fits.open(self.temp('new.fits')) - - assert_equal(hdul1[0].header['NAXIS'], 1) - assert_equal(hdul1[0].header['NAXIS1'], 10) - assert_equal(hdul1[0].header['PIXVALUE'], 3) - - assert_raises(KeyError, lambda: hdul1[0].header['NPIX1']) - - assert_true((hdul1[0].data == - (np.zeros(10, dtype=np.int32) + 3)).all()) - - assert_equal(hdul2[0].header['NAXIS'], 0) - assert_equal(hdul2[0].header['NPIX1'], 10) - assert_equal(hdul2[0].header['PIXVALUE'], 3) - - assert_raises(KeyError, lambda: hdul2[0].header['NAXIS1']) - - assert_equal(hdul2[0].data, None) - - hdul1.close() - hdul2.close() - - hdul3 = stpyfits.open(self.temp('new.fits'), 'update') - d = np.arange(15, dtype=np.int32) - d = d * 0 - d = d + 4 - hdul3[0].data = d - hdul3.close() # Note that close calls flush - - assert_equal(stpyfits.info(self.temp('new.fits'), output=False), - [(0, 'PRIMARY', 'PrimaryHDU', 6, (15,), 'int32', ''), - (1, '', 'ImageHDU', 8, (10, 10), 'int32', '')]) - assert_equal(fits.info(self.temp('new.fits'), output=False), - [(0, 'PRIMARY', 'PrimaryHDU', 6, (), '', ''), - (1, '', 'ImageHDU', 8, (), '', '')]) - - hdul1 = stpyfits.open(self.temp('new.fits')) - hdul2 = fits.open(self.temp('new.fits')) - - assert_equal(hdul1[0].header['NAXIS'], 1) - assert_equal(hdul1[0].header['NAXIS1'], 15) - assert_equal(hdul1[0].header['PIXVALUE'], 4) - - assert_raises(KeyError, lambda: hdul1[0].header['NPIX1']) - - assert_true((hdul1[0].data == - (np.zeros(15, dtype=np.int32) + 4)).all()) - - assert_equal(hdul2[0].header['NAXIS'], 0) - assert_equal(hdul2[0].header['NPIX1'], 15) - assert_equal(hdul2[0].header['PIXVALUE'], 4) - - assert_raises(KeyError, lambda: hdul2[0].header['NAXIS1']) - - assert_equal(hdul2[0].data, None) - - hdul1.close() - hdul2.close() - - def testImageBaseHDU__getattr__Method(self): - """Test the __getattr__ method of ImageBaseHDU in both the fits - and stpyfits namespace.""" - - hdul = stpyfits.open(self.data('cdva2.fits')) - hdul1 = fits.open(self.data('cdva2.fits')) - - hdu = hdul[0] - hdu1 = hdul1[0] - - assert_true((hdu.data == np.ones((10, 10), dtype=np.int32)).all()) - assert_equal(hdu1.data, None) - - hdul.close() - hdul1.close() - - def testImageBaseHDUWriteToMethod(self): - """Test the writeto method of _ConstantValueImageBaseHDU in the - stpyfits namespace.""" - - n = np.zeros(10) - n = n + 1 - - hdu = stpyfits.PrimaryHDU(n) - hdu.header.set('PIXVALUE', 1., 'constant pixel value', after='EXTEND') - - if ASTROPY_VER_GE13: - hdu.writeto(self.temp('new.fits'), overwrite=True) - else: - hdu.writeto(self.temp('new.fits'), clobber=True) - - hdul = stpyfits.open(self.temp('new.fits')) - hdul1 = fits.open(self.temp('new.fits')) - - assert_equal(hdul[0].header['NAXIS'], 1) - assert_equal(hdul[0].header['NAXIS1'], 10) - assert_equal(hdul[0].header['PIXVALUE'], 1.0) - - assert_raises(KeyError, lambda: hdul[0].header['NPIX1']) - - assert_true((hdul[0].data == np.ones(10, dtype=np.float32)).all()) - - assert_equal(hdul1[0].header['NAXIS'], 0) - assert_equal(hdul1[0].header['NPIX1'], 10) - assert_equal(hdul1[0].header['PIXVALUE'], 1.0) - - assert_raises(KeyError, lambda: hdul1[0].header['NAXIS1']) - - assert_equal(hdul1[0].data, None) - - hdul.close() - hdul1.close() - - def testStrayPixvalue(self): - """Regression test for #885 - (https://svn.stsci.edu/trac/ssb/stsci_python/ticket/885) - - Tests that HDUs containing a non-zero NAXIS as well as a PIXVALUE - keyword in their header are not treated as constant value HDUs. - """ - - data = np.arange(100).reshape((10, 10)) - phdu = fits.PrimaryHDU(data=data) - hdu = fits.ImageHDU(data=data) - - phdu.header['PIXVALUE'] = 10 - hdu.header['PIXVALUE'] = 10 - - hdul = fits.HDUList([phdu, hdu]) - hdul.writeto(self.temp('test.fits')) - - with stpyfits.open(self.temp('test.fits')) as h: - assert_false(isinstance(h[0], stpyfits.ConstantValuePrimaryHDU)) - assert_false(isinstance(h[1], stpyfits.ConstantValueImageHDU)) - assert_true((h[0].data == data).all()) - assert_true((h[1].data == data).all()) - - def testDimensionlessConstantValueArray(self): - """Tests a case that was reported where an HDU can be a constant - value HDU (it has a PIXVALUE and NAXIS=0) but NPIX1 = NPIX2 = 0 as - well. - """ - - hdu = stpyfits.PrimaryHDU() - hdu.header['NAXIS'] = 0 - hdu.header['BITPIX'] = 16 - hdu.header['NPIX1'] = 0 - hdu.header['NPIX2'] = 0 - hdu.header['PIXVALUE'] = 0 - - hdu.writeto(self.temp('test.fits')) - - with stpyfits.open(self.temp('test.fits')) as h: - assert_true(h[0].data is None) - - h.writeto(self.temp('test2.fits')) - - def testDeconvertConstantArray(self): - """When a constant value array's data is overridden with non- - constant data, test that when saving the file it removes - all constant value array keywords and is treated as a normal image - HDU. - """ - - data = np.ones((100, 100)) - hdu = stpyfits.PrimaryHDU(data=data) - hdu.header['PIXVALUE'] = 1 - hdu.writeto(self.temp('test.fits')) - - with stpyfits.open(self.temp('test.fits'), mode='update') as h: - assert_equal(h[0].header['PIXVALUE'], 1) - h[0].data[20:80, 20:80] = 2 - - with fits.open(self.temp('test.fits')) as h: - assert_true('PIXVALUE' not in h[0].header) - assert_true('NPIX1' not in h[0].header) - assert_true('NPIX2' not in h[0].header) - assert_equal(h[0].header.count('NAXIS'), 1) - assert_equal(h[0].header['NAXIS'], 2) - assert_equal(h[0].header['NAXIS1'], 100) - assert_equal(h[0].header['NAXIS2'], 100) - assert_equal(h[0].data.max(), 2) - assert_equal(h[0].data.min(), 1) - - def testGetvalExtensionHDU(self): - """Regression test for an issue that came up with the fact that - ImageHDU has a different argument signature from PrimaryHDU. - """ - - data = np.ones((100, 100)) - hdu = stpyfits.ImageHDU(data=data) - hdu.header['PIXVALUE'] = 1 - hdu.header['FOO'] = 'test' - hdul = stpyfits.HDUList([stpyfits.PrimaryHDU(), hdu]) - hdul.writeto(self.temp('test.fits')) - - assert_equal(stpyfits.getval(self.temp('test.fits'), 'FOO', ext=1), - 'test') diff -Nru stsci.tools-3.4.11/lib/stsci/tools/version.py stsci.tools-3.4.12/lib/stsci/tools/version.py --- stsci.tools-3.4.11/lib/stsci/tools/version.py 2017-12-18 16:35:29.000000000 +0000 +++ stsci.tools-3.4.12/lib/stsci/tools/version.py 2018-02-15 02:42:02.000000000 +0000 @@ -1,83 +1,30 @@ -"""This is an automatically generated file created by stsci.distutils.hooks.version_setup_hook. -Do not modify this file by hand. -""" -__all__ = ['__version__', '__vdate__', '__svn_revision__', '__svn_full_info__', - '__setup_datetime__'] - -import datetime - -__version__ = '3.4.11' -__vdate__ = 'unspecified' -__svn_revision__ = 'Unversioned directory' -__svn_full_info__ = 'unknown' -__setup_datetime__ = datetime.datetime(2017, 12, 18, 11, 35, 29, 744195) - -# what version of stsci.distutils created this version.py -stsci_distutils_version = '0.3.8.dev' - -if '.dev' in __version__: - def update_svn_info(): - """Update the SVN info if running out of an SVN working copy.""" - - import os - import string - import subprocess - - global __svn_revision__ - global __svn_full_info__ - - path = os.path.abspath(os.path.dirname(__file__)) - - run_svnversion = True - - try: - pipe = subprocess.Popen(['svn', 'info', path], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - stdout, _ = pipe.communicate() - if pipe.returncode == 0: - lines = [] - for line in stdout.splitlines(): - line = line.decode('latin1').strip() - if not line: - continue - lines.append(line) - - if not lines: - __svn_full_info__ = ['unknown'] - else: - __svn_full_info__ = lines - else: - run_svnversion = False - except OSError: - run_svnversion = False - - if run_svnversion: - # If updating the __svn_full_info__ succeeded then use its output - # to find the base of the working copy and use svnversion to get - # the svn revision. - for line in __svn_full_info__: - if line.startswith('Working Copy Root Path'): - path = line.split(':', 1)[1].strip() - break - - try: - pipe = subprocess.Popen(['svnversion', path], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - stdout, _ = pipe.communicate() - if pipe.returncode == 0: - stdout = stdout.decode('latin1').strip() - if stdout and stdout[0] in string.digits: - __svn_revision__ = stdout - except OSError: - pass - - # Convert __svn_full_info__ back to a string - if isinstance(__svn_full_info__, list): - __svn_full_info__ = '\n'.join(__svn_full_info__) - - - update_svn_info() - del update_svn_info +# AUTOMATICALLY GENERATED BY 'RELIC': +# * DO NOT EDIT THIS MODULE MANUALLY. +# * DO NOT COMMIT THIS MODULE TO YOUR GIT REPOSITORY + +__all__ = [ + '__version__', + '__version_short__', + '__version_long__', + '__version_post__', + '__version_commit__', + '__version_date__', + '__version_dirty__', + '__build_date__', + '__build_time__', + '__build_status__' +] + +__version__ = '3.4.12' +__version_short__ = '3.4.12' +__version_long__ = '3.4.12-0-gfd82437d' +__version_post__ = '0' +__version_commit__ = 'fd82437d' +__version_date__ = '2018-02-07 16:36:45 -0500' +__version_dirty__ = False +__build_date__ = '2018-02-14' +__build_time__ = '21:42:02.379382' +__build_status__ = 'release' if not int(__version_post__) > 0 \ + and not __version_dirty__ \ + else 'development' diff -Nru stsci.tools-3.4.11/lib/stsci.tools.egg-info/entry_points.txt stsci.tools-3.4.12/lib/stsci.tools.egg-info/entry_points.txt --- stsci.tools-3.4.11/lib/stsci.tools.egg-info/entry_points.txt 1970-01-01 00:00:00.000000000 +0000 +++ stsci.tools-3.4.12/lib/stsci.tools.egg-info/entry_points.txt 2018-02-15 02:42:02.000000000 +0000 @@ -0,0 +1,4 @@ +[console_scripts] +convertlog = stsci.tools.convertlog:main +convertwaiveredfits = stsci.tools.convertwaiveredfits:main + diff -Nru stsci.tools-3.4.11/lib/stsci.tools.egg-info/namespace_packages.txt stsci.tools-3.4.12/lib/stsci.tools.egg-info/namespace_packages.txt --- stsci.tools-3.4.11/lib/stsci.tools.egg-info/namespace_packages.txt 2017-12-18 16:35:30.000000000 +0000 +++ stsci.tools-3.4.12/lib/stsci.tools.egg-info/namespace_packages.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -stsci diff -Nru stsci.tools-3.4.11/lib/stsci.tools.egg-info/not-zip-safe stsci.tools-3.4.12/lib/stsci.tools.egg-info/not-zip-safe --- stsci.tools-3.4.11/lib/stsci.tools.egg-info/not-zip-safe 2017-12-18 16:24:22.000000000 +0000 +++ stsci.tools-3.4.12/lib/stsci.tools.egg-info/not-zip-safe 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ - diff -Nru stsci.tools-3.4.11/lib/stsci.tools.egg-info/PKG-INFO stsci.tools-3.4.12/lib/stsci.tools.egg-info/PKG-INFO --- stsci.tools-3.4.11/lib/stsci.tools.egg-info/PKG-INFO 2017-12-18 16:35:30.000000000 +0000 +++ stsci.tools-3.4.12/lib/stsci.tools.egg-info/PKG-INFO 2018-02-15 02:42:02.000000000 +0000 @@ -1,11 +1,12 @@ Metadata-Version: 1.1 Name: stsci.tools -Version: 3.4.11 -Summary: UNKNOWN -Home-page: http://www.stsci.edu/resources/software_hardware/stsci_python +Version: 3.4.12 +Summary: Collection of STScI utility functions +Home-page: https://github.com/spacetelescope/stsci.tools Author: STScI Author-email: help@stsci.edu License: UNKNOWN +Description-Content-Type: UNKNOWN Description: UNKNOWN Platform: UNKNOWN Classifier: Intended Audience :: Science/Research diff -Nru stsci.tools-3.4.11/lib/stsci.tools.egg-info/requires.txt stsci.tools-3.4.12/lib/stsci.tools.egg-info/requires.txt --- stsci.tools-3.4.11/lib/stsci.tools.egg-info/requires.txt 2017-12-18 16:35:30.000000000 +0000 +++ stsci.tools-3.4.12/lib/stsci.tools.egg-info/requires.txt 2018-02-15 02:42:02.000000000 +0000 @@ -1,5 +1,2 @@ -d2to1 -setuptools -stsci.distutils -astropy>=0.3.1 -numpy>=1.5.1 +astropy +numpy diff -Nru stsci.tools-3.4.11/lib/stsci.tools.egg-info/SOURCES.txt stsci.tools-3.4.12/lib/stsci.tools.egg-info/SOURCES.txt --- stsci.tools-3.4.11/lib/stsci.tools.egg-info/SOURCES.txt 2017-12-18 16:35:30.000000000 +0000 +++ stsci.tools-3.4.12/lib/stsci.tools.egg-info/SOURCES.txt 2018-02-15 02:42:02.000000000 +0000 @@ -1,11 +1,13 @@ +MANIFEST.in +README.md +RELIC-INFO setup.cfg setup.py lib/stsci/__init__.py lib/stsci.tools.egg-info/PKG-INFO lib/stsci.tools.egg-info/SOURCES.txt lib/stsci.tools.egg-info/dependency_links.txt -lib/stsci.tools.egg-info/namespace_packages.txt -lib/stsci.tools.egg-info/not-zip-safe +lib/stsci.tools.egg-info/entry_points.txt lib/stsci.tools.egg-info/requires.txt lib/stsci.tools.egg-info/top_level.txt lib/stsci/tools/__init__.py @@ -47,7 +49,6 @@ lib/stsci/tools/readgeis.py lib/stsci/tools/stash.py lib/stsci/tools/stpyfits.py -lib/stsci/tools/stsci_distutils_hack.py lib/stsci/tools/swapgeis.py lib/stsci/tools/taskpars.py lib/stsci/tools/teal.py @@ -65,8 +66,6 @@ lib/stsci/tools/tests/__init__.py lib/stsci/tools/tests/cdva2.fits lib/stsci/tools/tests/o4sp040b0_raw.fits -lib/stsci/tools/tests/testStpyfits.py -lib/stsci/tools/tests/test_xyinterp.py -scripts/convertlog -scripts/convertwaiveredfits -scripts/stscidocs \ No newline at end of file +lib/stsci/tools/tests/test_bitmask.py +lib/stsci/tools/tests/test_stpyfits.py +lib/stsci/tools/tests/test_xyinterp.py \ No newline at end of file diff -Nru stsci.tools-3.4.11/MANIFEST.in stsci.tools-3.4.12/MANIFEST.in --- stsci.tools-3.4.11/MANIFEST.in 1970-01-01 00:00:00.000000000 +0000 +++ stsci.tools-3.4.12/MANIFEST.in 2018-02-15 01:51:12.000000000 +0000 @@ -0,0 +1,2 @@ +include RELIC-INFO +recursive-include lib/stsci/tools/tests * diff -Nru stsci.tools-3.4.11/PKG-INFO stsci.tools-3.4.12/PKG-INFO --- stsci.tools-3.4.11/PKG-INFO 2017-12-18 16:35:30.000000000 +0000 +++ stsci.tools-3.4.12/PKG-INFO 2018-02-15 02:42:02.000000000 +0000 @@ -1,11 +1,12 @@ Metadata-Version: 1.1 Name: stsci.tools -Version: 3.4.11 -Summary: UNKNOWN -Home-page: http://www.stsci.edu/resources/software_hardware/stsci_python +Version: 3.4.12 +Summary: Collection of STScI utility functions +Home-page: https://github.com/spacetelescope/stsci.tools Author: STScI Author-email: help@stsci.edu License: UNKNOWN +Description-Content-Type: UNKNOWN Description: UNKNOWN Platform: UNKNOWN Classifier: Intended Audience :: Science/Research diff -Nru stsci.tools-3.4.11/README.md stsci.tools-3.4.12/README.md --- stsci.tools-3.4.11/README.md 1970-01-01 00:00:00.000000000 +0000 +++ stsci.tools-3.4.12/README.md 2018-02-15 01:51:12.000000000 +0000 @@ -0,0 +1,6 @@ +# stsci.tools + +[![Build Status](https://travis-ci.org/spacetelescope/stsci.tools.svg?branch=master)](https://travis-ci.org/spacetelescope/stsci.tools) +[![Documentation Status](https://readthedocs.org/projects/stscitools/badge/?version=latest)](http://stscitools.readthedocs.io/en/latest/?badge=latest) + +STScI utility functions. diff -Nru stsci.tools-3.4.11/RELIC-INFO stsci.tools-3.4.12/RELIC-INFO --- stsci.tools-3.4.11/RELIC-INFO 1970-01-01 00:00:00.000000000 +0000 +++ stsci.tools-3.4.12/RELIC-INFO 2018-02-15 02:24:53.000000000 +0000 @@ -0,0 +1 @@ +{"pep386": "3.4.12", "short": "3.4.12", "long": "3.4.12-0-gfd82437d", "date": "2018-02-07 16:36:45 -0500", "dirty": false, "commit": "fd82437d", "post": "0"} diff -Nru stsci.tools-3.4.11/scripts/convertlog stsci.tools-3.4.12/scripts/convertlog --- stsci.tools-3.4.11/scripts/convertlog 2017-12-18 16:19:42.000000000 +0000 +++ stsci.tools-3.4.12/scripts/convertlog 1970-01-01 00:00:00.000000000 +0000 @@ -1,5 +0,0 @@ -#!/usr/bin/env python - -if __name__ == '__main__': - from stsci.tools import convertlog - convertlog.main() diff -Nru stsci.tools-3.4.11/scripts/convertwaiveredfits stsci.tools-3.4.12/scripts/convertwaiveredfits --- stsci.tools-3.4.11/scripts/convertwaiveredfits 2017-12-18 16:19:42.000000000 +0000 +++ stsci.tools-3.4.12/scripts/convertwaiveredfits 1970-01-01 00:00:00.000000000 +0000 @@ -1,6 +0,0 @@ -#! python -from __future__ import division # confidence high - -import stsci.tools.convertwaiveredfits -stsci.tools.convertwaiveredfits.main() - diff -Nru stsci.tools-3.4.11/scripts/stscidocs stsci.tools-3.4.12/scripts/stscidocs --- stsci.tools-3.4.11/scripts/stscidocs 2017-12-18 16:19:42.000000000 +0000 +++ stsci.tools-3.4.12/scripts/stscidocs 1970-01-01 00:00:00.000000000 +0000 @@ -1,26 +0,0 @@ -#!/usr/bin/env python - -from __future__ import print_function - -import os -import sys -import webbrowser - - -DOCUMENTATION_URL = 'http://stsdas.stsci.edu/stsci_python_epydoc' - - -if __name__ == '__main__': - for arg in sys.argv: - if arg in ('-h', '--help'): - print('Uses the default web browser to display the ' \ - 'stsci_python documentation') - break - - try: - webbrowser.open(DOCUMENTATION_URL, new=1) - except: - print('There was a problem display the documentation.') - print('To view the documentation, direct your web browser to the ' \ - 'following URL:\n') - print(' ' + DOCUMENTATION_URL) diff -Nru stsci.tools-3.4.11/setup.cfg stsci.tools-3.4.12/setup.cfg --- stsci.tools-3.4.11/setup.cfg 2017-12-18 16:35:30.000000000 +0000 +++ stsci.tools-3.4.12/setup.cfg 2018-02-15 02:42:02.000000000 +0000 @@ -1,52 +1,17 @@ -[metadata] -name = stsci.tools -version = 3.4.11 -author = STScI -author-email = help@stsci.edu -home-page = http://www.stsci.edu/resources/software_hardware/stsci_python -classifier = - Intended Audience :: Science/Research - License :: OSI Approved :: BSD License - Operating System :: OS Independent - Programming Language :: Python - Topic :: Scientific/Engineering :: Astronomy - Topic :: Software Development :: Libraries :: Python Modules -requires-python = >=2.6 -requires-dist = - d2to1 - setuptools - stsci.distutils - astropy (>=0.3.1) - numpy (>=1.5.1) +[aliases] +test = pytest -[files] -packages_root = lib -packages = - stsci - stsci.tools - stsci.tools.tests -package_data = - stsci.tools.tests = *.fits -scripts = - scripts/convertwaiveredfits - scripts/stscidocs - scripts/convertlog +[tool:pytest] +python_files = lib/stsci/tools/tests/*.py -[nosetests] -exclude = .*(testutil|tester) +[flake8] +ignore = E501 +exclude = setup.py,conf.py -[global] -setup_hooks = - stsci.distutils.hooks.use_packages_root - stsci.distutils.hooks.tag_svn_revision - stsci.distutils.hooks.version_setup_hook - -[backwards_compat] -use_2to3 = False -zip_safe = False +[bdist_wheel] +universal = 1 [egg_info] tag_build = tag_date = 0 -tag_svn_revision = 0 diff -Nru stsci.tools-3.4.11/setup.py stsci.tools-3.4.12/setup.py --- stsci.tools-3.4.11/setup.py 2017-12-18 16:19:42.000000000 +0000 +++ stsci.tools-3.4.12/setup.py 2018-02-15 01:51:12.000000000 +0000 @@ -1,15 +1,65 @@ #!/usr/bin/env python +import os +import subprocess +import sys +from setuptools import setup, find_packages -try: - from setuptools import setup -except ImportError: - from ez_setup import use_setuptools - use_setuptools() - from setuptools import setup +if os.path.exists('relic'): + sys.path.insert(1, 'relic') + import relic.release +else: + try: + import relic.release + except ImportError: + try: + subprocess.check_call( + ['git', 'clone', 'https://github.com/jhunkeler/relic.git']) + sys.path.insert(1, 'relic') + import relic.release + except subprocess.CalledProcessError as e: + print(e) + exit(1) +version = relic.release.get_info() +relic.release.write_template(version, 'lib/stsci/tools') setup( - setup_requires=['d2to1>=0.2.11', 'stsci.distutils>=0.3'], - namespace_packages=['stsci'], packages=['stsci'], - d2to1=True, + name = 'stsci.tools', + version = version.pep386, + author = 'STScI', + author_email = 'help@stsci.edu', + description = 'Collection of STScI utility functions', + url = 'https://github.com/spacetelescope/stsci.tools', + classifiers = [ + 'Intended Audience :: Science/Research', + 'License :: OSI Approved :: BSD License', + 'Operating System :: OS Independent', + 'Programming Language :: Python', + 'Topic :: Scientific/Engineering :: Astronomy', + 'Topic :: Software Development :: Libraries :: Python Modules', + ], + install_requires = [ + 'astropy', + 'numpy', + ], + setup_requires = [ + 'pytest-runner' + ], + tests_require = [ + 'pytest' + ], + package_dir = { + '': 'lib', + }, + packages = find_packages('lib'), + package_data = { + '': ['LICENSE.txt'], + 'stsci/tools/tests': ['*.fits'] + }, + entry_points = { + 'console_scripts': [ + 'convertwaiveredfits=stsci.tools.convertwaiveredfits:main', + 'convertlog=stsci.tools.convertlog:main' + ], + }, )