def preProcess(self, _edObject=None): """ Preprocess methods for the EDPluginSPDCorrectv10 : - Reads input parameters - Creates the displacement matrix if the the detector is tilted - create the configuration for SPD - selects the worker (SPD program under control) """ EDPluginExecProcess.preProcess(self) self.DEBUG("EDPluginSPDCorrectv10.preProcess") # Check that the input data and correction images are present self.getInputParameter() if "SpatialDistortionFile" in self.dictGeometry: splineDM = Spline() splineDM.read(self.dictGeometry["SpatialDistortionFile"]) self.dictGeometry["PixelSizeX"], self.dictGeometry[ "PixelSizeY"] = splineDM.getPixelSize() else: splineDM = None if self.dictGeometry["AngleOfTilt"] != 0: EDPluginSPDCorrectv10.__lockTilt.acquire() if splineDM == None: edfFile = fabio.open(self.pathToInputFile) data = edfFile.data size = data.shape splineDM = splineDM.zeros(xmin=0.0, ymin=0.0, xmax=size[0], ymax=size[1]) if ("PixelSizeX" in self.dictGeometry) and ("PixelSizeY" in self.dictGeometry): splineDM.setPixelSize = (self.dictGeometry["PixelSizeX"], self.dictGeometry["PixelSizeY"]) strtmp = os.path.join( self.getSPDCommonDirectory(), os.path.basename( os.path.splitext( self.dictGeometry["SpatialDistortionFile"])[0])) if not (os.path.isfile(strtmp + "-tilted-x.edf") and os.path.isfile(strtmp + "-tilted-y.edf")): # self.DEBUG("preProcess: \t EDPluginSPDCorrectv10.__lock.acquire(), currently: %i" % EDPluginSPDCorrectv10.__lock._Semaphore__value) if not (os.path.isfile(strtmp + "-tilted-x.edf") and os.path.isfile(strtmp + "-tilted-y.edf")): #The second test is just here to gain some time as the global semaphore could be in use elsewhere self.createDisplacementMatrix(splineDM) self.dictGeometry["DistortionFileX"] = strtmp + "-tilted-x.edf" self.dictGeometry["DistortionFileY"] = strtmp + "-tilted-y.edf" EDPluginSPDCorrectv10.__lockTilt.release() self.generateSPDCommand()
def testSpatialDistortion(self): strRefX = "spline-3-18x.edf" strRefY = "spline-3-18y.edf" self.loadTestImage([strRefX, strRefY]) edPluginSPD = self.createPlugin() strXMLInput = EDUtilsFile.readFileAndParseVariables( self.strReferenceInputFileName) xsDataInputSPDCake = XSDataInputSPDCake.parseString(strXMLInput) edPluginSPD.setDataInput(xsDataInputSPDCake) edPluginSPD.configure() edPluginSPD.getInputParameter() ######################################################################## # Enforce some values ######################################################################## edPluginSPD.dictGeometry["SpatialDistortionFile"] = os.path.join( self.getTestsDataImagesHome(), "frelon_spline_file_to_correct_SPD.spline") edPluginSPD.dictGeometry["TiltRotation"] = 18 edPluginSPD.dictGeometry["AngleOfTilt"] = 3 spline = Spline() spline.read(edPluginSPD.dictGeometry["SpatialDistortionFile"]) edPluginSPD.dictGeometry["PixelSizeX"], edPluginSPD.dictGeometry[ "PixelSizeY"] = spline.getPixelSize() edPluginSPD.createDisplacementMatrix(spline) edPluginSPD.cleanDispMat(edPluginSPD.getWorkingDirectory()) refX = fabio.openimage.openimage( os.path.join(self.getTestsDataImagesHome(), strRefX)).data obtX = fabio.openimage.openimage( os.path.join( edPluginSPD.getWorkingDirectory(), "frelon_spline_file_to_correct_SPD-tilted-x.edf")).data refY = fabio.openimage.openimage( os.path.join(self.getTestsDataImagesHome(), strRefY)).data obtY = fabio.openimage.openimage( os.path.join( edPluginSPD.getWorkingDirectory(), "frelon_spline_file_to_correct_SPD-tilted-y.edf")).data # print edPluginSPD.dictGeometry EDAssert.arraySimilar(obtX, refX, _fAbsMaxDelta=0.1, _strComment="X displacement Matrix is the same") EDAssert.arraySimilar(obtY, refY, _fAbsMaxDelta=0.1, _strComment="Y displacement Matrix is the same")
def preProcess(self, _edObject=None): """ Preprocess methods for the EDPluginSPDCorrectv10 : - Reads input parameters - Creates the displacement matrix if the the detector is tilted - create the configuration for SPD - selects the worker (SPD program under control) """ EDPluginExecProcess.preProcess(self) self.DEBUG("EDPluginSPDCorrectv10.preProcess") # Check that the input data and correction images are present self.getInputParameter() if "SpatialDistortionFile" in self.dictGeometry: splineDM = Spline() splineDM.read(self.dictGeometry["SpatialDistortionFile"]) self.dictGeometry["PixelSizeX"], self.dictGeometry["PixelSizeY"] = splineDM.getPixelSize() else: splineDM = None if self.dictGeometry["AngleOfTilt"] != 0: EDPluginSPDCorrectv10.__lockTilt.acquire() if splineDM == None: edfFile = fabio.open(self.pathToInputFile) data = edfFile.data size = data.shape splineDM = splineDM.zeros(xmin=0.0, ymin=0.0, xmax=size[0], ymax=size[1]) if ("PixelSizeX" in self.dictGeometry) and ("PixelSizeY" in self.dictGeometry): splineDM.setPixelSize = (self.dictGeometry["PixelSizeX"], self.dictGeometry["PixelSizeY"]) strtmp = os.path.join( self.getSPDCommonDirectory(), os.path.basename(os.path.splitext(self.dictGeometry["SpatialDistortionFile"])[0]), ) if not (os.path.isfile(strtmp + "-tilted-x.edf") and os.path.isfile(strtmp + "-tilted-y.edf")): # self.DEBUG("preProcess: \t EDPluginSPDCorrectv10.__lock.acquire(), currently: %i" % EDPluginSPDCorrectv10.__lock._Semaphore__value) if not (os.path.isfile(strtmp + "-tilted-x.edf") and os.path.isfile(strtmp + "-tilted-y.edf")): # The second test is just here to gain some time as the global semaphore could be in use elsewhere self.createDisplacementMatrix(splineDM) self.dictGeometry["DistortionFileX"] = strtmp + "-tilted-x.edf" self.dictGeometry["DistortionFileY"] = strtmp + "-tilted-y.edf" EDPluginSPDCorrectv10.__lockTilt.release() self.generateSPDCommand()
def testSpatialDistortion(self): strRefX = "spline-3-18x.edf" strRefY = "spline-3-18y.edf" self.loadTestImage([strRefX, strRefY]) edPluginSPD = self.createPlugin() strXMLInput = EDUtilsFile.readFileAndParseVariables(self.strReferenceInputFileName) xsDataInputSPDCake = XSDataInputSPDCake.parseString(strXMLInput) edPluginSPD.setDataInput(xsDataInputSPDCake) edPluginSPD.configure() edPluginSPD.getInputParameter() ######################################################################## # Enforce some values ######################################################################## edPluginSPD.dictGeometry["SpatialDistortionFile"] = os.path.join(self.getTestsDataImagesHome(), "frelon_spline_file_to_correct_SPD.spline") edPluginSPD.dictGeometry["TiltRotation"] = 18 edPluginSPD.dictGeometry["AngleOfTilt"] = 3 spline = Spline() spline.read(edPluginSPD.dictGeometry["SpatialDistortionFile"]) edPluginSPD.dictGeometry["PixelSizeX"], edPluginSPD.dictGeometry["PixelSizeY"] = spline.getPixelSize() edPluginSPD.createDisplacementMatrix(spline) edPluginSPD.cleanDispMat(edPluginSPD.getWorkingDirectory()) refX = fabio.openimage.openimage(os.path.join(self.getTestsDataImagesHome(), strRefX)).data obtX = fabio.openimage.openimage(os.path.join(edPluginSPD.getWorkingDirectory(), "frelon_spline_file_to_correct_SPD-tilted-x.edf")).data refY = fabio.openimage.openimage(os.path.join(self.getTestsDataImagesHome(), strRefY)).data obtY = fabio.openimage.openimage(os.path.join(edPluginSPD.getWorkingDirectory(), "frelon_spline_file_to_correct_SPD-tilted-y.edf")).data # print edPluginSPD.dictGeometry EDAssert.arraySimilar(obtX, refX , _fAbsMaxDelta=0.1, _strComment="X displacement Matrix is the same") EDAssert.arraySimilar(obtY, refY , _fAbsMaxDelta=0.1, _strComment="Y displacement Matrix is the same")