-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor
utils.interpolate
module (#210)
* Rename to iwdinterp2d; adapt docstrings, variable names, and interface * Fix interface * Initial wrapper to scipy's method * Aesthetics * Use mode=N-D to do multivariate interpolation * Fix black check By upgrading black to latest version * Support parameters of the original function * Refactor idw method * Aesthetics * Implement checks as a decorator * Add tests * Aesthetics * Remove unnecessary test * Remove unnecessary test * Test for wrong number of dimensions * Chunking of the dst grid is done in the preamble * Fix chunking * Simplify idw * Add LRU caching of interpolator classes * Small adjustments * Change default interp method to idw * Adapt test * Adapt examples * Silence some warnings And other super minor changes * Fix black check * Fix tests * Aesthetics * Fix docstrings Or at least try... * Fix univariate interpolation And include test * Fix black check * Super minor changes * Update precommit config * Define RBF in docstring * Add function to append extra kwrds to docstrings * Rename decorator * Test idw with k=1 or k=None * Test that all outputs are finite nuumberrs * Update pysteps/utils/interpolate.py Co-authored-by: Loris Foresti <39999237+loforest@users.noreply.github.com> * Improve variable naming * Workaround for TypeError issue with Pillow 8.3 * Add abbreviation for inverse distance weighting * Fix typo * Docstring polishing in idwinterp2d * Small refactoring * Docstring polishing * Improve docstrings * Adapt variable naming * Inputs must be ndarrays * Fix typo * Make the offset contant a user-selectable parameter Co-authored-by: Andres Perez Hortal <16256571+aperezhortal@users.noreply.github.com> Co-authored-by: Loris Foresti <39999237+loforest@users.noreply.github.com> Co-authored-by: Seppo Pulkkinen <pulkkins@gmail.com>
- Loading branch information
1 parent
76324d8
commit 69061dd
Showing
15 changed files
with
484 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
repos: | ||
- repo: https://github.com/psf/black | ||
rev: 20.8b1 | ||
rev: 21.6b0 | ||
hooks: | ||
- id: black | ||
language_version: python3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# -*- coding: utf-8 -*- | ||
import time | ||
|
||
from pysteps.decorators import memoize | ||
|
||
|
||
def test_memoize(): | ||
@memoize(maxsize=1) | ||
def _slow_function(x, **kwargs): | ||
time.sleep(1) | ||
return x | ||
|
||
for i in range(2): | ||
out = _slow_function(i, hkey=i) | ||
assert out == i | ||
|
||
# cached result | ||
t0 = time.monotonic() | ||
out = _slow_function(1, hkey=1) | ||
assert time.monotonic() - t0 < 1 | ||
assert out == 1 | ||
|
||
# maxsize exceeded | ||
t0 = time.monotonic() | ||
out = _slow_function(0, hkey=0) | ||
assert time.monotonic() - t0 >= 1 | ||
assert out == 0 | ||
|
||
# no hash | ||
t0 = time.monotonic() | ||
out = _slow_function(1) | ||
assert time.monotonic() - t0 >= 1 | ||
assert out == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.