From dce5077d4598bab98a1e519d756e8b50c04bac4e 2019-05-26 15:27:49 From: Alexis Jeandet Date: 2019-05-26 15:27:49 Subject: [PATCH] Some added fake specro and switched to new spwc getting rid of DataFrames Signed-off-by: Alexis Jeandet --- diff --git a/core b/core index 39bf3ff..698d7cf 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 39bf3ff40b41fc01170241f3e471c708c866118b +Subproject commit 698d7cfa01b05427c2377ce2799f1290b9eab2ca diff --git a/gui/src/Visualization/VisualizationGraphHelper.cpp b/gui/src/Visualization/VisualizationGraphHelper.cpp index 198255f..2039998 100644 --- a/gui/src/Visualization/VisualizationGraphHelper.cpp +++ b/gui/src/Visualization/VisualizationGraphHelper.cpp @@ -271,8 +271,8 @@ struct PlottablesUpdaterv() ); - maxValue = std::max( maxValue, std::max_element(v.begin(), v.end())->v() ); + minValue = std::min(minValue, std::min_element(v.begin(), v.end())->v()); + maxValue = std::max(maxValue, std::max_element(v.begin(), v.end())->v()); }); } plot.yAxis->setRange(QCPRange { minValue, maxValue }); @@ -329,25 +329,58 @@ struct PlottablesUpdatersetRange(QCPRange { min, max }); // } + double minValue = 0., maxValue = 0.; + if (auto serie = dynamic_cast(&dataSeries)) + { + auto& yAxis = serie->axis(1); + if (yAxis.size()) + { + minValue = *std::min_element(std::cbegin(yAxis), std::cend(yAxis)); + maxValue = *std::max_element(std::cbegin(yAxis), std::cend(yAxis)); + } + } + plot.yAxis->setRange(QCPRange { minValue, maxValue }); } static void updatePlottables( T& dataSeries, PlottablesMap& plottables, const DateTimeRange& range, bool rescaleAxes) { // TODO - // if (plottables.empty()) - // { - // qCDebug(LOG_VisualizationGraphHelper()) - // << QObject::tr("Can't update spectrogram: no colormap has been - // associated"); - // return; - // } + if (plottables.empty()) + { + qCDebug(LOG_VisualizationGraphHelper()) + << QObject::tr("Can't update spectrogram: no colormap has been associated"); + return; + } - // // Gets the colormap to update (normally there is only one colormap) - // Q_ASSERT(plottables.size() == 1); - // auto colormap = dynamic_cast(plottables.at(0)); - // Q_ASSERT(colormap != nullptr); + // // Gets the colormap to update (normally there is only one colormap) + Q_ASSERT(plottables.size() == 1); + auto colormap = dynamic_cast(plottables.at(0)); + Q_ASSERT(colormap != nullptr); + if (auto serie = dynamic_cast(&dataSeries)) + { + colormap->data()->setSize(serie->shape()[0], serie->shape()[1]); + if (serie->size(0)) + { + colormap->data()->setRange( + QCPRange { serie->begin()->t(), (serie->end() - 1)->t() }, + QCPRange { 1., 1000. }); + for (int x_index = 0; x_index < serie->shape()[0]; x_index++) + { + auto pixline = (*serie)[x_index]; + for (int y_index = 0; y_index < serie->shape()[1]; y_index++) + { + auto value = pixline[y_index]; + colormap->data()->setCell(x_index, y_index, value); + if (std::isnan(value)) + { + colormap->data()->setAlpha(x_index, y_index, 0); + } + } + } + } + } // dataSeries.lockRead(); // // Processing spectrogram data for display in QCustomPlot @@ -389,12 +422,12 @@ struct PlottablesUpdaterparentPlot(); - - // if (rescaleAxes) - // { - // plot->rescaleAxes(); - // } + auto plot = colormap->parentPlot(); + setPlotYAxisRange(dataSeries, {}, *plot); + if (rescaleAxes) + { + plot->rescaleAxes(); + } } }; diff --git a/plugins/python_providers/resources/amda.py b/plugins/python_providers/resources/amda.py index 7d9e3cc..5f83387 100644 --- a/plugins/python_providers/resources/amda.py +++ b/plugins/python_providers/resources/amda.py @@ -4,7 +4,6 @@ from datetime import datetime, timedelta, timezone import PythonProviders import pysciqlopcore import numpy as np -import pandas as pds import requests import copy from spwc.amda import AMDA @@ -27,10 +26,8 @@ def get_sample(metadata,start,stop): default_ctor_args = (0,2) tstart=datetime.fromtimestamp(start, tz=timezone.utc) tend=datetime.fromtimestamp(stop, tz=timezone.utc) - df = amda.get_parameter(start_time=tstart, stop_time=tend, parameter_id=param_id, method="REST") - t = np.array([d.timestamp() for d in df.index]) - values = df.values - return ts_type(t,values) + var = amda.get_parameter(start_time=tstart, stop_time=tend, parameter_id=param_id, method="REST") + return ts_type(var.time,var.data) except Exception as e: print(traceback.format_exc()) print("Error in amda.py ",str(e)) @@ -55,7 +52,10 @@ for key,parameter in parameters.items(): if n_components is '3': metadata.append(("type","vector")) elif n_components !=0: - metadata.append(("type","multicomponent")) + if parameter.get('display_type','')=="spectrogram": + metadata.append(("type","spectrogram")) + else: + metadata.append(("type","multicomponent")) else: metadata.append(("type","scalar")) products.append( (path, components, metadata)) diff --git a/plugins/python_providers/resources/test.py b/plugins/python_providers/resources/test.py index 15ca60c..8bb1bf6 100644 --- a/plugins/python_providers/resources/test.py +++ b/plugins/python_providers/resources/test.py @@ -8,25 +8,30 @@ from spwc.cache import _cache from spwc.common.datetime_range import DateTimeRange from functools import partial from datetime import datetime, timedelta, timezone - -someglobal = 1 +from spwc.common.variable import SpwcVariable def make_scalar(x): y = np.cos(x/10.) - return pds.DataFrame(index=[datetime.fromtimestamp(t, tz=timezone.utc) for t in x], data=y) + return SpwcVariable(time=x, data=y) def make_vector(x): v=np.ones((len(x),3)) for i in range(3): v.transpose()[:][i] = np.cos(x/10. + float(i)) + (100. * np.cos(x/10000. + float(i))) - return pds.DataFrame(index=[datetime.fromtimestamp(t, tz=timezone.utc) for t in x], data=v) + return SpwcVariable(time=x, data=v) def make_multicomponent(x): v=np.ones((len(x),4)) for i in range(4): v.transpose()[:][i] = float(i+1) * np.cos(x/10. + float(i)) - return pds.DataFrame(index=[datetime.fromtimestamp(t, tz=timezone.utc) for t in x], data=v) + return SpwcVariable(time=x, data=v) + +def make_spectrogram(x): + v=np.ones((len(x),32)) + for i in range(32): + v.transpose()[:][i] = 100.*(2.+ float(i+1) * np.cos(x/1024. + float(i))) + return SpwcVariable(time=x, data=v) def _get_data(p_type, start, stop): @@ -40,6 +45,8 @@ def _get_data(p_type, start, stop): return make_vector(x) if p_type == 'multicomponent': return make_multicomponent(x) + if p_type == 'spectrogram': + return make_spectrogram(np.arange(math.ceil(start), math.floor(stop),15.)) return None def get_data(metadata,start,stop): @@ -56,19 +63,20 @@ def get_data(metadata,start,stop): elif value == 'multicomponent': ts_type = pysciqlopcore.MultiComponentTimeSerie default_ctor_args = (0,2) + elif value == 'spectrogram': + ts_type = lambda t,values: pysciqlopcore.SpectrogramTimeSerie(t,np.logspace(1,3,32),values) + default_ctor_args = (0,2) if key == 'cache' and value == 'true': use_cache = True if use_cache: cache_product = f"tests/{p_type}" - df = _cache.get_data(cache_product, DateTimeRange(datetime.fromtimestamp(start, tz=timezone.utc), datetime.fromtimestamp(stop, tz=timezone.utc)), + var = _cache.get_data(cache_product, DateTimeRange(datetime.fromtimestamp(start, tz=timezone.utc), datetime.fromtimestamp(stop, tz=timezone.utc)), partial(_get_data, p_type), fragment_hours=24) else: print("No Cache") - df = _get_data(p_type, start, stop) - t = np.array([d.timestamp() for d in df.index]) - values = df.values - return ts_type(t,values) + var = _get_data(p_type, start, stop) + return ts_type(var.time,var.data) except Exception as e: print(traceback.format_exc()) print("Error in test.py ",str(e)) @@ -78,6 +86,7 @@ products = [ ("/tests/without_cache/scalar",[],[("type","scalar")]), ("/tests/without_cache/vector",[],[("type","vector")]), ("/tests/without_cache/multicomponent",[],[("type","multicomponent"),('size','4')]), + ("/tests/without_cache/spectrogram",[],[("type","spectrogram"),('size','32')]), ("/tests/with_cache/scalar",[],[("type","scalar"), ("cache","true")]), ("/tests/with_cache/vector",[],[("type","vector"), ("cache","true")]), ("/tests/with_cache/multicomponent",[],[("type","multicomponent"),('size','4'), ("cache","true")])