-
Notifications
You must be signed in to change notification settings - Fork 7
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
Compute gradients with respect to grid spacing #116
Conversation
Signed-off-by: Christopher T. Lee <[email protected]>
Hello @ctlee! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2024-08-20 10:36:04 UTC |
@ctlee Apologies for the very late response here - unfortunately membrane curvature doesn't have an active maintainer currently so there haven't been anyone to shephred pull requests. We will try to get someone to review your code as soon as possible. Pinging @MDAnalysis/coredevs here in case someone might want to take on an initial review to help this process along. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initial review, :)
You may need to investigate some changes to docs, but otherwise great start,
) | ||
mean = mean_curvature(height_field, dx, dy) | ||
gauss = gaussian_curvature(height_field, dx, dy) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can also check that has 0 gaussian curvature at origin?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 0 gaussian curvature at origin condition is implicitly checked by conditions where nx and ny are odd. If the discretization doesn't include (0, 0) then we'd have to interpolate or skip the test. I think comparison against the analytical formula at corresponding grid points should be robust and complete enough.
@@ -401,23 +481,23 @@ def test_analysis_get_z_surface_wrap_xy(self, universe_dummy_wrap_xy, dummy_surf | |||
# test mean curvature | |||
def test_analysis_mean_wrap(self, curvature_unwrapped_universe, dummy_surface): | |||
avg_mean = curvature_unwrapped_universe.results.average_mean | |||
expected_mean = mean_curvature(dummy_surface) | |||
expected_mean = mean_curvature(dummy_surface, curvature_unwrapped_universe.dy, curvature_unwrapped_universe.dx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parametrize over these arguments, to check that the original implementation still functions as intended.
@pytest.mark.parametrize("varargs", [, [], [dy, dx]])
``
Or if the parametrization is too complicated split into two tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what to do here. The original implementation is fundamentally flawed.
The test fixture universe_dummy_wrap
has a specific grid spacing and system dimension. Taking derivatives with respect to the default dx
, dy
value (=1) is like saying:
When the derivatives must be taken with respect to the spacing,
To have dx
, dy
as parameters, the fixture would have to be changed to produce meshes with varied discretization.
assert_almost_equal(avg_mean, expected_mean) | ||
|
||
def test_analysis_mean_wrap_xy(self, curvature_unwrapped_universe, dummy_surface): | ||
avg_mean = curvature_unwrapped_universe.results.average_mean | ||
expected_mean = mean_curvature(dummy_surface) | ||
expected_mean = mean_curvature(dummy_surface, curvature_unwrapped_universe.dy, curvature_unwrapped_universe.dx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as before
assert_almost_equal(avg_mean, expected_mean) | ||
|
||
# test gaussian | ||
def test_analysis_gaussian_wrap(self, curvature_unwrapped_universe, dummy_surface): | ||
avg_gaussian = curvature_unwrapped_universe.results.average_gaussian | ||
expected_gaussian = gaussian_curvature(dummy_surface) | ||
expected_gaussian = gaussian_curvature(dummy_surface, curvature_unwrapped_universe.dy, curvature_unwrapped_universe.dx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as before
Updating against |
Signed-off-by: Christopher T. Lee <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -401,23 +481,23 @@ def test_analysis_get_z_surface_wrap_xy(self, universe_dummy_wrap_xy, dummy_surf | |||
# test mean curvature | |||
def test_analysis_mean_wrap(self, curvature_unwrapped_universe, dummy_surface): | |||
avg_mean = curvature_unwrapped_universe.results.average_mean | |||
expected_mean = mean_curvature(dummy_surface) | |||
expected_mean = mean_curvature(dummy_surface, curvature_unwrapped_universe.dy, curvature_unwrapped_universe.dx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what to do here. The original implementation is fundamentally flawed.
The test fixture universe_dummy_wrap
has a specific grid spacing and system dimension. Taking derivatives with respect to the default dx
, dy
value (=1) is like saying:
When the derivatives must be taken with respect to the spacing,
To have dx
, dy
as parameters, the fixture would have to be changed to produce meshes with varied discretization.
assert_almost_equal(avg_mean, expected_mean) | ||
|
||
def test_analysis_mean_wrap_xy(self, curvature_unwrapped_universe, dummy_surface): | ||
avg_mean = curvature_unwrapped_universe.results.average_mean | ||
expected_mean = mean_curvature(dummy_surface) | ||
expected_mean = mean_curvature(dummy_surface, curvature_unwrapped_universe.dy, curvature_unwrapped_universe.dx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as before
assert_almost_equal(avg_mean, expected_mean) | ||
|
||
# test gaussian | ||
def test_analysis_gaussian_wrap(self, curvature_unwrapped_universe, dummy_surface): | ||
avg_gaussian = curvature_unwrapped_universe.results.average_gaussian | ||
expected_gaussian = gaussian_curvature(dummy_surface) | ||
expected_gaussian = gaussian_curvature(dummy_surface, curvature_unwrapped_universe.dy, curvature_unwrapped_universe.dx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as before
Sounds reasonble @ctlee, I am happy to give my approval on a purely code basis, but from a scientific basis I will have to take your assertions about the correctness of the new implementation relative to the old one on trust. I will tag @ojeda-e as the principal developer as she may have a view here. I will leave my view blocking for now pending waiting for feedback. :) |
Following up on this as new versions appear to be released! Folks will get incorrect curvature values if their grid spacing isn't 1. Can verify this issue in the current implementation by comparing with the parametric surface tests added in this PR. An alternative approach is to add a check that the dx, dy is 1 and to throw an error otherwise. @ojeda-e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ctlee
Thanks for working on this changes! I left two question below to clarify my understanding.
Would it be possible to offer an example where*varargs
is illustrated? It would be a nice addition to the docs.
Signed-off-by: Christopher T. Lee <[email protected]>
@ojeda-e are we happy with this PR as is? I would be happy to go ahead, but thought would check with you? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description
The calculation of the gradients of the height field should respect the grid spacing. This PR adds support for variable grid spacing. It also adds some tests against parametric surfaces.
fixes #115
Todos
Notable points that this PR has either accomplished or will accomplish.
np.gradient
respect grid spacingQuestions
N/A
Status