From 2739006ee497291126f69091280d6ecde8feb9f4 2025-04-22 22:42:46 From: Christian Portilla Date: 2025-04-22 22:42:46 Subject: [PATCH] Added ToLilBlock class from Roberto --- diff --git a/schainpy/controller.py b/schainpy/controller.py index 51301d7..70fda95 100644 --- a/schainpy/controller.py +++ b/schainpy/controller.py @@ -647,21 +647,49 @@ class Project(Process): err = False n = len(self.configurations) - #print(n) - + flag_no_read = False + nProc_noRead = 0 + + #while not err: + # for conf in self.getUnits(): + # ok = conf.run() + # if ok == 'Error': + # n -= 1 + # continue + # elif not ok: + # break + # if n == 0: + # err = True + while not err: - #print(self.getUnits()) + n_proc = 0 for conf in self.getUnits(): - #print(conf) - ok = conf.run() - #print("ok", ok) + if flag_no_read: + if n_proc >= nProc_noRead: + ok = conf.run() + else: + n_proc += 1 + continue + else: + ok = conf.run() + + n_proc += 1 + if ok == 'Error': n -= 1 continue + + elif ok == 'no_Read' and (not flag_no_read): + nProc_noRead = n_proc - 1 + flag_no_read = True + continue + elif ok == 'new_Read': + nProc_noRead = 0 + flag_no_read = False + continue elif not ok: break - #print("****************************************************end") - #exit(1) + if n == 0: err = True diff --git a/schainpy/model/proc/jroproc_base.py b/schainpy/model/proc/jroproc_base.py index 9ebcb6c..606d51f 100644 --- a/schainpy/model/proc/jroproc_base.py +++ b/schainpy/model/proc/jroproc_base.py @@ -67,29 +67,25 @@ class ProcessingUnit(object): return self.operations[objId] def call(self, **kwargs): - ''' - ''' + mybool = (self.dataOut.type == 'Voltage') and self.dataOut.useInputBuffer and (not self.dataOut.buffer_empty) #liberar desde buffer + try: - if self.dataIn is not None and self.dataIn.flagNoData and not self.dataIn.error: - #if self.dataIn is not None and self.dataIn.flagNoData and not self.dataIn.error and not self.dataIn.runNextUnit: - if self.dataIn.runNextUnit: - #print("SUCCESSSSSSS") - #exit(1) - return not self.dataIn.isReady() - else: - return self.dataIn.isReady() - elif self.dataIn is None or not self.dataIn.error: - if 'Reader' in self.name and self.bypass: - print('Skipping...reader') - return self.dataOut.isReady() + if mybool: + #print("run jeje") self.run(**kwargs) - elif self.dataIn.error: - #print("Elif 2") - self.dataOut.error = self.dataIn.error - self.dataOut.flagNoData = True + else: + if self.dataIn is not None and self.dataIn.flagNoData and not self.dataIn.error: + return self.dataIn.isReady() + elif self.dataIn is None or not self.dataIn.error: #unidad de lectura o procesamiento regular + self.run(**kwargs) + elif self.dataIn.error: + self.dataOut.error = self.dataIn.error + self.dataOut.flagNoData = True + print("exec proc error") + except: - #print("Except") + err = traceback.format_exc() if 'SchainWarning' in err: log.warning(err.split('SchainWarning:')[-1].split('\n')[0].strip(), self.name) @@ -98,39 +94,37 @@ class ProcessingUnit(object): else: log.error(err, self.name) self.dataOut.error = True - #print("before op") + + for op, optype, opkwargs in self.operations: - aux = self.dataOut.copy() - #aux = copy.deepcopy(self.dataOut) - #print("**********************Before",op) - if optype == 'other' and not self.dataOut.flagNoData: - #print("**********************Other",op) - #print(self.dataOut.flagNoData) - self.dataOut = op.run(self.dataOut, **opkwargs) - elif optype == 'external' and not self.dataOut.flagNoData: - op.queue.put(aux) + + if (optype == 'other' and self.dataOut.isReady()) or mybool: + try: + self.dataOut = op.run(self.dataOut, **opkwargs) + except Exception as e: + print(e) + self.dataOut.error = True + return 'Error' + elif optype == 'external' and self.dataOut.isReady() : + op.queue.put(copy.deepcopy(self.dataOut)) elif optype == 'external' and self.dataOut.error: - op.queue.put(aux) - #elif optype == 'external' and self.dataOut.isReady(): - #op.queue.put(copy.deepcopy(self.dataOut)) - #print(not self.dataOut.isReady()) + op.queue.put(copy.deepcopy(self.dataOut)) - try: - if self.dataOut.runNextUnit: - runNextUnit = self.dataOut.runNextUnit - #print(self.operations) - #print("Tru") + if not self.dataOut.error: + if self.dataOut.type == 'Voltage': + if not self.dataOut.buffer_empty : #continue + return 'no_Read' + elif self.dataOut.useInputBuffer and (self.dataOut.buffer_empty) and self.dataOut.isReady() : + return 'new_Read' + else: + return True else: - runNextUnit = self.dataOut.isReady() - except: - runNextUnit = self.dataOut.isReady() - #exit(1) - #if not self.dataOut.isReady(): - #return 'Error' if self.dataOut.error else input() - #print("NexT",runNextUnit) - #print("error: ",self.dataOut.error) - return 'Error' if self.dataOut.error else runNextUnit# self.dataOut.isReady() + #print("ret True") + return True + else: + return 'Error' + #return 'Error' if self.dataOut.error else True #self.dataOut.isReady() def setup(self): diff --git a/schainpy/model/proc/jroproc_voltage.py b/schainpy/model/proc/jroproc_voltage.py index 694c9e0..dc88c81 100644 --- a/schainpy/model/proc/jroproc_voltage.py +++ b/schainpy/model/proc/jroproc_voltage.py @@ -7483,3 +7483,97 @@ class PulsePairVoltage(Operation): # self.__startIndex += self.__newNSamples # # return + +class ToLilBlock(Operation): + + ''' + Class to separate blocks of data + + ''' + + isConfig = False + n = None + __timeInterval = None + __profIndex = 0 + __byTime = False + __dataReady = False + __buffer_data = [] + __buffer_times = [] + __initime = None + __count_exec = 0 + __profIndex = 0 + buffer = None + lenProfileOut = 1 + init_prof = 0 + end_prof = 0 + n_profiles = 0 + first_utcBlock = None + __dh = 0 + + + def __init__(self, **kwargs): + + Operation.__init__(self, **kwargs) + + self.isConfig = False + + + def setup(self,dataOut): + + self.init_prof = 0 + self.end_prof = 0 + + def releaseBlock(self, dataOut): + + if self.n % self.lenProfileOut != 0: + raise ValueError("lenProfileOut %d must be submultiple of nProfiles %d" %(self.lenProfileOut, self.n_profiles)) + return None + + dataOut.data = self.buffer[:,self.init_prof:self.end_prof,:] #ch, prof, alt + self.init_prof = self.end_prof + self.end_prof += self.lenProfileOut + if self.init_prof == self.n: + #if self.end_prof >= (self.n +self.lenProfileOut): + self.init_prof = 0 + self.__profIndex = 0 + self.buffer = None + dataOut.buffer_empty = True + #print("done") + return dataOut + + + def run(self, dataOut, nProfilesOut=1): + + self.n = dataOut.nProfiles + self.nChannels = dataOut.nChannels + self.nHeights = dataOut.nHeights + + #print(dataOut.data.shape) + #exit(1) + if not self.isConfig: + self.setup(dataOut) + self.isConfig = True + + dataBlock = None + + if not dataOut.buffer_empty: + if self.init_prof == 0: + self.lenProfileOut = nProfilesOut + dataOut.flagNoData = False + self.init_prof = 0 + self.end_prof = self.lenProfileOut + dataOut.nProfiles = self.lenProfileOut + dataOut.error = False + + dataOut.flagNoData = False + + return self.releaseBlock(dataOut) + + dataOut.flagNoData = True + self.buffer = dataOut.data.copy() + dataOut.error = False + dataOut.useInputBuffer = True + dataOut.buffer_empty = False + + + return dataOut \ No newline at end of file