Skip to content

Commit

Permalink
import astshim -> import astshim as ast
Browse files Browse the repository at this point in the history
Use `import astshim as ast` in Python as best practice,
so the Python looks more like the C++, which uses namespace `ast`.
  • Loading branch information
r-owen committed Sep 13, 2017
1 parent 7dcc60c commit fed4e85
Show file tree
Hide file tree
Showing 37 changed files with 346 additions and 346 deletions.
4 changes: 2 additions & 2 deletions python/astshim/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def makePolyMapCoeffs(nIn, nOut):


def makeTwoWayPolyMap(nIn, nOut):
"""Make an astShim.PolyMap suitable for testing
"""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)
Expand All @@ -184,7 +184,7 @@ def makeTwoWayPolyMap(nIn, nOut):


def makeForwardPolyMap(nIn, nOut):
"""Make an astShim.PolyMap suitable for testing
"""Make an astshim.PolyMap suitable for testing
The forward transform is the same as for `makeTwoWayPolyMap`.
This map does not have a reverse transform.
Expand Down
26 changes: 13 additions & 13 deletions tests/test_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import unittest

import astshim
import astshim as ast
from astshim.test import MappingTestCase

DataDir = os.path.join(os.path.dirname(__file__))
Expand All @@ -15,34 +15,34 @@ def test_ChannelFileStream(self):
path1 = os.path.join(DataDir, "channelFileStream1.txt")
path2 = os.path.join(DataDir, "channelFileStream2.txt")

outstream = astshim.FileStream(path1, True)
outchan = astshim.Channel(outstream)
self.assertIsInstance(outchan, astshim.Object)
self.assertIsInstance(outchan, astshim.Channel)
outstream = ast.FileStream(path1, True)
outchan = ast.Channel(outstream)
self.assertIsInstance(outchan, ast.Object)
self.assertIsInstance(outchan, ast.Channel)

zoommap = astshim.ZoomMap(2, 0.1, "ID=Hello there")
zoommap = ast.ZoomMap(2, 0.1, "ID=Hello there")
nobj = outchan.write(zoommap)
self.assertEqual(nobj, 1)

with self.assertRaises(RuntimeError):
obj = outchan.read()

instream = astshim.FileStream(path1, False)
inchan = astshim.Channel(instream)
instream = ast.FileStream(path1, False)
inchan = ast.Channel(instream)
obj = inchan.read()
self.assertEqual(obj.show(), zoommap.show())

outstream2 = astshim.FileStream(path2, True)
outchan2 = astshim.Channel(outstream2)
outstream2 = ast.FileStream(path2, True)
outchan2 = ast.Channel(outstream2)
outchan2.write(obj)
self.assertTrue(filecmp.cmp(path1, path2, shallow=False))
os.remove(path1)
os.remove(path2)

def test_ChannelStringStream(self):
ss = astshim.StringStream()
channel = astshim.Channel(ss)
zoommap = astshim.ZoomMap(2, 0.1, "ID=Hello there")
ss = ast.StringStream()
channel = ast.Channel(ss)
zoommap = ast.ZoomMap(2, 0.1, "ID=Hello there")
n = channel.write(zoommap)
self.assertEqual(n, 1)
sinkData1 = ss.getSinkData()
Expand Down
40 changes: 20 additions & 20 deletions tests/test_chebyMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from numpy.polynomial.chebyshev import chebval, chebval2d
import numpy.testing as npt

import astshim
import astshim as ast
from astshim.test import MappingTestCase


Expand All @@ -20,7 +20,7 @@ def normalize(inArray, lbnd, ubnd):
----------
inArray : `numpy.array` of float
Value(s) to normalize; a list of nAxes x nPoints values
(the form used by astshim.Mapping.applyForward)
(the form used by ast.Mapping.applyForward)
lbnd : sequence of `float`
Lower bounds (one element per axis)
ubnd : sequence of `float`
Expand Down Expand Up @@ -138,10 +138,10 @@ def referenceFunc(point):
refCheby = ReferenceCheby(referenceFunc, lbnd_f, ubnd_f)

# forward-only constructor
chebyMap1 = astshim.ChebyMap(coeff_f, nout, lbnd_f, ubnd_f)
self.assertIsInstance(chebyMap1, astshim.Object)
self.assertIsInstance(chebyMap1, astshim.Mapping)
self.assertIsInstance(chebyMap1, astshim.ChebyMap)
chebyMap1 = ast.ChebyMap(coeff_f, nout, lbnd_f, ubnd_f)
self.assertIsInstance(chebyMap1, ast.Object)
self.assertIsInstance(chebyMap1, ast.Mapping)
self.assertIsInstance(chebyMap1, ast.ChebyMap)
self.assertEqual(chebyMap1.nIn, nin)
self.assertEqual(chebyMap1.nOut, nout)
self.assertTrue(chebyMap1.hasForward)
Expand All @@ -162,10 +162,10 @@ def referenceFunc(point):
npt.assert_allclose(outdata, pred_outdata)

# bidirectional constructor, forward only specified
chebyMap2 = astshim.ChebyMap(coeff_f, null_coeff, lbnd_f, ubnd_f, [], [])
self.assertIsInstance(chebyMap2, astshim.Object)
self.assertIsInstance(chebyMap2, astshim.Mapping)
self.assertIsInstance(chebyMap2, astshim.ChebyMap)
chebyMap2 = ast.ChebyMap(coeff_f, null_coeff, lbnd_f, ubnd_f, [], [])
self.assertIsInstance(chebyMap2, ast.Object)
self.assertIsInstance(chebyMap2, ast.Mapping)
self.assertIsInstance(chebyMap2, ast.ChebyMap)
self.assertEqual(chebyMap2.nIn, nin)
self.assertEqual(chebyMap2.nOut, nout)
self.assertTrue(chebyMap2.hasForward)
Expand All @@ -184,10 +184,10 @@ def referenceFunc(point):
chebyMap2.applyInverse(indata)

# bidirectional constructor, inverse only specified
chebyMap3 = astshim.ChebyMap(null_coeff, coeff_f, [], [], lbnd_f, ubnd_f)
self.assertIsInstance(chebyMap3, astshim.Object)
self.assertIsInstance(chebyMap3, astshim.Mapping)
self.assertIsInstance(chebyMap3, astshim.ChebyMap)
chebyMap3 = ast.ChebyMap(null_coeff, coeff_f, [], [], lbnd_f, ubnd_f)
self.assertIsInstance(chebyMap3, ast.Object)
self.assertIsInstance(chebyMap3, ast.Mapping)
self.assertIsInstance(chebyMap3, ast.ChebyMap)
self.assertEqual(chebyMap3.nIn, nin)
self.assertEqual(chebyMap3.nOut, nout)
self.assertFalse(chebyMap3.hasForward)
Expand Down Expand Up @@ -267,7 +267,7 @@ def referenceFunc_i(point):
refCheby_f = ReferenceCheby(referenceFunc_f, lbnd_f, ubnd_f)
refCheby_i = ReferenceCheby(referenceFunc_i, lbnd_i, ubnd_i)

chebyMap = astshim.ChebyMap(coeff_f, coeff_i, lbnd_f, ubnd_f, lbnd_i, ubnd_i)
chebyMap = ast.ChebyMap(coeff_f, coeff_i, lbnd_f, ubnd_f, lbnd_i, ubnd_i)
self.assertEqual(chebyMap.nIn, 2)
self.assertEqual(chebyMap.nOut, 1)

Expand Down Expand Up @@ -331,7 +331,7 @@ def referenceFunc(point):
chebval2d(x1, x2, c2),
)

chebyMap1 = astshim.ChebyMap(coeff_f, nout, lbnd_f, ubnd_f)
chebyMap1 = ast.ChebyMap(coeff_f, nout, lbnd_f, ubnd_f)
self.checkBasicSimplify(chebyMap1)
self.assertTrue(chebyMap1.hasForward)
self.assertFalse(chebyMap1.hasInverse)
Expand Down Expand Up @@ -404,7 +404,7 @@ def referenceFunc(point):
chebval2d(x1, x2, c2),
)

chebyMap1 = astshim.ChebyMap(coeff_f, nout, lbnd_f, ubnd_f)
chebyMap1 = ast.ChebyMap(coeff_f, nout, lbnd_f, ubnd_f)
self.checkBasicSimplify(chebyMap1)
self.assertTrue(chebyMap1.hasForward)
self.assertFalse(chebyMap1.hasInverse)
Expand Down Expand Up @@ -439,7 +439,7 @@ def test_chebyGetDomain(self):
[-2.0, 2, 0, 3],
])

chebyMap1 = astshim.ChebyMap(coeff_f, nout, lbnd_f, ubnd_f)
chebyMap1 = ast.ChebyMap(coeff_f, nout, lbnd_f, ubnd_f)

# compute indata as a grid of points that cover the input range
x1Edge = np.linspace(lbnd_f[0], ubnd_f[0], 1000)
Expand Down Expand Up @@ -499,11 +499,11 @@ def test_ChebyMapDM10496(self):

# execute many times to increase the odds of a segfault
for i in range(1000):
amap = astshim.ChebyMap(coeff_f, coeff_i, lbnd_f, ubnd_f, lbnd_i, ubnd_i)
amap = ast.ChebyMap(coeff_f, coeff_i, lbnd_f, ubnd_f, lbnd_i, ubnd_i)
amapinv = amap.getInverse()
cmp2 = amapinv.then(amap)
result = cmp2.simplify()
self.assertIsInstance(result, astshim.UnitMap)
self.assertIsInstance(result, ast.UnitMap)


if __name__ == "__main__":
Expand Down
8 changes: 4 additions & 4 deletions tests/test_cmpFrame.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from __future__ import absolute_import, division, print_function
import unittest

import astshim
import astshim as ast
from astshim.test import MappingTestCase


class TestCmpFrame(MappingTestCase):

def test_CmpFrame(self):
frame1 = astshim.Frame(2, "label(1)=a, label(2)=b")
frame2 = astshim.Frame(1, "label(1)=c")
cmpframe = astshim.CmpFrame(frame1, frame2)
frame1 = ast.Frame(2, "label(1)=a, label(2)=b")
frame2 = ast.Frame(1, "label(1)=c")
cmpframe = ast.CmpFrame(frame1, frame2)
# adding to a CmpFrame increases by 1
self.assertEqual(frame1.getRefCount(), 2)
# adding to a CmpFrame increases by 1
Expand Down
18 changes: 9 additions & 9 deletions tests/test_cmpMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
from numpy.testing import assert_allclose

import astshim
import astshim as ast
from astshim.test import MappingTestCase


Expand All @@ -17,11 +17,11 @@ def setUp(self):
self.nin = 2
self.zoom = 1.3
self.shift = [-0.5, 1.2]
self.zoommap = astshim.ZoomMap(self.nin, self.zoom)
self.shiftmap = astshim.ShiftMap(self.shift)
self.zoommap = ast.ZoomMap(self.nin, self.zoom)
self.shiftmap = ast.ShiftMap(self.shift)

def test_SeriesMap(self):
sermap = astshim.SeriesMap(self.shiftmap, self.zoommap)
sermap = ast.SeriesMap(self.shiftmap, self.zoommap)
# adding to a SeriesMap increases by 1
self.assertEqual(self.shiftmap.getRefCount(), 2)
# adding to a SeriesMap increases by 1
Expand All @@ -36,7 +36,7 @@ def test_SeriesMap(self):

sermap2 = self.shiftmap.then(self.zoommap)

sermap3 = astshim.CmpMap(self.shiftmap, self.zoommap, True)
sermap3 = ast.CmpMap(self.shiftmap, self.zoommap, True)

indata = np.array([
[1.0, 2.0, -6.0, 30.0, 0.2],
Expand All @@ -57,7 +57,7 @@ def test_SeriesMap(self):
self.checkRoundTrip(sermap3, indata)

def test_ParallelMap(self):
parmap = astshim.ParallelMap(self.shiftmap, self.zoommap)
parmap = ast.ParallelMap(self.shiftmap, self.zoommap)
# adding to a ParallelMap increases by 1
self.assertEqual(self.shiftmap.getRefCount(), 2)
# adding to a ParallelMap increases by 1
Expand Down Expand Up @@ -87,7 +87,7 @@ def test_ParallelMap(self):
topos2 = parmap2.applyForward(indata)
assert_allclose(topos2, pred_outdata)

parmap3 = astshim.CmpMap(self.shiftmap, self.zoommap, False)
parmap3 = ast.CmpMap(self.shiftmap, self.zoommap, False)
topos3 = parmap3.applyForward(indata)
assert_allclose(topos3, pred_outdata)

Expand All @@ -103,10 +103,10 @@ def test_SeriesMapMatrixShiftSimplify(self):
m1 = 1.0
m2 = 2.0
shift = 3.0
matrixMap = astshim.MatrixMap(np.array([[m1, m2]]))
matrixMap = ast.MatrixMap(np.array([[m1, m2]]))
self.assertEqual(matrixMap.nIn, 2)
self.assertEqual(matrixMap.nOut, 1)
shiftMap = astshim.ShiftMap([shift])
shiftMap = ast.ShiftMap([shift])
seriesMap = matrixMap.then(shiftMap)

indata = np.array([
Expand Down

0 comments on commit fed4e85

Please sign in to comment.