@@ -18,6 +18,16 public: | |||||
18 | .begin()); |
|
18 | .begin()); | |
19 |
|
19 | |||
20 | SpectrogramTimeSerie() {} |
|
20 | SpectrogramTimeSerie() {} | |
|
21 | SpectrogramTimeSerie(SpectrogramTimeSerie::axis_t& t, | |||
|
22 | SpectrogramTimeSerie::axis_t& y, | |||
|
23 | SpectrogramTimeSerie::container_type< | |||
|
24 | SpectrogramTimeSerie::raw_value_type>& values, | |||
|
25 | std::vector<std::size_t>& shape) | |||
|
26 | : TimeSeries::TimeSerie<double, SpectrogramTimeSerie, 2>(t, values, shape) | |||
|
27 | { | |||
|
28 | _axes[1] = y; | |||
|
29 | } | |||
|
30 | ||||
21 | ~SpectrogramTimeSerie() = default; |
|
31 | ~SpectrogramTimeSerie() = default; | |
22 | using TimeSerie::TimeSerie; |
|
32 | using TimeSerie::TimeSerie; | |
23 | }; |
|
33 | }; |
@@ -59,14 +59,36 void copy_scalar(py::array_t<double>& t, py::array_t<double>& values, T& dest_t, | |||||
59 | } |
|
59 | } | |
60 | } |
|
60 | } | |
61 | } |
|
61 | } | |
|
62 | template<typename T, typename U> | |||
|
63 | void copy_multicomp(py::array_t<double>& t, py::array_t<double>& values, | |||
|
64 | T& dest_t, U& dest_values) | |||
|
65 | { | |||
|
66 | auto t_view = t.unchecked<1>(); | |||
|
67 | auto values_view = values.unchecked<2>(); | |||
|
68 | const auto width = values.shape(1); | |||
|
69 | for(std::size_t i = 0; i < t.size(); i++) | |||
|
70 | { | |||
|
71 | dest_t[i] = t_view[i]; | |||
|
72 | for(int j = 0; j < width; j++) | |||
|
73 | { | |||
|
74 | dest_values[i * width + j] = values_view(i, j); | |||
|
75 | } | |||
|
76 | } | |||
|
77 | } | |||
62 |
|
78 | |||
63 | template<typename T, typename U> |
|
79 | template<typename T, typename U> | |
64 |
void copy_spectro(py::array_t<double>& t, py::array_t<double>& |
|
80 | void copy_spectro(py::array_t<double>& t, py::array_t<double>& y, | |
65 |
T& dest_t, |
|
81 | py::array_t<double>& values, T& dest_t, T& dest_y, | |
|
82 | U& dest_values) | |||
66 | { |
|
83 | { | |
67 | auto t_view = t.unchecked<1>(); |
|
84 | auto t_view = t.unchecked<1>(); | |
|
85 | auto y_view = y.unchecked<1>(); | |||
68 | auto values_view = values.unchecked<2>(); |
|
86 | auto values_view = values.unchecked<2>(); | |
69 | const auto width = values.shape(1); |
|
87 | const auto width = values.shape(1); | |
|
88 | for(std::size_t i = 0; i < y.size(); i++) | |||
|
89 | { | |||
|
90 | dest_y[i] = y_view[i]; | |||
|
91 | } | |||
70 | for(std::size_t i = 0; i < t.size(); i++) |
|
92 | for(std::size_t i = 0; i < t.size(); i++) | |
71 | { |
|
93 | { | |
72 | dest_t[i] = t_view[i]; |
|
94 | dest_t[i] = t_view[i]; | |
@@ -112,6 +134,11 PYBIND11_MODULE(pysciqlopcore, m) | |||||
112 | [](TimeSeries::ITimeSerie& ts) -> decltype(ts.axis(0))& { |
|
134 | [](TimeSeries::ITimeSerie& ts) -> decltype(ts.axis(0))& { | |
113 | return ts.axis(0); |
|
135 | return ts.axis(0); | |
114 | }, |
|
136 | }, | |
|
137 | py::return_value_policy::reference) | |||
|
138 | .def( | |||
|
139 | "axis", | |||
|
140 | [](TimeSeries::ITimeSerie& ts, unsigned int index) | |||
|
141 | -> decltype(ts.axis(0))& { return ts.axis(index); }, | |||
115 | py::return_value_policy::reference); |
|
142 | py::return_value_policy::reference); | |
116 |
|
143 | |||
117 | py::class_<ScalarTimeSerie, TimeSeries::ITimeSerie, |
|
144 | py::class_<ScalarTimeSerie, TimeSeries::ITimeSerie, | |
@@ -150,10 +177,11 PYBIND11_MODULE(pysciqlopcore, m) | |||||
150 | copy_vector(t, values, _t, _values); |
|
177 | copy_vector(t, values, _t, _values); | |
151 | return VectorTimeSerie(_t, _values); |
|
178 | return VectorTimeSerie(_t, _values); | |
152 | })) |
|
179 | })) | |
153 |
.def( |
|
180 | .def( | |
154 | [](VectorTimeSerie& ts, std::size_t key) |
|
181 | "__getitem__", | |
155 | -> VectorTimeSerie::raw_value_type& { return ts[key]; }, |
|
182 | [](VectorTimeSerie& ts, std::size_t key) | |
156 | py::return_value_policy::reference) |
|
183 | -> VectorTimeSerie::raw_value_type& { return ts[key]; }, | |
|
184 | py::return_value_policy::reference) | |||
157 | .def("__setitem__", [](VectorTimeSerie& ts, std::size_t key, |
|
185 | .def("__setitem__", [](VectorTimeSerie& ts, std::size_t key, | |
158 | VectorTimeSerie::raw_value_type value) { |
|
186 | VectorTimeSerie::raw_value_type value) { | |
159 | *(ts.begin() + key) = value; |
|
187 | *(ts.begin() + key) = value; | |
@@ -179,7 +207,7 PYBIND11_MODULE(pysciqlopcore, m) | |||||
179 | MultiComponentTimeSerie::container_type< |
|
207 | MultiComponentTimeSerie::container_type< | |
180 | MultiComponentTimeSerie::raw_value_type> |
|
208 | MultiComponentTimeSerie::raw_value_type> | |
181 | _values(values.size()); |
|
209 | _values(values.size()); | |
182 |
copy_ |
|
210 | copy_multicomp(t, values, _t, _values); | |
183 | std::vector<std::size_t> shape; |
|
211 | std::vector<std::size_t> shape; | |
184 | shape.push_back(values.shape(0)); |
|
212 | shape.push_back(values.shape(0)); | |
185 | shape.push_back(values.shape(1)); |
|
213 | shape.push_back(values.shape(1)); | |
@@ -202,17 +230,20 PYBIND11_MODULE(pysciqlopcore, m) | |||||
202 | std::shared_ptr<SpectrogramTimeSerie>>(m, "SpectrogramTimeSerie") |
|
230 | std::shared_ptr<SpectrogramTimeSerie>>(m, "SpectrogramTimeSerie") | |
203 | .def(py::init<>()) |
|
231 | .def(py::init<>()) | |
204 | .def(py::init<const std::vector<std::size_t>>()) |
|
232 | .def(py::init<const std::vector<std::size_t>>()) | |
205 |
.def(py::init([](py::array_t<double> t, py::array_t<double> |
|
233 | .def(py::init([](py::array_t<double> t, py::array_t<double> y, | |
|
234 | py::array_t<double> values) { | |||
206 | assert(t.size() < values.size()); // TODO check geometry |
|
235 | assert(t.size() < values.size()); // TODO check geometry | |
|
236 | assert(y.size() == values.shape(1)); | |||
207 | SpectrogramTimeSerie::axis_t _t(t.size()); |
|
237 | SpectrogramTimeSerie::axis_t _t(t.size()); | |
|
238 | SpectrogramTimeSerie::axis_t _y(y.size()); | |||
208 | SpectrogramTimeSerie::container_type< |
|
239 | SpectrogramTimeSerie::container_type< | |
209 | SpectrogramTimeSerie::raw_value_type> |
|
240 | SpectrogramTimeSerie::raw_value_type> | |
210 | _values(values.size()); |
|
241 | _values(values.size()); | |
211 | copy_spectro(t, values, _t, _values); |
|
242 | copy_spectro(t, y, values, _t, _y, _values); | |
212 | std::vector<std::size_t> shape; |
|
243 | std::vector<std::size_t> shape; | |
213 | shape.push_back(values.shape(0)); |
|
244 | shape.push_back(values.shape(0)); | |
214 | shape.push_back(values.shape(1)); |
|
245 | shape.push_back(values.shape(1)); | |
215 | return SpectrogramTimeSerie(_t, _values, shape); |
|
246 | return SpectrogramTimeSerie(_t, _y, _values, shape); | |
216 | })) |
|
247 | })) | |
217 | .def("__getitem__", |
|
248 | .def("__getitem__", | |
218 | [](SpectrogramTimeSerie& ts, |
|
249 | [](SpectrogramTimeSerie& ts, |
@@ -126,13 +126,15 class TimeSeriesData(unittest.TestCase): | |||||
126 | self.assertEqual(ts[i].z,i*100.) |
|
126 | self.assertEqual(ts[i].z,i*100.) | |
127 |
|
127 | |||
128 | def test_build_SpectrogramTimeSerie_from_np_arrays(self): |
|
128 | def test_build_SpectrogramTimeSerie_from_np_arrays(self): | |
129 |
v=np.ones((10, |
|
129 | v=np.ones((10,30)) | |
130 |
for i in range( |
|
130 | for i in range(30): | |
131 | v.transpose()[:][i] = np.arange(10)*10**i |
|
131 | v.transpose()[:][i] = np.arange(10)*10**(i/10.) | |
132 | ts = pysciqlopcore.SpectrogramTimeSerie(np.arange(10), v) |
|
132 | ts = pysciqlopcore.SpectrogramTimeSerie(np.arange(10),np.arange(30), v) | |
133 | for i in range(len(ts)): |
|
133 | for i in range(len(ts)): | |
134 |
for j in range( |
|
134 | for j in range(30): | |
135 | self.assertEqual(ts[i][j], i*10**j) |
|
135 | self.assertEqual(ts[i][j], i*10**(j/10.)) | |
|
136 | for i in range(30): | |||
|
137 | self.assertEqual(ts.axis(1)[i], i) | |||
136 |
|
138 | |||
137 | class VariableData(unittest.TestCase): |
|
139 | class VariableData(unittest.TestCase): | |
138 | def test_default_state(self): |
|
140 | def test_default_state(self): |
General Comments 0
You need to be logged in to leave comments.
Login now