@@ -1,1 +1,1 | |||||
1 | Subproject commit 39bf3ff40b41fc01170241f3e471c708c866118b |
|
1 | Subproject commit 698d7cfa01b05427c2377ce2799f1290b9eab2ca |
@@ -271,8 +271,8 struct PlottablesUpdater<T, | |||||
271 | { |
|
271 | { | |
272 | std::for_each( |
|
272 | std::for_each( | |
273 | std::begin(*serie), std::end(*serie), [&minValue, &maxValue](const auto& v) { |
|
273 | std::begin(*serie), std::end(*serie), [&minValue, &maxValue](const auto& v) { | |
274 |
minValue = std::min( |
|
274 | minValue = std::min(minValue, std::min_element(v.begin(), v.end())->v()); | |
275 |
maxValue = std::max( |
|
275 | maxValue = std::max(maxValue, std::max_element(v.begin(), v.end())->v()); | |
276 | }); |
|
276 | }); | |
277 | } |
|
277 | } | |
278 | plot.yAxis->setRange(QCPRange { minValue, maxValue }); |
|
278 | plot.yAxis->setRange(QCPRange { minValue, maxValue }); | |
@@ -329,25 +329,58 struct PlottablesUpdater<T, | |||||
329 | // { |
|
329 | // { | |
330 | // plot.yAxis->setRange(QCPRange { min, max }); |
|
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 | static void updatePlottables( |
|
345 | static void updatePlottables( | |
335 | T& dataSeries, PlottablesMap& plottables, const DateTimeRange& range, bool rescaleAxes) |
|
346 | T& dataSeries, PlottablesMap& plottables, const DateTimeRange& range, bool rescaleAxes) | |
336 | { |
|
347 | { | |
337 | // TODO |
|
348 | // TODO | |
338 |
|
|
349 | if (plottables.empty()) | |
339 |
|
|
350 | { | |
340 |
|
|
351 | qCDebug(LOG_VisualizationGraphHelper()) | |
341 |
|
|
352 | << QObject::tr("Can't update spectrogram: no colormap has been associated"); | |
342 | // associated"); |
|
353 | return; | |
343 | // return; |
|
354 | } | |
344 | // } |
|
|||
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 | // dataSeries.lockRead(); |
|
384 | // dataSeries.lockRead(); | |
352 |
|
385 | |||
353 | // // Processing spectrogram data for display in QCustomPlot |
|
386 | // // Processing spectrogram data for display in QCustomPlot | |
@@ -389,12 +422,12 struct PlottablesUpdater<T, | |||||
389 | // } |
|
422 | // } | |
390 |
|
423 | |||
391 | // // Rescales axes |
|
424 | // // Rescales axes | |
392 |
|
|
425 | auto plot = colormap->parentPlot(); | |
393 |
|
426 | setPlotYAxisRange(dataSeries, {}, *plot); | ||
394 |
|
|
427 | if (rescaleAxes) | |
395 |
|
|
428 | { | |
396 |
|
|
429 | plot->rescaleAxes(); | |
397 |
|
|
430 | } | |
398 | } |
|
431 | } | |
399 | }; |
|
432 | }; | |
400 |
|
433 |
@@ -4,7 +4,6 from datetime import datetime, timedelta, timezone | |||||
4 | import PythonProviders |
|
4 | import PythonProviders | |
5 | import pysciqlopcore |
|
5 | import pysciqlopcore | |
6 | import numpy as np |
|
6 | import numpy as np | |
7 | import pandas as pds |
|
|||
8 | import requests |
|
7 | import requests | |
9 | import copy |
|
8 | import copy | |
10 | from spwc.amda import AMDA |
|
9 | from spwc.amda import AMDA | |
@@ -27,10 +26,8 def get_sample(metadata,start,stop): | |||||
27 | default_ctor_args = (0,2) |
|
26 | default_ctor_args = (0,2) | |
28 | tstart=datetime.fromtimestamp(start, tz=timezone.utc) |
|
27 | tstart=datetime.fromtimestamp(start, tz=timezone.utc) | |
29 | tend=datetime.fromtimestamp(stop, tz=timezone.utc) |
|
28 | tend=datetime.fromtimestamp(stop, tz=timezone.utc) | |
30 |
|
|
29 | var = 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]) |
|
30 | return ts_type(var.time,var.data) | |
32 | values = df.values |
|
|||
33 | return ts_type(t,values) |
|
|||
34 | except Exception as e: |
|
31 | except Exception as e: | |
35 | print(traceback.format_exc()) |
|
32 | print(traceback.format_exc()) | |
36 | print("Error in amda.py ",str(e)) |
|
33 | print("Error in amda.py ",str(e)) | |
@@ -55,7 +52,10 for key,parameter in parameters.items(): | |||||
55 | if n_components is '3': |
|
52 | if n_components is '3': | |
56 | metadata.append(("type","vector")) |
|
53 | metadata.append(("type","vector")) | |
57 | elif n_components !=0: |
|
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 | else: |
|
59 | else: | |
60 | metadata.append(("type","scalar")) |
|
60 | metadata.append(("type","scalar")) | |
61 | products.append( (path, components, metadata)) |
|
61 | products.append( (path, components, metadata)) |
@@ -8,25 +8,30 from spwc.cache import _cache | |||||
8 | from spwc.common.datetime_range import DateTimeRange |
|
8 | from spwc.common.datetime_range import DateTimeRange | |
9 | from functools import partial |
|
9 | from functools import partial | |
10 | from datetime import datetime, timedelta, timezone |
|
10 | from datetime import datetime, timedelta, timezone | |
11 |
|
11 | from spwc.common.variable import SpwcVariable | ||
12 | someglobal = 1 |
|
|||
13 |
|
12 | |||
14 | def make_scalar(x): |
|
13 | def make_scalar(x): | |
15 | y = np.cos(x/10.) |
|
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 | def make_vector(x): |
|
17 | def make_vector(x): | |
19 | v=np.ones((len(x),3)) |
|
18 | v=np.ones((len(x),3)) | |
20 | for i in range(3): |
|
19 | for i in range(3): | |
21 | v.transpose()[:][i] = np.cos(x/10. + float(i)) + (100. * np.cos(x/10000. + float(i))) |
|
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 | def make_multicomponent(x): |
|
24 | def make_multicomponent(x): | |
26 | v=np.ones((len(x),4)) |
|
25 | v=np.ones((len(x),4)) | |
27 | for i in range(4): |
|
26 | for i in range(4): | |
28 | v.transpose()[:][i] = float(i+1) * np.cos(x/10. + float(i)) |
|
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 | def _get_data(p_type, start, stop): |
|
37 | def _get_data(p_type, start, stop): | |
@@ -40,6 +45,8 def _get_data(p_type, start, stop): | |||||
40 | return make_vector(x) |
|
45 | return make_vector(x) | |
41 | if p_type == 'multicomponent': |
|
46 | if p_type == 'multicomponent': | |
42 | return make_multicomponent(x) |
|
47 | return make_multicomponent(x) | |
|
48 | if p_type == 'spectrogram': | |||
|
49 | return make_spectrogram(np.arange(math.ceil(start), math.floor(stop),15.)) | |||
43 | return None |
|
50 | return None | |
44 |
|
51 | |||
45 | def get_data(metadata,start,stop): |
|
52 | def get_data(metadata,start,stop): | |
@@ -56,19 +63,20 def get_data(metadata,start,stop): | |||||
56 | elif value == 'multicomponent': |
|
63 | elif value == 'multicomponent': | |
57 | ts_type = pysciqlopcore.MultiComponentTimeSerie |
|
64 | ts_type = pysciqlopcore.MultiComponentTimeSerie | |
58 | default_ctor_args = (0,2) |
|
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 | if key == 'cache' and value == 'true': |
|
69 | if key == 'cache' and value == 'true': | |
60 | use_cache = True |
|
70 | use_cache = True | |
61 | if use_cache: |
|
71 | if use_cache: | |
62 | cache_product = f"tests/{p_type}" |
|
72 | cache_product = f"tests/{p_type}" | |
63 |
|
|
73 | var = _cache.get_data(cache_product, DateTimeRange(datetime.fromtimestamp(start, tz=timezone.utc), datetime.fromtimestamp(stop, tz=timezone.utc)), | |
64 | partial(_get_data, p_type), |
|
74 | partial(_get_data, p_type), | |
65 | fragment_hours=24) |
|
75 | fragment_hours=24) | |
66 | else: |
|
76 | else: | |
67 | print("No Cache") |
|
77 | print("No Cache") | |
68 |
|
|
78 | var = _get_data(p_type, start, stop) | |
69 | t = np.array([d.timestamp() for d in df.index]) |
|
79 | return ts_type(var.time,var.data) | |
70 | values = df.values |
|
|||
71 | return ts_type(t,values) |
|
|||
72 | except Exception as e: |
|
80 | except Exception as e: | |
73 | print(traceback.format_exc()) |
|
81 | print(traceback.format_exc()) | |
74 | print("Error in test.py ",str(e)) |
|
82 | print("Error in test.py ",str(e)) | |
@@ -78,6 +86,7 products = [ | |||||
78 | ("/tests/without_cache/scalar",[],[("type","scalar")]), |
|
86 | ("/tests/without_cache/scalar",[],[("type","scalar")]), | |
79 | ("/tests/without_cache/vector",[],[("type","vector")]), |
|
87 | ("/tests/without_cache/vector",[],[("type","vector")]), | |
80 | ("/tests/without_cache/multicomponent",[],[("type","multicomponent"),('size','4')]), |
|
88 | ("/tests/without_cache/multicomponent",[],[("type","multicomponent"),('size','4')]), | |
|
89 | ("/tests/without_cache/spectrogram",[],[("type","spectrogram"),('size','32')]), | |||
81 | ("/tests/with_cache/scalar",[],[("type","scalar"), ("cache","true")]), |
|
90 | ("/tests/with_cache/scalar",[],[("type","scalar"), ("cache","true")]), | |
82 | ("/tests/with_cache/vector",[],[("type","vector"), ("cache","true")]), |
|
91 | ("/tests/with_cache/vector",[],[("type","vector"), ("cache","true")]), | |
83 | ("/tests/with_cache/multicomponent",[],[("type","multicomponent"),('size','4'), ("cache","true")]) |
|
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