##// END OF EJS Templates
Updated TS lib...
Updated TS lib Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>

File last commit:

r88:4e4ec6844f70
r88:4e4ec6844f70
Show More
CoreWrappers.cpp
297 lines | 11.2 KiB | text/x-c | CppLexer
Added new TS classes and tiny cleanup...
r60 #include "CoreWrappers.h"
First init from SciQLop Core module...
r0
#include "pywrappers_common.h"
Updated to fixed TS lib, added spectrogram min/max sampling hints when available...
r85 #include <Common/debug.h>
First init from SciQLop Core module...
r0 #include <Data/DataSeriesType.h>
Added new TS classes and tiny cleanup...
r60 #include <Data/IDataProvider.h>
First init from SciQLop Core module...
r0 #include <Network/Downloader.h>
Added new TS classes and tiny cleanup...
r60 #include <Time/TimeController.h>
New TimeSeries integration WIP...
r62 #include <Variable/Variable2.h>
Added new TS classes and tiny cleanup...
r60 #include <Variable/VariableController2.h>
#include <pybind11/chrono.h>
#include <pybind11/embed.h>
#include <pybind11/functional.h>
#include <pybind11/numpy.h>
#include <pybind11/operators.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
New TimeSeries integration WIP...
r62 #include <pybind11/stl_bind.h>
Added new TS classes and tiny cleanup...
r60 #include <sstream>
#include <string>
First init from SciQLop Core module...
r0
namespace py = pybind11;
using namespace std::chrono;
New TimeSeries classes mostly usable from Python...
r65 template<typename T, typename U, bool row_major = true>
void copy_vector(py::array_t<double>& t, py::array_t<double>& values, T& dest_t,
U& dest_values)
{
auto t_view = t.unchecked<1>();
auto values_view = values.unchecked<2>();
Made TS Python API only compatible with pandas shape (line, column)...
r78 for(std::size_t i = 0; i < t.size(); i++)
New TimeSeries classes mostly usable from Python...
r65 {
Made TS Python API only compatible with pandas shape (line, column)...
r78 dest_t[i] = t_view[i];
dest_values[i] = {values_view(i, 0), values_view(i, 1), values_view(i, 2)};
}
}
template<typename T, typename U>
void copy_scalar(py::array_t<double>& t, py::array_t<double>& values, T& dest_t,
U& dest_values)
{
auto t_view = t.unchecked<1>();
if(values.ndim() == 1)
{
auto values_view = values.unchecked<1>();
New TimeSeries classes mostly usable from Python...
r65 for(std::size_t i = 0; i < t.size(); i++)
{
dest_t[i] = t_view[i];
Made TS Python API only compatible with pandas shape (line, column)...
r78 dest_values[i] = values_view[i];
New TimeSeries classes mostly usable from Python...
r65 }
}
Made TS Python API only compatible with pandas shape (line, column)...
r78 else if(values.ndim() == 2 && values.shape(1) == 1)
New TimeSeries classes mostly usable from Python...
r65 {
Made TS Python API only compatible with pandas shape (line, column)...
r78 auto values_view = values.unchecked<2>();
New TimeSeries classes mostly usable from Python...
r65 for(std::size_t i = 0; i < t.size(); i++)
{
dest_t[i] = t_view[i];
Made TS Python API only compatible with pandas shape (line, column)...
r78 dest_values[i] = values_view(i, 0);
New TimeSeries classes mostly usable from Python...
r65 }
}
}
Some work on SpectrogramTS Python wrapper...
r83 template<typename T, typename U>
void copy_multicomp(py::array_t<double>& t, py::array_t<double>& values,
T& dest_t, U& dest_values)
{
auto t_view = t.unchecked<1>();
auto values_view = values.unchecked<2>();
const auto width = values.shape(1);
for(std::size_t i = 0; i < t.size(); i++)
{
dest_t[i] = t_view[i];
for(int j = 0; j < width; j++)
{
dest_values[i * width + j] = values_view(i, j);
}
}
}
New TimeSeries classes mostly usable from Python...
r65
template<typename T, typename U>
Some work on SpectrogramTS Python wrapper...
r83 void copy_spectro(py::array_t<double>& t, py::array_t<double>& y,
py::array_t<double>& values, T& dest_t, T& dest_y,
U& dest_values)
New TimeSeries classes mostly usable from Python...
r65 {
auto t_view = t.unchecked<1>();
Some work on SpectrogramTS Python wrapper...
r83 auto y_view = y.unchecked<1>();
New TimeSeries classes mostly usable from Python...
r65 auto values_view = values.unchecked<2>();
Made TS Python API only compatible with pandas shape (line, column)...
r78 const auto width = values.shape(1);
Some work on SpectrogramTS Python wrapper...
r83 for(std::size_t i = 0; i < y.size(); i++)
{
dest_y[i] = y_view[i];
}
New TimeSeries classes mostly usable from Python...
r65 for(std::size_t i = 0; i < t.size(); i++)
{
dest_t[i] = t_view[i];
for(int j = 0; j < width; j++)
{
Made TS Python API only compatible with pandas shape (line, column)...
r78 dest_values[i * width + j] = values_view(i, j);
New TimeSeries classes mostly usable from Python...
r65 }
}
}
Added new TS classes and tiny cleanup...
r60 PYBIND11_MODULE(pysciqlopcore, m)
{
New TimeSeries integration WIP...
r62 pybind11::bind_vector<std::vector<double>>(m, "VectorDouble");
Added new TS classes and tiny cleanup...
r60 py::enum_<DataSeriesType>(m, "DataSeriesType")
.value("SCALAR", DataSeriesType::SCALAR)
.value("SPECTROGRAM", DataSeriesType::SPECTROGRAM)
.value("VECTOR", DataSeriesType::VECTOR)
MultiComponent TS almost done, still blows up when built from python with empty data...
r76 .value("MULTICOMPONENT", DataSeriesType::MULTICOMPONENT)
New TimeSeries integration WIP...
r62 .value("NONE", DataSeriesType::NONE)
Added new TS classes and tiny cleanup...
r60 .export_values();
py::class_<Response>(m, "Response")
.def("status_code", &Response::status_code);
py::class_<Downloader>(m, "Downloader")
.def_static("get", Downloader::get)
.def_static("getAsync", Downloader::getAsync)
.def_static("downloadFinished", Downloader::downloadFinished);
py::class_<IDataProvider, std::shared_ptr<IDataProvider>>(m, "IDataProvider");
Fixed all tests \o/ with new TS impl...
r68 py::class_<TimeSeries::ITimeSerie, std::shared_ptr<TimeSeries::ITimeSerie>>(
m, "ITimeSerie")
New TimeSeries integration WIP...
r62 .def_property_readonly(
"size", [](const TimeSeries::ITimeSerie& ts) { return ts.size(); })
New TimeSeries classes mostly usable from Python...
r65 .def("__len__",
[](const TimeSeries::ITimeSerie& ts) { return ts.size(); })
More work on new Variable python bindings...
r63 .def_property_readonly(
"shape", [](const TimeSeries::ITimeSerie& ts) { return ts.shape(); })
New TimeSeries integration WIP...
r62 .def_property_readonly(
"t",
[](TimeSeries::ITimeSerie& ts) -> decltype(ts.axis(0))& {
return ts.axis(0);
},
Some work on SpectrogramTS Python wrapper...
r83 py::return_value_policy::reference)
.def(
"axis",
[](TimeSeries::ITimeSerie& ts, unsigned int index)
-> decltype(ts.axis(0))& { return ts.axis(index); },
New TimeSeries integration WIP...
r62 py::return_value_policy::reference);
Few minor tweaks and removed memory leak.....
r73 py::class_<ScalarTimeSerie, TimeSeries::ITimeSerie,
std::shared_ptr<ScalarTimeSerie>>(m, "ScalarTimeSerie")
New TimeSeries integration WIP...
r62 .def(py::init<>())
.def(py::init<std::size_t>())
More work on new Variable python bindings...
r63 .def(py::init([](py::array_t<double> t, py::array_t<double> values) {
assert(t.size() == values.size());
ScalarTimeSerie::axis_t _t(t.size());
ScalarTimeSerie::axis_t _values(t.size());
New TimeSeries classes mostly usable from Python...
r65 copy_scalar(t, values, _t, _values);
More work on new Variable python bindings...
r63 return ScalarTimeSerie(_t, _values);
}))
New TimeSeries integration WIP...
r62 .def("__getitem__",
[](ScalarTimeSerie& ts, std::size_t key) { return ts[key]; })
.def("__setitem__", [](ScalarTimeSerie& ts, std::size_t key,
double value) { *(ts.begin() + key) = value; });
py::class_<VectorTimeSerie::raw_value_type>(m, "vector")
.def(py::init<>())
.def(py::init<double, double, double>())
.def("__repr__", __repr__<VectorTimeSerie::raw_value_type>)
.def_readwrite("x", &VectorTimeSerie::raw_value_type::x)
.def_readwrite("y", &VectorTimeSerie::raw_value_type::y)
.def_readwrite("z", &VectorTimeSerie::raw_value_type::z);
Few minor tweaks and removed memory leak.....
r73 py::class_<VectorTimeSerie, TimeSeries::ITimeSerie,
std::shared_ptr<VectorTimeSerie>>(m, "VectorTimeSerie")
New TimeSeries integration WIP...
r62 .def(py::init<>())
.def(py::init<std::size_t>())
Added vector build from numpy arrays...
r64 .def(py::init([](py::array_t<double> t, py::array_t<double> values) {
assert(t.size() * 3 == values.size());
VectorTimeSerie::axis_t _t(t.size());
Updated TS lib...
r88 VectorTimeSerie::data_t _values(t.size());
Made TS Python API only compatible with pandas shape (line, column)...
r78 copy_vector(t, values, _t, _values);
Added vector build from numpy arrays...
r64 return VectorTimeSerie(_t, _values);
}))
Some work on SpectrogramTS Python wrapper...
r83 .def(
"__getitem__",
[](VectorTimeSerie& ts, std::size_t key)
-> VectorTimeSerie::raw_value_type& { return ts[key]; },
py::return_value_policy::reference)
New TimeSeries integration WIP...
r62 .def("__setitem__", [](VectorTimeSerie& ts, std::size_t key,
VectorTimeSerie::raw_value_type value) {
*(ts.begin() + key) = value;
});
MultiComponent TS almost done, still blows up when built from python with empty data...
r76 py::class_<MultiComponentTimeSerie::iterator_t>(m,
"MultiComponentTimeSerieItem")
WIP Multicomponent TS...
r75 .def("__getitem__", [](MultiComponentTimeSerie::iterator_t& self,
std::size_t key) { return (*self)[key]; })
.def("__setitem__",
[](MultiComponentTimeSerie::iterator_t& self, std::size_t key,
double value) { (*self)[key] = value; });
py::class_<MultiComponentTimeSerie, TimeSeries::ITimeSerie,
std::shared_ptr<MultiComponentTimeSerie>>(
m, "MultiComponentTimeSerie")
.def(py::init<>())
.def(py::init<const std::vector<std::size_t>>())
.def(py::init([](py::array_t<double> t, py::array_t<double> values) {
MultiComponent TS almost done, still blows up when built from python with empty data...
r76 assert((t.size() < values.size()) |
(t.size() == 0)); // TODO check geometry
WIP Multicomponent TS...
r75 MultiComponentTimeSerie::axis_t _t(t.size());
Updated TS lib...
r88 MultiComponentTimeSerie::data_t _values(values.size());
Some work on SpectrogramTS Python wrapper...
r83 copy_multicomp(t, values, _t, _values);
WIP Multicomponent TS...
r75 std::vector<std::size_t> shape;
shape.push_back(values.shape(0));
Made TS Python API only compatible with pandas shape (line, column)...
r78 shape.push_back(values.shape(1));
WIP Multicomponent TS...
r75 return MultiComponentTimeSerie(_t, _values, shape);
}))
.def("__getitem__",
[](MultiComponentTimeSerie& ts,
std::size_t key) -> MultiComponentTimeSerie::iterator_t {
return ts.begin() + key;
});
Spectrogram wrapper allow to set values from python...
r66 py::class_<SpectrogramTimeSerie::iterator_t>(m, "SpectrogramTimeSerieItem")
.def("__getitem__", [](SpectrogramTimeSerie::iterator_t& self,
std::size_t key) { return (*self)[key]; })
.def("__setitem__",
[](SpectrogramTimeSerie::iterator_t& self, std::size_t key,
double value) { (*self)[key] = value; });
New TimeSeries classes mostly usable from Python...
r65
Few minor tweaks and removed memory leak.....
r73 py::class_<SpectrogramTimeSerie, TimeSeries::ITimeSerie,
std::shared_ptr<SpectrogramTimeSerie>>(m, "SpectrogramTimeSerie")
More work on new Variable python bindings...
r63 .def(py::init<>())
New TimeSeries classes mostly usable from Python...
r65 .def(py::init<const std::vector<std::size_t>>())
Some work on SpectrogramTS Python wrapper...
r83 .def(py::init([](py::array_t<double> t, py::array_t<double> y,
Updated to fixed TS lib, added spectrogram min/max sampling hints when available...
r85 py::array_t<double> values, double min_sampling,
Added Y log tag for Spectrograms...
r87 double max_sampling, bool y_is_log) {
Updated to fixed TS lib, added spectrogram min/max sampling hints when available...
r85 if(t.size() >= values.size() and t.size() != 0)
SCIQLOP_ERROR(decltype(py::self), "Doesn't look like a Spectrogram");
if(y.size() != values.shape(1))
SCIQLOP_ERROR(decltype(py::self),
"Y axis size and data shape are incompatible");
New TimeSeries classes mostly usable from Python...
r65 SpectrogramTimeSerie::axis_t _t(t.size());
Some work on SpectrogramTS Python wrapper...
r83 SpectrogramTimeSerie::axis_t _y(y.size());
Updated TS lib...
r88 SpectrogramTimeSerie::data_t _values(values.size());
Some work on SpectrogramTS Python wrapper...
r83 copy_spectro(t, y, values, _t, _y, _values);
New TimeSeries classes mostly usable from Python...
r65 std::vector<std::size_t> shape;
shape.push_back(values.shape(0));
Made TS Python API only compatible with pandas shape (line, column)...
r78 shape.push_back(values.shape(1));
Mostly working Spectrograms...
r84 return SpectrogramTimeSerie(std::move(_t), std::move(_y),
Updated to fixed TS lib, added spectrogram min/max sampling hints when available...
r85 std::move(_values), shape, min_sampling,
Added Y log tag for Spectrograms...
r87 max_sampling, y_is_log);
New TimeSeries classes mostly usable from Python...
r65 }))
.def("__getitem__",
Spectrogram wrapper allow to set values from python...
r66 [](SpectrogramTimeSerie& ts,
std::size_t key) -> SpectrogramTimeSerie::iterator_t {
return ts.begin() + key;
});
More work on new Variable python bindings...
r63
New TimeSeries integration WIP...
r62 py::class_<Variable2, std::shared_ptr<Variable2>>(m, "Variable2")
.def(py::init<const QString&>())
.def_property("name", &Variable2::name, &Variable2::setName)
.def_property_readonly("range", &Variable2::range)
.def_property_readonly("nbPoints", &Variable2::nbPoints)
Fixed all tests \o/ with new TS impl...
r68 .def_property_readonly(
"data",
[](Variable2& var) -> std::shared_ptr<TimeSeries::ITimeSerie> {
return var.data();
})
More work on new Variable python bindings...
r63 .def("set_data",
[](Variable2& var, std::vector<TimeSeries::ITimeSerie*> ts_list,
const DateTimeRange& range) { var.setData(ts_list, range); })
New TimeSeries integration WIP...
r62 .def("__len__", &Variable2::nbPoints)
.def("__repr__", __repr__<Variable2>);
Added new TS classes and tiny cleanup...
r60 py::class_<DateTimeRange>(m, "SqpRange")
//.def("fromDateTime", &DateTimeRange::fromDateTime,
New TimeSeries integration WIP...
r62 // py::return_value_policy::move)
Added new TS classes and tiny cleanup...
r60 .def(py::init([](double start, double stop) {
return DateTimeRange{start, stop};
}))
.def(py::init(
[](system_clock::time_point start, system_clock::time_point stop) {
double start_ =
0.001 *
duration_cast<milliseconds>(start.time_since_epoch()).count();
double stop_ =
0.001 *
duration_cast<milliseconds>(stop.time_since_epoch()).count();
return DateTimeRange{start_, stop_};
}))
.def_property_readonly("start",
[](const DateTimeRange& range) {
return system_clock::from_time_t(range.m_TStart);
})
.def_property_readonly("stop",
[](const DateTimeRange& range) {
return system_clock::from_time_t(range.m_TEnd);
})
.def("__repr__", __repr__<DateTimeRange>);
First init from SciQLop Core module...
r0 }