def prepareQuery(cls, filename, width): """ prepare the query to be submitted @return: query @rtype: XSDataQuery """ query = XSDataQuery() query.setRemoveItems(XSDataBoolean(0)) dirname, basename = os.path.split(filename) prefix, ext = os.path.splitext(basename) suffix = ext bStarted = False strNum = "" for i, c in enumerate(prefix[-1::-1]): if bStarted and not c.isdigit(): prefix = prefix[:-i] break if c.isdigit(): bStarted = True strNum = c + strNum else: suffix = c + suffix if strNum == "": EDVerbose.WARNING("EDPluginControlMedianFilterImagev1_0.prepareQuery: No number in this filename !!! ") query.setItem([XSDataString(filename)]) else: num = int(strNum) l = len(strNum) minNum = num - width // 2 maxNum = minNum + width query.setItem([XSDataString(os.path.join(dirname, prefix + "0" * (l - len(str(i))) + str(i) + suffix)) for i in range(minNum, maxNum)]) return query
def process(self, _edObject=None): EDPluginControl.process(self) self.DEBUG("EDPluginWaitMultiFile.process global time-out is set to: %s (default value)" % (self.getTimeOut())) self.setTimeInit() ################################################################################ # Initialize the accumulator with the query ################################################################################ xsdiAccumulator = XSDataInputAccumulator() xsdQuery = XSDataQuery() xsdQuery.setRemoveItems(XSDataBoolean(1)) xsdQuery.setItem(self.listXsdStrings) xsdiAccumulator.setQuery([xsdQuery]) edPluginAccumulator = self.loadPlugin(self.__strControlledPluginAccumulator) edPluginAccumulator.setDataInput(xsdiAccumulator) edPluginAccumulator.connectSUCCESS(self.doSuccessAccumulator) edPluginAccumulator.connectFAILURE(self.doFailureAccumulator) edPluginAccumulator.execute() for oneXSDImage in self.listXsdFiles: xsdiWaitFile = XSDataInputWaitFile() xsdiWaitFile.setExpectedFile(oneXSDImage) xsdiWaitFile.setExpectedSize(self.dataInput.expectedSize) xsdiWaitFile.setTimeOut(self.dataInput.timeOut) edPluginWaitFile = self.loadPlugin(self.__strControlledPluginWaitFile) edPluginWaitFile.setDataInput(xsdiWaitFile) edPluginWaitFile.connectSUCCESS(self.doSuccessWaitFile) edPluginWaitFile.connectFAILURE(self.doFailureWaitFile) edPluginWaitFile.execute()
def __init__(self): """ """ EDPluginControl.__init__(self) self.setXSDataInputClass(XSDataInputMedianFilterImage) self.__strControlledPluginAccumulator = "EDPluginAccumulatorv1_0" self.__strControlledPluginMedian = "EDPluginExecMedianFilterv1_0" self.__edPluginExecAccumulator = None self.__edPluginExecMedian = None self.query = XSDataQuery() self.xsdMedian = None self.filename = None self.outputImage = None self.width = None self.xsdOut = None
def prepareQuery(cls, filename, width): """ prepare the query to be submitted @return: query @rtype: XSDataQuery """ query = XSDataQuery() query.setRemoveItems(XSDataBoolean(0)) dirname, basename = os.path.split(filename) prefix, ext = os.path.splitext(basename) suffix = ext bStarted = False strNum = "" for i, c in enumerate(prefix[-1::-1]): if bStarted and not c.isdigit(): prefix = prefix[:-i] break if c.isdigit(): bStarted = True strNum = c + strNum else: suffix = c + suffix if strNum == "": EDVerbose.WARNING( "EDPluginControlMedianFilterImagev1_0.prepareQuery: No number in this filename !!! " ) query.setItem([XSDataString(filename)]) else: num = int(strNum) l = len(strNum) minNum = num - width // 2 maxNum = minNum + width query.setItem([ XSDataString( os.path.join( dirname, prefix + "0" * (l - len(str(i))) + str(i) + suffix)) for i in range(minNum, maxNum) ]) return query
def process(self, _edObject=None): EDPluginControl.process(self) self.DEBUG("EDPluginControlAlignStackv1_0.process") for iFrame in self.iFrames: edPluginExecAccumulator = self.loadPlugin( self.__strControlledPluginAccumulator) queryRaw = XSDataQuery() queryShift = XSDataQuery() queryRaw.setRemoveItems(XSDataBoolean(False)) queryShift.setRemoveItems(XSDataBoolean(False)) xsdataAcc = XSDataInputAccumulator() if (EDPluginControlAlignStackv1_0.__iRefFrame == iFrame) or (self.bDoAlign == False): EDPluginControlAlignStackv1_0.__dictAbsShift[iFrame] = (0.0, 0.0) EDPluginControlAlignStackv1_0.__dictRelShift[iFrame] = (0.0, 0.0) self.hdf5_offset(index=iFrame, offset=[0.0, 0.0]) edPluginExecShift = self.loadPlugin( self.__strControlledPluginShift) xsdata = XSDataInputShiftImage( index=XSDataInteger(iFrame), offset=[ XSDataDouble(i) for i in EDPluginControlAlignStackv1_0.__dictAbsShift[iFrame] ], inputImage=self.getFrameRef(iFrame), outputImage=XSDataImageExt( shared=XSDataString("Shifted-%06i" % iFrame))) edPluginExecShift.setDataInput(xsdata) edPluginExecShift.connectSUCCESS(self.doSuccessExecShiftImage) edPluginExecShift.connectFAILURE(self.doFailureExecShiftImage) self.queue.put(edPluginExecShift) if (self.bDoAlign == False): self.executeControlledPlugins() return elif EDPluginControlAlignStackv1_0.__iRefFrame < iFrame: if self.bAlwaysMOvsRef: queryRaw.setItem([ XSDataString( "raw %04i" % (EDPluginControlAlignStackv1_0.__iRefFrame)), XSDataString("raw %04i" % iFrame) ]) xsdataAcc.setQuery([queryRaw]) else: queryRaw.setItem([ XSDataString("raw %04i" % (iFrame - 1)), XSDataString("raw %04i" % iFrame) ]) queryShift.setItem([ XSDataString("shift %04i" % i) for i in range( EDPluginControlAlignStackv1_0.__iRefFrame + 1, iFrame + 1) ]) xsdataAcc.setQuery([queryRaw, queryShift]) elif EDPluginControlAlignStackv1_0.__iRefFrame > iFrame: if self.bAlwaysMOvsRef: queryRaw.setItem([ XSDataString("raw %04i" % iFrame), XSDataString( "raw %04i" % (EDPluginControlAlignStackv1_0.__iRefFrame)) ]) xsdataAcc.setQuery([queryRaw]) else: queryRaw.setItem([ XSDataString("raw %04i" % (iFrame + 1)), XSDataString("raw %04i" % iFrame) ]) queryShift.setItem([ XSDataString("shift %04i" % i) for i in range( EDPluginControlAlignStackv1_0.__iRefFrame - 1, iFrame - 1, -1) ]) xsdataAcc.setQuery([queryRaw, queryShift]) if (EDPluginControlAlignStackv1_0.__iRefFrame == iFrame): self.saveReferenceFrame(iFrame) xsdataAcc.setItem([XSDataString("raw %04i" % iFrame)]) edPluginExecAccumulator.setDataInput(xsdataAcc) edPluginExecAccumulator.connectSUCCESS( self.doSuccessExecAccumultor) edPluginExecAccumulator.connectFAILURE( self.doFailureExecAccumulator) self.queue.put(edPluginExecAccumulator) self.executeControlledPlugins()
def process(self, _edObject=None): EDPluginControl.process(self) self.DEBUG("EDPluginControlAlignStackv1_0.process") for iFrame in self.iFrames: edPluginExecAccumulator = self.loadPlugin(self.__strControlledPluginAccumulator) queryRaw = XSDataQuery() queryShift = XSDataQuery() queryRaw.setRemoveItems(XSDataBoolean(False)) queryShift.setRemoveItems(XSDataBoolean(False)) xsdataAcc = XSDataInputAccumulator() if (EDPluginControlAlignStackv1_0.__iRefFrame == iFrame) or (self.bDoAlign == False) : EDPluginControlAlignStackv1_0.__dictAbsShift[iFrame] = (0.0, 0.0) EDPluginControlAlignStackv1_0.__dictRelShift[iFrame] = (0.0, 0.0) self.hdf5_offset(index=iFrame, offset=[0.0, 0.0]) edPluginExecShift = self.loadPlugin(self.__strControlledPluginShift) xsdata = XSDataInputShiftImage(index=XSDataInteger(iFrame), offset=[XSDataDouble(i) for i in EDPluginControlAlignStackv1_0.__dictAbsShift[iFrame]], inputImage=self.getFrameRef(iFrame), outputImage=XSDataImageExt(shared=XSDataString("Shifted-%06i" % iFrame))) edPluginExecShift.setDataInput(xsdata) edPluginExecShift.connectSUCCESS(self.doSuccessExecShiftImage) edPluginExecShift.connectFAILURE(self.doFailureExecShiftImage) self.queue.put(edPluginExecShift) if (self.bDoAlign == False): self.executeControlledPlugins() return elif EDPluginControlAlignStackv1_0.__iRefFrame < iFrame: if self.bAlwaysMOvsRef: queryRaw.setItem([XSDataString("raw %04i" % (EDPluginControlAlignStackv1_0.__iRefFrame)), XSDataString("raw %04i" % iFrame)]) xsdataAcc.setQuery([queryRaw]) else: queryRaw.setItem([XSDataString("raw %04i" % (iFrame - 1)), XSDataString("raw %04i" % iFrame)]) queryShift.setItem([XSDataString("shift %04i" % i) for i in range(EDPluginControlAlignStackv1_0.__iRefFrame + 1, iFrame + 1)]) xsdataAcc.setQuery([queryRaw, queryShift]) elif EDPluginControlAlignStackv1_0.__iRefFrame > iFrame: if self.bAlwaysMOvsRef: queryRaw.setItem([ XSDataString("raw %04i" % iFrame), XSDataString("raw %04i" % (EDPluginControlAlignStackv1_0.__iRefFrame))]) xsdataAcc.setQuery([queryRaw]) else: queryRaw.setItem([XSDataString("raw %04i" % (iFrame + 1)), XSDataString("raw %04i" % iFrame)]) queryShift.setItem([XSDataString("shift %04i" % i) for i in range(EDPluginControlAlignStackv1_0.__iRefFrame - 1, iFrame - 1, -1)]) xsdataAcc.setQuery([queryRaw, queryShift]) if (EDPluginControlAlignStackv1_0.__iRefFrame == iFrame): self.saveReferenceFrame(iFrame) xsdataAcc.setItem([XSDataString("raw %04i" % iFrame)]) edPluginExecAccumulator.setDataInput(xsdataAcc) edPluginExecAccumulator.connectSUCCESS(self.doSuccessExecAccumultor) edPluginExecAccumulator.connectFAILURE(self.doFailureExecAccumulator) self.queue.put(edPluginExecAccumulator) self.executeControlledPlugins()
def process(self, _edObject=None): EDPlugin.process(self) self.DEBUG("EDPluginAccumulatorv1_0.process") queriesToRemove = [] listXsdQuery = [] if not self.flush: self.__semaphore.acquire() for query in self.__queries: present = True for item in query: if not item in self.__items: present = False break if present is True: queriesToRemove.append(query) xsdQuery = XSDataQuery() xsdQuery.setItem([XSDataString(item) for item in query]) if self.__queries[query] is True: xsdQuery.setRemoveItems(XSDataBoolean(True)) for item in query: self.__items.remove(item) else: xsdQuery.setRemoveItems(XSDataBoolean(False)) listXsdQuery.append(xsdQuery) #Remove the query from the list of queries for query in queriesToRemove: self.__queries.pop(query) self.__semaphore.release() else: xsdQuery = XSDataQuery() self.__semaphore.acquire() xsdQuery.setItem([XSDataString(item) for item in self.__items]) xsdQuery.setRemoveItems(XSDataBoolean(True)) self.__class__.__items = [] self.__semaphore.release() listXsdQuery.append(xsdQuery) self.xsDataResult.setQuery(listXsdQuery)
def process(self, _edObject=None): EDPlugin.process(self) self.DEBUG("EDPluginAccumulatorv1_0.process") queriesToRemove = [] listXsdQuery = [] if not self.flush: with self.__class__._semaphore: for query in self._queries: present = True for item in query: if not item in self._items: present = False break if present is True: queriesToRemove.append(query) xsdQuery = XSDataQuery() xsdQuery.setItem( [XSDataString(item) for item in query]) if self._queries[query] is True: xsdQuery.setRemoveItems(XSDataBoolean(True)) for item in query: self._items.remove(item) else: xsdQuery.setRemoveItems(XSDataBoolean(False)) listXsdQuery.append(xsdQuery) #Remove the query from the list of queries for query in queriesToRemove: self._queries.pop(query) else: xsdQuery = XSDataQuery() with self.__class__._semaphore: xsdQuery.setItem([XSDataString(item) for item in self._items]) xsdQuery.setRemoveItems(XSDataBoolean(True)) self.__class__._items = [] listXsdQuery.append(xsdQuery) self.xsDataResult.setQuery(listXsdQuery)