##// END OF EJS Templates
Product tree features:...
jeandet -
r1497:1e241bda0af5
parent child
Show More
@@ -1,124 +1,124
1 import traceback
1 import traceback
2 import os
2 import os
3 from datetime import datetime, timedelta, timezone
3 from datetime import datetime, timedelta, timezone
4 from SciQLopBindings import PyDataProvider, Product, VectorTimeSerie, ScalarTimeSerie, DataSeriesType
4 from SciQLopBindings import PyDataProvider, Product, VectorTimeSerie, ScalarTimeSerie, DataSeriesType
5 import numpy as np
5 import numpy as np
6 import requests
6 import requests
7 import copy
7 import copy
8 from spwc.amda import AMDA
8 from spwc.amda import AMDA
9
9
10 amda = AMDA()
10 amda = AMDA()
11
11
12 def amda_make_scalar(var=None):
12 def amda_make_scalar(var=None):
13 if var is None:
13 if var is None:
14 return ((np.array(), np.array()), DataSeriesType.SCALAR)
14 return ((np.array(), np.array()), DataSeriesType.SCALAR)
15 else:
15 else:
16 return ((var.time.copy(),var.data.copy()), DataSeriesType.SCALAR)
16 return ((var.time,var.data), DataSeriesType.SCALAR)
17
17
18 def amda_make_vector(var=None):
18 def amda_make_vector(var=None):
19 if var is None:
19 if var is None:
20 return ((np.array(), np.array()), DataSeriesType.VECTOR)
20 return ((np.array(), np.array()), DataSeriesType.VECTOR)
21 else:
21 else:
22 return ((var.time.copy(),var.data.copy()), DataSeriesType.VECTOR)
22 return ((var.time,var.data), DataSeriesType.VECTOR)
23
23
24 def amda_make_multi_comp(var=None):
24 def amda_make_multi_comp(var=None):
25 if var is None:
25 if var is None:
26 return ((np.array(), np.array()), DataSeriesType.MULTICOMPONENT)
26 return ((np.array(), np.array()), DataSeriesType.MULTICOMPONENT)
27 else:
27 else:
28 return ((var.time.copy(),var.data.copy()), DataSeriesType.MULTICOMPONENT)
28 return ((var.time,var.data), DataSeriesType.MULTICOMPONENT)
29
29
30 def amda_make_spectro(var=None):
30 def amda_make_spectro(var=None):
31 if var is None:
31 if var is None:
32 return ((np.array(), np.array()), DataSeriesType.SPECTROGRAM)
32 return ((np.array(), np.array()), DataSeriesType.SPECTROGRAM)
33 else:
33 else:
34 min_sampling = float(var.meta.get("DATASET_MIN_SAMPLING","nan"))
34 min_sampling = float(var.meta.get("DATASET_MIN_SAMPLING","nan"))
35 max_sampling = float(var.meta.get("DATASET_MAX_SAMPLING","nan"))
35 max_sampling = float(var.meta.get("DATASET_MAX_SAMPLING","nan"))
36 if "PARAMETER_TABLE_MIN_VALUES[1]" in var.meta:
36 if "PARAMETER_TABLE_MIN_VALUES[1]" in var.meta:
37 min_v = np.array([ float(v) for v in var.meta["PARAMETER_TABLE_MIN_VALUES[1]"].split(',') ])
37 min_v = np.array([ float(v) for v in var.meta["PARAMETER_TABLE_MIN_VALUES[1]"].split(',') ])
38 max_v = np.array([ float(v) for v in var.meta["PARAMETER_TABLE_MAX_VALUES[1]"].split(',') ])
38 max_v = np.array([ float(v) for v in var.meta["PARAMETER_TABLE_MAX_VALUES[1]"].split(',') ])
39 y = (max_v + min_v)/2.
39 y = (max_v + min_v)/2.
40 elif "PARAMETER_TABLE_MIN_VALUES[0]" in var.meta:
40 elif "PARAMETER_TABLE_MIN_VALUES[0]" in var.meta:
41 min_v = np.array([ float(v) for v in var.meta["PARAMETER_TABLE_MIN_VALUES[0]"].split(',') ])
41 min_v = np.array([ float(v) for v in var.meta["PARAMETER_TABLE_MIN_VALUES[0]"].split(',') ])
42 max_v = np.array([ float(v) for v in var.meta["PARAMETER_TABLE_MAX_VALUES[0]"].split(',') ])
42 max_v = np.array([ float(v) for v in var.meta["PARAMETER_TABLE_MAX_VALUES[0]"].split(',') ])
43 y = (max_v + min_v)/2.
43 y = (max_v + min_v)/2.
44 else:
44 else:
45 y = np.logspace(1,3,var.data.shape[1])[::-1]
45 y = np.logspace(1,3,var.data.shape[1])[::-1]
46 return ((var.time.copy(),var.data.copy()), DataSeriesType.SPECTROGRAM)
46 return ((var.time,var.data), DataSeriesType.SPECTROGRAM)
47 #return pysciqlopcore.SpectrogramTimeSerie(var.time,y,var.data,min_sampling,max_sampling,True)
47 #return pysciqlopcore.SpectrogramTimeSerie(var.time,y,var.data,min_sampling,max_sampling,True)
48
48
49 def amda_get_sample(metadata,start,stop):
49 def amda_get_sample(metadata,start,stop):
50 ts_type = amda_make_scalar
50 ts_type = amda_make_scalar
51 try:
51 try:
52 param_id = None
52 param_id = None
53 for key,value in metadata:
53 for key,value in metadata:
54 if key == 'xml:id':
54 if key == 'xml:id':
55 param_id = value
55 param_id = value
56 elif key == 'type':
56 elif key == 'type':
57 if value == 'vector':
57 if value == 'vector':
58 ts_type = amda_make_vector
58 ts_type = amda_make_vector
59 elif value == 'multicomponent':
59 elif value == 'multicomponent':
60 ts_type = amda_make_multi_comp
60 ts_type = amda_make_multi_comp
61 elif value == 'spectrogram':
61 elif value == 'spectrogram':
62 ts_type = amda_make_spectro
62 ts_type = amda_make_spectro
63 tstart=datetime.fromtimestamp(start, tz=timezone.utc)
63 tstart=datetime.fromtimestamp(start, tz=timezone.utc)
64 tend=datetime.fromtimestamp(stop, tz=timezone.utc)
64 tend=datetime.fromtimestamp(stop, tz=timezone.utc)
65 var = amda.get_parameter(start_time=tstart, stop_time=tend, parameter_id=param_id, method="REST")
65 var = amda.get_parameter(start_time=tstart, stop_time=tend, parameter_id=param_id, method="REST")
66 return ts_type(var)
66 return ts_type(var)
67 except Exception as e:
67 except Exception as e:
68 print(traceback.format_exc())
68 print(traceback.format_exc())
69 print("Error in amda.py ",str(e))
69 print("Error in amda.py ",str(e))
70 return ts_type()
70 return ts_type()
71
71
72
72
73 class AmdaProvider(PyDataProvider):
73 class AmdaProvider(PyDataProvider):
74 def __init__(self):
74 def __init__(self):
75 super(AmdaProvider,self).__init__()
75 super(AmdaProvider,self).__init__()
76 if len(amda.component) is 0:
76 if len(amda.component) is 0:
77 amda.update_inventory()
77 amda.update_inventory()
78 parameters = copy.deepcopy(amda.parameter)
78 parameters = copy.deepcopy(amda.parameter)
79 for name,component in amda.component.items():
79 for name,component in amda.component.items():
80 if 'components' in parameters[component['parameter']]:
80 if 'components' in parameters[component['parameter']]:
81 parameters[component['parameter']]['components'].append(component)
81 parameters[component['parameter']]['components'].append(component)
82 else:
82 else:
83 parameters[component['parameter']]['components']=[component]
83 parameters[component['parameter']]['components']=[component]
84
84
85 products = []
85 products = []
86 for key,parameter in parameters.items():
86 for key,parameter in parameters.items():
87 path = f"/AMDA/{parameter['mission']}/{parameter.get('observatory','')}/{parameter['instrument']}/{parameter['dataset']}/{parameter['name']}"
87 path = f"/AMDA/{parameter['mission']}/{parameter.get('observatory','')}/{parameter['instrument']}/{parameter['dataset']}/{parameter['name']}"
88 components = [component['name'] for component in parameter.get('components',[])]
88 components = [component['name'] for component in parameter.get('components',[])]
89 metadata = { key:item for key,item in parameter.items() if key is not 'components' }
89 metadata = { key:item for key,item in parameter.items() if key is not 'components' }
90 n_components = parameter.get('size',0)
90 n_components = parameter.get('size',0)
91 if n_components == '3':
91 if n_components == '3':
92 metadata["type"]="vector"
92 metadata["type"]="vector"
93 elif parameter.get('display_type','')=="spectrogram":
93 elif parameter.get('display_type','')=="spectrogram":
94 metadata["type"]="spectrogram"
94 metadata["type"]="spectrogram"
95 elif n_components !=0:
95 elif n_components !=0:
96 metadata["type"]="multicomponent"
96 metadata["type"]="multicomponent"
97 else:
97 else:
98 metadata["type"]="scalar"
98 metadata["type"]="scalar"
99 products.append( Product(path, components, metadata))
99 products.append( Product(path, components, metadata))
100 self.register_products(products)
100 self.register_products(products)
101 for mission in amda.mission:
101 for mission in amda.mission:
102 self.set_icon(f'/AMDA/{mission}','satellite')
102 self.set_icon(f'/AMDA/{mission}','satellite')
103
103
104 def get_data(self,metadata,start,stop):
104 def get_data(self,metadata,start,stop):
105 ts_type = amda_make_scalar
105 ts_type = amda_make_scalar
106 try:
106 try:
107 param_id = metadata['xml:id']
107 param_id = metadata['xml:id']
108 ts_type_str = metadata['type']
108 ts_type_str = metadata['type']
109 if ts_type_str == 'vector':
109 if ts_type_str == 'vector':
110 ts_type = amda_make_vector
110 ts_type = amda_make_vector
111 elif ts_type_str == 'multicomponent':
111 elif ts_type_str == 'multicomponent':
112 ts_type = amda_make_multi_comp
112 ts_type = amda_make_multi_comp
113 elif ts_type_str == 'spectrogram':
113 elif ts_type_str == 'spectrogram':
114 ts_type = amda_make_spectro
114 ts_type = amda_make_spectro
115 tstart=datetime.fromtimestamp(start, tz=timezone.utc)
115 tstart=datetime.fromtimestamp(start, tz=timezone.utc)
116 tend=datetime.fromtimestamp(stop, tz=timezone.utc)
116 tend=datetime.fromtimestamp(stop, tz=timezone.utc)
117 var = amda.get_parameter(start_time=tstart, stop_time=tend, parameter_id=param_id, method="REST")
117 var = amda.get_parameter(start_time=tstart, stop_time=tend, parameter_id=param_id, method="REST")
118 return ts_type(var)
118 return ts_type(var)
119 except Exception as e:
119 except Exception as e:
120 print(traceback.format_exc())
120 print(traceback.format_exc())
121 print("Error in amda.py ",str(e))
121 print("Error in amda.py ",str(e))
122 return ts_type()
122 return ts_type()
123
123
124 _amda = AmdaProvider()
124 _amda = AmdaProvider()
@@ -1,1 +1,1
1 Subproject commit 46467fb43b8d07fe4f4a45df949ec4ae858ccf9d
1 Subproject commit 9f4e10a342eece28498d9b732bf59f8d1908b716
@@ -1,42 +1,63
1 #include <DataSource/DataSourceWidget.h>
1 #include <DataSource/DataSourceWidget.h>
2
2
3 #include <ui_DataSourceWidget.h>
3 #include <ui_DataSourceWidget.h>
4
4
5 #include <DataSource/datasources.h>
5 #include <DataSource/datasources.h>
6
6
7 #include <QCompleter>
7 #include <SqpApplication.h>
8 #include <SqpApplication.h>
8
9
10 #include <QAction>
11
9
12
10 namespace
13 namespace
11 {
14 {
12
15
13 /// Number of columns displayed in the tree
16 /// Number of columns displayed in the tree
14 const auto TREE_NB_COLUMNS = 1;
17 const auto TREE_NB_COLUMNS = 1;
15
18
16 /// Header labels for the tree
19 /// Header labels for the tree
17 const auto TREE_HEADER_LABELS = QStringList { QObject::tr("Name") };
20 const auto TREE_HEADER_LABELS = QStringList { QObject::tr("Name") };
18
21
19 } // namespace
22 } // namespace
20
23
21 DataSourceWidget::DataSourceWidget(QWidget* parent)
24 DataSourceWidget::DataSourceWidget(QWidget* parent)
22 : QWidget { parent }
25 : QWidget { parent }, ui { new Ui::DataSourceWidget }
23 , ui { new Ui::DataSourceWidget }
24 {
26 {
25 ui->setupUi(this);
27 ui->setupUi(this);
26 m_model_proxy.setSourceModel(&(sqpApp->dataSources()));
28 m_model_proxy.setSourceModel(&(sqpApp->dataSources()));
27 ui->treeView->setModel(&m_model_proxy);
29 ui->treeView->setModel(&m_model_proxy);
28 ui->treeView->setDragEnabled(true);
30 ui->treeView->setDragEnabled(true);
29 m_model_proxy.setFilterRole(Qt::ToolTipRole);
31 m_model_proxy.setFilterRole(Qt::ToolTipRole);
30 m_model_proxy.setRecursiveFilteringEnabled(true);
32 m_model_proxy.setRecursiveFilteringEnabled(true);
31
33
32 // Connection to filter tree
34 // Connection to filter tree
33 connect(ui->filterLineEdit, &QLineEdit::textChanged, &m_model_proxy, static_cast<void (QSortFilterProxyModel::*)(const QString&)>(
35 connect(ui->filterLineEdit, &QLineEdit::textChanged, &m_model_proxy,
36 static_cast<void (QSortFilterProxyModel::*)(const QString&)>(
34 &QSortFilterProxyModel::setFilterRegExp));
37 &QSortFilterProxyModel::setFilterRegExp));
35 sqpApp->dataSources().addIcon("satellite",QVariant(QIcon(":/icones/satellite.svg")));
38 sqpApp->dataSources().addIcon("satellite", QVariant(QIcon(":/icones/satellite.svg")));
39
40 QAction* expandAll = new QAction("Expand all");
41 QAction* collapseAll = new QAction("Collapse all");
42 ui->treeView->addAction(expandAll);
43 ui->treeView->addAction(collapseAll);
44 ui->treeView->setContextMenuPolicy(Qt::ActionsContextMenu);
45 connect(expandAll, &QAction::triggered, [treeView = ui->treeView](bool checked) {
46 (void)checked;
47 treeView->expandAll();
48 });
49 connect(collapseAll, &QAction::triggered, [treeView = ui->treeView](bool checked) {
50 (void)checked;
51 treeView->collapseAll();
52 });
53
54 QCompleter* completer = new QCompleter(this);
55 completer->setModel(sqpApp->dataSources().completionModel());
56 completer->setCaseSensitivity(Qt::CaseInsensitive);
57 ui->filterLineEdit->setCompleter(completer);
36 }
58 }
37
59
38 DataSourceWidget::~DataSourceWidget() noexcept
60 DataSourceWidget::~DataSourceWidget() noexcept
39 {
61 {
40 delete ui;
62 delete ui;
41 }
63 }
42
@@ -1,37 +1,40
1 <?xml version="1.0" encoding="UTF-8"?>
1 <?xml version="1.0" encoding="UTF-8"?>
2 <ui version="4.0">
2 <ui version="4.0">
3 <class>DataSourceWidget</class>
3 <class>DataSourceWidget</class>
4 <widget class="QWidget" name="DataSourceWidget">
4 <widget class="QWidget" name="DataSourceWidget">
5 <property name="geometry">
5 <property name="geometry">
6 <rect>
6 <rect>
7 <x>0</x>
7 <x>0</x>
8 <y>0</y>
8 <y>0</y>
9 <width>400</width>
9 <width>400</width>
10 <height>300</height>
10 <height>300</height>
11 </rect>
11 </rect>
12 </property>
12 </property>
13 <property name="windowTitle">
13 <property name="windowTitle">
14 <string>Data sources</string>
14 <string>Data sources</string>
15 </property>
15 </property>
16 <layout class="QGridLayout" name="gridLayout">
16 <layout class="QGridLayout" name="gridLayout">
17 <item row="0" column="0">
17 <item row="0" column="0">
18 <widget class="QLineEdit" name="filterLineEdit"/>
18 <widget class="QLineEdit" name="filterLineEdit"/>
19 </item>
19 </item>
20 <item row="1" column="0">
20 <item row="1" column="0">
21 <widget class="QTreeView" name="treeView">
21 <widget class="QTreeView" name="treeView">
22 <property name="dragEnabled">
22 <property name="dragEnabled">
23 <bool>true</bool>
23 <bool>true</bool>
24 </property>
24 </property>
25 <property name="dragDropMode">
25 <property name="dragDropMode">
26 <enum>QAbstractItemView::DragOnly</enum>
26 <enum>QAbstractItemView::DragOnly</enum>
27 </property>
27 </property>
28 <property name="selectionMode">
28 <property name="selectionMode">
29 <enum>QAbstractItemView::ExtendedSelection</enum>
29 <enum>QAbstractItemView::ExtendedSelection</enum>
30 </property>
30 </property>
31 <attribute name="headerVisible">
32 <bool>false</bool>
33 </attribute>
31 </widget>
34 </widget>
32 </item>
35 </item>
33 </layout>
36 </layout>
34 </widget>
37 </widget>
35 <resources/>
38 <resources/>
36 <connections/>
39 <connections/>
37 </ui>
40 </ui>
General Comments 0
You need to be logged in to leave comments. Login now