From db5304cf6c8cd01ed7b6a5c718f447999e02420b 2019-04-09 17:42:47 From: Alexis Jeandet Date: 2019-04-09 17:42:47 Subject: [PATCH] MultiComponent TS almost complete Signed-off-by: Alexis Jeandet --- diff --git a/core b/core index 41273d8..9a080a3 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 41273d8529cddde1c8b6bcea03d71d9cd1a18c06 +Subproject commit 9a080a34054c21a67236f761e8843005c07ff0ba diff --git a/gui/src/Visualization/AxisRenderingUtils.cpp b/gui/src/Visualization/AxisRenderingUtils.cpp index 779b62e..f6e9dc0 100644 --- a/gui/src/Visualization/AxisRenderingUtils.cpp +++ b/gui/src/Visualization/AxisRenderingUtils.cpp @@ -95,7 +95,8 @@ struct AxisSetter template struct AxisSetter::value - or std::is_base_of::value>> + or std::is_base_of::value + or std::is_base_of::value>> { static void setProperties(QCustomPlot&, SqpColorScale&) { @@ -204,6 +205,9 @@ std::unique_ptr IAxisHelperFactory::create(Variable2& variable) noe case DataSeriesType::VECTOR: return std::make_unique>( std::dynamic_pointer_cast(variable.data())); + case DataSeriesType::MULTICOMPONENT: + return std::make_unique>( + std::dynamic_pointer_cast(variable.data())); default: // Creates default helper break; diff --git a/gui/src/Visualization/PlottablesRenderingUtils.cpp b/gui/src/Visualization/PlottablesRenderingUtils.cpp index d2ca2fb..65b723d 100644 --- a/gui/src/Visualization/PlottablesRenderingUtils.cpp +++ b/gui/src/Visualization/PlottablesRenderingUtils.cpp @@ -33,7 +33,8 @@ struct PlottablesSetter template struct PlottablesSetter::value - or std::is_base_of::value>> + or std::is_base_of::value + or std::is_base_of::value>> { static void setProperties(PlottablesMap& plottables) { @@ -124,6 +125,8 @@ std::unique_ptr IPlottablesHelperFactory::create(Variable2& v return std::make_unique>(); case DataSeriesType::VECTOR: return std::make_unique>(); + case DataSeriesType::MULTICOMPONENT: + return std::make_unique>(); default: // Returns default helper break; diff --git a/gui/src/Visualization/VisualizationGraphHelper.cpp b/gui/src/Visualization/VisualizationGraphHelper.cpp index 1a89d27..570baa6 100644 --- a/gui/src/Visualization/VisualizationGraphHelper.cpp +++ b/gui/src/Visualization/VisualizationGraphHelper.cpp @@ -261,7 +261,8 @@ struct PlottablesUpdater -struct PlottablesUpdater::value>> +struct PlottablesUpdater::value>> { static void setPlotYAxisRange(T& dataSeries, const DateTimeRange& xAxisRange, QCustomPlot& plot) { @@ -269,11 +270,13 @@ struct PlottablesUpdater(&dataSeries)) { // TODO -// std::for_each( -// std::begin(*serie), std::end(*serie), [&minValue, &maxValue](const auto& v) { -// minValue = std::min({ minValue, std::min_element(v.begin(),v.end()) }); -// maxValue = std::max({ maxValue, std::max_element(v.begin(),v.end()) }); -// }); + // std::for_each( + // std::begin(*serie), std::end(*serie), [&minValue, &maxValue](const + // auto& v) { + // minValue = std::min({ minValue, + // std::min_element(v.begin(),v.end()) }); maxValue = std::max({ + // maxValue, std::max_element(v.begin(),v.end()) }); + // }); } plot.yAxis->setRange(QCPRange { minValue, maxValue }); @@ -289,7 +292,12 @@ struct PlottablesUpdater::create(); if (auto serie = dynamic_cast(&dataSeries)) { -// TODO + // TODO + std::for_each(std::begin(*serie), std::end(*serie), + [&dataContainer, component = plottable.first](const auto& value) { + dataContainer->appendGraphData( + QCPGraphData(value.t(), value[component])); + }); } graph->setData(dataContainer); } diff --git a/plugins/python_providers/resources/amda.py b/plugins/python_providers/resources/amda.py index c4b469f..399f8f0 100644 --- a/plugins/python_providers/resources/amda.py +++ b/plugins/python_providers/resources/amda.py @@ -8,6 +8,7 @@ import pysciqlopcore import numpy as np import pandas as pds import requests +import copy from spwc.amda import AMDA amda = AMDA() @@ -22,13 +23,15 @@ def get_sample(metadata,start,stop): elif key == 'type': if value == 'vector': ts_type = pysciqlopcore.VectorTimeSerie - tstart=datetime.datetime.utcfromtimestamp(start) - tend=datetime.datetime.utcfromtimestamp(stop) + elif value == 'multicomponent': + ts_type = pysciqlopcore.MultiComponentTimeSerie + tstart=datetime.datetime.fromtimestamp(start, tz=timezone.utc) + tend=datetime.datetime.fromtimestamp(stop, tz=timezone.utc) df = amda.get_parameter(start_time=tstart, stop_time=tend, parameter_id=param_id) #t = np.array([d.timestamp()-7200 for d in df.index]) t = np.array([d.timestamp() for d in df.index]) values = df.values - return ts_type(t,values) + return ts_type(t,values.transpose()) return ts_type(1) except Exception as e: print(traceback.format_exc()) @@ -38,7 +41,7 @@ def get_sample(metadata,start,stop): if len(amda.component) is 0: amda.update_inventory() -parameters = amda.parameter.copy() +parameters = copy.deepcopy(amda.parameter) for name,component in amda.component.items(): if 'components' in parameters[component['parameter']]: parameters[component['parameter']]['components'].append(component) @@ -50,8 +53,11 @@ for key,parameter in parameters.items(): path = f"/AMDA/{parameter['mission']}/{parameter['instrument']}/{parameter['dataset']}/{parameter['name']}" components = [component['name'] for component in parameter.get('components',[])] metadata = [ (key,item) for key,item in parameter.items() if key is not 'components' ] - if parameter.get('size',0) is '3': + n_components = parameter.get('size',0) + if n_components is '3': metadata.append(("type","vector")) + elif n_components !=0: + 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 467e704..2e0f27e 100644 --- a/plugins/python_providers/resources/test.py +++ b/plugins/python_providers/resources/test.py @@ -6,12 +6,39 @@ import numpy as np someglobal = 1 -def test(name,start,stop): - x = np.arange(start, stop) +def make_scalar(x): y = np.cos(x/10.) return pysciqlopcore.ScalarTimeSerie(x,y) +def make_vector(x): + v=np.ones((3,len(x))) + for i in range(3): + v[:][i] = np.cos(x/10. + float(i)) + return pysciqlopcore.VectorTimeSerie(x,v) + + +def make_multicomponent(x): + v=np.ones((4,len(x))) + for i in range(4): + v[:][i] = float(i+1) * np.cos(x/10. + float(i)) + return pysciqlopcore.MultiComponentTimeSerie(x,v) + + +def get_data(metadata,start,stop): + x = np.arange(start, stop) + for key,value in metadata: + if key == 'xml:id': + param_id = value + elif key == 'type': + if value == 'vector': + return make_vector(x) + elif value == 'multicomponent': + return make_multicomponent(x) + return make_scalar(x) + + + -#PythonProviders.register_product(["/folder1/folder2/product1", "/folder1/folder3/product2", "/folder4/folder5/product3"],test) +PythonProviders.register_product([("/tests/scalar",[],[("type","scalar")]), ("/tests/vector",[],[("type","vector")]), ("/tests/multicomponent",[],[("type","multicomponent"),('size','4')])],get_data)