##// END OF EJS Templates
MultiComponent TS almost complete...
jeandet -
r1432:db5304cf6c8c
parent child
Show More
@@ -1,1 +1,1
1 Subproject commit 41273d8529cddde1c8b6bcea03d71d9cd1a18c06
1 Subproject commit 9a080a34054c21a67236f761e8843005c07ff0ba
@@ -95,7 +95,8 struct AxisSetter
95 template <typename T>
95 template <typename T>
96 struct AxisSetter<T,
96 struct AxisSetter<T,
97 typename std::enable_if_t<std::is_base_of<ScalarTimeSerie, T>::value
97 typename std::enable_if_t<std::is_base_of<ScalarTimeSerie, T>::value
98 or std::is_base_of<VectorTimeSerie, T>::value>>
98 or std::is_base_of<VectorTimeSerie, T>::value
99 or std::is_base_of<MultiComponentTimeSerie, T>::value>>
99 {
100 {
100 static void setProperties(QCustomPlot&, SqpColorScale&)
101 static void setProperties(QCustomPlot&, SqpColorScale&)
101 {
102 {
@@ -204,6 +205,9 std::unique_ptr<IAxisHelper> IAxisHelperFactory::create(Variable2& variable) noe
204 case DataSeriesType::VECTOR:
205 case DataSeriesType::VECTOR:
205 return std::make_unique<AxisHelper<VectorTimeSerie>>(
206 return std::make_unique<AxisHelper<VectorTimeSerie>>(
206 std::dynamic_pointer_cast<VectorTimeSerie>(variable.data()));
207 std::dynamic_pointer_cast<VectorTimeSerie>(variable.data()));
208 case DataSeriesType::MULTICOMPONENT:
209 return std::make_unique<AxisHelper<MultiComponentTimeSerie>>(
210 std::dynamic_pointer_cast<MultiComponentTimeSerie>(variable.data()));
207 default:
211 default:
208 // Creates default helper
212 // Creates default helper
209 break;
213 break;
@@ -33,7 +33,8 struct PlottablesSetter
33 template <typename T>
33 template <typename T>
34 struct PlottablesSetter<T,
34 struct PlottablesSetter<T,
35 typename std::enable_if_t<std::is_base_of<ScalarTimeSerie, T>::value
35 typename std::enable_if_t<std::is_base_of<ScalarTimeSerie, T>::value
36 or std::is_base_of<VectorTimeSerie, T>::value>>
36 or std::is_base_of<VectorTimeSerie, T>::value
37 or std::is_base_of<MultiComponentTimeSerie, T>::value>>
37 {
38 {
38 static void setProperties(PlottablesMap& plottables)
39 static void setProperties(PlottablesMap& plottables)
39 {
40 {
@@ -124,6 +125,8 std::unique_ptr<IPlottablesHelper> IPlottablesHelperFactory::create(Variable2& v
124 return std::make_unique<PlottablesHelper<SpectrogramTimeSerie>>();
125 return std::make_unique<PlottablesHelper<SpectrogramTimeSerie>>();
125 case DataSeriesType::VECTOR:
126 case DataSeriesType::VECTOR:
126 return std::make_unique<PlottablesHelper<VectorTimeSerie>>();
127 return std::make_unique<PlottablesHelper<VectorTimeSerie>>();
128 case DataSeriesType::MULTICOMPONENT:
129 return std::make_unique<PlottablesHelper<MultiComponentTimeSerie>>();
127 default:
130 default:
128 // Returns default helper
131 // Returns default helper
129 break;
132 break;
@@ -261,7 +261,8 struct PlottablesUpdater<T, typename std::enable_if_t<std::is_base_of<VectorTime
261
261
262
262
263 template <typename T>
263 template <typename T>
264 struct PlottablesUpdater<T, typename std::enable_if_t<std::is_base_of<MultiComponentTimeSerie, T>::value>>
264 struct PlottablesUpdater<T,
265 typename std::enable_if_t<std::is_base_of<MultiComponentTimeSerie, T>::value>>
265 {
266 {
266 static void setPlotYAxisRange(T& dataSeries, const DateTimeRange& xAxisRange, QCustomPlot& plot)
267 static void setPlotYAxisRange(T& dataSeries, const DateTimeRange& xAxisRange, QCustomPlot& plot)
267 {
268 {
@@ -269,11 +270,13 struct PlottablesUpdater<T, typename std::enable_if_t<std::is_base_of<MultiCompo
269 if (auto serie = dynamic_cast<MultiComponentTimeSerie*>(&dataSeries))
270 if (auto serie = dynamic_cast<MultiComponentTimeSerie*>(&dataSeries))
270 {
271 {
271 // TODO
272 // TODO
272 // std::for_each(
273 // std::for_each(
273 // std::begin(*serie), std::end(*serie), [&minValue, &maxValue](const auto& v) {
274 // std::begin(*serie), std::end(*serie), [&minValue, &maxValue](const
274 // minValue = std::min({ minValue, std::min_element(v.begin(),v.end()) });
275 // auto& v) {
275 // maxValue = std::max({ maxValue, std::max_element(v.begin(),v.end()) });
276 // minValue = std::min({ minValue,
276 // });
277 // std::min_element(v.begin(),v.end()) }); maxValue = std::max({
278 // maxValue, std::max_element(v.begin(),v.end()) });
279 // });
277 }
280 }
278
281
279 plot.yAxis->setRange(QCPRange { minValue, maxValue });
282 plot.yAxis->setRange(QCPRange { minValue, maxValue });
@@ -289,7 +292,12 struct PlottablesUpdater<T, typename std::enable_if_t<std::is_base_of<MultiCompo
289 auto dataContainer = QSharedPointer<SqpDataContainer>::create();
292 auto dataContainer = QSharedPointer<SqpDataContainer>::create();
290 if (auto serie = dynamic_cast<MultiComponentTimeSerie*>(&dataSeries))
293 if (auto serie = dynamic_cast<MultiComponentTimeSerie*>(&dataSeries))
291 {
294 {
292 // TODO
295 // TODO
296 std::for_each(std::begin(*serie), std::end(*serie),
297 [&dataContainer, component = plottable.first](const auto& value) {
298 dataContainer->appendGraphData(
299 QCPGraphData(value.t(), value[component]));
300 });
293 }
301 }
294 graph->setData(dataContainer);
302 graph->setData(dataContainer);
295 }
303 }
@@ -8,6 +8,7 import pysciqlopcore
8 import numpy as np
8 import numpy as np
9 import pandas as pds
9 import pandas as pds
10 import requests
10 import requests
11 import copy
11 from spwc.amda import AMDA
12 from spwc.amda import AMDA
12
13
13 amda = AMDA()
14 amda = AMDA()
@@ -22,13 +23,15 def get_sample(metadata,start,stop):
22 elif key == 'type':
23 elif key == 'type':
23 if value == 'vector':
24 if value == 'vector':
24 ts_type = pysciqlopcore.VectorTimeSerie
25 ts_type = pysciqlopcore.VectorTimeSerie
25 tstart=datetime.datetime.utcfromtimestamp(start)
26 elif value == 'multicomponent':
26 tend=datetime.datetime.utcfromtimestamp(stop)
27 ts_type = pysciqlopcore.MultiComponentTimeSerie
28 tstart=datetime.datetime.fromtimestamp(start, tz=timezone.utc)
29 tend=datetime.datetime.fromtimestamp(stop, tz=timezone.utc)
27 df = amda.get_parameter(start_time=tstart, stop_time=tend, parameter_id=param_id)
30 df = amda.get_parameter(start_time=tstart, stop_time=tend, parameter_id=param_id)
28 #t = np.array([d.timestamp()-7200 for d in df.index])
31 #t = np.array([d.timestamp()-7200 for d in df.index])
29 t = np.array([d.timestamp() for d in df.index])
32 t = np.array([d.timestamp() for d in df.index])
30 values = df.values
33 values = df.values
31 return ts_type(t,values)
34 return ts_type(t,values.transpose())
32 return ts_type(1)
35 return ts_type(1)
33 except Exception as e:
36 except Exception as e:
34 print(traceback.format_exc())
37 print(traceback.format_exc())
@@ -38,7 +41,7 def get_sample(metadata,start,stop):
38
41
39 if len(amda.component) is 0:
42 if len(amda.component) is 0:
40 amda.update_inventory()
43 amda.update_inventory()
41 parameters = amda.parameter.copy()
44 parameters = copy.deepcopy(amda.parameter)
42 for name,component in amda.component.items():
45 for name,component in amda.component.items():
43 if 'components' in parameters[component['parameter']]:
46 if 'components' in parameters[component['parameter']]:
44 parameters[component['parameter']]['components'].append(component)
47 parameters[component['parameter']]['components'].append(component)
@@ -50,8 +53,11 for key,parameter in parameters.items():
50 path = f"/AMDA/{parameter['mission']}/{parameter['instrument']}/{parameter['dataset']}/{parameter['name']}"
53 path = f"/AMDA/{parameter['mission']}/{parameter['instrument']}/{parameter['dataset']}/{parameter['name']}"
51 components = [component['name'] for component in parameter.get('components',[])]
54 components = [component['name'] for component in parameter.get('components',[])]
52 metadata = [ (key,item) for key,item in parameter.items() if key is not 'components' ]
55 metadata = [ (key,item) for key,item in parameter.items() if key is not 'components' ]
53 if parameter.get('size',0) is '3':
56 n_components = parameter.get('size',0)
57 if n_components is '3':
54 metadata.append(("type","vector"))
58 metadata.append(("type","vector"))
59 elif n_components !=0:
60 metadata.append(("type","multicomponent"))
55 else:
61 else:
56 metadata.append(("type","scalar"))
62 metadata.append(("type","scalar"))
57 products.append( (path, components, metadata))
63 products.append( (path, components, metadata))
@@ -6,12 +6,39 import numpy as np
6
6
7 someglobal = 1
7 someglobal = 1
8
8
9 def test(name,start,stop):
9 def make_scalar(x):
10 x = np.arange(start, stop)
11 y = np.cos(x/10.)
10 y = np.cos(x/10.)
12 return pysciqlopcore.ScalarTimeSerie(x,y)
11 return pysciqlopcore.ScalarTimeSerie(x,y)
13
12
13 def make_vector(x):
14 v=np.ones((3,len(x)))
15 for i in range(3):
16 v[:][i] = np.cos(x/10. + float(i))
17 return pysciqlopcore.VectorTimeSerie(x,v)
18
19
20 def make_multicomponent(x):
21 v=np.ones((4,len(x)))
22 for i in range(4):
23 v[:][i] = float(i+1) * np.cos(x/10. + float(i))
24 return pysciqlopcore.MultiComponentTimeSerie(x,v)
25
26
27 def get_data(metadata,start,stop):
28 x = np.arange(start, stop)
29 for key,value in metadata:
30 if key == 'xml:id':
31 param_id = value
32 elif key == 'type':
33 if value == 'vector':
34 return make_vector(x)
35 elif value == 'multicomponent':
36 return make_multicomponent(x)
37 return make_scalar(x)
38
39
40
14
41
15 #PythonProviders.register_product(["/folder1/folder2/product1", "/folder1/folder3/product2", "/folder4/folder5/product3"],test)
42 PythonProviders.register_product([("/tests/scalar",[],[("type","scalar")]), ("/tests/vector",[],[("type","vector")]), ("/tests/multicomponent",[],[("type","multicomponent"),('size','4')])],get_data)
16
43
17
44
General Comments 0
You need to be logged in to leave comments. Login now