##// END OF EJS Templates
Bump Core, ready to integrate new DataSources model class...
jeandet -
r1494:8ad169c5af90
parent child
Show More
@@ -1,94 +1,93
1 import traceback
1 import traceback
2 from SciQLopBindings import PyDataProvider, Product, VectorTimeSerie, ScalarTimeSerie, DataSeriesType
2 from SciQLopBindings import PyDataProvider, Product, VectorTimeSerie, ScalarTimeSerie, DataSeriesType
3 import numpy as np
3 import numpy as np
4 import math
4 import math
5 from spwc.cache import _cache
5 from spwc.cache import _cache
6 from spwc.common.datetime_range import DateTimeRange
6 from spwc.common.datetime_range import DateTimeRange
7 from functools import partial
7 from functools import partial
8 from datetime import datetime, timedelta, timezone
8 from datetime import datetime, timedelta, timezone
9 from spwc.common.variable import SpwcVariable
9 from spwc.common.variable import SpwcVariable
10
10
11
11
12 def make_scalar(x):
12 def make_scalar(x):
13 y = np.cos(x/10.)
13 y = np.cos(x/10.)
14 return SpwcVariable(time=x, data=y)
14 return SpwcVariable(time=x, data=y)
15
15
16 def make_vector(x):
16 def make_vector(x):
17 v=np.ones((len(x),3))
17 v=np.ones((len(x),3))
18 for i in range(3):
18 for i in range(3):
19 v.transpose()[:][i] = np.cos(x/10. + float(i)) + (100. * np.cos(x/10000. + float(i)))
19 v.transpose()[:][i] = np.cos(x/10. + float(i)) + (100. * np.cos(x/10000. + float(i)))
20 return SpwcVariable(time=x, data=v)
20 return SpwcVariable(time=x, data=v)
21
21
22
22
23 def make_multicomponent(x):
23 def make_multicomponent(x):
24 v=np.ones((len(x),4))
24 v=np.ones((len(x),4))
25 for i in range(4):
25 for i in range(4):
26 v.transpose()[:][i] = float(i+1) * np.cos(x/10. + float(i))
26 v.transpose()[:][i] = float(i+1) * np.cos(x/10. + float(i))
27 return SpwcVariable(time=x, data=v)
27 return SpwcVariable(time=x, data=v)
28
28
29 def make_spectrogram(x):
29 def make_spectrogram(x):
30 v=np.ones((len(x),32))
30 v=np.ones((len(x),32))
31 for i in range(32):
31 for i in range(32):
32 v.transpose()[:][i] = 100.*(2.+ float(i+1) * np.cos(x/1024. + float(i)))
32 v.transpose()[:][i] = 100.*(2.+ float(i+1) * np.cos(x/1024. + float(i)))
33 return SpwcVariable(time=x, data=v)
33 return SpwcVariable(time=x, data=v)
34
34
35
35
36 def _get_data(p_type, start, stop):
36 def _get_data(p_type, start, stop):
37 if type(start) is datetime:
37 if type(start) is datetime:
38 start = start.timestamp()
38 start = start.timestamp()
39 stop = stop.timestamp()
39 stop = stop.timestamp()
40 x = np.arange(math.ceil(start), math.floor(stop))*1.
40 x = np.arange(math.ceil(start), math.floor(stop))*1.
41 if p_type == 'scalar':
41 if p_type == 'scalar':
42 return make_scalar(x)
42 return make_scalar(x)
43 if p_type == 'vector':
43 if p_type == 'vector':
44 return make_vector(x)
44 return make_vector(x)
45 if p_type == 'multicomponent':
45 if p_type == 'multicomponent':
46 return make_multicomponent(x)
46 return make_multicomponent(x)
47 if p_type == 'spectrogram':
47 if p_type == 'spectrogram':
48 return make_spectrogram(np.arange(math.ceil(start), math.floor(stop),15.))
48 return make_spectrogram(np.arange(math.ceil(start), math.floor(stop),15.))
49 return None
49 return None
50
50
51 class MyProvider(PyDataProvider):
51 class MyProvider(PyDataProvider):
52 def __init__(self):
52 def __init__(self):
53 super(MyProvider,self).__init__()
53 super(MyProvider,self).__init__()
54 self.register_products([Product("/tests/without_cache/scalar",[],{"type":"scalar"}),
54 self.register_products([Product("/tests/without_cache/scalar",[],{"type":"scalar"}),
55 Product("/tests/without_cache/vector",[],{"type":"vector"}),
55 Product("/tests/without_cache/vector",[],{"type":"vector"}),
56 Product("/tests/without_cache/multicomponent",[],{"type":"multicomponent",'size':'4'}),
56 Product("/tests/without_cache/multicomponent",[],{"type":"multicomponent",'size':'4'}),
57 Product("/tests/without_cache/spectrogram",[],{"type":"spectrogram",'size':'32'}),
57 Product("/tests/without_cache/spectrogram",[],{"type":"spectrogram",'size':'32'}),
58 Product("/tests/with_cache/scalar",[],{"type":"scalar", "cache":"true"}),
58 Product("/tests/with_cache/scalar",[],{"type":"scalar", "cache":"true"}),
59 Product("/tests/with_cache/vector",[],{"type":"vector", "cache":"true"}),
59 Product("/tests/with_cache/vector",[],{"type":"vector", "cache":"true"}),
60 Product("/tests/with_cache/multicomponent",[],{"type":"multicomponent",'size':'4', "cache":"true"})
60 Product("/tests/with_cache/multicomponent",[],{"type":"multicomponent",'size':'4', "cache":"true"})
61 ])
61 ])
62
62
63 def get_data(self,metadata,start,stop):
63 def get_data(self,metadata,start,stop):
64 ts_type = DataSeriesType.SCALAR
64 ts_type = DataSeriesType.SCALAR
65 default_ctor_args = 1
65 default_ctor_args = 1
66 use_cache = False
66 use_cache = False
67 p_type = 'scalar'
67 p_type = 'scalar'
68 try:
68 try:
69 for key,value in metadata.items():
69 for key,value in metadata.items():
70 if key == 'type':
70 if key == 'type':
71 p_type = value
71 p_type = value
72 if value == 'vector':
72 if value == 'vector':
73 ts_type = DataSeriesType.VECTOR
73 ts_type = DataSeriesType.VECTOR
74 elif value == 'multicomponent':
74 elif value == 'multicomponent':
75 ts_type = DataSeriesType.MULTICOMPONENT
75 ts_type = DataSeriesType.MULTICOMPONENT
76 elif value == 'spectrogram':
76 elif value == 'spectrogram':
77 ts_type = DataSeriesType.SPECTROGRAM
77 ts_type = DataSeriesType.SPECTROGRAM
78 if key == 'cache' and value == 'true':
78 if key == 'cache' and value == 'true':
79 use_cache = True
79 use_cache = True
80 if use_cache:
80 if use_cache:
81 cache_product = f"tests/{p_type}"
81 cache_product = f"tests/{p_type}"
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)
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 else:
83 else:
84 print("No Cache")
85 var = _get_data(p_type, start, stop)
84 var = _get_data(p_type, start, stop)
86 return ((var.time,var.data), ts_type)
85 return ((var.time,var.data), ts_type)
87 except Exception as e:
86 except Exception as e:
88 print(traceback.format_exc())
87 print(traceback.format_exc())
89 print("Error in test.py ",str(e))
88 print("Error in test.py ",str(e))
90 return ((np.array(), np.array()), ts_type)
89 return ((np.array(), np.array()), ts_type)
91
90
92
91
93 t=MyProvider()
92 t=MyProvider()
94
93
@@ -1,1 +1,1
1 Subproject commit 9868166a1d6d779910b93a996b2b69d399168914
1 Subproject commit b081849458c211dcc59f72b11542959db2301162
General Comments 0
You need to be logged in to leave comments. Login now