@@ -1,1 +1,1 | |||||
1 | Subproject commit 22e3e4553178230053aac40131b4fdb36c163075 |
|
1 | Subproject commit 1c245f84d0728d99b6f5deab7793fb238105a54d |
@@ -4,11 +4,14 | |||||
4 | #include "CoreGlobal.h" |
|
4 | #include "CoreGlobal.h" | |
5 |
|
5 | |||
6 | #include <TimeSeries.h> |
|
6 | #include <TimeSeries.h> | |
|
7 | #include <cmath> | |||
7 |
|
8 | |||
8 | class SCIQLOP_CORE_EXPORT SpectrogramTimeSerie |
|
9 | class SCIQLOP_CORE_EXPORT SpectrogramTimeSerie | |
9 | : public TimeSeries::TimeSerie<double, SpectrogramTimeSerie, 2> |
|
10 | : public TimeSeries::TimeSerie<double, SpectrogramTimeSerie, 2> | |
10 | { |
|
11 | { | |
11 | public: |
|
12 | public: | |
|
13 | double min_sampling = std::nan(""); | |||
|
14 | double max_sampling = std::nan(""); | |||
12 | using item_t = |
|
15 | using item_t = | |
13 | decltype(std::declval< |
|
16 | decltype(std::declval< | |
14 | TimeSeries::TimeSerie<double, SpectrogramTimeSerie, 2>>()[0]); |
|
17 | TimeSeries::TimeSerie<double, SpectrogramTimeSerie, 2>>()[0]); | |
@@ -22,8 +25,11 public: | |||||
22 | SpectrogramTimeSerie::axis_t&& y, |
|
25 | SpectrogramTimeSerie::axis_t&& y, | |
23 | SpectrogramTimeSerie::container_type< |
|
26 | SpectrogramTimeSerie::container_type< | |
24 | SpectrogramTimeSerie::raw_value_type>&& values, |
|
27 | SpectrogramTimeSerie::raw_value_type>&& values, | |
25 |
std::vector<std::size_t>& shape |
|
28 | std::vector<std::size_t>& shape, double min_sampling, | |
26 | : TimeSeries::TimeSerie<double, SpectrogramTimeSerie, 2>(t, values, shape) |
|
29 | double max_sampling) | |
|
30 | : TimeSeries::TimeSerie<double, SpectrogramTimeSerie, 2>(t, values, | |||
|
31 | shape), | |||
|
32 | min_sampling{min_sampling}, max_sampling{max_sampling} | |||
27 | { |
|
33 | { | |
28 | _axes[1] = y; |
|
34 | _axes[1] = y; | |
29 | } |
|
35 | } |
@@ -43,6 +43,8 namespace TimeSeriesUtils | |||||
43 | double range; |
|
43 | double range; | |
44 | double max_resolution; |
|
44 | double max_resolution; | |
45 | bool is_log; |
|
45 | bool is_log; | |
|
46 | double min; | |||
|
47 | double max; | |||
46 | }; |
|
48 | }; | |
47 |
|
49 | |||
48 | constexpr auto IsLog = true; |
|
50 | constexpr auto IsLog = true; | |
@@ -54,7 +56,8 namespace TimeSeriesUtils | |||||
54 | template<bool is_log, bool check_median> |
|
56 | template<bool is_log, bool check_median> | |
55 | axis_properties axis_analysis( |
|
57 | axis_properties axis_analysis( | |
56 | typename std::conditional<is_log, std::vector<double>&, |
|
58 | typename std::conditional<is_log, std::vector<double>&, | |
57 |
const std::vector<double>&>::type axis |
|
59 | const std::vector<double>&>::type axis, | |
|
60 | double given_max_resolution = std::nan("")) | |||
58 | { |
|
61 | { | |
59 | std::vector<double> axis_diff(axis.size()); |
|
62 | std::vector<double> axis_diff(axis.size()); | |
60 | if constexpr(is_log) |
|
63 | if constexpr(is_log) | |
@@ -62,20 +65,27 namespace TimeSeriesUtils | |||||
62 | std::transform(std::cbegin(axis), std::cend(axis), std::begin(axis), |
|
65 | std::transform(std::cbegin(axis), std::cend(axis), std::begin(axis), | |
63 | [](const auto v) { return std::log10(v); }); |
|
66 | [](const auto v) { return std::log10(v); }); | |
64 | } |
|
67 | } | |
65 |
auto |
|
68 | auto min = *std::begin(axis); | |
66 | std::adjacent_difference(std::cbegin(axis), std::cend(axis), |
|
69 | auto max = *(std::cend(axis) - 1); | |
67 | std::begin(axis_diff)); |
|
70 | auto range = max - min; | |
68 | auto min_diff = |
|
71 | auto min_diff = given_max_resolution; | |
69 | (*std::min_element(std::cbegin(axis_diff) + 1, std::cend(axis_diff))); |
|
72 | if(std::isnan(min_diff)) | |
70 | if constexpr(check_median) |
|
|||
71 | { |
|
73 | { | |
72 | std::nth_element(std::begin(axis_diff) + 1, |
|
74 | std::adjacent_difference(std::cbegin(axis), std::cend(axis), | |
73 |
std::begin(axis_diff) |
|
75 | std::begin(axis_diff)); | |
74 | std::end(axis_diff)); |
|
76 | min_diff = | |
75 |
|
|
77 | (*std::min_element(std::cbegin(axis_diff) + 1, std::cend(axis_diff))); | |
76 | if(median_diff > (4 * min_diff)) min_diff = median_diff; |
|
78 | if constexpr(check_median) | |
|
79 | { | |||
|
80 | std::nth_element(std::begin(axis_diff) + 1, | |||
|
81 | std::begin(axis_diff) + axis_diff.size() / 2, | |||
|
82 | std::end(axis_diff)); | |||
|
83 | auto median_diff = *(std::begin(axis_diff) + axis_diff.size() / 2); | |||
|
84 | if(median_diff > (4 * min_diff)) min_diff = median_diff; | |||
|
85 | } | |||
77 | } |
|
86 | } | |
78 | return {range, min_diff, is_log}; |
|
87 | ||
|
88 | return {range, min_diff, is_log, min, max}; | |||
79 | } |
|
89 | } | |
80 |
|
90 | |||
81 | } // namespace TimeSeriesUtils |
|
91 | } // namespace TimeSeriesUtils |
@@ -65,7 +65,7 public: | |||||
65 | { |
|
65 | { | |
66 | auto ds = _provider->getData( |
|
66 | auto ds = _provider->getData( | |
67 | DataProviderParameters{{range}, _variable->metadata()}); |
|
67 | DataProviderParameters{{range}, _variable->metadata()}); | |
68 | if(ds) data.push_back(ds); |
|
68 | if(ds and ds->size()) data.push_back(ds); // skip empty dataSeries | |
69 | } |
|
69 | } | |
70 | if(_overwrite) |
|
70 | if(_overwrite) | |
71 | _variable->setData(data, _range, true); |
|
71 | _variable->setData(data, _range, true); |
@@ -203,6 +203,18 _merge(std::vector<TimeSeries::ITimeSerie*> source, const DateTimeRange& range) | |||||
203 | std::back_inserter(dest->axis(ax_index))); |
|
203 | std::back_inserter(dest->axis(ax_index))); | |
204 | } |
|
204 | } | |
205 | } |
|
205 | } | |
|
206 | if constexpr(std::is_same_v<T, SpectrogramTimeSerie>) | |||
|
207 | { | |||
|
208 | auto d = std::dynamic_pointer_cast<SpectrogramTimeSerie>(dest); | |||
|
209 | if(std::isnan(d->max_sampling)) | |||
|
210 | { | |||
|
211 | std::for_each(std::begin(source), std::end(source), [&d](auto src) { | |||
|
212 | auto s = dynamic_cast<SpectrogramTimeSerie*>(src); | |||
|
213 | if(!std::isnan(s->max_sampling)) { d->max_sampling = s->max_sampling; } | |||
|
214 | if(!std::isnan(s->min_sampling)) { d->min_sampling = s->min_sampling; } | |||
|
215 | }); | |||
|
216 | } | |||
|
217 | } | |||
206 | return dest; |
|
218 | return dest; | |
207 | } |
|
219 | } | |
208 |
|
220 |
@@ -264,6 +264,7 class VariableController2::VariableController2Private | |||||
264 | } |
|
264 | } | |
265 | data.push_back(var->data().get()); // might be smarter |
|
265 | data.push_back(var->data().get()); // might be smarter | |
266 | var->setData(data, r, true); |
|
266 | var->setData(data, r, true); | |
|
267 | std::for_each(std::begin(data), std::end(data), [](auto ts) { delete ts; }); | |||
267 | } |
|
268 | } | |
268 |
|
269 | |||
269 | public: |
|
270 | public: |
@@ -2,6 +2,7 | |||||
2 |
|
2 | |||
3 | #include "pywrappers_common.h" |
|
3 | #include "pywrappers_common.h" | |
4 |
|
4 | |||
|
5 | #include <Common/debug.h> | |||
5 | #include <Data/DataSeriesType.h> |
|
6 | #include <Data/DataSeriesType.h> | |
6 | #include <Data/IDataProvider.h> |
|
7 | #include <Data/IDataProvider.h> | |
7 | #include <Network/Downloader.h> |
|
8 | #include <Network/Downloader.h> | |
@@ -231,12 +232,13 PYBIND11_MODULE(pysciqlopcore, m) | |||||
231 | .def(py::init<>()) |
|
232 | .def(py::init<>()) | |
232 | .def(py::init<const std::vector<std::size_t>>()) |
|
233 | .def(py::init<const std::vector<std::size_t>>()) | |
233 | .def(py::init([](py::array_t<double> t, py::array_t<double> y, |
|
234 | .def(py::init([](py::array_t<double> t, py::array_t<double> y, | |
234 |
py::array_t<double> values |
|
235 | py::array_t<double> values, double min_sampling, | |
235 | auto t_s = t.size(); |
|
236 | double max_sampling) { | |
236 | auto v_s = values.size(); |
|
237 | if(t.size() >= values.size() and t.size() != 0) | |
237 | assert(t.size() < values.size() or |
|
238 | SCIQLOP_ERROR(decltype(py::self), "Doesn't look like a Spectrogram"); | |
238 | t.size() == 0); // TODO check geometry |
|
239 | if(y.size() != values.shape(1)) | |
239 | assert(y.size() == values.shape(1)); |
|
240 | SCIQLOP_ERROR(decltype(py::self), | |
|
241 | "Y axis size and data shape are incompatible"); | |||
240 | SpectrogramTimeSerie::axis_t _t(t.size()); |
|
242 | SpectrogramTimeSerie::axis_t _t(t.size()); | |
241 | SpectrogramTimeSerie::axis_t _y(y.size()); |
|
243 | SpectrogramTimeSerie::axis_t _y(y.size()); | |
242 | SpectrogramTimeSerie::container_type< |
|
244 | SpectrogramTimeSerie::container_type< | |
@@ -247,7 +249,8 PYBIND11_MODULE(pysciqlopcore, m) | |||||
247 | shape.push_back(values.shape(0)); |
|
249 | shape.push_back(values.shape(0)); | |
248 | shape.push_back(values.shape(1)); |
|
250 | shape.push_back(values.shape(1)); | |
249 | return SpectrogramTimeSerie(std::move(_t), std::move(_y), |
|
251 | return SpectrogramTimeSerie(std::move(_t), std::move(_y), | |
250 |
std::move(_values), shape |
|
252 | std::move(_values), shape, min_sampling, | |
|
253 | max_sampling); | |||
251 | })) |
|
254 | })) | |
252 | .def("__getitem__", |
|
255 | .def("__getitem__", | |
253 | [](SpectrogramTimeSerie& ts, |
|
256 | [](SpectrogramTimeSerie& ts, |
General Comments 0
You need to be logged in to leave comments.
Login now