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