##// END OF EJS Templates
Adds basic demo plugin to explain how to write custom plugins in C++...
Adds basic demo plugin to explain how to write custom plugins in C++ Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>

File last commit:

r1502:239919e8e177
r1509:3eb0350f563b
Show More
SPWC-Amda.py
128 lines | 5.3 KiB | text/x-python | PythonLexer
Added back AMDA plugin, but Python impl this time :)...
r1496 import traceback
import os
from datetime import datetime, timedelta, timezone
from SciQLopBindings import PyDataProvider, Product, VectorTimeSerie, ScalarTimeSerie, DataSeriesType
import numpy as np
import requests
import copy
from spwc.amda import AMDA
amda = AMDA()
Spectrograms works again, needs more polish......
r1498
Added back AMDA plugin, but Python impl this time :)...
r1496 def amda_make_scalar(var=None):
if var is None:
Spectrograms works again, needs more polish......
r1498 return (((np.array([]), np.array([])), np.array([])), DataSeriesType.SCALAR)
Added back AMDA plugin, but Python impl this time :)...
r1496 else:
Spectrograms works again, needs more polish......
r1498 return (((var.time, np.array([])), var.data), DataSeriesType.SCALAR)
Added back AMDA plugin, but Python impl this time :)...
r1496
def amda_make_vector(var=None):
if var is None:
Spectrograms works again, needs more polish......
r1498 return (((np.array([]), np.array([])), np.array([])), DataSeriesType.VECTOR)
Added back AMDA plugin, but Python impl this time :)...
r1496 else:
Spectrograms works again, needs more polish......
r1498 return (((var.time, np.array([])), var.data), DataSeriesType.VECTOR)
Added back AMDA plugin, but Python impl this time :)...
r1496
def amda_make_multi_comp(var=None):
if var is None:
Spectrograms works again, needs more polish......
r1498 return (((np.array([]), np.array([])), np.array([])), DataSeriesType.MULTICOMPONENT)
Added back AMDA plugin, but Python impl this time :)...
r1496 else:
Spectrograms works again, needs more polish......
r1498 return (((var.time, np.array([])), var.data), DataSeriesType.MULTICOMPONENT)
Added back AMDA plugin, but Python impl this time :)...
r1496
def amda_make_spectro(var=None):
if var is None:
Spectrograms works again, needs more polish......
r1498 return (((np.array([]), np.array([])), np.array([])), DataSeriesType.SPECTROGRAM)
Added back AMDA plugin, but Python impl this time :)...
r1496 else:
Spectrograms works again, needs more polish......
r1498 min_sampling = float(var.meta.get("DATASET_MIN_SAMPLING", "nan"))
max_sampling = float(var.meta.get("DATASET_MAX_SAMPLING", "nan"))
if var.y is None and len(var.data):
var.y = np.logspace(1, 3, var.data.shape[1])[::-1]
return (((var.time, var.y), var.data), DataSeriesType.SPECTROGRAM)
Added back AMDA plugin, but Python impl this time :)...
r1496 #return pysciqlopcore.SpectrogramTimeSerie(var.time,y,var.data,min_sampling,max_sampling,True)
Spectrograms works again, needs more polish......
r1498
def amda_get_sample(metadata, start, stop):
Added back AMDA plugin, but Python impl this time :)...
r1496 ts_type = amda_make_scalar
try:
param_id = None
Spectrograms works again, needs more polish......
r1498 for key, value in metadata:
Added back AMDA plugin, but Python impl this time :)...
r1496 if key == 'xml:id':
param_id = value
elif key == 'type':
if value == 'vector':
ts_type = amda_make_vector
elif value == 'multicomponent':
ts_type = amda_make_multi_comp
elif value == 'spectrogram':
ts_type = amda_make_spectro
Spectrograms works again, needs more polish......
r1498 tstart = datetime.fromtimestamp(start, tz=timezone.utc)
tend = datetime.fromtimestamp(stop, tz=timezone.utc)
Added back AMDA plugin, but Python impl this time :)...
r1496 var = amda.get_parameter(start_time=tstart, stop_time=tend, parameter_id=param_id, method="REST")
return ts_type(var)
except Exception as e:
print(traceback.format_exc())
Spectrograms works again, needs more polish......
r1498 print("Error in amda.py ", str(e))
Added back AMDA plugin, but Python impl this time :)...
r1496 return ts_type()
class AmdaProvider(PyDataProvider):
def __init__(self):
Spectrograms works again, needs more polish......
r1498 super(AmdaProvider, self).__init__()
Added back AMDA plugin, but Python impl this time :)...
r1496 if len(amda.component) is 0:
amda.update_inventory()
parameters = copy.deepcopy(amda.parameter)
Spectrograms works again, needs more polish......
r1498 for name, component in amda.component.items():
Added back AMDA plugin, but Python impl this time :)...
r1496 if 'components' in parameters[component['parameter']]:
parameters[component['parameter']]['components'].append(component)
else:
parameters[component['parameter']]['components']=[component]
products = []
Spectrograms works again, needs more polish......
r1498 for key, parameter in parameters.items():
Improved AMDA tree, uses node names instead of xml:id which is more...
r1502 mission_name = amda.mission[parameter['mission']]['name']
observatory_name = parameter.get('observatory','')
if observatory_name != '':
observatory_name = amda.observatory[observatory_name]['name']
instrument_name = amda.instrument[parameter['instrument']]['name']
dataset_name = amda.dataset[parameter['dataset']]['name']
path = f"/AMDA/{mission_name}/{observatory_name}/{instrument_name}/{dataset_name}/{parameter['name']}"
Added back AMDA plugin, but Python impl this time :)...
r1496 components = [component['name'] for component in parameter.get('components',[])]
Spectrograms works again, needs more polish......
r1498 metadata = {key: item for key, item in parameter.items() if key is not 'components'}
n_components = parameter.get('size', 0)
Added back AMDA plugin, but Python impl this time :)...
r1496 if n_components == '3':
Spectrograms works again, needs more polish......
r1498 metadata["type"] = "vector"
elif parameter.get('display_type', '')=="spectrogram":
metadata["type"] = "spectrogram"
elif n_components != 0:
metadata["type"] = "multicomponent"
Added back AMDA plugin, but Python impl this time :)...
r1496 else:
Spectrograms works again, needs more polish......
r1498 metadata["type"] = "scalar"
products.append(Product(path, components, metadata))
Added back AMDA plugin, but Python impl this time :)...
r1496 self.register_products(products)
Improved AMDA tree, uses node names instead of xml:id which is more...
r1502 for _,mission in amda.mission.items():
if ('target' in mission) and (mission['xml:id'] != 'Ephemerides') and (mission['target'] != 'Earth'):
self.set_icon(f'/AMDA/{mission["name"]}','satellite')
Added back AMDA plugin, but Python impl this time :)...
r1496
Spectrograms works again, needs more polish......
r1498 def get_data(self, metadata, start, stop):
Added back AMDA plugin, but Python impl this time :)...
r1496 ts_type = amda_make_scalar
try:
param_id = metadata['xml:id']
ts_type_str = metadata['type']
if ts_type_str == 'vector':
ts_type = amda_make_vector
elif ts_type_str == 'multicomponent':
ts_type = amda_make_multi_comp
elif ts_type_str == 'spectrogram':
ts_type = amda_make_spectro
Spectrograms works again, needs more polish......
r1498 tstart = datetime.fromtimestamp(start, tz=timezone.utc)
tend = datetime.fromtimestamp(stop, tz=timezone.utc)
Added back AMDA plugin, but Python impl this time :)...
r1496 var = amda.get_parameter(start_time=tstart, stop_time=tend, parameter_id=param_id, method="REST")
return ts_type(var)
except Exception as e:
print(traceback.format_exc())
Spectrograms works again, needs more polish......
r1498 print("Error in amda.py ", str(e))
Added back AMDA plugin, but Python impl this time :)...
r1496 return ts_type()
_amda = AmdaProvider()