Skip to content

Commit

Permalink
Remove more Python 2-isms; part of #262
Browse files Browse the repository at this point in the history
  • Loading branch information
mperrin committed Aug 16, 2018
1 parent b254e64 commit 360af2f
Show file tree
Hide file tree
Showing 15 changed files with 24 additions and 254 deletions.
3 changes: 1 addition & 2 deletions poppy/dms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import numpy as np
import matplotlib.pyplot as plt
import six
import scipy.ndimage.interpolation
import scipy.signal
import astropy.io.fits as fits
Expand Down Expand Up @@ -87,7 +86,7 @@ def __init__(self, dm_shape=(10, 10), actuator_spacing=None,
if self.include_actuator_print_through:
self._load_actuator_surface_file(actuator_print_through_file)

if isinstance(influence_func, six.string_types):
if isinstance(influence_func, str):
self.influence_type = "from file"
self._load_influence_fn(filename=influence_func)
elif isinstance(influence_func, fits.HDUList):
Expand Down
1 change: 0 additions & 1 deletion poppy/fresnel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
import astropy.units as u
Expand Down
2 changes: 0 additions & 2 deletions poppy/fwcentroid.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
M. Perrin, 2011-02-17, based on IDL code by Jeff Valenti et al.
"""
from __future__ import (absolute_import, division, print_function, unicode_literals)

import numpy as np


Expand Down
8 changes: 3 additions & 5 deletions poppy/instrument.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import (absolute_import, division, print_function, unicode_literals)
import getpass
import os
import platform
Expand All @@ -10,7 +9,6 @@
import numpy as np
import scipy.interpolate
import scipy.ndimage
import six
import warnings

try:
Expand Down Expand Up @@ -428,7 +426,7 @@ def _get_fits_header(self, result, options):
__version__ = ''

# --- update FITS header, display, and output.
if isinstance(self.pupil, six.string_types):
if isinstance(self.pupil, str):
pupilstr = os.path.basename(self.pupil)
elif isinstance(self.pupil, fits.HDUList):
pupilstr = 'pupil from supplied FITS HDUList object'
Expand All @@ -438,7 +436,7 @@ def _get_fits_header(self, result, options):

if self.pupilopd is None:
opdstring = "NONE - perfect telescope! "
elif isinstance(self.pupilopd, six.string_types):
elif isinstance(self.pupilopd, str):
opdstring = os.path.basename(self.pupilopd)
elif isinstance(self.pupilopd, fits.HDUList):
opdstring = 'OPD from supplied FITS HDUlist object'
Expand Down Expand Up @@ -559,7 +557,7 @@ def _get_optical_system(self, fft_oversample=2, detector_oversample=None, fov_ar
full_opd_path = self.pupilopd if os.path.exists(self.pupilopd) else os.path.join(self._datapath, "OPD",
self.pupilopd)
elif hasattr(self.pupilopd, '__getitem__') and isinstance(self.pupilopd[0],
six.string_types): # tuple with filename and slice
str): # tuple with filename and slice
full_opd_path = (
self.pupilopd[0] if os.path.exists(self.pupilopd[0]) else os.path.join(self._datapath, "OPD",
self.pupilopd[0]),
Expand Down
2 changes: 0 additions & 2 deletions poppy/matrixDFT.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
PEP8 formatting pass (except variable names)-- J. Long
"""
from __future__ import (absolute_import, division, print_function,
unicode_literals)

__all__ = ['MatrixFourierTransform']

Expand Down
1 change: 0 additions & 1 deletion poppy/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Airy functions for comparison's sake
#
############################################################################
from __future__ import (absolute_import, division, print_function, unicode_literals)

import numpy as np
import scipy
Expand Down
1 change: 0 additions & 1 deletion poppy/optics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import (absolute_import, division, print_function, unicode_literals)
import numpy as np
import scipy.special
import scipy.ndimage.interpolation
Expand Down
1 change: 0 additions & 1 deletion poppy/physical_wavefront.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-

from __future__ import division
import numpy as np
import scipy.constants as const
import astropy.units as u
Expand Down
15 changes: 6 additions & 9 deletions poppy/poppy_core.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
from __future__ import (absolute_import, division, print_function, unicode_literals)
import multiprocessing
import copy
import time
import enum
import warnings
import textwrap

import six

import numpy as np
import matplotlib.pyplot as plt
import scipy.ndimage.interpolation
Expand Down Expand Up @@ -1144,7 +1141,7 @@ def add_pupil(self, optic=None, function=None, index=None, **kwargs):
# OpticalElement object provided.
# We can use it directly, but make sure the plane type is set.
optic.planetype = PlaneType.pupil
elif isinstance(optic, six.string_types):
elif isinstance(optic, str):
# convenience code to instantiate objects from a string name.
raise NotImplementedError('Setting optics based on strings is now deprecated.')
elif optic is None and len(kwargs) > 0: # create image from files specified in kwargs
Expand Down Expand Up @@ -1204,7 +1201,7 @@ def add_image(self, optic=None, function=None, index=None, **kwargs):
"""

if isinstance(optic, six.string_types):
if isinstance(optic, str):
function = optic
optic = None

Expand Down Expand Up @@ -2286,7 +2283,7 @@ def __init__(self, name="unnamed optic", transmission=None, opd=None, opdunits=N
else:
# load transmission file.
if transmission is not None:
if isinstance(transmission, six.string_types):
if isinstance(transmission, str):
self.amplitude_file = transmission
self.amplitude, self.amplitude_header = fits.getdata(self.amplitude_file, header=True)
self.amplitude = self.amplitude.astype('=f8') # ensure native byte order, see #213
Expand Down Expand Up @@ -2331,15 +2328,15 @@ def __init__(self, name="unnamed optic", transmission=None, opd=None, opdunits=N
if self.name == 'unnamed optic':
self.name = 'OPD from supplied fits.HDUList object'
_log.info(self.name + ": Loaded OPD from supplied fits.HDUList object")
elif isinstance(opd, six.string_types):
elif isinstance(opd, str):
# load from regular FITS filename
self.opd_file = opd
self.opd, self.opd_header = fits.getdata(self.opd_file, header=True)
self.opd = self.opd.astype('=f8')
if self.name == 'unnamed optic': self.name = 'OPD from ' + self.opd_file
_log.info(self.name + ": Loaded OPD from " + self.opd_file)

elif len(opd) == 2 and isinstance(opd[0], six.string_types):
elif len(opd) == 2 and isinstance(opd[0], str):
# if OPD is specified as a 2-element iterable, treat the first element as the filename
# and 2nd as the slice of a cube.
self.opd_file = opd[0]
Expand Down Expand Up @@ -2490,7 +2487,7 @@ def _find_pixelscale_in_headers(keywords, headers):
('PIXELSCL', 'PUPLSCAL',),
(self.amplitude_header, self.opd_header)
)
elif isinstance(pixelscale, six.string_types):
elif isinstance(pixelscale, str):
# If provided as a keyword string, check for it using the same helper function
_log.debug(" Getting pixel scale from FITS keyword:" + pixelscale)
_, self.pixelscale = _find_pixelscale_in_headers(
Expand Down
1 change: 0 additions & 1 deletion poppy/special_prop.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Specialized optical system propagators
# In particular for efficient modeling of astronomical coronagraphs

from __future__ import (absolute_import, division, print_function, unicode_literals)
import numpy as np
import time
import logging
Expand Down
23 changes: 10 additions & 13 deletions poppy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
# These provide various utilities to measure the PSF's properties in certain ways, display it on screen etc.
#

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

import json
import logging
import os.path
Expand All @@ -16,7 +14,6 @@
import numpy as np
import scipy.interpolate
import scipy.ndimage
import six
import warnings

from astropy import config
Expand Down Expand Up @@ -148,7 +145,7 @@ def display_psf(HDUlist_or_filename, ext=0, vmin=1e-7, vmax=1e-1,
meaning it is taken from matplotlib's `image.interpolation`
rcParam.
"""
if isinstance(HDUlist_or_filename, six.string_types):
if isinstance(HDUlist_or_filename, str):
hdulist = fits.open(HDUlist_or_filename)
elif isinstance(HDUlist_or_filename, fits.HDUList):
hdulist = HDUlist_or_filename
Expand Down Expand Up @@ -180,7 +177,7 @@ def display_psf(HDUlist_or_filename, ext=0, vmin=1e-7, vmax=1e-1,
norm = matplotlib.colors.LogNorm(vmin=vmin, vmax=vmax)

psf_array_shape = hdulist[ext].data.shape
if isinstance(pixelscale, six.string_types):
if isinstance(pixelscale, str):
pixelscale = hdulist[ext].header[pixelscale]
halffov_x = pixelscale * psf_array_shape[1] / 2.0
halffov_y = pixelscale * psf_array_shape[0] / 2.0
Expand Down Expand Up @@ -316,13 +313,13 @@ def display_psf_difference(hdulist_or_filename1=None, HDUlist_or_filename2=None,
the difference image. Mutually exclusive to `normalize`.
(Default: False)
"""
if isinstance(hdulist_or_filename1, six.string_types):
if isinstance(hdulist_or_filename1, str):
hdulist1 = fits.open(hdulist_or_filename1)
elif isinstance(hdulist_or_filename1, fits.HDUList):
hdulist1 = hdulist_or_filename1
else:
raise ValueError("input must be a filename or HDUlist")
if isinstance(HDUlist_or_filename2, six.string_types):
if isinstance(HDUlist_or_filename2, str):
hdulist2 = fits.open(HDUlist_or_filename2)
elif isinstance(HDUlist_or_filename2, fits.HDUList):
hdulist2 = HDUlist_or_filename2
Expand Down Expand Up @@ -416,7 +413,7 @@ def display_ee(HDUlist_or_filename=None, ext=0, overplot=False, ax=None, mark_le
Default is True
"""
if isinstance(HDUlist_or_filename, six.string_types):
if isinstance(HDUlist_or_filename, str):
hdu_list = fits.open(HDUlist_or_filename)
elif isinstance(HDUlist_or_filename, fits.HDUList):
hdu_list = HDUlist_or_filename
Expand Down Expand Up @@ -459,7 +456,7 @@ def display_profiles(HDUlist_or_filename=None, ext=0, overplot=False, title=None
Title for plot
"""
if isinstance(HDUlist_or_filename, six.string_types):
if isinstance(HDUlist_or_filename, str):
hdu_list = fits.open(HDUlist_or_filename, ext=ext)
elif isinstance(HDUlist_or_filename, fits.HDUList):
hdu_list = HDUlist_or_filename
Expand Down Expand Up @@ -540,7 +537,7 @@ def radial_profile(hdulist_or_filename=None, ext=0, ee=False, center=None, stdde
so you should use (radius+binsize/2) for the radius of the EE curve if you want to be
as precise as possible.
"""
if isinstance(hdulist_or_filename, six.string_types):
if isinstance(hdulist_or_filename, str):
hdu_list = fits.open(hdulist_or_filename)
elif isinstance(hdulist_or_filename, fits.HDUList):
hdu_list = hdulist_or_filename
Expand Down Expand Up @@ -791,7 +788,7 @@ def measure_fwhm(HDUlist_or_filename, ext=0, center=None, plot=False, threshold=
"""
from astropy.modeling import models, fitting

if isinstance(HDUlist_or_filename, six.string_types):
if isinstance(HDUlist_or_filename, str):
HDUlist = fits.open(HDUlist_or_filename)
elif isinstance(HDUlist_or_filename, fits.HDUList):
HDUlist = HDUlist_or_filename
Expand Down Expand Up @@ -928,7 +925,7 @@ def measure_sharpness(HDUlist_or_filename=None, ext=0):
Same as above
"""
if isinstance(HDUlist_or_filename, six.string_types):
if isinstance(HDUlist_or_filename, str):
HDUlist = fits.open(HDUlist_or_filename)
elif isinstance(HDUlist_or_filename, fits.HDUList):
HDUlist = HDUlist_or_filename
Expand Down Expand Up @@ -981,7 +978,7 @@ def measure_centroid(HDUlist_or_filename=None, ext=0, slice=0, boxsize=20, verbo
"""
from .fwcentroid import fwcentroid

if isinstance(HDUlist_or_filename, six.string_types):
if isinstance(HDUlist_or_filename, str):
HDUlist = fits.open(HDUlist_or_filename)
elif isinstance(HDUlist_or_filename, fits.HDUList):
HDUlist = HDUlist_or_filename
Expand Down
Empty file removed poppy/vendor/__init__.py
Empty file.
Loading

0 comments on commit 360af2f

Please sign in to comment.