##// END OF EJS Templates
WIP...
jeandet -
r1434:865bdf496f65
parent child
Show More
@@ -1,1 +1,1
1 Subproject commit 5f1aaa704ac36252027b9da0064bdf1de063df0d
1 Subproject commit 7c86e13f8a6242eb5fe07f0da91a96a4cf68b5bf
@@ -1,68 +1,67
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 default_ctor_args = 1
19 try:
19 try:
20 param_id = None
20 param_id = None
21 for key,value in metadata:
21 for key,value in metadata:
22 if key == 'xml:id':
22 if key == 'xml:id':
23 param_id = value
23 param_id = value
24 elif key == 'type':
24 elif key == 'type':
25 if value == 'vector':
25 if value == 'vector':
26 ts_type = pysciqlopcore.VectorTimeSerie
26 ts_type = pysciqlopcore.VectorTimeSerie
27 elif value == 'multicomponent':
27 elif value == 'multicomponent':
28 ts_type = pysciqlopcore.MultiComponentTimeSerie
28 ts_type = pysciqlopcore.MultiComponentTimeSerie
29 default_ctor_args = (0,2)
29 default_ctor_args = (0,2)
30 tstart=datetime.datetime.fromtimestamp(start, tz=timezone.utc)
30 tstart=datetime.datetime.fromtimestamp(start, tz=timezone.utc)
31 tend=datetime.datetime.fromtimestamp(stop, tz=timezone.utc)
31 tend=datetime.datetime.fromtimestamp(stop, tz=timezone.utc)
32 df = amda.get_parameter(start_time=tstart, stop_time=tend, parameter_id=param_id, method="REST")
32 df = amda.get_parameter(start_time=tstart, stop_time=tend, parameter_id=param_id, method="REST")
33 #t = np.array([d.timestamp()-7200 for d in df.index])
34 t = np.array([d.timestamp() for d in df.index])
33 t = np.array([d.timestamp() for d in df.index])
35 values = df.values
34 values = df.values
36 return ts_type(t,values.transpose())
35 return ts_type(t,values)
37 except Exception as e:
36 except Exception as e:
38 print(traceback.format_exc())
37 print(traceback.format_exc())
39 print("Error in amda.py ",str(e))
38 print("Error in amda.py ",str(e))
40 return ts_type(default_ctor_args)
39 return ts_type(default_ctor_args)
41
40
42
41
43 if len(amda.component) is 0:
42 if len(amda.component) is 0:
44 amda.update_inventory()
43 amda.update_inventory()
45 parameters = copy.deepcopy(amda.parameter)
44 parameters = copy.deepcopy(amda.parameter)
46 for name,component in amda.component.items():
45 for name,component in amda.component.items():
47 if 'components' in parameters[component['parameter']]:
46 if 'components' in parameters[component['parameter']]:
48 parameters[component['parameter']]['components'].append(component)
47 parameters[component['parameter']]['components'].append(component)
49 else:
48 else:
50 parameters[component['parameter']]['components']=[component]
49 parameters[component['parameter']]['components']=[component]
51
50
52 products = []
51 products = []
53 for key,parameter in parameters.items():
52 for key,parameter in parameters.items():
54 path = f"/AMDA/{parameter['mission']}/{parameter['instrument']}/{parameter['dataset']}/{parameter['name']}"
53 path = f"/AMDA/{parameter['mission']}/{parameter['instrument']}/{parameter['dataset']}/{parameter['name']}"
55 components = [component['name'] for component in parameter.get('components',[])]
54 components = [component['name'] for component in parameter.get('components',[])]
56 metadata = [ (key,item) for key,item in parameter.items() if key is not 'components' ]
55 metadata = [ (key,item) for key,item in parameter.items() if key is not 'components' ]
57 n_components = parameter.get('size',0)
56 n_components = parameter.get('size',0)
58 if n_components is '3':
57 if n_components is '3':
59 metadata.append(("type","vector"))
58 metadata.append(("type","vector"))
60 elif n_components !=0:
59 elif n_components !=0:
61 metadata.append(("type","multicomponent"))
60 metadata.append(("type","multicomponent"))
62 else:
61 else:
63 metadata.append(("type","scalar"))
62 metadata.append(("type","scalar"))
64 products.append( (path, components, metadata))
63 products.append( (path, components, metadata))
65
64
66 PythonProviders.register_product(products, get_sample)
65 PythonProviders.register_product(products, get_sample)
67
66
68
67
@@ -1,29 +1,52
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 os
3 import os
4 import datetime
4 import datetime
5 import PythonProviders
5 import PythonProviders
6 import pysciqlopcore
6 import pysciqlopcore
7 import numpy as np
7 import numpy as np
8 import pandas as pds
8 import pandas as pds
9 import requests
9 import requests
10 from spwc.cdaweb import cdaweb
10 from spwc.cdaweb import cdaweb
11
11
12 cd = cdaweb()
12 cd = cdaweb()
13
13
14 def get_sample(name,start,stop):
14 def cda_get_sample(metadata, start,stop):
15 ts_type = pysciqlopcore.ScalarTimeSerie
16 default_ctor_args = 1
15 try:
17 try:
16 tstart=datetime.datetime.fromtimestamp(start)
18 variable_id = None
17 tend=datetime.datetime.fromtimestamp(stop)
19 dataset_id = None
18 df = cd.get_variable(dataset="MMS2_SCM_SRVY_L2_SCSRVY",variable="mms2_scm_acb_gse_scsrvy_srvy_l2",tstart=tstart,tend=tend)
20 for key,value in metadata:
19 t = np.array([d.timestamp()-7200 for d in df.index])
21 if key == 'VAR_ID':
22 variable_id = value
23 elif key == 'DATASET_ID':
24 dataset_id = value
25 elif key == 'type':
26 if value == 'vector':
27 ts_type = pysciqlopcore.VectorTimeSerie
28 elif value == 'multicomponent':
29 ts_type = pysciqlopcore.MultiComponentTimeSerie
30 default_ctor_args = (0,2)
31 tstart=datetime.datetime.fromtimestamp(start, tz=timezone.utc)
32 tend=datetime.datetime.fromtimestamp(stop, tz=timezone.utc)
33 df = cd.get_variable(dataset=dataset_id,variable=variable_id,tstart=tstart,tend=tend)
34 t = np.array([d.timestamp() for d in df.index])
20 values = df.values
35 values = df.values
21 return pysciqlopcore.VectorTimeSerie(t,values)
36 print(values.shape)
22 except Exception as e:
37 return ts_type(t,values)
23 print("fuck ",str(e))
38 except Exception as e:
24 return pysciqlopcore.VectorTimeSerie(1)
39 print(traceback.format_exc())
40 print("Error in amda.py ",str(e))
41 return ts_type(default_ctor_args)
25
42
26
43
27 PythonProviders.register_product([("/CDA/mms4_scm_acb_gse_scsrvy_srvy_l2",[],[("type","vector")])],get_sample)
44 products = [
45 ("/CDA/Themis/ThA/tha_fgl_gsm", [], [("type","multicomponent"), ('size','4'), ("DATASET_ID","THA_L2_FGM"), ("VAR_ID","tha_fgl_gsm")]),
46 ("/CDA/Themis/ThB/thb_fgl_gsm", [], [("type","multicomponent"), ('size','4'), ("DATASET_ID","THB_L2_FGM"), ("VAR_ID","thb_fgl_gsm")]),
47
48 ]
49
50 PythonProviders.register_product(products, cda_get_sample)
28
51
29
52
General Comments 0
You need to be logged in to leave comments. Login now