##// END OF EJS Templates
More fixes on spectrograms...
More fixes on spectrograms Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>

File last commit:

r1467:da44adcd99e4
r1471:d48510a1cc4a
Show More
amda.py
100 lines | 3.8 KiB | text/x-python | PythonLexer
WIP Multicomponent TS...
r1431 import traceback
Some more progress on Python Providers side, works with a simple request on CDAWeb....
r1429 import os
WIP Multicomponent TS...
r1431 from datetime import datetime, timedelta, timezone
Some more progress on Python Providers side, works with a simple request on CDAWeb....
r1429 import PythonProviders
import pysciqlopcore
import numpy as np
import requests
MultiComponent TS almost complete...
r1432 import copy
Added POC AMDA python impl and CDAWEB bits...
r1430 from spwc.amda import AMDA
Some more progress on Python Providers side, works with a simple request on CDAWeb....
r1429
Added POC AMDA python impl and CDAWEB bits...
r1430 amda = AMDA()
Mostly working Spectrograms...
r1465 def amda_make_scalar(var=None):
if var is None:
return pysciqlopcore.ScalarTimeSerie(1)
else:
return pysciqlopcore.ScalarTimeSerie(var.time,var.data)
def amda_make_vector(var=None):
if var is None:
return pysciqlopcore.VectorTimeSerie(1)
else:
return pysciqlopcore.VectorTimeSerie(var.time,var.data)
def amda_make_multi_comp(var=None):
if var is None:
return pysciqlopcore.MultiComponentTimeSerie((0,2))
else:
return pysciqlopcore.MultiComponentTimeSerie(var.time,var.data)
def amda_make_spectro(var=None):
if var is None:
return pysciqlopcore.SpectrogramTimeSerie((0,2))
else:
Spectrogram segfault should be fixed now, added ability to provide Spectrogram min sampling time to avoid computation when possible...
r1467 min_sampling = float(var.meta.get("DATASET_MIN_SAMPLING","nan"))
max_sampling = float(var.meta.get("DATASET_MAX_SAMPLING","nan"))
Mostly working Spectrograms...
r1465 if "PARAMETER_TABLE_MIN_VALUES[1]" in var.meta:
min_v = np.array([ float(v) for v in var.meta["PARAMETER_TABLE_MIN_VALUES[1]"].split(',') ])
max_v = np.array([ float(v) for v in var.meta["PARAMETER_TABLE_MAX_VALUES[1]"].split(',') ])
y = (max_v + min_v)/2.
elif "PARAMETER_TABLE_MIN_VALUES[0]" in var.meta:
min_v = np.array([ float(v) for v in var.meta["PARAMETER_TABLE_MIN_VALUES[0]"].split(',') ])
max_v = np.array([ float(v) for v in var.meta["PARAMETER_TABLE_MAX_VALUES[0]"].split(',') ])
y = (max_v + min_v)/2.
else:
y = np.logspace(1,3,var.data.shape[1])[::-1]
Spectrogram segfault should be fixed now, added ability to provide Spectrogram min sampling time to avoid computation when possible...
r1467 return pysciqlopcore.SpectrogramTimeSerie(var.time,y,var.data,min_sampling,max_sampling)
Mostly working Spectrograms...
r1465
def amda_get_sample(metadata,start,stop):
ts_type = amda_make_scalar
Some more progress on Python Providers side, works with a simple request on CDAWeb....
r1429 try:
Added POC AMDA python impl and CDAWEB bits...
r1430 param_id = None
for key,value in metadata:
if key == 'xml:id':
param_id = value
elif key == 'type':
if value == 'vector':
Mostly working Spectrograms...
r1465 ts_type = amda_make_vector
MultiComponent TS almost complete...
r1432 elif value == 'multicomponent':
Mostly working Spectrograms...
r1465 ts_type = amda_make_multi_comp
elif value == 'spectrogram':
ts_type = amda_make_spectro
Better AMDA tree and test data cat also go through cache...
r1439 tstart=datetime.fromtimestamp(start, tz=timezone.utc)
tend=datetime.fromtimestamp(stop, tz=timezone.utc)
Some added fake specro and switched to new spwc getting rid of DataFrames...
r1464 var = amda.get_parameter(start_time=tstart, stop_time=tend, parameter_id=param_id, method="REST")
Mostly working Spectrograms...
r1465 return ts_type(var)
Some more progress on Python Providers side, works with a simple request on CDAWeb....
r1429 except Exception as e:
WIP Multicomponent TS...
r1431 print(traceback.format_exc())
Added POC AMDA python impl and CDAWEB bits...
r1430 print("Error in amda.py ",str(e))
Mostly working Spectrograms...
r1465 return ts_type()
Added POC AMDA python impl and CDAWEB bits...
r1430
if len(amda.component) is 0:
amda.update_inventory()
MultiComponent TS almost complete...
r1432 parameters = copy.deepcopy(amda.parameter)
Added POC AMDA python impl and CDAWEB bits...
r1430 for name,component in amda.component.items():
if 'components' in parameters[component['parameter']]:
parameters[component['parameter']]['components'].append(component)
else:
parameters[component['parameter']]['components']=[component]
products = []
for key,parameter in parameters.items():
Better AMDA tree and test data cat also go through cache...
r1439 path = f"/AMDA/{parameter['mission']}/{parameter.get('observatory','')}/{parameter['instrument']}/{parameter['dataset']}/{parameter['name']}"
Added POC AMDA python impl and CDAWEB bits...
r1430 components = [component['name'] for component in parameter.get('components',[])]
metadata = [ (key,item) for key,item in parameter.items() if key is not 'components' ]
MultiComponent TS almost complete...
r1432 n_components = parameter.get('size',0)
Mostly working Spectrograms...
r1465 if n_components == '3':
Added POC AMDA python impl and CDAWEB bits...
r1430 metadata.append(("type","vector"))
Mostly working Spectrograms...
r1465 elif parameter.get('display_type','')=="spectrogram":
metadata.append(("type","spectrogram"))
MultiComponent TS almost complete...
r1432 elif n_components !=0:
Mostly working Spectrograms...
r1465 metadata.append(("type","multicomponent"))
Added POC AMDA python impl and CDAWEB bits...
r1430 else:
metadata.append(("type","scalar"))
products.append( (path, components, metadata))
Some more progress on Python Providers side, works with a simple request on CDAWeb....
r1429
Mostly working Spectrograms...
r1465 PythonProviders.register_product(products, amda_get_sample)
Some more progress on Python Providers side, works with a simple request on CDAWeb....
r1429