##// END OF EJS Templates
A new Plotter Class was added for plotting using queues
A new Plotter Class was added for plotting using queues

File last commit:

r691:4042108b4f6b
r691:4042108b4f6b
Show More
jroproc_base.py
293 lines | 8.2 KiB | text/x-python | PythonLexer
Daniel Valdez
This is the new organization by packages and scripts for Signal Chain, this version contains new features and bugs fixed until August 2014
r487 '''
Miguel Valdez
Merge with branch schain_julia_drifts from rev. 803 to 995....
r568
$Author: murco $
$Id: jroproc_base.py 1 2012-11-12 18:56:07Z murco $
Daniel Valdez
This is the new organization by packages and scripts for Signal Chain, this version contains new features and bugs fixed until August 2014
r487 '''
Miguel Valdez
Merge with branch schain_julia_drifts from rev. 803 to 995....
r568 class ProcessingUnit(object):
Daniel Valdez
This is the new organization by packages and scripts for Signal Chain, this version contains new features and bugs fixed until August 2014
r487
"""
Esta es la clase base para el procesamiento de datos.
Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser:
- Metodos internos (callMethod)
- Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos
tienen que ser agreagados con el metodo "add".
"""
# objeto de datos de entrada (Voltage, Spectra o Correlation)
dataIn = None
dataInList = []
# objeto de datos de entrada (Voltage, Spectra o Correlation)
dataOut = None
operations2RunDict = None
isConfig = False
def __init__(self):
self.dataIn = None
self.dataInList = []
Miguel Valdez
A new SendToServer Unit has been created to upload files to a remote server....
r573 self.dataOut = None
Daniel Valdez
This is the new organization by packages and scripts for Signal Chain, this version contains new features and bugs fixed until August 2014
r487
self.operations2RunDict = {}
self.isConfig = False
def addOperation(self, opObj, objId):
"""
Agrega un objeto del tipo "Operation" (opObj) a la lista de objetos "self.objectList" y retorna el
identificador asociado a este objeto.
Input:
object : objeto de la clase "Operation"
Return:
objId : identificador del objeto, necesario para ejecutar la operacion
"""
self.operations2RunDict[objId] = opObj
return objId
Miguel Valdez
r577 def getOperationObj(self, objId):
if objId not in self.operations2RunDict.keys():
return None
return self.operations2RunDict[objId]
Daniel Valdez
This is the new organization by packages and scripts for Signal Chain, this version contains new features and bugs fixed until August 2014
r487 def operation(self, **kwargs):
"""
Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los
atributos del objeto dataOut
Input:
**kwargs : Diccionario de argumentos de la funcion a ejecutar
"""
Miguel Valdez
-Using ValueError raises instead of IOError...
r684 raise NotImplementedError
Daniel Valdez
This is the new organization by packages and scripts for Signal Chain, this version contains new features and bugs fixed until August 2014
r487
def callMethod(self, name, **kwargs):
"""
Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase.
Input:
name : nombre del metodo a ejecutar
**kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
"""
Miguel Valdez
Merge with branch schain_julia_drifts from rev. 803 to 995....
r568
#Checking the inputs
Daniel Valdez
This is the new organization by packages and scripts for Signal Chain, this version contains new features and bugs fixed until August 2014
r487 if name == 'run':
if not self.checkInputs():
self.dataOut.flagNoData = True
return False
else:
#Si no es un metodo RUN la entrada es la misma dataOut (interna)
if self.dataOut.isEmpty():
return False
#Getting the pointer to method
methodToCall = getattr(self, name)
#Executing the self method
methodToCall(**kwargs)
#Checkin the outputs
# if name == 'run':
# pass
# else:
# pass
#
# if name != 'run':
# return True
Miguel Valdez
A new SendToServer Unit has been created to upload files to a remote server....
r573
Miguel Valdez
Bug fixed: Padding decode data with zeros at the first heights was eliminated.
r611 if self.dataOut is None:
Miguel Valdez
A new SendToServer Unit has been created to upload files to a remote server....
r573 return False
Daniel Valdez
This is the new organization by packages and scripts for Signal Chain, this version contains new features and bugs fixed until August 2014
r487 if self.dataOut.isEmpty():
return False
return True
def callObject(self, objId, **kwargs):
"""
Ejecuta la operacion asociada al identificador del objeto "objId"
Input:
objId : identificador del objeto a ejecutar
**kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
Return:
None
"""
if self.dataOut.isEmpty():
return False
externalProcObj = self.operations2RunDict[objId]
externalProcObj.run(self.dataOut, **kwargs)
return True
def call(self, opType, opName=None, opId=None, **kwargs):
"""
Miguel Valdez
Merge with branch schain_julia_drifts from rev. 803 to 995....
r568 Return True si ejecuta la operacion interna nombrada "opName" o la operacion externa
identificada con el id "opId"; con los argumentos "**kwargs".
Daniel Valdez
This is the new organization by packages and scripts for Signal Chain, this version contains new features and bugs fixed until August 2014
r487
Miguel Valdez
Merge with branch schain_julia_drifts from rev. 803 to 995....
r568 False si la operacion no se ha ejecutado.
Input:
opType : Puede ser "self" o "external"
Miguel Valdez
A new Plotter Class was added for plotting using queues
r691 Depende del tipo de operacion para llamar a:callMethod or callObject:
Daniel Valdez
This is the new organization by packages and scripts for Signal Chain, this version contains new features and bugs fixed until August 2014
r487
Miguel Valdez
A new Plotter Class was added for plotting using queues
r691 1. If opType = "self": Llama a un metodo propio de esta clase:
name_method = getattr(self, name)
name_method(**kwargs)
Miguel Valdez
Merge with branch schain_julia_drifts from rev. 803 to 995....
r568
Daniel Valdez
This is the new organization by packages and scripts for Signal Chain, this version contains new features and bugs fixed until August 2014
r487
Miguel Valdez
A new Plotter Class was added for plotting using queues
r691 2. If opType = "other" o"external": Llama al metodo "run()" de una instancia de la
clase "Operation" o de un derivado de ella:
Miguel Valdez
Merge with branch schain_julia_drifts from rev. 803 to 995....
r568
Miguel Valdez
A new Plotter Class was added for plotting using queues
r691 instanceName = self.operationList[opId]
instanceName.run(**kwargs)
Daniel Valdez
This is the new organization by packages and scripts for Signal Chain, this version contains new features and bugs fixed until August 2014
r487
Miguel Valdez
Merge with branch schain_julia_drifts from rev. 803 to 995....
r568 opName : Si la operacion es interna (opType = 'self'), entonces el "opName" sera
usada para llamar a un metodo interno de la clase Processing
Miguel Valdez
A new Plotter Class was added for plotting using queues
r691 opId : Si la operacion es externa (opType = 'other' o 'external), entonces el
"opId" sera usada para llamar al metodo "run" de la clase Operation
registrada anteriormente con ese Id
Daniel Valdez
This is the new organization by packages and scripts for Signal Chain, this version contains new features and bugs fixed until August 2014
r487
Miguel Valdez
Merge with branch schain_julia_drifts from rev. 803 to 995....
r568 Exception:
Este objeto de tipo Operation debe de haber sido agregado antes con el metodo:
"addOperation" e identificado con el valor "opId" = el id de la operacion.
Miguel Valdez
A new Plotter Class was added for plotting using queues
r691 De lo contrario retornara un error del tipo ValueError
Daniel Valdez
This is the new organization by packages and scripts for Signal Chain, this version contains new features and bugs fixed until August 2014
r487
"""
if opType == 'self':
if not opName:
Miguel Valdez
-Using ValueError raises instead of IOError...
r684 raise ValueError, "opName parameter should be defined"
Daniel Valdez
This is the new organization by packages and scripts for Signal Chain, this version contains new features and bugs fixed until August 2014
r487
sts = self.callMethod(opName, **kwargs)
Miguel Valdez
A new Plotter Class was added for plotting using queues
r691 elif opType == 'other' or opType == 'external' or opType == 'plotter':
Daniel Valdez
This is the new organization by packages and scripts for Signal Chain, this version contains new features and bugs fixed until August 2014
r487
if not opId:
Miguel Valdez
-Using ValueError raises instead of IOError...
r684 raise ValueError, "opId parameter should be defined"
Daniel Valdez
This is the new organization by packages and scripts for Signal Chain, this version contains new features and bugs fixed until August 2014
r487
if opId not in self.operations2RunDict.keys():
Miguel Valdez
A new Plotter Class was added for plotting using queues
r691 raise ValueError, "Any operation with id=%s has been added" %str(opId)
Daniel Valdez
This is the new organization by packages and scripts for Signal Chain, this version contains new features and bugs fixed until August 2014
r487
sts = self.callObject(opId, **kwargs)
Miguel Valdez
A new Plotter Class was added for plotting using queues
r691 else:
raise ValueError, "opType should be 'self', 'external' or 'plotter'; and not '%s'" %opType
Daniel Valdez
This is the new organization by packages and scripts for Signal Chain, this version contains new features and bugs fixed until August 2014
r487 return sts
def setInput(self, dataIn):
self.dataIn = dataIn
self.dataInList.append(dataIn)
def getOutputObj(self):
return self.dataOut
def checkInputs(self):
for thisDataIn in self.dataInList:
if thisDataIn.isEmpty():
return False
return True
def setup(self):
Miguel Valdez
-Using ValueError raises instead of IOError...
r684 raise NotImplementedError
Daniel Valdez
This is the new organization by packages and scripts for Signal Chain, this version contains new features and bugs fixed until August 2014
r487
def run(self):
Miguel Valdez
-Using ValueError raises instead of IOError...
r684 raise NotImplementedError
Miguel Valdez
A new SendToServer Unit has been created to upload files to a remote server....
r573
def close(self):
#Close every thread, queue or any other object here is it is neccesary.
return
Miguel Valdez
Merge with branch schain_julia_drifts from rev. 803 to 995....
r568 class Operation(object):
Daniel Valdez
This is the new organization by packages and scripts for Signal Chain, this version contains new features and bugs fixed until August 2014
r487
"""
Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit
y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de
acumulacion dentro de esta clase
Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer)
"""
__buffer = None
isConfig = False
def __init__(self):
self.__buffer = None
self.isConfig = False
def setup(self):
self.isConfig = True
Miguel Valdez
-Using ValueError raises instead of IOError...
r684 raise NotImplementedError
Daniel Valdez
This is the new organization by packages and scripts for Signal Chain, this version contains new features and bugs fixed until August 2014
r487
def run(self, dataIn, **kwargs):
"""
Miguel Valdez
Merge with branch schain_julia_drifts from rev. 803 to 995....
r568 Realiza las operaciones necesarias sobre la dataIn.data y actualiza los
atributos del objeto dataIn.
Daniel Valdez
This is the new organization by packages and scripts for Signal Chain, this version contains new features and bugs fixed until August 2014
r487
Input:
dataIn : objeto del tipo JROData
Return:
None
Affected:
__buffer : buffer de recepcion de datos.
"""
if not self.isConfig:
self.setup(**kwargs)
Miguel Valdez
-Using ValueError raises instead of IOError...
r684 raise NotImplementedError
Miguel Valdez
r577
def close(self):
pass