Skip to content

Commit

Permalink
Edit PEP8 for to_spec and from_spec calls, tests, fix test variable d…
Browse files Browse the repository at this point in the history
…efinitons
  • Loading branch information
ricaenriquez committed Nov 13, 2018
1 parent bbf0c62 commit 0ea685f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
10 changes: 6 additions & 4 deletions pygridgen/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,11 @@ def to_spec(self):

def from_spec(foci):
f = Focus()
for focuspoint in foci:
for focuspoint in foci:
f.add_focus(**focuspoint)
return f


class CGrid(object):
"""
Curvilinear Arakawa C-Grid.
Expand Down Expand Up @@ -984,9 +985,9 @@ def generate_grid(self):
super(Gridgen, self).__init__(x, y)

def to_spec(self):
output_dict = {'xbry':self.xbry, 'ybry':self.ybry,
'beta':self.beta, 'shape':self.shape,
'focus':self.focus}
output_dict = {'xbry': self.xbry, 'ybry': self.ybry,
'beta': self.beta, 'shape': self.shape,
'focus': self.focus}

return output_dict

Expand All @@ -995,6 +996,7 @@ def from_spec(attributes):
g = Gridgen(**attributes)
return g


def rho_to_vert(xr, yr, pm, pn, ang): # pragma: no cover
""" Possibly converts centroids to nodes """
Mp, Lp = xr.shape
Expand Down
10 changes: 5 additions & 5 deletions pygridgen/tests/test_focus.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,18 @@ def test_focus_to_from_spec():
fpy = pygridgen.grid._FocusPoint(0.33, 'y', 0.1, 0.2)
f1 = pygridgen.grid.Focus(fpx, fpy)

## Check that the spec dictionary returns desired results
# Check that the spec dictionary returns desired results
assert f1.to_spec() == [
{'pos': 0.25, 'axis': 'x', 'factor': 4, 'extent': 0.5},
{'pos': 0.33, 'axis': 'y', 'factor': 0.1, 'extent': 0.2}
]

f2 = pygridgen.grid.Focus.from_spec(f1.to_spec())

## Check that the spec dictionary returns desired results of the orignal
## focus and the focus generated from .to_spec()
## First check the keys are in order and then check the values
# Check that the spec dictionary returns desired results of the orignal
# focus and the focus generated from .to_spec()
# First check the keys are in order and then check the values
for dict1, dict2 in zip(f1.to_spec(), f2.to_spec()):
numpy.testing.assert_equal(dict1.keys(), dict2.keys())
for value1, value2 in zip(dict1.values(), dict2.values()):
assert value1==value2
assert value1 == value2
8 changes: 6 additions & 2 deletions pygridgen/tests/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,13 +591,17 @@ def test_mask_poylgon(grid_and_knowns):
nptest.assert_array_almost_equal(grid.mask_rho, known_mask_rho)

def test_gridgen_to_from_spec():
x = numpy.array([0.50, 2.00, 2.00, 3.50, 3.50, 2.00, 2.00, 0.50, 0.50])
y = numpy.array([0.50, 0.50, 1.75, 1.75, 2.25, 2.25, 3.50, 3.50, 0.50])
beta = numpy.array([1, 1, -1, 1, 1, -1, 1, 1, 0])

focus = pygridgen.Focus()
focus.add_focus(0.50, 'y', factor=5, extent=0.25)
focus.add_focus(0.50, 'x', factor=5, extent=0.25)

grid1 = pygridgen.Gridgen(x, y, beta, shape=(20, 10), focus=focus)
grid2 = pygridgen.grid.Gridgen.from_spec((grid1.to_spec()))

# testing - using almost equal due to rounding issues with floats
numpy.testing.assert_array_almost_equal(grid1.x, grid2.x)
numpy.testing.assert_array_almost_equal(grid1.y, grid2.y)
numpy.testing.assert_array_almost_equal(grid1.y, grid2.y)

0 comments on commit 0ea685f

Please sign in to comment.