Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-23172: modernize code and setup.cfg #54

Merged
merged 4 commits into from
Jan 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion python/astshim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

"""lsst.astshim
"""
from __future__ import absolute_import
from .base import *
from .object import *
from .stream import *
Expand Down
2 changes: 0 additions & 2 deletions python/astshim/detail/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
from __future__ import absolute_import

from .testUtils import *
13 changes: 7 additions & 6 deletions python/astshim/fitsChanContinued.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .fitsChan import FitsChan, CardType
from .fitsChan import * # noqa: F403 F401
__all__ = ["CardType", "FitsChan", "FitsKeyState"]

from .fitsChan import CardType, FitsChan, FitsKeyState


def _calc_card_pos(self, index):
Expand Down Expand Up @@ -281,9 +282,9 @@ def setitem(self, name, value):
try:
self.clearCard()

# Look for a card with the specified name
# We do not care about the result, if nothing is found we will be at the
# end of the header
# Look for a card with the specified name.
# We do not care about the result; if nothing is found we will be
# at the end of the header.
self.findFits(name, False)

# pyast seems to want to delete items if the value is None but
Expand All @@ -297,7 +298,7 @@ def setitem(self, name, value):
elif isinstance(value, bool):
self.setFitsL(name, value, overwrite=True)
else:
# Force to string
# Force to string.
self.setFitsS(name, str(value), overwrite=True)

# Delete any later cards with matching keyword
Expand Down
7 changes: 4 additions & 3 deletions python/astshim/fitsTableContinued.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .fitsTable import * # noqa: F401 F403
__all__ = ["FitsTable", "getColumnData"]

from . import base
from .fitsTable import FitsTable
from .base import DataType as _DataType


def getColumnData(self, column):
Expand All @@ -20,7 +21,7 @@ def getColumnData(self, column):
shape = self.columnShape(column)
dtype = self.columnType(column)

if dtype == _DataType.DoubleType:
if dtype == base.DataType.DoubleType:
newshape = list(shape)
newshape.append(nrows)
coldata = self.getColumnData1D(column)
Expand Down
2 changes: 0 additions & 2 deletions python/astshim/keyMap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,5 @@
# see <https://www.lsstcorp.org/LegalNotices/>.
#/

from __future__ import absolute_import
from .keyMap import *
from .keyMapContinued import *

4 changes: 1 addition & 3 deletions python/astshim/keyMap/keyMapContinued.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from __future__ import absolute_import, division, print_function
__all__ = ["KeyMap"]

from .keyMap import KeyMap

__all__ = [] # import only for side effects


def keys(self):
for i in range(len(self)):
Expand Down
29 changes: 18 additions & 11 deletions python/astshim/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ def checkBasicSimplify(self, amap):
"""Check basic simplfication for a reversible mapping

Check the following:
- A compound mapping of a amap and its inverse simplifies to a unit amap
- A compound mapping of a amap and a unit amap simplifies to the original amap
- A compound mapping of a amap and its inverse simplifies to
a unit amap.
- A compound mapping of a amap and a unit amap simplifies to
the original amap.
"""
amapinv = amap.inverted()
cmp1 = amap.then(amapinv)
Expand Down Expand Up @@ -220,7 +222,8 @@ def checkMemoryForCompoundObject(self, obj1, obj2, cmpObj, isSeries):
obj1: first object in compound object
obj2: second object in compound object
cmpObj: compound object (SeriesMap, ParallelMap, CmpMap or CmpFrame)
isSeries: is compound object in series? None to not test (e.g. CmpFrame)
isSeries: is compound object in series? None to not test
(e.g. CmpFrame)
"""
# if obj1 and obj2 are the same type then copying the compound object
# will increase the NObject of each by 2, otherwise 1
Expand All @@ -240,8 +243,8 @@ def checkMemoryForCompoundObject(self, obj1, obj2, cmpObj, isSeries):
elif isSeries is False:
self.assertFalse(cmpObj.series)

# making a deep copy should increase the object count of the contained objects
# but should not affect the reference count
# Making a deep copy should increase the object count of the contained
# objects but should not affect the reference count.
cp = cmpObj.copy()
self.assertEqual(cmpObj.getRefCount(), initialRefCountCmpObj)
self.assertEqual(cmpObj.getNObject(), initialNumCmpObj + 1)
Expand All @@ -261,7 +264,8 @@ def checkMemoryForCompoundObject(self, obj1, obj2, cmpObj, isSeries):


def makePolyMapCoeffs(nIn, nOut):
"""Make an array of coefficients for astshim.PolyMap for the following equation:
"""Make an array of coefficients for astshim.PolyMap for the following
equation:

fj(x) = C0j x0^2 + C1j x1^2 + C2j x2^2 + ... + CNj xN^2
where:
Expand All @@ -284,15 +288,17 @@ def makeTwoWayPolyMap(nIn, nOut):
"""Make an astshim.PolyMap suitable for testing

The forward transform is as follows:
fj(x) = C0j x0^2 + C1j x1^2 + C2j x2^2 + ... + CNj xN^2 where Cij = 0.001 (i+j+1)
fj(x) = C0j x0^2 + C1j x1^2 + C2j x2^2 + ...
+ CNj xN^2 where Cij = 0.001 (i+j+1)

The reverse transform is the same equation with i and j reversed
thus it is NOT the inverse of the forward direction,
but is something that can be easily evaluated.

The equation is chosen for the following reasons:
- It is well defined for any positive value of nIn, nOut
- It stays small for small x, to avoid wraparound of angles for SpherePoint endpoints
- It is well defined for any positive value of nIn, nOut.
- It stays small for small x, to avoid wraparound of angles for
SpherePoint endpoints.
"""
forwardCoeffs = makePolyMapCoeffs(nIn, nOut)
reverseCoeffs = makePolyMapCoeffs(nOut, nIn)
Expand All @@ -311,8 +317,9 @@ def makeForwardPolyMap(nIn, nOut):
This map does not have a reverse transform.

The equation is chosen for the following reasons:
- It is well defined for any positive value of nIn, nOut
- It stays small for small x, to avoid wraparound of angles for SpherePoint endpoints
- It is well defined for any positive value of nIn, nOut.
- It stays small for small x, to avoid wraparound of angles for
SpherePoint endpoints.
"""
forwardCoeffs = makePolyMapCoeffs(nIn, nOut)
polyMap = PolyMap(forwardCoeffs, nOut, "IterInverse=0")
Expand Down
5 changes: 3 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[flake8]
max-line-length = 110
ignore = E133, E226, E228, N802, N803, N806, N812, N816
max-doc-length = 79
ignore = E133, E226, E228, N802, N803, N806, N812, N813, N815, N816, W503
exclude = __init__.py

[tool:pytest]
addopts = --flake8
flake8-ignore = E133 E226 E228 N802 N803 N806 N812 N816
flake8-ignore = E133 E226 E228 N802 N803 N806 N812 N813 N815 N816 W503
4 changes: 2 additions & 2 deletions tests/test_append.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import, division, print_function
import unittest
from numpy.testing import assert_allclose

Expand Down Expand Up @@ -122,7 +121,8 @@ def test_AppendIndependent(self):
self.assertEqual(set12.applyForward(x), y)

def test_AppendMismatch(self):
"""Check that append behaves as expected when joining non-identical frames.
"""Check that append behaves as expected when joining non-identical
frames.
"""
set1 = self.makeFrameSet(3, 2)
set2 = self.makeFrameSet(2, 3)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import, division, print_function
import unittest

import numpy as np
Expand All @@ -23,7 +22,8 @@ def test_arrayFromVector(self):
dataArr2 = ast.arrayFromVector(vec=list(dataVec), nAxes=nAxes)
assert_equal(dataArr2, desiredDataArr)

# make sure dataArr is a deep copy; changing dataVec should not change dataArr
# make sure dataArr is a deep copy; changing dataVec should
# not change dataArr
dataVec[0] += 10
assert_equal(dataArr, desiredDataArr)

Expand Down
1 change: 0 additions & 1 deletion tests/test_channel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import, division, print_function
import filecmp
import os
import unittest
Expand Down
11 changes: 6 additions & 5 deletions tests/test_chebyMap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import, division, print_function
import unittest

import numpy as np
Expand Down Expand Up @@ -298,8 +297,10 @@ def test_ChebyMapPolyTran(self):
])

# Coefficients for the following gently varying polynomial:
# y1 = -2.0 T0(x1') T0(x2') + 0.11 T1(x1') T0(x2') - 0.2 T0(x1') T1(x2') + 0.001 T2(x1') T1(x2')
# y2 = 5.1 T0(x1') T0(x2') - 0.55 T1(x1') T0(x2') + 0.13 T0(x1') T1(x2') - 0.002 T1(x1') T2(x2')
# y1 = -2.0 T0(x1') T0(x2') + 0.11 T1(x1') T0(x2')
# - 0.2 T0(x1') T1(x2') + 0.001 T2(x1') T1(x2')
# y2 = 5.1 T0(x1') T0(x2') - 0.55 T1(x1') T0(x2')
# + 0.13 T0(x1') T1(x2') - 0.002 T1(x1') T2(x2')
coeff_f = np.array([
[-2.0, 1, 0, 0],
[0.11, 1, 1, 0],
Expand Down Expand Up @@ -353,8 +354,8 @@ def referenceFunc(point):
roundTripIn2 = chebyMap2.applyInverse(outdata)
npt.assert_allclose(roundTripIn2, indata, atol=0.0002)

# fit an inverse transform with default bounds (which are the same bounds
# used for fitting chebyMap2, so the results should be the same)
# fit an inverse transform with default bounds (which are the same
# bounds used for fitting chebyMap2, so the results should be the same)
chebyMap3 = chebyMap1.polyTran(forward=False, acc=0.0001, maxacc=0.001, maxorder=6)
self.assertTrue(chebyMap2.hasForward)
self.assertTrue(chebyMap2.hasInverse)
Expand Down
1 change: 0 additions & 1 deletion tests/test_cmpFrame.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import, division, print_function
import unittest

import astshim as ast
Expand Down
4 changes: 2 additions & 2 deletions tests/test_cmpMap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import, division, print_function
import unittest

import numpy as np
Expand Down Expand Up @@ -111,7 +110,8 @@ def test_ParallelMap(self):
self.checkMappingPersistence(parmap3, indata)

def test_SeriesMapMatrixShiftSimplify(self):
"""Test that a non-square matrix map followed by a shift map can be simplified
"""Test that a non-square matrix map followed by a shift map can be
simplified.

This is ticket DM-10946
"""
Expand Down
36 changes: 20 additions & 16 deletions tests/test_fitsChan.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import, division, print_function
import os.path
import unittest
import numpy as np
Expand Down Expand Up @@ -52,7 +51,8 @@ def setUp(self):
self.cards = [pad(card) for card in shortCards]

def insertPixelMapping(self, mapping, frameSet):
"""Make a new WCS by inserting a new mapping at the beginnning of the GRID-IWC mapping
"""Make a new WCS by inserting a new mapping at the beginnning of the
GRID-IWC mapping

Return the new FrameSet (the original is not altered).
"""
Expand All @@ -74,7 +74,8 @@ def insertPixelMapping(self, mapping, frameSet):
oldGridToIwc = frameSet.getMapping(gridIndex, oldIwcIndex)
iwcToSky = frameSet.getMapping(oldIwcIndex, oldSkyIndex)

# Remove frames in order high to low, so removal doesn't alter the indices remaining to be removed;
# Remove frames in order high to low, so removal doesn't alter the
# indices remaining to be removed;
# update gridIndex during removal so it still points to the GRID frame
framesToRemove = reversed(sorted([oldIwcIndex, oldSkyIndex]))
for index in framesToRemove:
Expand Down Expand Up @@ -153,9 +154,10 @@ def test_FitsChanPreloaded(self):
[card.split(" ", 1)[0] for card in self.cards])

def test_FitsChanFileStream(self):
"""Test a FitsChan with a FileStream
"""Test a FitsChan with a FileStream/

In particular, make sure that cards are written as the channel is destroyed
In particular, make sure that cards are written as the channel is
destroyed.
"""
path = os.path.join(self.dataDir, "test_fitsChanFileStream.fits")
fc1 = ast.FitsChan(ast.FileStream(path, True))
Expand Down Expand Up @@ -337,8 +339,8 @@ def test_FitsChanGetCurrentForNonexistentCard(self):
fc.setFitsI("ANINT", 200)
fc.setFitsS("ASTRING", "string value")
fc.setCard(fc.nCard + 1)
self.assertEqual(fc.getCardType(), ast.NOTYPE)
self.assertEqual(fc.testFits(), ast.ABSENT)
self.assertEqual(fc.getCardType(), ast.CardType.NOTYPE)
self.assertEqual(fc.testFits(), ast.FitsKeyState.ABSENT)
with self.assertRaises(RuntimeError):
fc.getFitsCN()
with self.assertRaises(RuntimeError):
Expand All @@ -355,7 +357,8 @@ def test_FitsChanGetCurrentForNonexistentCard(self):
self.assertEqual(fc.getCardComm(), "")

def test_FitsChanGetFitsMissing(self):
"""Test FitsChan.getFits<X> for missing cards, with and without defaults
"""Test FitsChan.getFits<X> for missing cards, with and without
defaults
"""
fc = ast.FitsChan(ast.StringStream())
fc.setFitsI("ANINT", 200)
Expand Down Expand Up @@ -617,17 +620,17 @@ def test_FitsChanTestFits(self):
fc.setFitsS("ASTRING", "a string")
fc.setFitsU("UNDEFVAL")

self.assertEqual(fc.testFits("AFLOAT"), ast.PRESENT)
self.assertEqual(fc.testFits("ASTRING"), ast.PRESENT)
self.assertEqual(fc.testFits("UNDEFVAL"), ast.NOVALUE)
self.assertEqual(fc.testFits("BADNAME"), ast.ABSENT)
self.assertEqual(fc.testFits("AFLOAT"), ast.FitsKeyState.PRESENT)
self.assertEqual(fc.testFits("ASTRING"), ast.FitsKeyState.PRESENT)
self.assertEqual(fc.testFits("UNDEFVAL"), ast.FitsKeyState.NOVALUE)
self.assertEqual(fc.testFits("BADNAME"), ast.FitsKeyState.ABSENT)

fc.setCard(1)
self.assertEqual(fc.getCardName(), "AFLOAT")
self.assertEqual(fc.testFits(), ast.PRESENT)
self.assertEqual(fc.testFits(), ast.FitsKeyState.PRESENT)
fc.setCard(3)
self.assertEqual(fc.getCardName(), "UNDEFVAL")
self.assertEqual(fc.testFits(), ast.NOVALUE)
self.assertEqual(fc.testFits(), ast.FitsKeyState.NOVALUE)

def test_FitsChanInsertShift(self):
"""Check that a simple WCS can still be written as FITS-WCS
Expand Down Expand Up @@ -657,10 +660,11 @@ def test_FitsChanInsertShift(self):
fv = fc3.getFitsF("CRPIX%d" % (i,))
self.assertAlmostEqual(fv.value, 100 - shift)
for name in fc2.getAllCardNames():
self.assertEqual(fc3.testFits(name), ast.PRESENT)
self.assertEqual(fc3.testFits(name), ast.FitsKeyState.PRESENT)

def test_FitsChanFitsTol(self):
"""Test that increasing FitsTol allows writing a WCS with distortion as FITS-WCS
"""Test that increasing FitsTol allows writing a WCS with distortion
as FITS-WCS.
"""
ss = ast.StringStream("".join(self.cards))
fc = ast.FitsChan(ss, "Encoding=FITS-WCS, IWC=1")
Expand Down
1 change: 0 additions & 1 deletion tests/test_frame.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import, division, print_function
import math
import unittest

Expand Down
1 change: 0 additions & 1 deletion tests/test_frameDict.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import, division, print_function
import unittest

import numpy as np
Expand Down
4 changes: 2 additions & 2 deletions tests/test_frameSet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import, division, print_function
import unittest

import numpy as np
Expand Down Expand Up @@ -135,7 +134,8 @@ def test_FrameSetRemoveFrame(self):
# remove the frame named "base", leaving the frame named "current"
frameSet.removeFrame(1)
self.assertEqual(frameSet.nFrame, 1)
# removing one frame leaves frame, newFrame and a copy of newFrame in FrameSet
# Removing one frame leaves frame, newFrame and a copy of newFrame in
# FrameSet.
self.assertEqual(frame.getNObject(), initialNumFrames + 2)
self.assertEqual(zoomMap.getNObject(), initialNumZoomMap)
frameDeep = frameSet.getFrame(1)
Expand Down
1 change: 0 additions & 1 deletion tests/test_functions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import, division, print_function
import unittest

import astshim as ast
Expand Down
1 change: 0 additions & 1 deletion tests/test_keyMap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import, division, print_function
import unittest

from numpy.testing import assert_allclose
Expand Down
1 change: 0 additions & 1 deletion tests/test_lutMap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import, division, print_function
import sys
import unittest

Expand Down