def postProcess(self, _edObject=None): EDPluginExec.postProcess(self) self.DEBUG("EDPluginExecShiftImagev1_0.postProcess") # Create some output data xsDataResult = XSDataResultShiftImage() if self.strOutputType is None: xsDataResult.setOutputArray( EDUtilsArray.arrayToXSData(self.npaImage)) elif self.strOutputType == "file": image = edfimage(data=self.npaImage, header={ "Offset_1": self.tOffset[0], "Offset_2": self.tOffset[1], "Max_Offset": self.MAX_OFFSET_VALUE }) image.write(self.strOutputImage, force_type=self.npaImage.dtype) xsdimg = XSDataImageExt(path=XSDataString(self.strOutputImage)) xsDataResult.outputImage = xsdimg elif self.strOutputType == "shared": EDShare[self.strOutputImage] = self.npaImage xsdimg = XSDataImageExt(shared=XSDataString(self.strOutputImage)) xsDataResult.outputImage = xsdimg elif self.strOutputType == "array": xsdimg = XSDataImageExt( array=EDUtilsArray.arrayToXSData(self.npaImage)) xsDataResult.outputImage = xsdimg self.setDataOutput(xsDataResult) self.npaImage = None
def process(self, _edObject=None): EDPluginControl.process(self) h5Grp = EDPluginHDF5.createStructure(self.HDF5filename.path.value, self.internalHDF5Path.value) self.DEBUG("EDPluginControlFullFieldXASv1_0.process") self.makeHDF5OffsetStructure() if self.energy is not None: self.makeHDF5EnergyStructure() edPluginExecNormalize = self.loadPlugin(self.__strControlledNormalize) edPluginExecNormalize.connectSUCCESS(self.doSuccessExecNormalize) edPluginExecNormalize.connectFAILURE(self.doFailureExecNormalize) sdi = self.dataInput xsdInNorm = XSDataInputNormalize(data=sdi.data, flat=sdi.flat, dark=sdi.dark, dataScaleFactor=sdi.dataScaleFactor, darkScaleFactor=sdi.darkScaleFactor, flatScaleFactor=sdi.flatScaleFactor) if self.xsdNormalizedFilename is not None: xsdInNorm.output = XSDataImageExt( path=self.xsdNormalizedFilename.path) else: xsdInNorm.output = XSDataImageExt( shared=XSDataString("Normalized-%06i" % sdi.index.value)) edPluginExecNormalize.dataInput = xsdInNorm edPluginExecNormalize.executeSynchronous() if self.xsdAlignStack is not None: edPluginAlign = self.loadPlugin(self.__strControlledAlign) edPluginAlign.dataInput = self.xsdAlignStack edPluginAlign.connectSUCCESS(self.doSuccessExecAlign) edPluginAlign.connectFAILURE(self.doFailureExecAlign) edPluginAlign.executeSynchronous()
def testCheckParameters(self): xsDataInput = XSDataInputPyFAI(detector=XSDataDetector(), geometry=XSDataGeometry(), output=XSDataImageExt(), input=XSDataImageExt(), nbPt=XSDataInteger()) edPluginExecPyFAIv1_0 = self.createPlugin() edPluginExecPyFAIv1_0.setDataInput(xsDataInput) edPluginExecPyFAIv1_0.checkParameters()
def buildChildren(self, child_, nodeName_): if child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'inputMatrix': obj_ = XSDataImageExt() obj_.build(child_) self.setInputMatrix(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'outputMatrix': obj_ = XSDataImageExt() obj_.build(child_) self.setOutputMatrix(obj_) XSDataInput.buildChildren(self, child_, nodeName_)
def postProcess(self, _edObject=None): EDPluginExec.postProcess(self) self.DEBUG("EDPluginExecPyFAIv1_0.postProcess") # Create some output data if self.strOutputFile: output = XSDataImageExt(path=XSDataString(self.strOutputFile)) elif self.shared: output = XSDataImageExt(shared=XSDataString(self.shared)) else: output = XSDataImageExt(array=EDUtilsArray.arrayToXSData(self.npaOut)) xsDataResult = XSDataResultPyFAI(output=output) self.setDataOutput(xsDataResult)
def buildChildren(self, child_, nodeName_): if child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'output': obj_ = XSDataImageExt() obj_.build(child_) self.setOutput(obj_) XSDataResult.buildChildren(self, child_, nodeName_)
def getFrameRef(cls, index): """ Just retrieves the reference in the EDShare store @return: reference to the frame in EDShare @rtype: XSDataImageExt """ return XSDataImageExt(shared=XSDataString("Normalized-%06i" % int(index)))
def postProcess(self, _edObject=None): EDPluginExec.postProcess(self) self.DEBUG("EDPluginExecNormalizeImagev1_1.postProcess") xsDataResult = XSDataResultNormalize() if self.strOutputFilename is not None: self.DEBUG("Writing file %s" % self.strOutputFilename) edf = fabio.edfimage.edfimage(data=self.npaNormalized, header={}) edf.write(self.strOutputFilename) xsdo = XSDataImageExt(path=XSDataString(self.strOutputFilename)) elif self.strOutputShared is not None: self.DEBUG("EDShare --> %s" % self.strOutputShared) EDShare[ self.strOutputShared] = self.npaNormalized xsdo = XSDataImageExt(shared=XSDataString(self.strOutputShared)) else: xsdo = XSDataImageExt(array=EDUtilsArray.arrayToXSData(self.npaNormalized)) xsDataResult.output = xsdo # Create some output data self.setDataOutput(xsDataResult)
def getXsdDark(self): """ return XSDataDark object """ if self._xsDataDark is None: self._xsDataDark = [XSDataImageExt(path=XSDataString(i["path"]), exposureTime=XSDataTime(i["exposureTime"])) for i in self.darks] return self._xsDataDark
def buildChildren(self, child_, nodeName_): if child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'data': obj_ = XSDataImageExt() obj_.build(child_) self.data.append(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'dark': obj_ = XSDataImageExt() obj_.build(child_) self.dark.append(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'flat': obj_ = XSDataImageExt() obj_.build(child_) self.flat.append(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'output': obj_ = XSDataImageExt() obj_.build(child_) self.setOutput(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'dataScaleFactor': obj_ = XSDataDouble() obj_.build(child_) self.setDataScaleFactor(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'darkScaleFactor': obj_ = XSDataDouble() obj_.build(child_) self.setDarkScaleFactor(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'flatScaleFactor': obj_ = XSDataDouble() obj_.build(child_) self.setFlatScaleFactor(obj_) XSDataInput.buildChildren(self, child_, nodeName_)
def postProcess(self, _edObject=None): EDPluginExec.postProcess(self) EDVerbose.DEBUG("EDPluginExecShiftImagev1_0.postProcess") # Create some output data xsDataResult = XSDataResultShiftImage() if self.strOutputImage is None: #ArrayOutput xsDataResult.setOutputArray( EDUtilsArray.arrayToXSData(self.npaImage)) else: image = edfimage(data=self.npaImage, header={ "Offset_1": self.tOffset[0], "Offset_2": self.tOffset[1] }) image.write(self.strOutputImage, force_type=self.npaImage.dtype) xsdimg = XSDataImageExt(path=XSDataString(self.strOutputImage)) xsDataResult.setOutputImage(xsdimg) self.setDataOutput(xsDataResult)
def doSuccessExecAccumultor(self, _edPlugin=None): with self.semAccumulator: self.DEBUG("EDPluginControlAlignStackv1_0.doSuccessExecAccumultor") self.retrieveSuccessMessages( _edPlugin, "EDPluginControlAlignStackv1_0.doSuccessExecAccumultor") for query in _edPlugin.dataOutput.getQuery(): self.addExtraTime(60) _edPlugin.addExtraTime(60) accType = query.getItem()[0].getValue().split()[0] listInt = [ int(i.getValue().split()[1]) for i in query.getItem() ] if accType == "raw": listFrame = [self.getFrameRef(i) for i in listInt] xsdata = XSDataInputMeasureOffset(image=listFrame) doSIFT = False if self.xsdMeasureOffset is not None: xsdata.setCropBorders( self.xsdMeasureOffset.getCropBorders()) xsdata.setSmoothBorders( self.xsdMeasureOffset.getSmoothBorders()) xsdata.setBackgroundSubtraction( self.xsdMeasureOffset.getRemoveBackground()) if self.xsdMeasureOffset.useSift is not None: doSIFT = self.xsdMeasureOffset.useSift.value if max(listInt ) > EDPluginControlAlignStackv1_0.__iRefFrame: listInt.sort() else: listInt.sort(reverse=True) xsdata.setIndex([XSDataInteger(i) for i in listInt]) if doSIFT: edPluginExecMeasure = self.loadPlugin( self.__strControlledPluginMeasureSIFT) else: edPluginExecMeasure = self.loadPlugin( self.__strControlledPluginMeasureFFT) edPluginExecMeasure.setDataInput(xsdata) edPluginExecMeasure.connectSUCCESS( self.doSuccessExecMeasureOffset) edPluginExecMeasure.connectFAILURE( self.doFailureExecMeasureOffset) self.queue.put(edPluginExecMeasure) elif accType == "shift": shift_1 = 0.0 shift_2 = 0.0 for frame in listInt: shift_1 += EDPluginControlAlignStackv1_0.__dictRelShift[ frame][0] shift_2 += EDPluginControlAlignStackv1_0.__dictRelShift[ frame][1] if listInt[0] > EDPluginControlAlignStackv1_0.__iRefFrame: iFrameShift = max(listInt) else: iFrameShift = min(listInt) EDPluginControlAlignStackv1_0.__dictAbsShift[ iFrameShift] = (shift_1, shift_2) self.screen( "Frame number %i has absolute offset of %.3f,%.3f" % (iFrameShift, shift_1, shift_2)) edPluginExecShift = self.loadPlugin( self.__strControlledPluginShift) edPluginExecShift.dataInput = XSDataInputShiftImage( index=XSDataInteger(iFrameShift), offset=[XSDataDouble(shift_1), XSDataDouble(shift_2)], inputImage=self.getFrameRef(iFrameShift), outputImage=XSDataImageExt( shared=XSDataString("Shifted-%06i" % iFrameShift))) edPluginExecShift.connectSUCCESS( self.doSuccessExecShiftImage) edPluginExecShift.connectFAILURE( self.doFailureExecShiftImage) self.queue.put(edPluginExecShift) self.DEBUG("Items: %s" % EDPluginAccumulatorv1_0.getItems()) self.DEBUG("Queries: %s" % EDPluginAccumulatorv1_0.getQueries())
def doSuccessExecMeasureOffset(self, _edPlugin=None): with self.semMeasure: self.DEBUG( "EDPluginControlAlignStackv1_0.doSuccessExecMeasureOffset") self.retrieveSuccessMessages( _edPlugin, "EDPluginControlAlignStackv1_0.doSuccessExecMeasureOffset") listIndex = [i.getValue() for i in _edPlugin.dataInput.index] listIndex.sort() dataOutput = _edPlugin.dataOutput if self.bAlwaysMOvsRef: if min(listIndex) < EDPluginControlAlignStackv1_0.__iRefFrame: iToShift, iRef = tuple(listIndex) EDPluginControlAlignStackv1_0.__dictAbsShift[ iToShift] = tuple( [-i.getValue() for i in dataOutput.getOffset()]) else: iRef, iToShift = tuple(listIndex) EDPluginControlAlignStackv1_0.__dictAbsShift[ iToShift] = tuple( [i.getValue() for i in dataOutput.getOffset()]) self.screen( "Frame number %i has absolute offset of %.3f,%.3f" % (iToShift, EDPluginControlAlignStackv1_0.__dictAbsShift[iToShift][0], EDPluginControlAlignStackv1_0.__dictAbsShift[iToShift][1]) ) edPluginExecShift = self.loadPlugin( self.__strControlledPluginShift) xsdata = XSDataInputShiftImage( index=XSDataInteger(iToShift), offset=[ XSDataDouble(i) for i in EDPluginControlAlignStackv1_0.__dictAbsShift[iToShift] ], inputImage=self.getFrameRef(iToShift), outputImage=XSDataImageExt( shared=XSDataString("Shifted-%06i" % iToShift))) edPluginExecShift.setDataInput(xsdata) edPluginExecShift.connectSUCCESS(self.doSuccessExecShiftImage) edPluginExecShift.connectFAILURE(self.doFailureExecShiftImage) self.queue.put(edPluginExecShift) else: if min(listIndex) < EDPluginControlAlignStackv1_0.__iRefFrame: iToShift, iRef = tuple(listIndex) EDPluginControlAlignStackv1_0.__dictRelShift[ iToShift] = tuple( [-i.value for i in dataOutput.offset]) else: iRef, iToShift = tuple(listIndex) EDPluginControlAlignStackv1_0.__dictRelShift[ iToShift] = tuple([i.value for i in dataOutput.offset]) self.screen( "Frame number %i has relative offset of %.3f,%.3f" % (iToShift, EDPluginControlAlignStackv1_0.__dictRelShift[iToShift][0], EDPluginControlAlignStackv1_0.__dictRelShift[iToShift][1]) ) xsdata = XSDataInputAccumulator( item=[XSDataString("shift %04i" % iToShift)]) edPluginExecAccumulator = self.loadPlugin( self.__strControlledPluginAccumulator) edPluginExecAccumulator.setDataInput(xsdata) edPluginExecAccumulator.connectSUCCESS( self.doSuccessExecAccumultor) edPluginExecAccumulator.connectFAILURE( self.doFailureExecAccumulator) self.queue.put(edPluginExecAccumulator)
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 makeXML(self, filename): """Here we create the XML string to be passed to the EDNA plugin from the input filename This can / should be modified by the final user @param filename: full path of the input file @type filename: python string representing the path @rtype: XML string @return: python string """ self.header = None dirname, basename = os.path.split(filename) if not basename.startswith(self.prefix): return if self.normalizedSuffix and basename.endswith(self.normalizedSuffix): return if basename.startswith(self.flatPrefix): return if not basename.endswith(self.suffix): return if self.fScaleData: fScaleData = self.fScaleData else: fScaleData = self.getNbFrames(filename) if not fScaleData: fScaleData = 1.0 if self.fScaleDark: fScaleDark = self.fScaleDark else: fScaleDark = self.getNbFrames(self.darks[0]["path"]) if not fScaleDark: fScaleDark = 1.0 if isinstance(self.reference, int): reference = self.reference else: reference = -1 xsd = XSDataInputFullFieldXAS(HDF5File=XSDataFile(path=XSDataString(self.HDF5)), internalHDF5Path=XSDataString(self.internalHdf5), measureOffset=self.getXSDMeasureOffset(), dark=self.getXsdDark(), reference=XSDataInteger(reference), data=[XSDataImageExt(path=XSDataString(filename), exposureTime=XSDataTime(self.getExposureTime(filename)))], dataScaleFactor=XSDataDouble(fScaleData), darkScaleFactor=XSDataDouble(fScaleDark), ) if self.dontAlign: xsd.dontAlign = XSDataBoolean(self.dontAlign) extendedPrefix = "" number = "" started = False if self.lstSubscanSize: subScanDigit = [] for i in basename[len(self.prefix):]: if started and i == "_": if len(number) > 0: subScanDigit.append(number) number = "" continue if started and not i.isdigit(): if number: subScanDigit.append(number) number = "" break if not started: if i.isdigit(): started = True else: extendedPrefix += i if started: number += i if not subScanDigit: print("ERROR: no index guessed !!!") return "" elif len(subScanDigit) == 1: index = int(subScanDigit[0]) else:# len(subScanDigit) > 1: index = 0 for i in range(int(subScanDigit[0])): index += self.lstSubscanSize[i] index += int(subScanDigit[1]) extendedPrefix += "_".join(subScanDigit[:2]) else: for i in basename[len(self.prefix):]: extendedPrefix += i if started and not i.isdigit(): break if not started and i.isdigit(): started = True if started: number += i index = int(number) xsd.index = XSDataInteger(index) if self.normalizedSuffix: pr = os.path.splitext(os.path.abspath(filename))[0] xsd.saveNormalized = XSDataFile(path=XSDataString(pr + self.normalizedSuffix)) energy = self.getEnergy(filename) if energy is not None: xsd.energy = XSDataDouble(energy) flatprefix = self.flatPrefix + extendedPrefix listFlats = [] for oneFile in os.listdir(dirname): if oneFile.startswith(flatprefix) and oneFile.endswith(self.suffix): oneCompleteFile = os.path.abspath(os.path.join(dirname, oneFile)) xsdFileFlat1 = XSDataImageExt(path=XSDataString(oneCompleteFile), exposureTime=XSDataTime(self.getExposureTime(oneCompleteFile))) listFlats.append(xsdFileFlat1) xsd.flat = listFlats if len(listFlats) != 2: EDVerbose.WARNING("Not exactly 2 flats were found:" + " ".join([a.path.value for a in listFlats ])) EDVerbose.WARNING("Those are the flat prefix ans suffix: %s\t%s" % (flatprefix, self.suffix)) if self.fScaleFlat: fScaleFlat = self.fScaleFlat else: fScaleFlat = self.getNbFrames(oneCompleteFile) if not fScaleFlat: fScaleFlat = 1.0 xsd.flatScaleFactor = XSDataDouble(fScaleFlat) return xsd.marshal()