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

Fix Centers function #78

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ Contributors:
* Giacomo Fiorin <giacomofiorin>
* Eloy Félix <eloyfelix>
* René Hafner (Hamburger) <renehamburger1993>
* Anthony Cruz-Balberdy <acruzpr>
4 changes: 3 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ The rules for this file:
* accompany each entry with github issue/PR number (Issue #xyz)

------------------------------------------------------------------------------
??/??/2019 eloyfelix, renehamburger1993
??/??/2020 eloyfelix, renehamburger1993, acruzpr

* 0.6.0

Enhancements

* Allow parsing/writing gzipped DX files
* Allow the generation of coordinates for the cell centers using the origin as defined by APBS DX file format
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's how you add entries.

There's a space missing

Suggested change
* Allow the generation of coordinates for the cell centers using the origin as defined by APBS DX file format
or as defined by the Original DX file format (#78)

and we first have to make sure that we understand what APBS thinks, see #77

or as defined by the Original DX file format (#78)


Fixes
Expand Down
22 changes: 18 additions & 4 deletions gridData/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def __init__(self, grid=None, edges=None, origin=None, delta=None,


.. versionchanged:: 0.5.0
New *file_format* keyword argument.
New *file_format* keyword argument

"""
# file formats are guess from extension == lower case key
Expand Down Expand Up @@ -573,11 +573,25 @@ def save(self, filename):
"""
self.export(filename, file_format="pickle")

def centers(self):
def centers(self, origin_centered=False):
"""Returns the coordinates of the centers of all grid cells as an
iterator."""
iterator.

Parameters
----------
origin_centered : bool
When is set to True the origin will be set to the lower-left corner of the grid following
the APBS DX format specifications.

When is set to False the origin will be set to the center of the first grid cell following
the official DX format specifications.

.. versionchanged:: 0.6.0
New *origin_centered* keyword argument
Comment on lines +589 to +590
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

de-dent, so that it sits under everything

Suggested change
.. versionchanged:: 0.6.0
New *origin_centered* keyword argument
.. versionchanged:: 0.6.0
New *origin_centered* keyword argument

"""
for idx in numpy.ndindex(self.grid.shape):
yield self.delta * numpy.array(idx) + self.origin
offset = 0.5 * self.delta if not origin_centered else 0
yield self.delta * numpy.array(idx) + self.origin + offset

def check_compatible(self, other):
"""Check if *other* can be used in an arithmetic operation.
Expand Down
15 changes: 13 additions & 2 deletions gridData/tests/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,23 @@ def test_non_orthonormal_boxes(self, data):
with pytest.raises(NotImplementedError):
Grid(data['griddata'], origin=data['origin'], delta=delta)

def test_centers(self, data):
def test_centers_false(self, data):
# this only checks the edges. If you know an alternative
# algorithm that isn't an exact duplicate of the one in
# g.centers to test this please implement it.
g = Grid(data['griddata'], origin=np.ones(3), delta=data['delta'])
centers = np.array(list(g.centers()))
centers = np.array(list(g.centers(False)))
offset = g.delta * 0.5
assert_array_equal(centers[0], g.origin + offset)
assert_array_equal(centers[-1] - g.origin - offset,
(np.array(g.grid.shape) - 1) * data['delta'])

def test_centers_true(self, data):
# this only checks the edges. If you know an alternative
# algorithm that isn't an exact duplicate of the one in
# g.centers to test this please implement it.
g = Grid(data['griddata'], origin=np.ones(3), delta=data['delta'])
centers = np.array(list(g.centers(True)))
assert_array_equal(centers[0], g.origin)
assert_array_equal(centers[-1] - g.origin,
(np.array(g.grid.shape) - 1) * data['delta'])
Expand Down