##// END OF EJS Templates
Improved AMDA tree, uses node names instead of xml:id which is more...
jeandet -
r1502:239919e8e177
parent child
Show More
@@ -1,15 +1,16
1 build/
1 build/
2 _build/
2 CMakeLists.txt.user
3 CMakeLists.txt.user
3 /.project
4 /.project
4 core/src/Version.cpp
5 core/src/Version.cpp
5 core/include/Version.h
6 core/include/Version.h
6 3rdparty/
7 3rdparty/
7 subprojects/*
8 subprojects/*
8 documentation/*
9 documentation/*
9 **/.idea/*
10 **/.idea/*
10 **/__pycache__/*
11 **/__pycache__/*
11 *.srctrl*
12 *.srctrl*
12 *.kdev4
13 *.kdev4
13 .vscode
14 .vscode
14 *.pyc
15 *.pyc
15 *.swp
16 *.swp
@@ -1,121 +1,128
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
12
13 def amda_make_scalar(var=None):
13 def amda_make_scalar(var=None):
14 if var is None:
14 if var is None:
15 return (((np.array([]), np.array([])), np.array([])), DataSeriesType.SCALAR)
15 return (((np.array([]), np.array([])), np.array([])), DataSeriesType.SCALAR)
16 else:
16 else:
17 return (((var.time, np.array([])), var.data), DataSeriesType.SCALAR)
17 return (((var.time, np.array([])), var.data), DataSeriesType.SCALAR)
18
18
19
19
20 def amda_make_vector(var=None):
20 def amda_make_vector(var=None):
21 if var is None:
21 if var is None:
22 return (((np.array([]), np.array([])), np.array([])), DataSeriesType.VECTOR)
22 return (((np.array([]), np.array([])), np.array([])), DataSeriesType.VECTOR)
23 else:
23 else:
24 return (((var.time, np.array([])), var.data), DataSeriesType.VECTOR)
24 return (((var.time, np.array([])), var.data), DataSeriesType.VECTOR)
25
25
26
26
27 def amda_make_multi_comp(var=None):
27 def amda_make_multi_comp(var=None):
28 if var is None:
28 if var is None:
29 return (((np.array([]), np.array([])), np.array([])), DataSeriesType.MULTICOMPONENT)
29 return (((np.array([]), np.array([])), np.array([])), DataSeriesType.MULTICOMPONENT)
30 else:
30 else:
31 return (((var.time, np.array([])), var.data), DataSeriesType.MULTICOMPONENT)
31 return (((var.time, np.array([])), var.data), DataSeriesType.MULTICOMPONENT)
32
32
33
33
34 def amda_make_spectro(var=None):
34 def amda_make_spectro(var=None):
35 if var is None:
35 if var is None:
36 return (((np.array([]), np.array([])), np.array([])), DataSeriesType.SPECTROGRAM)
36 return (((np.array([]), np.array([])), np.array([])), DataSeriesType.SPECTROGRAM)
37 else:
37 else:
38 min_sampling = float(var.meta.get("DATASET_MIN_SAMPLING", "nan"))
38 min_sampling = float(var.meta.get("DATASET_MIN_SAMPLING", "nan"))
39 max_sampling = float(var.meta.get("DATASET_MAX_SAMPLING", "nan"))
39 max_sampling = float(var.meta.get("DATASET_MAX_SAMPLING", "nan"))
40 if var.y is None and len(var.data):
40 if var.y is None and len(var.data):
41 var.y = np.logspace(1, 3, var.data.shape[1])[::-1]
41 var.y = np.logspace(1, 3, var.data.shape[1])[::-1]
42 return (((var.time, var.y), var.data), DataSeriesType.SPECTROGRAM)
42 return (((var.time, var.y), var.data), DataSeriesType.SPECTROGRAM)
43 #return pysciqlopcore.SpectrogramTimeSerie(var.time,y,var.data,min_sampling,max_sampling,True)
43 #return pysciqlopcore.SpectrogramTimeSerie(var.time,y,var.data,min_sampling,max_sampling,True)
44
44
45
45
46 def amda_get_sample(metadata, start, stop):
46 def amda_get_sample(metadata, start, stop):
47 ts_type = amda_make_scalar
47 ts_type = amda_make_scalar
48 try:
48 try:
49 param_id = None
49 param_id = None
50 for key, value in metadata:
50 for key, value in metadata:
51 if key == 'xml:id':
51 if key == 'xml:id':
52 param_id = value
52 param_id = value
53 elif key == 'type':
53 elif key == 'type':
54 if value == 'vector':
54 if value == 'vector':
55 ts_type = amda_make_vector
55 ts_type = amda_make_vector
56 elif value == 'multicomponent':
56 elif value == 'multicomponent':
57 ts_type = amda_make_multi_comp
57 ts_type = amda_make_multi_comp
58 elif value == 'spectrogram':
58 elif value == 'spectrogram':
59 ts_type = amda_make_spectro
59 ts_type = amda_make_spectro
60 tstart = datetime.fromtimestamp(start, tz=timezone.utc)
60 tstart = datetime.fromtimestamp(start, tz=timezone.utc)
61 tend = datetime.fromtimestamp(stop, tz=timezone.utc)
61 tend = datetime.fromtimestamp(stop, tz=timezone.utc)
62 var = amda.get_parameter(start_time=tstart, stop_time=tend, parameter_id=param_id, method="REST")
62 var = amda.get_parameter(start_time=tstart, stop_time=tend, parameter_id=param_id, method="REST")
63 return ts_type(var)
63 return ts_type(var)
64 except Exception as e:
64 except Exception as e:
65 print(traceback.format_exc())
65 print(traceback.format_exc())
66 print("Error in amda.py ", str(e))
66 print("Error in amda.py ", str(e))
67 return ts_type()
67 return ts_type()
68
68
69
69
70 class AmdaProvider(PyDataProvider):
70 class AmdaProvider(PyDataProvider):
71 def __init__(self):
71 def __init__(self):
72 super(AmdaProvider, self).__init__()
72 super(AmdaProvider, self).__init__()
73 if len(amda.component) is 0:
73 if len(amda.component) is 0:
74 amda.update_inventory()
74 amda.update_inventory()
75 parameters = copy.deepcopy(amda.parameter)
75 parameters = copy.deepcopy(amda.parameter)
76 for name, component in amda.component.items():
76 for name, component in amda.component.items():
77 if 'components' in parameters[component['parameter']]:
77 if 'components' in parameters[component['parameter']]:
78 parameters[component['parameter']]['components'].append(component)
78 parameters[component['parameter']]['components'].append(component)
79 else:
79 else:
80 parameters[component['parameter']]['components']=[component]
80 parameters[component['parameter']]['components']=[component]
81
81
82 products = []
82 products = []
83 for key, parameter in parameters.items():
83 for key, parameter in parameters.items():
84 path = f"/AMDA/{parameter['mission']}/{parameter.get('observatory','')}/{parameter['instrument']}/{parameter['dataset']}/{parameter['name']}"
84 mission_name = amda.mission[parameter['mission']]['name']
85 observatory_name = parameter.get('observatory','')
86 if observatory_name != '':
87 observatory_name = amda.observatory[observatory_name]['name']
88 instrument_name = amda.instrument[parameter['instrument']]['name']
89 dataset_name = amda.dataset[parameter['dataset']]['name']
90 path = f"/AMDA/{mission_name}/{observatory_name}/{instrument_name}/{dataset_name}/{parameter['name']}"
85 components = [component['name'] for component in parameter.get('components',[])]
91 components = [component['name'] for component in parameter.get('components',[])]
86 metadata = {key: item for key, item in parameter.items() if key is not 'components'}
92 metadata = {key: item for key, item in parameter.items() if key is not 'components'}
87 n_components = parameter.get('size', 0)
93 n_components = parameter.get('size', 0)
88 if n_components == '3':
94 if n_components == '3':
89 metadata["type"] = "vector"
95 metadata["type"] = "vector"
90 elif parameter.get('display_type', '')=="spectrogram":
96 elif parameter.get('display_type', '')=="spectrogram":
91 metadata["type"] = "spectrogram"
97 metadata["type"] = "spectrogram"
92 elif n_components != 0:
98 elif n_components != 0:
93 metadata["type"] = "multicomponent"
99 metadata["type"] = "multicomponent"
94 else:
100 else:
95 metadata["type"] = "scalar"
101 metadata["type"] = "scalar"
96 products.append(Product(path, components, metadata))
102 products.append(Product(path, components, metadata))
97 self.register_products(products)
103 self.register_products(products)
98 for mission in amda.mission:
104 for _,mission in amda.mission.items():
99 self.set_icon(f'/AMDA/{mission}','satellite')
105 if ('target' in mission) and (mission['xml:id'] != 'Ephemerides') and (mission['target'] != 'Earth'):
106 self.set_icon(f'/AMDA/{mission["name"]}','satellite')
100
107
101 def get_data(self, metadata, start, stop):
108 def get_data(self, metadata, start, stop):
102 ts_type = amda_make_scalar
109 ts_type = amda_make_scalar
103 try:
110 try:
104 param_id = metadata['xml:id']
111 param_id = metadata['xml:id']
105 ts_type_str = metadata['type']
112 ts_type_str = metadata['type']
106 if ts_type_str == 'vector':
113 if ts_type_str == 'vector':
107 ts_type = amda_make_vector
114 ts_type = amda_make_vector
108 elif ts_type_str == 'multicomponent':
115 elif ts_type_str == 'multicomponent':
109 ts_type = amda_make_multi_comp
116 ts_type = amda_make_multi_comp
110 elif ts_type_str == 'spectrogram':
117 elif ts_type_str == 'spectrogram':
111 ts_type = amda_make_spectro
118 ts_type = amda_make_spectro
112 tstart = datetime.fromtimestamp(start, tz=timezone.utc)
119 tstart = datetime.fromtimestamp(start, tz=timezone.utc)
113 tend = datetime.fromtimestamp(stop, tz=timezone.utc)
120 tend = datetime.fromtimestamp(stop, tz=timezone.utc)
114 var = amda.get_parameter(start_time=tstart, stop_time=tend, parameter_id=param_id, method="REST")
121 var = amda.get_parameter(start_time=tstart, stop_time=tend, parameter_id=param_id, method="REST")
115 return ts_type(var)
122 return ts_type(var)
116 except Exception as e:
123 except Exception as e:
117 print(traceback.format_exc())
124 print(traceback.format_exc())
118 print("Error in amda.py ", str(e))
125 print("Error in amda.py ", str(e))
119 return ts_type()
126 return ts_type()
120
127
121 _amda = AmdaProvider()
128 _amda = AmdaProvider()
General Comments 0
You need to be logged in to leave comments. Login now