Skip to content
Snippets Groups Projects
Commit 58ca07aa authored by Raphael's avatar Raphael
Browse files

added ignore for apply_func_on_time_window_function

parent 1ba9dceb
No related branches found
No related tags found
2 merge requests!12version 0.2a,!10Resolve "Image creation bugs with 0 size windows"
......@@ -39,6 +39,13 @@ def apply_func_on_window(dat, func, radius, on_edge='copy'):
data = dat[i - radius:i + radius + 1]
result[i - radius] = func(data)
return result
elif on_edge == 'ignore':
for i in range(0, dat.shape[0]):
lower_bound = max(0, i-radius)
upper_bound = min(dat.shape[0], i + radius + 1)
data = dat[lower_bound:upper_bound]
result[i] = func(data)
return result
else:
raise ValueError
......@@ -96,9 +103,9 @@ class AISTrajectory(AISPoints):
return result
def apply_func_on_time_window(self, func, radius, column, new_column=None):
def apply_func_on_time_window(self, func, radius, column, new_column=None, on_edge='copy'):
dat = self.df[column].to_numpy()
result = apply_func_on_window(dat, func, radius, on_edge='copy')
result = apply_func_on_window(dat, func, radius, on_edge)
if new_column is None:
self.df[column] = result
......
......@@ -320,3 +320,17 @@ class TestAISTrajectory(unittest.TestCase):
def test_apply_func_on_window(self):
self.assertRaises(ValueError, apply_func_on_window,np.arange(10), 0, 0, 'not valid string')
def test_apply_func_on_window_ignore(self):
result = apply_func_on_window(np.arange(10), np.mean, 2, 'ignore')
expected = np.array([1, 1.5, 2, 3, 4, 5, 6, 7, 7.5, 8])
np.testing.assert_equal(result, expected)
def test_apply_func_on_window_ignore_short(self):
result = apply_func_on_window(np.arange(5), np.mean, 10, 'ignore')
expected = np.array([2, 2, 2, 2, 2])
np.testing.assert_equal(result, expected)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment