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

Added generic 1d nearest neighbor helper function #119

Merged
merged 7 commits into from
Jan 25, 2016
Merged

Added generic 1d nearest neighbor helper function #119

merged 7 commits into from
Jan 25, 2016

Conversation

ahaberlie
Copy link
Contributor

As requested, created generic version of function discussed in:

#99

Subsequent commits were done to fix whitespace/formatting issues after lint failed for initial commit.

Allow resampling based on given data and centers

Added an example to Simple Sounding notebook
Removed whitespace, changed function name, added spaces after commas
@@ -8,6 +8,28 @@
from ..units import concatenate


def resample_nn_1d(a, centers):
"""Helper function that returns one-dimensional nearest-neighbor
indexes based on user-specified centers.
Copy link
Member

Choose a reason for hiding this comment

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

Numpy docstring standard says this needs to start with Parameters: https://raw.githubusercontent.com/numpy/numpy/master/doc/EXAMPLE_DOCSTRING.rst.txt

@dopplershift
Copy link
Member

Thanks for putting this in--I just picked a few minor nits above.

I'm also trying to decide: would this make more sense under something like metpy.calc.tools ? It seems like this function could be more generally useful outside plotting--plus currently metpy.plots.util doesn't have any public API functions.

Regarding the test coverage, can you add a test function as well? It helps to make sure it's working correctly now and, more importantly, doesn't break in the future. It can be really simple like:

import numpy as np
from numpy.testing import assert_array_equal
def test_resample_nn():
    a = np.arange(5.)
    b = np.array([2.1, 3.8])
    truth = np.array([2, 4])
   asset_array_equal(truth, resample_nn_1d(a, b))

(I hope I got that right.) It should go in something like test_tools.py under metpy/calc, assuming that's where we put the function.

Anyhow, I hope I didn't scare you off with the requests. 😄

@ahaberlie
Copy link
Contributor Author

No problem! I understand needing to keep up the integrity of the codebase. I will incorporate your points as soon as I have some time.

@dopplershift
Copy link
Member

FYI, we just moved from nose to pytest for testing, so don't rely on anything in nose.tools when you add a test. It shouldn't really matter to you, but I just wanted to give you a heads up.

@dopplershift
Copy link
Member

Thanks for getting this in shape.

For future reference, it's better not to merge master into your branch, but rather rebase your branch onto master (assuming it's up-to-date) using:

git rebase master <mybranch>

This just keeps the history cleaner.

Thanks for the contribution!

dopplershift added a commit that referenced this pull request Jan 25, 2016
Added generic 1d nearest neighbor helper function
@dopplershift dopplershift merged commit e66c1d2 into Unidata:master Jan 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants