@@ -1,1 +1,1 | |||
|
1 | Subproject commit 39bf3ff40b41fc01170241f3e471c708c866118b | |
|
1 | Subproject commit 698d7cfa01b05427c2377ce2799f1290b9eab2ca |
@@ -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 |
|
|
|
339 |
|
|
|
340 |
|
|
|
341 |
|
|
|
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 |
|
|
|
393 | ||
|
394 |
|
|
|
395 |
|
|
|
396 |
|
|
|
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 |
|
|
|
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,6 +52,9 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: |
|
55 | if parameter.get('display_type','')=="spectrogram": | |
|
56 | metadata.append(("type","spectrogram")) | |
|
57 | else: | |
|
58 | 58 | metadata.append(("type","multicomponent")) |
|
59 | 59 | else: |
|
60 | 60 | metadata.append(("type","scalar")) |
@@ -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 |
|
|
|
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 |
|
|
|
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