##// END OF EJS Templates
Mostly working Spectrograms...
Mostly working Spectrograms Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>

File last commit:

r1465:42e61e7ce5b3
r1465:42e61e7ce5b3
Show More
test.py
96 lines | 3.5 KiB | text/x-python | PythonLexer
Amda, cdaweb and test python are now fully embedded in SciQLop...
r1440 import traceback
import pandas as pds
WIP Multicomponent TS...
r1431 import PythonProviders
import pysciqlopcore
import numpy as np
Few fixes with merging empty csv files from Web Services...
r1433 import math
Better AMDA tree and test data cat also go through cache...
r1439 from spwc.cache import _cache
from spwc.common.datetime_range import DateTimeRange
from functools import partial
from datetime import datetime, timedelta, timezone
Some added fake specro and switched to new spwc getting rid of DataFrames...
r1464 from spwc.common.variable import SpwcVariable
WIP Multicomponent TS...
r1431
MultiComponent TS almost complete...
r1432 def make_scalar(x):
WIP Multicomponent TS...
r1431 y = np.cos(x/10.)
Some added fake specro and switched to new spwc getting rid of DataFrames...
r1464 return SpwcVariable(time=x, data=y)
WIP Multicomponent TS...
r1431
MultiComponent TS almost complete...
r1432 def make_vector(x):
Implemented MultiComponent TS initial plot auto-scale...
r1436 v=np.ones((len(x),3))
MultiComponent TS almost complete...
r1432 for i in range(3):
Better AMDA tree and test data cat also go through cache...
r1439 v.transpose()[:][i] = np.cos(x/10. + float(i)) + (100. * np.cos(x/10000. + float(i)))
Some added fake specro and switched to new spwc getting rid of DataFrames...
r1464 return SpwcVariable(time=x, data=v)
MultiComponent TS almost complete...
r1432
def make_multicomponent(x):
Implemented MultiComponent TS initial plot auto-scale...
r1436 v=np.ones((len(x),4))
MultiComponent TS almost complete...
r1432 for i in range(4):
Implemented MultiComponent TS initial plot auto-scale...
r1436 v.transpose()[:][i] = float(i+1) * np.cos(x/10. + float(i))
Some added fake specro and switched to new spwc getting rid of DataFrames...
r1464 return SpwcVariable(time=x, data=v)
def make_spectrogram(x):
v=np.ones((len(x),32))
for i in range(32):
v.transpose()[:][i] = 100.*(2.+ float(i+1) * np.cos(x/1024. + float(i)))
return SpwcVariable(time=x, data=v)
MultiComponent TS almost complete...
r1432
Better AMDA tree and test data cat also go through cache...
r1439 def _get_data(p_type, start, stop):
if type(start) is datetime:
start = start.timestamp()
stop = stop.timestamp()
Few fixes with merging empty csv files from Web Services...
r1433 x = np.arange(math.ceil(start), math.floor(stop))
Better AMDA tree and test data cat also go through cache...
r1439 if p_type == 'scalar':
return make_scalar(x)
if p_type == 'vector':
return make_vector(x)
if p_type == 'multicomponent':
return make_multicomponent(x)
Some added fake specro and switched to new spwc getting rid of DataFrames...
r1464 if p_type == 'spectrogram':
return make_spectrogram(np.arange(math.ceil(start), math.floor(stop),15.))
Better AMDA tree and test data cat also go through cache...
r1439 return None
MultiComponent TS almost complete...
r1432
Better AMDA tree and test data cat also go through cache...
r1439 def get_data(metadata,start,stop):
ts_type = pysciqlopcore.ScalarTimeSerie
default_ctor_args = 1
use_cache = False
p_type = 'scalar'
try:
for key,value in metadata:
if key == 'type':
p_type = value
if value == 'vector':
ts_type = pysciqlopcore.VectorTimeSerie
elif value == 'multicomponent':
ts_type = pysciqlopcore.MultiComponentTimeSerie
default_ctor_args = (0,2)
Some added fake specro and switched to new spwc getting rid of DataFrames...
r1464 elif value == 'spectrogram':
Mostly working Spectrograms...
r1465 ts_type = lambda t,values: pysciqlopcore.SpectrogramTimeSerie(t,np.logspace(1,3,32)[::-1],values)
Some added fake specro and switched to new spwc getting rid of DataFrames...
r1464 default_ctor_args = (0,2)
Better AMDA tree and test data cat also go through cache...
r1439 if key == 'cache' and value == 'true':
use_cache = True
if use_cache:
cache_product = f"tests/{p_type}"
Some added fake specro and switched to new spwc getting rid of DataFrames...
r1464 var = _cache.get_data(cache_product, DateTimeRange(datetime.fromtimestamp(start, tz=timezone.utc), datetime.fromtimestamp(stop, tz=timezone.utc)),
Better AMDA tree and test data cat also go through cache...
r1439 partial(_get_data, p_type),
fragment_hours=24)
else:
print("No Cache")
Some added fake specro and switched to new spwc getting rid of DataFrames...
r1464 var = _get_data(p_type, start, stop)
return ts_type(var.time,var.data)
Better AMDA tree and test data cat also go through cache...
r1439 except Exception as e:
print(traceback.format_exc())
print("Error in test.py ",str(e))
return ts_type(default_ctor_args)
WIP Multicomponent TS...
r1431
Better AMDA tree and test data cat also go through cache...
r1439 products = [
("/tests/without_cache/scalar",[],[("type","scalar")]),
("/tests/without_cache/vector",[],[("type","vector")]),
("/tests/without_cache/multicomponent",[],[("type","multicomponent"),('size','4')]),
Some added fake specro and switched to new spwc getting rid of DataFrames...
r1464 ("/tests/without_cache/spectrogram",[],[("type","spectrogram"),('size','32')]),
Better AMDA tree and test data cat also go through cache...
r1439 ("/tests/with_cache/scalar",[],[("type","scalar"), ("cache","true")]),
("/tests/with_cache/vector",[],[("type","vector"), ("cache","true")]),
("/tests/with_cache/multicomponent",[],[("type","multicomponent"),('size','4'), ("cache","true")])
]
WIP Multicomponent TS...
r1431
Better AMDA tree and test data cat also go through cache...
r1439 PythonProviders.register_product(products ,get_data)