##// END OF EJS Templates
Some added fake specro and switched to new spwc getting rid of DataFrames...
jeandet -
r1464:dce5077d4598
parent child
Show More
@@ -1,1 +1,1
1 Subproject commit 39bf3ff40b41fc01170241f3e471c708c866118b
1 Subproject commit 698d7cfa01b05427c2377ce2799f1290b9eab2ca
@@ -271,8 +271,8 struct PlottablesUpdater<T,
271 271 {
272 272 std::for_each(
273 273 std::begin(*serie), std::end(*serie), [&minValue, &maxValue](const auto& v) {
274 minValue = std::min( minValue, std::min_element(v.begin(), v.end())->v() );
275 maxValue = std::max( maxValue, std::max_element(v.begin(), v.end())->v() );
274 minValue = std::min(minValue, std::min_element(v.begin(), v.end())->v());
275 maxValue = std::max(maxValue, std::max_element(v.begin(), v.end())->v());
276 276 });
277 277 }
278 278 plot.yAxis->setRange(QCPRange { minValue, maxValue });
@@ -329,25 +329,58 struct PlottablesUpdater<T,
329 329 // {
330 330 // plot.yAxis->setRange(QCPRange { min, max });
331 331 // }
332 double minValue = 0., maxValue = 0.;
333 if (auto serie = dynamic_cast<SpectrogramTimeSerie*>(&dataSeries))
334 {
335 auto& yAxis = serie->axis(1);
336 if (yAxis.size())
337 {
338 minValue = *std::min_element(std::cbegin(yAxis), std::cend(yAxis));
339 maxValue = *std::max_element(std::cbegin(yAxis), std::cend(yAxis));
340 }
341 }
342 plot.yAxis->setRange(QCPRange { minValue, maxValue });
332 343 }
333 344
334 345 static void updatePlottables(
335 346 T& dataSeries, PlottablesMap& plottables, const DateTimeRange& range, bool rescaleAxes)
336 347 {
337 348 // TODO
338 // if (plottables.empty())
339 // {
340 // qCDebug(LOG_VisualizationGraphHelper())
341 // << QObject::tr("Can't update spectrogram: no colormap has been
342 // associated");
343 // return;
344 // }
349 if (plottables.empty())
350 {
351 qCDebug(LOG_VisualizationGraphHelper())
352 << QObject::tr("Can't update spectrogram: no colormap has been associated");
353 return;
354 }
345 355
346 // // Gets the colormap to update (normally there is only one colormap)
347 // Q_ASSERT(plottables.size() == 1);
348 // auto colormap = dynamic_cast<QCPColorMap*>(plottables.at(0));
349 // Q_ASSERT(colormap != nullptr);
350 356
357 // // Gets the colormap to update (normally there is only one colormap)
358 Q_ASSERT(plottables.size() == 1);
359 auto colormap = dynamic_cast<QCPColorMap*>(plottables.at(0));
360 Q_ASSERT(colormap != nullptr);
361 if (auto serie = dynamic_cast<SpectrogramTimeSerie*>(&dataSeries))
362 {
363 colormap->data()->setSize(serie->shape()[0], serie->shape()[1]);
364 if (serie->size(0))
365 {
366 colormap->data()->setRange(
367 QCPRange { serie->begin()->t(), (serie->end() - 1)->t() },
368 QCPRange { 1., 1000. });
369 for (int x_index = 0; x_index < serie->shape()[0]; x_index++)
370 {
371 auto pixline = (*serie)[x_index];
372 for (int y_index = 0; y_index < serie->shape()[1]; y_index++)
373 {
374 auto value = pixline[y_index];
375 colormap->data()->setCell(x_index, y_index, value);
376 if (std::isnan(value))
377 {
378 colormap->data()->setAlpha(x_index, y_index, 0);
379 }
380 }
381 }
382 }
383 }
351 384 // dataSeries.lockRead();
352 385
353 386 // // Processing spectrogram data for display in QCustomPlot
@@ -389,12 +422,12 struct PlottablesUpdater<T,
389 422 // }
390 423
391 424 // // Rescales axes
392 // auto plot = colormap->parentPlot();
393
394 // if (rescaleAxes)
395 // {
396 // plot->rescaleAxes();
397 // }
425 auto plot = colormap->parentPlot();
426 setPlotYAxisRange(dataSeries, {}, *plot);
427 if (rescaleAxes)
428 {
429 plot->rescaleAxes();
430 }
398 431 }
399 432 };
400 433
@@ -4,7 +4,6 from datetime import datetime, timedelta, timezone
4 4 import PythonProviders
5 5 import pysciqlopcore
6 6 import numpy as np
7 import pandas as pds
8 7 import requests
9 8 import copy
10 9 from spwc.amda import AMDA
@@ -27,10 +26,8 def get_sample(metadata,start,stop):
27 26 default_ctor_args = (0,2)
28 27 tstart=datetime.fromtimestamp(start, tz=timezone.utc)
29 28 tend=datetime.fromtimestamp(stop, tz=timezone.utc)
30 df = amda.get_parameter(start_time=tstart, stop_time=tend, parameter_id=param_id, method="REST")
31 t = np.array([d.timestamp() for d in df.index])
32 values = df.values
33 return ts_type(t,values)
29 var = amda.get_parameter(start_time=tstart, stop_time=tend, parameter_id=param_id, method="REST")
30 return ts_type(var.time,var.data)
34 31 except Exception as e:
35 32 print(traceback.format_exc())
36 33 print("Error in amda.py ",str(e))
@@ -55,7 +52,10 for key,parameter in parameters.items():
55 52 if n_components is '3':
56 53 metadata.append(("type","vector"))
57 54 elif n_components !=0:
58 metadata.append(("type","multicomponent"))
55 if parameter.get('display_type','')=="spectrogram":
56 metadata.append(("type","spectrogram"))
57 else:
58 metadata.append(("type","multicomponent"))
59 59 else:
60 60 metadata.append(("type","scalar"))
61 61 products.append( (path, components, metadata))
@@ -8,25 +8,30 from spwc.cache import _cache
8 8 from spwc.common.datetime_range import DateTimeRange
9 9 from functools import partial
10 10 from datetime import datetime, timedelta, timezone
11
12 someglobal = 1
11 from spwc.common.variable import SpwcVariable
13 12
14 13 def make_scalar(x):
15 14 y = np.cos(x/10.)
16 return pds.DataFrame(index=[datetime.fromtimestamp(t, tz=timezone.utc) for t in x], data=y)
15 return SpwcVariable(time=x, data=y)
17 16
18 17 def make_vector(x):
19 18 v=np.ones((len(x),3))
20 19 for i in range(3):
21 20 v.transpose()[:][i] = np.cos(x/10. + float(i)) + (100. * np.cos(x/10000. + float(i)))
22 return pds.DataFrame(index=[datetime.fromtimestamp(t, tz=timezone.utc) for t in x], data=v)
21 return SpwcVariable(time=x, data=v)
23 22
24 23
25 24 def make_multicomponent(x):
26 25 v=np.ones((len(x),4))
27 26 for i in range(4):
28 27 v.transpose()[:][i] = float(i+1) * np.cos(x/10. + float(i))
29 return pds.DataFrame(index=[datetime.fromtimestamp(t, tz=timezone.utc) for t in x], data=v)
28 return SpwcVariable(time=x, data=v)
29
30 def make_spectrogram(x):
31 v=np.ones((len(x),32))
32 for i in range(32):
33 v.transpose()[:][i] = 100.*(2.+ float(i+1) * np.cos(x/1024. + float(i)))
34 return SpwcVariable(time=x, data=v)
30 35
31 36
32 37 def _get_data(p_type, start, stop):
@@ -40,6 +45,8 def _get_data(p_type, start, stop):
40 45 return make_vector(x)
41 46 if p_type == 'multicomponent':
42 47 return make_multicomponent(x)
48 if p_type == 'spectrogram':
49 return make_spectrogram(np.arange(math.ceil(start), math.floor(stop),15.))
43 50 return None
44 51
45 52 def get_data(metadata,start,stop):
@@ -56,19 +63,20 def get_data(metadata,start,stop):
56 63 elif value == 'multicomponent':
57 64 ts_type = pysciqlopcore.MultiComponentTimeSerie
58 65 default_ctor_args = (0,2)
66 elif value == 'spectrogram':
67 ts_type = lambda t,values: pysciqlopcore.SpectrogramTimeSerie(t,np.logspace(1,3,32),values)
68 default_ctor_args = (0,2)
59 69 if key == 'cache' and value == 'true':
60 70 use_cache = True
61 71 if use_cache:
62 72 cache_product = f"tests/{p_type}"
63 df = _cache.get_data(cache_product, DateTimeRange(datetime.fromtimestamp(start, tz=timezone.utc), datetime.fromtimestamp(stop, tz=timezone.utc)),
73 var = _cache.get_data(cache_product, DateTimeRange(datetime.fromtimestamp(start, tz=timezone.utc), datetime.fromtimestamp(stop, tz=timezone.utc)),
64 74 partial(_get_data, p_type),
65 75 fragment_hours=24)
66 76 else:
67 77 print("No Cache")
68 df = _get_data(p_type, start, stop)
69 t = np.array([d.timestamp() for d in df.index])
70 values = df.values
71 return ts_type(t,values)
78 var = _get_data(p_type, start, stop)
79 return ts_type(var.time,var.data)
72 80 except Exception as e:
73 81 print(traceback.format_exc())
74 82 print("Error in test.py ",str(e))
@@ -78,6 +86,7 products = [
78 86 ("/tests/without_cache/scalar",[],[("type","scalar")]),
79 87 ("/tests/without_cache/vector",[],[("type","vector")]),
80 88 ("/tests/without_cache/multicomponent",[],[("type","multicomponent"),('size','4')]),
89 ("/tests/without_cache/spectrogram",[],[("type","spectrogram"),('size','32')]),
81 90 ("/tests/with_cache/scalar",[],[("type","scalar"), ("cache","true")]),
82 91 ("/tests/with_cache/vector",[],[("type","vector"), ("cache","true")]),
83 92 ("/tests/with_cache/multicomponent",[],[("type","multicomponent"),('size','4'), ("cache","true")])
General Comments 0
You need to be logged in to leave comments. Login now