timelined_array 0.0.9__tar.gz → 0.0.11__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {timelined_array-0.0.9 → timelined_array-0.0.11}/PKG-INFO +1 -1
- {timelined_array-0.0.9 → timelined_array-0.0.11}/pyproject.toml +1 -1
- timelined_array-0.0.11/src/timelined_array/__init__.py +3 -0
- {timelined_array-0.0.9 → timelined_array-0.0.11}/src/timelined_array/time.py +2 -2
- timelined_array-0.0.11/tests/__init__.py +111 -0
- timelined_array-0.0.9/src/timelined_array/__init__.py +0 -3
- timelined_array-0.0.9/tests/__init__.py +0 -0
- {timelined_array-0.0.9 → timelined_array-0.0.11}/LICENSE +0 -0
- {timelined_array-0.0.9 → timelined_array-0.0.11}/README.md +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: timelined_array
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.11
|
|
4
4
|
Summary: Manage easily 1 or multidimensionnal samples numpy arrays that are time related. Extends numpy without removing any of it's abilities on such arrays.
|
|
5
5
|
Author-Email: Timothe Jost <timothe.jost@wanadoo.fr>
|
|
6
6
|
License: MIT
|
|
@@ -182,8 +182,8 @@ class TimeIndexer:
|
|
|
182
182
|
self.set_edge_policy(start, stop)
|
|
183
183
|
|
|
184
184
|
def set_edge_policy(self, start="inclusive", stop="exclusive"):
|
|
185
|
-
self._start_operation = EdgePolicy["start"].value[start]
|
|
186
|
-
self._stop_operation = EdgePolicy["stop"].value[stop]
|
|
185
|
+
self._start_operation = EdgePolicy["start"].value[start].value
|
|
186
|
+
self._stop_operation = EdgePolicy["stop"].value[stop].value
|
|
187
187
|
return self
|
|
188
188
|
|
|
189
189
|
def time_to_index(
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
import numpy as np
|
|
3
|
+
from numpy.testing import assert_array_equal
|
|
4
|
+
from timelined_array.time import TimeIndexer, Timeline, TimelinedArray, MaskedTimelinedArray
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class TestTimeline(unittest.TestCase):
|
|
8
|
+
def test_timeline_creation(self):
|
|
9
|
+
timeline = Timeline([0, 1, 2, 3, 4])
|
|
10
|
+
self.assertEqual(timeline.max(), 4)
|
|
11
|
+
self.assertEqual(timeline.min(), 0)
|
|
12
|
+
|
|
13
|
+
def test_timeline_uniformize(self):
|
|
14
|
+
with self.assertRaises(NotImplementedError):
|
|
15
|
+
Timeline._uniformize([0, 1, 2, 3, 4])
|
|
16
|
+
|
|
17
|
+
def test_timeline_step(self):
|
|
18
|
+
timeline = Timeline([0, 1, 2, 3, 4])
|
|
19
|
+
self.assertEqual(timeline.step, 1)
|
|
20
|
+
|
|
21
|
+
def test_timeline_max_step(self):
|
|
22
|
+
timeline = Timeline([0, 1, 2, 3, 4])
|
|
23
|
+
self.assertEqual(timeline.max_step, 2)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class TestTimeIndexer(unittest.TestCase):
|
|
27
|
+
def setUp(self):
|
|
28
|
+
self.timeline = Timeline([0, 1, 2, 3, 4])
|
|
29
|
+
self.array = TimelinedArray(np.random.rand(5, 5), timeline=self.timeline, time_dimension=0)
|
|
30
|
+
self.indexer = TimeIndexer(self.array)
|
|
31
|
+
|
|
32
|
+
def test_time_to_index(self):
|
|
33
|
+
self.assertEqual(self.indexer.time_to_index(2), 2)
|
|
34
|
+
|
|
35
|
+
def test_get_iindex(self):
|
|
36
|
+
self.assertEqual(self.indexer.get_iindex(1, 3), slice(1, 3, 1))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class TestTimelinedArray(unittest.TestCase):
|
|
40
|
+
def setUp(self):
|
|
41
|
+
self.timeline = Timeline([0, 1, 2, 3, 4])
|
|
42
|
+
self.array = TimelinedArray(np.random.rand(5, 5), timeline=self.timeline, time_dimension=0)
|
|
43
|
+
|
|
44
|
+
def test_array_creation(self):
|
|
45
|
+
self.assertEqual(self.array.shape, (5, 5))
|
|
46
|
+
self.assertEqual(self.array.timeline.max(), 4)
|
|
47
|
+
self.assertEqual(self.array.time_dimension, 0)
|
|
48
|
+
|
|
49
|
+
def test_array_indexing(self):
|
|
50
|
+
indexed_array = self.array[1:3]
|
|
51
|
+
self.assertEqual(indexed_array.shape, (2, 5))
|
|
52
|
+
self.assertEqual(indexed_array.timeline.min(), 1)
|
|
53
|
+
self.assertEqual(indexed_array.timeline.max(), 2)
|
|
54
|
+
|
|
55
|
+
def test_array_transpose(self):
|
|
56
|
+
transposed_array = self.array.transpose()
|
|
57
|
+
self.assertEqual(transposed_array.shape, (5, 5))
|
|
58
|
+
self.assertEqual(transposed_array.time_dimension, 1)
|
|
59
|
+
|
|
60
|
+
def test_array_mean(self):
|
|
61
|
+
mean_value = self.array.mean(axis=0)
|
|
62
|
+
self.assertEqual(mean_value.shape, (5,))
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class TestMaskedTimelinedArray(unittest.TestCase):
|
|
66
|
+
def setUp(self):
|
|
67
|
+
self.timeline = Timeline([0, 1, 2, 3, 4])
|
|
68
|
+
self.data = np.random.rand(5, 5)
|
|
69
|
+
self.mask = np.zeros((5, 5), dtype=bool)
|
|
70
|
+
self.mask[0, 0] = True
|
|
71
|
+
self.array = MaskedTimelinedArray(self.data, mask=self.mask, timeline=self.timeline, time_dimension=0)
|
|
72
|
+
|
|
73
|
+
def test_masked_array_creation(self):
|
|
74
|
+
self.assertEqual(self.array.shape, (5, 5))
|
|
75
|
+
self.assertEqual(self.array.timeline.max(), 4)
|
|
76
|
+
self.assertEqual(self.array.time_dimension, 0)
|
|
77
|
+
self.assertTrue(self.array.mask[0, 0])
|
|
78
|
+
|
|
79
|
+
def test_masked_array_indexing(self):
|
|
80
|
+
indexed_array = self.array[1:3]
|
|
81
|
+
self.assertEqual(indexed_array.shape, (2, 5))
|
|
82
|
+
self.assertEqual(indexed_array.timeline.min(), 1)
|
|
83
|
+
self.assertEqual(indexed_array.timeline.max(), 2)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
class TestMultidimensionnalIndexing(unittest.TestCase):
|
|
87
|
+
def setUp(self):
|
|
88
|
+
dimension = (15, 150, 200, 200)
|
|
89
|
+
y_dim_scale = 2
|
|
90
|
+
prime = [
|
|
91
|
+
[
|
|
92
|
+
(
|
|
93
|
+
np.array(
|
|
94
|
+
[
|
|
95
|
+
np.roll(np.linspace(phase, phase * 2, num=dimension[3], endpoint=True), shift=r)
|
|
96
|
+
for r in np.arange(0, dimension[2] * y_dim_scale, y_dim_scale)
|
|
97
|
+
]
|
|
98
|
+
)
|
|
99
|
+
* t
|
|
100
|
+
)
|
|
101
|
+
for t in np.sin(np.linspace(phase, phase + 2, num=dimension[1]))
|
|
102
|
+
]
|
|
103
|
+
for phase in np.linspace(1, dimension[0], num=dimension[0], endpoint=True)
|
|
104
|
+
]
|
|
105
|
+
prime = np.array(prime)
|
|
106
|
+
sin = np.sin(prime)
|
|
107
|
+
self.array = TimelinedArray(sin, time_dimension=1, timeline=np.linspace(-2, 7, num=300))
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
if __name__ == "__main__":
|
|
111
|
+
unittest.main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|