@@ -1,1 +1,1 | |||||
1 | Subproject commit 9a080a34054c21a67236f761e8843005c07ff0ba |
|
1 | Subproject commit 5f1aaa704ac36252027b9da0064bdf1de063df0d |
@@ -1,67 +1,68 | |||||
1 | import sys |
|
1 | import sys | |
2 | sys.path.append("/home/jeandet/Documents/prog/build-SciQLop-Desktop-Debug/core") |
|
2 | sys.path.append("/home/jeandet/Documents/prog/build-SciQLop-Desktop-Debug/core") | |
3 | import traceback |
|
3 | import traceback | |
4 | import os |
|
4 | import os | |
5 | from datetime import datetime, timedelta, timezone |
|
5 | from datetime import datetime, timedelta, timezone | |
6 | import PythonProviders |
|
6 | import PythonProviders | |
7 | import pysciqlopcore |
|
7 | import pysciqlopcore | |
8 | import numpy as np |
|
8 | import numpy as np | |
9 | import pandas as pds |
|
9 | import pandas as pds | |
10 | import requests |
|
10 | import requests | |
11 | import copy |
|
11 | import copy | |
12 | from spwc.amda import AMDA |
|
12 | from spwc.amda import AMDA | |
13 |
|
13 | |||
14 | amda = AMDA() |
|
14 | amda = AMDA() | |
15 |
|
15 | |||
16 | def get_sample(metadata,start,stop): |
|
16 | def get_sample(metadata,start,stop): | |
17 | ts_type = pysciqlopcore.ScalarTimeSerie |
|
17 | ts_type = pysciqlopcore.ScalarTimeSerie | |
|
18 | default_ctor_args = 1 | |||
18 | try: |
|
19 | try: | |
19 | param_id = None |
|
20 | param_id = None | |
20 | for key,value in metadata: |
|
21 | for key,value in metadata: | |
21 | if key == 'xml:id': |
|
22 | if key == 'xml:id': | |
22 | param_id = value |
|
23 | param_id = value | |
23 | elif key == 'type': |
|
24 | elif key == 'type': | |
24 | if value == 'vector': |
|
25 | if value == 'vector': | |
25 | ts_type = pysciqlopcore.VectorTimeSerie |
|
26 | ts_type = pysciqlopcore.VectorTimeSerie | |
26 | elif value == 'multicomponent': |
|
27 | elif value == 'multicomponent': | |
27 | ts_type = pysciqlopcore.MultiComponentTimeSerie |
|
28 | ts_type = pysciqlopcore.MultiComponentTimeSerie | |
|
29 | default_ctor_args = (0,2) | |||
28 | tstart=datetime.datetime.fromtimestamp(start, tz=timezone.utc) |
|
30 | tstart=datetime.datetime.fromtimestamp(start, tz=timezone.utc) | |
29 | tend=datetime.datetime.fromtimestamp(stop, tz=timezone.utc) |
|
31 | tend=datetime.datetime.fromtimestamp(stop, tz=timezone.utc) | |
30 | df = amda.get_parameter(start_time=tstart, stop_time=tend, parameter_id=param_id) |
|
32 | df = amda.get_parameter(start_time=tstart, stop_time=tend, parameter_id=param_id, method="REST") | |
31 | #t = np.array([d.timestamp()-7200 for d in df.index]) |
|
33 | #t = np.array([d.timestamp()-7200 for d in df.index]) | |
32 | t = np.array([d.timestamp() for d in df.index]) |
|
34 | t = np.array([d.timestamp() for d in df.index]) | |
33 | values = df.values |
|
35 | values = df.values | |
34 | return ts_type(t,values.transpose()) |
|
36 | return ts_type(t,values.transpose()) | |
35 | return ts_type(1) |
|
|||
36 | except Exception as e: |
|
37 | except Exception as e: | |
37 | print(traceback.format_exc()) |
|
38 | print(traceback.format_exc()) | |
38 | print("Error in amda.py ",str(e)) |
|
39 | print("Error in amda.py ",str(e)) | |
39 |
return ts_type( |
|
40 | return ts_type(default_ctor_args) | |
40 |
|
41 | |||
41 |
|
42 | |||
42 | if len(amda.component) is 0: |
|
43 | if len(amda.component) is 0: | |
43 | amda.update_inventory() |
|
44 | amda.update_inventory() | |
44 | parameters = copy.deepcopy(amda.parameter) |
|
45 | parameters = copy.deepcopy(amda.parameter) | |
45 | for name,component in amda.component.items(): |
|
46 | for name,component in amda.component.items(): | |
46 | if 'components' in parameters[component['parameter']]: |
|
47 | if 'components' in parameters[component['parameter']]: | |
47 | parameters[component['parameter']]['components'].append(component) |
|
48 | parameters[component['parameter']]['components'].append(component) | |
48 | else: |
|
49 | else: | |
49 | parameters[component['parameter']]['components']=[component] |
|
50 | parameters[component['parameter']]['components']=[component] | |
50 |
|
51 | |||
51 | products = [] |
|
52 | products = [] | |
52 | for key,parameter in parameters.items(): |
|
53 | for key,parameter in parameters.items(): | |
53 | path = f"/AMDA/{parameter['mission']}/{parameter['instrument']}/{parameter['dataset']}/{parameter['name']}" |
|
54 | path = f"/AMDA/{parameter['mission']}/{parameter['instrument']}/{parameter['dataset']}/{parameter['name']}" | |
54 | components = [component['name'] for component in parameter.get('components',[])] |
|
55 | components = [component['name'] for component in parameter.get('components',[])] | |
55 | metadata = [ (key,item) for key,item in parameter.items() if key is not 'components' ] |
|
56 | metadata = [ (key,item) for key,item in parameter.items() if key is not 'components' ] | |
56 | n_components = parameter.get('size',0) |
|
57 | n_components = parameter.get('size',0) | |
57 | if n_components is '3': |
|
58 | if n_components is '3': | |
58 | metadata.append(("type","vector")) |
|
59 | metadata.append(("type","vector")) | |
59 | elif n_components !=0: |
|
60 | elif n_components !=0: | |
60 | metadata.append(("type","multicomponent")) |
|
61 | metadata.append(("type","multicomponent")) | |
61 | else: |
|
62 | else: | |
62 | metadata.append(("type","scalar")) |
|
63 | metadata.append(("type","scalar")) | |
63 | products.append( (path, components, metadata)) |
|
64 | products.append( (path, components, metadata)) | |
64 |
|
65 | |||
65 | PythonProviders.register_product(products, get_sample) |
|
66 | PythonProviders.register_product(products, get_sample) | |
66 |
|
67 | |||
67 |
|
68 |
@@ -1,44 +1,45 | |||||
1 | import sys |
|
1 | import sys | |
2 | sys.path.append("/home/jeandet/Documents/prog/build-SciQLop-Desktop-Debug/core") |
|
2 | sys.path.append("/home/jeandet/Documents/prog/build-SciQLop-Desktop-Debug/core") | |
3 | import PythonProviders |
|
3 | import PythonProviders | |
4 | import pysciqlopcore |
|
4 | import pysciqlopcore | |
5 | import numpy as np |
|
5 | import numpy as np | |
|
6 | import math | |||
6 |
|
7 | |||
7 | someglobal = 1 |
|
8 | someglobal = 1 | |
8 |
|
9 | |||
9 | def make_scalar(x): |
|
10 | def make_scalar(x): | |
10 | y = np.cos(x/10.) |
|
11 | y = np.cos(x/10.) | |
11 | return pysciqlopcore.ScalarTimeSerie(x,y) |
|
12 | return pysciqlopcore.ScalarTimeSerie(x,y) | |
12 |
|
13 | |||
13 | def make_vector(x): |
|
14 | def make_vector(x): | |
14 | v=np.ones((3,len(x))) |
|
15 | v=np.ones((3,len(x))) | |
15 | for i in range(3): |
|
16 | for i in range(3): | |
16 | v[:][i] = np.cos(x/10. + float(i)) |
|
17 | v[:][i] = np.cos(x/10. + float(i)) | |
17 | return pysciqlopcore.VectorTimeSerie(x,v) |
|
18 | return pysciqlopcore.VectorTimeSerie(x,v) | |
18 |
|
19 | |||
19 |
|
20 | |||
20 | def make_multicomponent(x): |
|
21 | def make_multicomponent(x): | |
21 | v=np.ones((4,len(x))) |
|
22 | v=np.ones((4,len(x))) | |
22 | for i in range(4): |
|
23 | for i in range(4): | |
23 | v[:][i] = float(i+1) * np.cos(x/10. + float(i)) |
|
24 | v[:][i] = float(i+1) * np.cos(x/10. + float(i)) | |
24 | return pysciqlopcore.MultiComponentTimeSerie(x,v) |
|
25 | return pysciqlopcore.MultiComponentTimeSerie(x,v) | |
25 |
|
26 | |||
26 |
|
27 | |||
27 | def get_data(metadata,start,stop): |
|
28 | def get_data(metadata,start,stop): | |
28 | x = np.arange(start, stop) |
|
29 | x = np.arange(math.ceil(start), math.floor(stop)) | |
29 | for key,value in metadata: |
|
30 | for key,value in metadata: | |
30 | if key == 'xml:id': |
|
31 | if key == 'xml:id': | |
31 | param_id = value |
|
32 | param_id = value | |
32 | elif key == 'type': |
|
33 | elif key == 'type': | |
33 | if value == 'vector': |
|
34 | if value == 'vector': | |
34 | return make_vector(x) |
|
35 | return make_vector(x) | |
35 | elif value == 'multicomponent': |
|
36 | elif value == 'multicomponent': | |
36 | return make_multicomponent(x) |
|
37 | return make_multicomponent(x) | |
37 | return make_scalar(x) |
|
38 | return make_scalar(x) | |
38 |
|
39 | |||
39 |
|
40 | |||
40 |
|
41 | |||
41 |
|
42 | |||
42 | PythonProviders.register_product([("/tests/scalar",[],[("type","scalar")]), ("/tests/vector",[],[("type","vector")]), ("/tests/multicomponent",[],[("type","multicomponent"),('size','4')])],get_data) |
|
43 | PythonProviders.register_product([("/tests/scalar",[],[("type","scalar")]), ("/tests/vector",[],[("type","vector")]), ("/tests/multicomponent",[],[("type","multicomponent"),('size','4')])],get_data) | |
43 |
|
44 | |||
44 |
|
45 |
General Comments 0
You need to be logged in to leave comments.
Login now