-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from WFP-VAM/linspace
`hdc-algo` utils & `linspace`
- Loading branch information
Showing
26 changed files
with
104 additions
and
22 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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
"""Seasonal Monitoring Algorithms.""" | ||
|
||
# isort: skip_file | ||
from ._version import __version__ | ||
|
||
|
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,2 +1,3 @@ | ||
"""Version only in this file.""" | ||
__version__ = "0.3.1" | ||
|
||
__version__ = "0.4.0" |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
"""Calculate the longest run of ones inside a 1d array.""" | ||
|
||
import numpy as np | ||
from numba import guvectorize | ||
|
||
|
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,4 +1,5 @@ | ||
"""Numba accelerated statistical funtions.""" | ||
|
||
from math import erf, log, sqrt | ||
|
||
|
||
|
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
"""Whittaker filter V-curve optimization os S.""" | ||
|
||
from math import log, sqrt | ||
|
||
import numpy as np | ||
|
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
numba implementations. | ||
""" | ||
|
||
# pyright: reportGeneralTypeIssues=false | ||
from math import log, sqrt | ||
|
||
|
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
"""Numba accelerated zonal statistics.""" | ||
|
||
from numba import njit | ||
import numpy as np | ||
|
||
|
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,23 @@ | ||
"""hcd-algo utility functions.""" | ||
|
||
from typing import List, Tuple | ||
|
||
import numpy as np | ||
|
||
|
||
def to_linspace(x) -> Tuple[np.ndarray, List[int]]: | ||
"""Map input array to linear space. | ||
Returns array with linear index (0 - n-1) and list of | ||
original keys matching the indices. | ||
""" | ||
keys = np.unique(x) | ||
keys.sort() | ||
values = np.arange(keys.size) | ||
|
||
idx = np.searchsorted(keys, x.ravel()).reshape(x.shape) | ||
idx[idx == keys.size] = 0 | ||
mask = keys[idx] == x.data | ||
new_pix = np.where(mask, values[idx], 0) | ||
|
||
return new_pix, list(keys) |
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 |
---|---|---|
|
@@ -3,7 +3,7 @@ twine | |
pytest | ||
pytest-runner | ||
pytest-cov | ||
black | ||
black>=24.1.0 | ||
pylint==2.17.2 | ||
astroid==2.15.3 | ||
pydocstyle | ||
|
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,29 @@ | ||
"""Test utility functions.""" | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
from hdc.algo.utils import to_linspace | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"input_array, expected_output", | ||
[ | ||
# Test case 1: Array with unique values | ||
( | ||
np.array([[1, 2, 3], [4, 5, 6]]), | ||
(np.array([[0, 1, 2], [3, 4, 5]]), [1, 2, 3, 4, 5, 6]), | ||
), | ||
# Test case 2: Array with repeated values | ||
( | ||
np.array([[1, 2, 2], [3, 4, 4]]), | ||
(np.array([[0, 1, 1], [2, 3, 3]]), [1, 2, 3, 4]), | ||
), | ||
# Test case 3: Empty array | ||
(np.array([]), (np.array([]), [])), | ||
], | ||
) | ||
def test_to_linspace(input_array, expected_output): | ||
x, y = to_linspace(input_array) | ||
np.testing.assert_equal(x, expected_output[0]) | ||
np.testing.assert_equal(y, expected_output[1]) |