##// END OF EJS Templates
Spectrograms works again, needs more polish......
jeandet -
r1498:d1a5badbcf0e
parent child
Show More
@@ -7,6 +7,7
7 7 #include <DataSource/datasources.h>
8 8
9 9 #include <QPair>
10 #include <QList>
10 11 #include <SqpApplication.h>
11 12 // must be included last because of Python/Qt definition of slots
12 13 #include "numpy_wrappers.h"
@@ -51,14 +52,14 MultiComponentTimeSerie* make_multi_comp(T& t, T& y)
51 52 }
52 53
53 54 template <typename T>
54 SpectrogramTimeSerie* make_spectro(T& t, T& y)
55 SpectrogramTimeSerie* make_spectro(T& t, T& y, T& z)
55 56 {
56 auto y_size = y.flat_size();
57 auto z_size = z.flat_size();
57 58 auto t_size = t.flat_size();
58 if (t_size && (y_size % t_size) == 0)
59 if (t_size && (z_size % t_size) == 0)
59 60 {
60 return new SpectrogramTimeSerie { std::move(t.data), std::move(y.data),
61 { t_size, y_size / t_size } };
61 return new SpectrogramTimeSerie { std::move(t.data), std::move(y.data), std::move(z.data),
62 { t_size, z_size / t_size }, std::nan("1"), std::nan("1") };
62 63 }
63 64 return nullptr;
64 65 }
@@ -75,7 +76,7 public:
75 76
76 77 virtual ~PyDataProvider() {}
77 78
78 virtual QPair<QPair<NpArray, NpArray>, DataSeriesType> get_data(
79 virtual QPair<QPair<QPair<NpArray,NpArray>,NpArray>, DataSeriesType> get_data(
79 80 const QMap<QString, QString>& key, double start_time, double stop_time)
80 81 {
81 82 (void)key, (void)start_time, (void)stop_time;
@@ -94,20 +95,21 public:
94 95 auto [data, type]
95 96 = get_data(metadata, parameters.m_Range.m_TStart, parameters.m_Range.m_TEnd);
96 97
97 auto& [t, y] = data;
98 auto& [axes, values] = data;
99 auto& [x, y] = axes;
98 100 switch (type)
99 101 {
100 102 case DataSeriesType::SCALAR:
101 ts = make_scalar(t, y);
103 ts = make_scalar(x, values);
102 104 break;
103 105 case DataSeriesType::VECTOR:
104 ts = make_vector(t, y);
106 ts = make_vector(x, values);
105 107 break;
106 108 case DataSeriesType::MULTICOMPONENT:
107 ts = make_multi_comp(t, y);
109 ts = make_multi_comp(x, values);
108 110 break;
109 111 case DataSeriesType::SPECTROGRAM:
110 ts = make_spectro(t, y);
112 ts = make_spectro(x, y, values);
111 113 break;
112 114 default:
113 115 break;
@@ -9,48 +9,45 from spwc.amda import AMDA
9 9
10 10 amda = AMDA()
11 11
12
12 13 def amda_make_scalar(var=None):
13 14 if var is None:
14 return ((np.array(), np.array()), DataSeriesType.SCALAR)
15 return (((np.array([]), np.array([])), np.array([])), DataSeriesType.SCALAR)
15 16 else:
16 return ((var.time,var.data), DataSeriesType.SCALAR)
17 return (((var.time, np.array([])), var.data), DataSeriesType.SCALAR)
18
17 19
18 20 def amda_make_vector(var=None):
19 21 if var is None:
20 return ((np.array(), np.array()), DataSeriesType.VECTOR)
22 return (((np.array([]), np.array([])), np.array([])), DataSeriesType.VECTOR)
21 23 else:
22 return ((var.time,var.data), DataSeriesType.VECTOR)
24 return (((var.time, np.array([])), var.data), DataSeriesType.VECTOR)
25
23 26
24 27 def amda_make_multi_comp(var=None):
25 28 if var is None:
26 return ((np.array(), np.array()), DataSeriesType.MULTICOMPONENT)
29 return (((np.array([]), np.array([])), np.array([])), DataSeriesType.MULTICOMPONENT)
27 30 else:
28 return ((var.time,var.data), DataSeriesType.MULTICOMPONENT)
31 return (((var.time, np.array([])), var.data), DataSeriesType.MULTICOMPONENT)
32
29 33
30 34 def amda_make_spectro(var=None):
31 35 if var is None:
32 return ((np.array(), np.array()), DataSeriesType.SPECTROGRAM)
36 return (((np.array([]), np.array([])), np.array([])), DataSeriesType.SPECTROGRAM)
33 37 else:
34 min_sampling = float(var.meta.get("DATASET_MIN_SAMPLING","nan"))
35 max_sampling = float(var.meta.get("DATASET_MAX_SAMPLING","nan"))
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(',') ])
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.
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(',') ])
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.
44 else:
45 y = np.logspace(1,3,var.data.shape[1])[::-1]
46 return ((var.time,var.data), DataSeriesType.SPECTROGRAM)
38 min_sampling = float(var.meta.get("DATASET_MIN_SAMPLING", "nan"))
39 max_sampling = float(var.meta.get("DATASET_MAX_SAMPLING", "nan"))
40 if var.y is None and len(var.data):
41 var.y = np.logspace(1, 3, var.data.shape[1])[::-1]
42 return (((var.time, var.y), var.data), DataSeriesType.SPECTROGRAM)
47 43 #return pysciqlopcore.SpectrogramTimeSerie(var.time,y,var.data,min_sampling,max_sampling,True)
48 44
49 def amda_get_sample(metadata,start,stop):
45
46 def amda_get_sample(metadata, start, stop):
50 47 ts_type = amda_make_scalar
51 48 try:
52 49 param_id = None
53 for key,value in metadata:
50 for key, value in metadata:
54 51 if key == 'xml:id':
55 52 param_id = value
56 53 elif key == 'type':
@@ -60,48 +57,48 def amda_get_sample(metadata,start,stop):
60 57 ts_type = amda_make_multi_comp
61 58 elif value == 'spectrogram':
62 59 ts_type = amda_make_spectro
63 tstart=datetime.fromtimestamp(start, tz=timezone.utc)
64 tend=datetime.fromtimestamp(stop, tz=timezone.utc)
60 tstart = datetime.fromtimestamp(start, tz=timezone.utc)
61 tend = datetime.fromtimestamp(stop, tz=timezone.utc)
65 62 var = amda.get_parameter(start_time=tstart, stop_time=tend, parameter_id=param_id, method="REST")
66 63 return ts_type(var)
67 64 except Exception as e:
68 65 print(traceback.format_exc())
69 print("Error in amda.py ",str(e))
66 print("Error in amda.py ", str(e))
70 67 return ts_type()
71 68
72 69
73 70 class AmdaProvider(PyDataProvider):
74 71 def __init__(self):
75 super(AmdaProvider,self).__init__()
72 super(AmdaProvider, self).__init__()
76 73 if len(amda.component) is 0:
77 74 amda.update_inventory()
78 75 parameters = copy.deepcopy(amda.parameter)
79 for name,component in amda.component.items():
76 for name, component in amda.component.items():
80 77 if 'components' in parameters[component['parameter']]:
81 78 parameters[component['parameter']]['components'].append(component)
82 79 else:
83 80 parameters[component['parameter']]['components']=[component]
84 81
85 82 products = []
86 for key,parameter in parameters.items():
83 for key, parameter in parameters.items():
87 84 path = f"/AMDA/{parameter['mission']}/{parameter.get('observatory','')}/{parameter['instrument']}/{parameter['dataset']}/{parameter['name']}"
88 85 components = [component['name'] for component in parameter.get('components',[])]
89 metadata = { key:item for key,item in parameter.items() if key is not 'components' }
90 n_components = parameter.get('size',0)
86 metadata = {key: item for key, item in parameter.items() if key is not 'components'}
87 n_components = parameter.get('size', 0)
91 88 if n_components == '3':
92 metadata["type"]="vector"
93 elif parameter.get('display_type','')=="spectrogram":
94 metadata["type"]="spectrogram"
95 elif n_components !=0:
96 metadata["type"]="multicomponent"
89 metadata["type"] = "vector"
90 elif parameter.get('display_type', '')=="spectrogram":
91 metadata["type"] = "spectrogram"
92 elif n_components != 0:
93 metadata["type"] = "multicomponent"
97 94 else:
98 metadata["type"]="scalar"
99 products.append( Product(path, components, metadata))
95 metadata["type"] = "scalar"
96 products.append(Product(path, components, metadata))
100 97 self.register_products(products)
101 98 for mission in amda.mission:
102 99 self.set_icon(f'/AMDA/{mission}','satellite')
103 100
104 def get_data(self,metadata,start,stop):
101 def get_data(self, metadata, start, stop):
105 102 ts_type = amda_make_scalar
106 103 try:
107 104 param_id = metadata['xml:id']
@@ -112,13 +109,13 class AmdaProvider(PyDataProvider):
112 109 ts_type = amda_make_multi_comp
113 110 elif ts_type_str == 'spectrogram':
114 111 ts_type = amda_make_spectro
115 tstart=datetime.fromtimestamp(start, tz=timezone.utc)
116 tend=datetime.fromtimestamp(stop, tz=timezone.utc)
112 tstart = datetime.fromtimestamp(start, tz=timezone.utc)
113 tend = datetime.fromtimestamp(stop, tz=timezone.utc)
117 114 var = amda.get_parameter(start_time=tstart, stop_time=tend, parameter_id=param_id, method="REST")
118 115 return ts_type(var)
119 116 except Exception as e:
120 117 print(traceback.format_exc())
121 print("Error in amda.py ",str(e))
118 print("Error in amda.py ", str(e))
122 119 return ts_type()
123 120
124 121 _amda = AmdaProvider()
@@ -82,11 +82,11 class MyProvider(PyDataProvider):
82 82 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)
83 83 else:
84 84 var = _get_data(p_type, start, stop)
85 return ((var.time,var.data), ts_type)
85 return (((var.time, np.array([])),var.data), ts_type)
86 86 except Exception as e:
87 87 print(traceback.format_exc())
88 88 print("Error in test.py ",str(e))
89 return ((np.array(), np.array()), ts_type)
89 return (((np.array([]), np.array([])), np.array([])), ts_type)
90 90
91 91
92 92 t=MyProvider()
@@ -1,1 +1,1
1 Subproject commit 9f4e10a342eece28498d9b732bf59f8d1908b716
1 Subproject commit 3bce297cb13e8337d71adceae6737c104c66ad52
General Comments 0
You need to be logged in to leave comments. Login now