Skip to content

Commit

Permalink
Merge pull request #187 from mwcraig/py2-future-proof
Browse files Browse the repository at this point in the history
First step in moving towards python 3 compatibility
  • Loading branch information
mwcraig committed Feb 25, 2015
2 parents 7ee90d7 + 691f1c1 commit 06aa83a
Show file tree
Hide file tree
Showing 26 changed files with 155 additions and 78 deletions.
9 changes: 6 additions & 3 deletions msumastro/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from image_collection import ImageFileCollection
from image import ImageWithWCS
from table_tree import TableTree
from __future__ import (print_function, division, absolute_import,
unicode_literals)

from .image_collection import ImageFileCollection
from .image import ImageWithWCS
from .table_tree import TableTree

from .version import version as __version__
3 changes: 3 additions & 0 deletions msumastro/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import (print_function, division, absolute_import,
unicode_literals)

from tempfile import mkdtemp
import os
from shutil import rmtree
Expand Down
3 changes: 2 additions & 1 deletion msumastro/customlogger.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import print_function
from __future__ import (print_function, division, absolute_import,
unicode_literals)

import logging
from os import path
Expand Down
11 changes: 7 additions & 4 deletions msumastro/header_processing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from fitskeyword import FITSKeyword
from __future__ import (print_function, division, absolute_import,
unicode_literals)

from .fitskeyword import FITSKeyword
try:
from feder import Feder
from .feder import Feder
except ImportError:
pass
from patchers import *
from astrometry import *
from .patchers import *
from .astrometry import *
3 changes: 3 additions & 0 deletions msumastro/header_processing/astrometry.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import (print_function, division, absolute_import,
unicode_literals)

import logging
import subprocess
from os import path, remove, rename
Expand Down
5 changes: 4 additions & 1 deletion msumastro/header_processing/feder.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import (print_function, division, absolute_import,
unicode_literals)

from itertools import chain
import logging
import datetime
Expand All @@ -7,7 +10,7 @@
import numpy as np
from ccdproc.utils.slices import slice_from_string

from fitskeyword import FITSKeyword
from .fitskeyword import FITSKeyword

logger = logging.getLogger(__name__)

Expand Down
3 changes: 3 additions & 0 deletions msumastro/header_processing/fitskeyword.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import (print_function, division, absolute_import,
unicode_literals)

import logging

from astropy.io.fits import Header
Expand Down
7 changes: 5 additions & 2 deletions msumastro/header_processing/patchers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import (print_function, division, absolute_import,
unicode_literals)

from os import path
from datetime import datetime
import logging
Expand All @@ -12,14 +15,14 @@
from astropy.table import Table

try:
from feder import Feder
from .feder import Feder
feder = Feder()
except ImportError:
feder = None
pass

from ..image_collection import ImageFileCollection
from fitskeyword import FITSKeyword
from .fitskeyword import FITSKeyword

logger = logging.getLogger(__name__)

Expand Down
3 changes: 3 additions & 0 deletions msumastro/header_processing/tests/test_feder.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import (print_function, division, absolute_import,
unicode_literals)

import pytest

have_astropysics = True
Expand Down
5 changes: 4 additions & 1 deletion msumastro/header_processing/tests/test_fitskeyword.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import (print_function, division, absolute_import,
unicode_literals)

import pytest
from astropy.io.fits.hdu import PrimaryHDU
from astropy.io.fits import Header
Expand Down Expand Up @@ -45,7 +48,7 @@ def test_add_header(self):

def test_add_header_history(self):
self.keyword.add_to_header(self.hdu, history=True)
print self.hdu.header['history']
print(self.hdu.header['history'])
assert (len(self.hdu.header['history']) ==
(1 + len(self.keyword.synonyms)))

Expand Down
39 changes: 21 additions & 18 deletions msumastro/header_processing/tests/test_patchers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import (print_function, division, absolute_import,
unicode_literals)

from os import path, chdir, getcwd, remove
from shutil import rmtree, copy, copytree, move
from tempfile import mkdtemp
Expand All @@ -7,7 +10,7 @@
from socket import timeout

import pytest
pytest_plugins = "capturelog"
pytest_plugins = str("capturelog")
import numpy as np
from numpy.testing import assert_almost_equal
from astropy.io import fits
Expand Down Expand Up @@ -129,11 +132,11 @@ def test_writing_patched_files_to_directory():
n_files_init = len(glob(path.join(_test_dir, '*.fit*')))
dest_dir = mkdtemp()
ph.patch_headers(_test_dir, new_file_ext='', save_location=dest_dir)
print files
print(files)
n_files_after = len(glob(path.join(_test_dir, '*.fit*')))
print n_files_after
print(n_files_after)
n_files_destination = len(glob(path.join(dest_dir, '*.fit*')))
print dest_dir
print(dest_dir)
rmtree(dest_dir)
assert ((n_files_init == n_files_after) &
(n_files_init == n_files_destination))
Expand Down Expand Up @@ -182,9 +185,9 @@ def test_adding_overscan_apogee_u9(make_overscan_test_files):
original_dir = getcwd()

apogee = ApogeeAltaU9()
print getcwd()
print(getcwd())
oscan_dir, has_oscan, has_no_oscan = make_overscan_test_files
print getcwd()
print(getcwd())

chdir(path.join(_test_dir, oscan_dir))
# first, does requesting *not* adding overscan actually leave it alone?
Expand All @@ -199,7 +202,7 @@ def test_adding_overscan_apogee_u9(make_overscan_test_files):
ph.patch_headers(dir='.', new_file_ext='', overwrite=True, purge_bad=False,
add_time=False, add_apparent_pos=False,
add_overscan=True, fix_imagetype=False)
print _test_dir
print(_test_dir)
header_no_oscan = fits.getheader(has_no_oscan)
# This image had no overscan, so should be missing the relevant keywords.
assert 'biassec' not in header_no_oscan
Expand All @@ -208,9 +211,9 @@ def test_adding_overscan_apogee_u9(make_overscan_test_files):
# This one as overscan, so should include both of the overscan keywords.
assert header_yes_oscan['biassec'] == apogee.useful_overscan
assert header_yes_oscan['trimsec'] == apogee.trim_region
print getcwd()
print(getcwd())
chdir(original_dir)
print getcwd()
print(getcwd())


def test_fix_imagetype():
Expand All @@ -223,15 +226,15 @@ def test_fix_imagetype():

header['imagetyp'] = im_type
# first run SHOULD change imagetyp
print header
print(header)
ph.change_imagetype_to_IRAF(header, history=False)
assert(header['imagetyp'] == imagetypes_to_check[im_type])
# second call should NOT change imagetyp
print header
print(header)
ph.change_imagetype_to_IRAF(header, history=True)
assert(header['imagetyp'] == imagetypes_to_check[im_type])
with pytest.raises(KeyError):
print header['history']
print(header['history'])
# change imagetype back to non-IRAF
header['imagetyp'] = im_type
# change with history
Expand Down Expand Up @@ -272,7 +275,7 @@ def test_adding_object_name(use_list=None,
fname = path.join(_test_dir, check_file)
fname += new_ext + new_ext
with_name = fits.open(fname + '.fit')
print 'add object name: %s' % fname
print('add object name: %s' % fname)
assert (with_name[0].header['object'] == 'm101')
return with_name

Expand Down Expand Up @@ -310,7 +313,7 @@ def test_adding_object_name_to_different_directory(use_list=None,
fname = path.join(destination_dir, test_file_basename)
fname += new_ext + new_ext
with_name = fits.open(fname + '.fit')
print 'add object name: %s' % fname
print('add object name: %s' % fname)
assert (with_name[0].header['object'] == 'm101')
return with_name

Expand Down Expand Up @@ -606,11 +609,11 @@ def test_purge_bad_keywords_logic_for_conditionals(caplog):
# that their is no history added to the header that contains the name of
# this keyword
key_to_delete = software.bad_keywords[0]
print software.bad_keywords
print(software.bad_keywords)
del a_header[key_to_delete]
print a_header
print(a_header)
ph.purge_bad_keywords(a_header, history=True)
print a_header
print(a_header)
assert all(key_to_delete.lower() not in h.lower()
for h in a_header['HISTORY'])

Expand Down Expand Up @@ -678,7 +681,7 @@ def setup_function(function):

_test_dir = path.join(mkdtemp(), 'data')
data_source = get_data_dir()
print data_source
print(data_source)
copytree(data_source, _test_dir)
object_file_with_ra_dec(_test_dir)

Expand Down
3 changes: 3 additions & 0 deletions msumastro/image.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import (print_function, division, absolute_import,
unicode_literals)

import logging

import numpy as np
Expand Down
3 changes: 3 additions & 0 deletions msumastro/image_collection.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import (print_function, division, absolute_import,
unicode_literals)

import fnmatch
from os import listdir, path
import logging
Expand Down
4 changes: 3 additions & 1 deletion msumastro/scripts/quick_add_keys_to_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
This script OVERWRITES the image files in the list specified on the
command line. There is NO WAY to override this behavior.
"""
from __future__ import (print_function, division, absolute_import,
unicode_literals)

from argparse import ArgumentParser
import logging
Expand Down Expand Up @@ -97,7 +99,7 @@ def add_keys(*files, **kwd):
for key, val in key_table:
keyword = FITSKeyword(name=key, value=val)
keyword.add_to_header(hdr, history=True)
print key, val
print(key, val)
hdr[key] = val
fil_fits.close()

Expand Down
3 changes: 3 additions & 0 deletions msumastro/scripts/run_astrometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
from msumastro.scripts import run_astrometry
run_astrometry.main(['/my/folder/of/images'])
"""
from __future__ import (print_function, division, absolute_import,
unicode_literals)

import shutil
from os import path, getcwd
import logging
Expand Down
2 changes: 2 additions & 0 deletions msumastro/scripts/run_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
run_patch.main(['--object-list', 'path/to/list.txt',
'dir1', 'dir2', 'dir3'])
"""
from __future__ import (print_function, division, absolute_import,
unicode_literals)

from os import getcwd
from os import path
Expand Down
3 changes: 3 additions & 0 deletions msumastro/scripts/run_standard_header_process.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import (print_function, division, absolute_import,
unicode_literals)

import os
import argparse
import subprocess
Expand Down
8 changes: 6 additions & 2 deletions msumastro/scripts/run_triage.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
run_triage.main(['--list-default'])
"""

from __future__ import (print_function, division, absolute_import,
unicode_literals)

import os
from argparse import ArgumentParser
from sys import exit
Expand Down Expand Up @@ -294,9 +298,9 @@ def main(arglist=None):
use_keys = list(DEFAULT_KEYS) # force a copy so DEFAULT_KEYS not modified

if args.list_default:
print 'Keys included by default are:\n'
print('Keys included by default are:\n')
keys_print = [key.upper() for key in use_keys]
print ', '.join(keys_print)
print(', '.join(keys_print))
return use_keys

use_keys.extend(args.key)
Expand Down
4 changes: 4 additions & 0 deletions msumastro/scripts/script_helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"""A set of functions to standardize some options for python scripts"""

from __future__ import (print_function, division, absolute_import,
unicode_literals)

import logging
import argparse
from os import getcwd, path
Expand Down
4 changes: 4 additions & 0 deletions msumastro/scripts/sort_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
"""

from __future__ import (print_function, division, absolute_import,
unicode_literals)

import os
import logging
from itertools import izip
Expand Down
Loading

0 comments on commit 06aa83a

Please sign in to comment.