def postProcess(self, _edObject=None): """ postProcess of the plugin EDPluginSPDCakev1_5.py: - convert to HDF if needed (to be implemented) - convert to chiplot or xye or cif if needed - move images (if needed) or delete .cor image - set result XML """ EDPluginSPDCorrectv10.postProcess(self) self.DEBUG("EDPluginSPDCakev1_5.postProcess") if not os.path.isdir(self.dictGeometry["OutputDirCake"]): os.makedirs(self.dictGeometry["OutputDirCake"]) strInputImagePathNoSfx = os.path.splitext( os.path.basename(self.pathToInputFile))[0] strSpdoutCake = strInputImagePathNoSfx + self.dictGeometry[ "OutputFileType"] strOutputCakeFilePath = os.path.join( self.dictGeometry["OutputDirCake"], strSpdoutCake) xsDataResultSPD = XSDataResultSPDCake() if not self.getFireAndForget(): strTempFilePath = None if "corrected" in self.dictRes: strSpdoutCor = self.dictRes["corrected"] if "regrouped" in self.dictRes: strTempFilePath = self.dictRes["regrouped"] if self.dictGeometry["OutputFileType"].lower() in [ ".hdf5", ".nexus", ".h5", ".nx" ]: self.WARNING( "HDF5/Nexus output is not yet implemented in the SPD plugin." ) if strTempFilePath is None: self.WARNING( "Cannot copy output to %s as there is not input: %s " % (strOutputCakeFilePath, self.dictRes)) elif os.path.exists(strOutputCakeFilePath): self.WARNING( "Destination file exists, I will leave result file in %s." % strTempFilePath) strOutputCakeFilePath = strTempFilePath else: shutil.move(strTempFilePath, strOutputCakeFilePath) strOutputCorFilePath = os.path.join(self.dictGeometry["OutputDir"], os.path.split(strSpdoutCor)[1]) if self.bDeleteCorImg: if os.path.isfile(strSpdoutCor): os.remove(strSpdoutCor) else: self.WARNING("Corrected file vanished before removal %s" % strSpdoutCor) else: strTempFilePathCor = os.path.join(self.getWorkingDirectory(), strSpdoutCor) if self.dictGeometry["OutputFileType"].lower() in [ ".hdf5", ".nexus", ".h5", ".nx" ]: self.WARNING( "HDF5/Nexus output is not yet implemented in the SPD plugin." ) elif self.dictGeometry["OutputFileType"].lower() not in [ ".edf", ".azim", ".cor" ]: self.WARNING( "Output file format %s is not yet implemented in the SPD plugin." % self.dictGeometry["OutputFileType"]) if os.path.exists(strOutputCorFilePath): self.WARNING( "Destination file exists, I will leave result file in %s." % strTempFilePathCor) strOutputCorFilePath = os.path.abspath(strTempFilePathCor) else: shutil.move(strTempFilePath, strOutputCorFilePath) xsDataFileCorr = XSDataFile() xsDataFileCorr.setPath(XSDataString(strOutputCorFilePath)) xsDataResultSPD.setcorrectedFile(xsDataFileCorr) # # Create the output data xsDataFileCake = XSDataFile() xsDataFileCake.setPath(XSDataString(strOutputCakeFilePath)) xsDataResultSPD.setCakedFile(xsDataFileCake) self.setDataOutput(xsDataResultSPD)
def postProcess(self, _edObject=None): """ postProcess of the plugin EDPluginSPDCakev1_5.py: - convert to HDF if needed (to be implemented) - convert to chiplot or xye or cif if needed - move images (if needed) or delete .cor image - set result XML """ EDPluginSPDCorrectv10.postProcess(self) self.DEBUG("EDPluginSPDCakev1_5.postProcess") if not os.path.isdir(self.dictGeometry["OutputDirCake"]): os.makedirs(self.dictGeometry["OutputDirCake"]) strInputImagePathNoSfx = os.path.splitext(os.path.basename(self.pathToInputFile))[0] strSpdoutCake = strInputImagePathNoSfx + self.dictGeometry["OutputFileType"] strOutputCakeFilePath = os.path.join(self.dictGeometry["OutputDirCake"], strSpdoutCake) xsDataResultSPD = XSDataResultSPDCake() if not self.getFireAndForget(): strTempFilePath = None if "corrected" in self.dictRes: strSpdoutCor = self.dictRes["corrected"] if "regrouped" in self.dictRes: strTempFilePath = self.dictRes["regrouped"] if self.dictGeometry["OutputFileType"].lower() in [".hdf5", ".nexus", ".h5", ".nx"]: self.WARNING("HDF5/Nexus output is not yet implemented in the SPD plugin.") if strTempFilePath is None: self.WARNING("Cannot copy output to %s as there is not input: %s " % (strOutputCakeFilePath, self.dictRes)) elif os.path.exists(strOutputCakeFilePath): self.WARNING("Destination file exists, I will leave result file in %s." % strTempFilePath) strOutputCakeFilePath = strTempFilePath else: shutil.move(strTempFilePath, strOutputCakeFilePath) strOutputCorFilePath = os.path.join(self.dictGeometry["OutputDir"], os.path.split(strSpdoutCor)[1]) if self.bDeleteCorImg: if os.path.isfile(strSpdoutCor): os.remove(strSpdoutCor) else: self.WARNING("Corrected file vanished before removal %s" % strSpdoutCor) else: strTempFilePathCor = os.path.join(self.getWorkingDirectory(), strSpdoutCor) if self.dictGeometry["OutputFileType"].lower() in [".hdf5", ".nexus", ".h5", ".nx"]: self.WARNING("HDF5/Nexus output is not yet implemented in the SPD plugin.") elif self.dictGeometry["OutputFileType"].lower() not in [".edf", ".azim", ".cor"] : self.WARNING("Output file format %s is not yet implemented in the SPD plugin." % self.dictGeometry["OutputFileType"]) if os.path.exists(strOutputCorFilePath): self.WARNING("Destination file exists, I will leave result file in %s." % strTempFilePathCor) strOutputCorFilePath = os.path.abspath(strTempFilePathCor) else: shutil.move(strTempFilePath, strOutputCorFilePath) xsDataFileCorr = XSDataFile() xsDataFileCorr.setPath(XSDataString(strOutputCorFilePath)) xsDataResultSPD.setcorrectedFile(xsDataFileCorr) # # Create the output data xsDataFileCake = XSDataFile() xsDataFileCake.setPath(XSDataString(strOutputCakeFilePath)) xsDataResultSPD.setCakedFile(xsDataFileCake) self.setDataOutput(xsDataResultSPD)
def postProcess(self, _edObject=None): EDPluginExecProcessScript.postProcess(self) EDVerbose.DEBUG("EDPluginSPDCakev1_1.postProcess") xsDataInputSPDCake = self.getDataInput() strOutputFileType = xsDataInputSPDCake.getOutputFileType().getValue() # Determine the image file name without path and suffix strInputImageFilePath = xsDataInputSPDCake.getInputFile().getPath( ).getValue() strInputFileNameWithoutSuffix = os.path.splitext( EDUtilsFile.getBaseName(strInputImageFilePath))[0] self.strOutputFileSuffix = "data" if (strOutputFileType == "PowderCIF"): self.strOutputFileSuffix = "cif" elif (strOutputFileType == "CHIPLOT"): self.strOutputFileSuffix = "chi" strOutputFileName = strInputFileNameWithoutSuffix + "." + self.strOutputFileSuffix if self.outputDir is None: self.m_strOutputFilePath = os.path.join(self.getWorkingDirectory(), strOutputFileName) else: self.m_strOutputFilePath = os.path.join(self.outputDir, strOutputFileName) PyStrCakeFilePrefix = os.path.splitext( os.path.split(strInputImageFilePath)[1])[0] ################################################################ #### Do some manipulation of the output image ############## ################################################################ EDFCakeFile = fabio.open( os.path.join(self.getWorkingDirectory(), PyStrCakeFilePrefix + ".azim.edf")) npaData = EDFCakeFile.data pydHeader = EDFCakeFile.header pyfPixSize = float(pydHeader["PSize_1"].split()[0]) pyfDist = float(pydHeader["SampleDistance"].split()[0]) EDVerbose.DEBUG("Calculation done with PixSize=%s, distance= %s" % (pydHeader["PSize_1"], pydHeader["SampleDistance"])) pyiNbAzimBin, pyiLength = npaData.shape nplInt = npaData.reshape((pyiLength)) nplTth = numpy.degrees( numpy.arctan( numpy.linspace( 0.5 * pyfPixSize / pyfDist, (pyiLength - 0.5) * pyfPixSize / pyfDist, pyiLength, ))) #for the description of the +0.5 term, please refer to http://www.esrf.fr/computing/scientific/SAXS/doc/SaxsKeywords/SaxsKeywords.pdf page 23 ######################################Debugging####################### f = open(os.path.join(self.getWorkingDirectory(), "original.dat"), "w") for i in range(pyiLength): f.write("%f\t%f\n" % (nplTth[i], nplInt[i])) f.close() ##############################end Debugging############################ XRPD = lambda tth: numpy.interp(tth, nplTth, nplInt, left=0, right=0) pyfTthMin = nplTth[0] pyfTthMax = nplTth[-1] pyfStep = (pyfTthMax - pyfTthMin) / (pyiLength - 1) ########### Remove large files to prevent disk saturation when not in debug mode ################### if not EDVerbose.isVerboseDebug(): os.remove( os.path.join(self.getWorkingDirectory(), PyStrCakeFilePrefix + ".cor.edf")) os.remove( os.path.join(self.getWorkingDirectory(), PyStrCakeFilePrefix + ".azim.edf")) # # Create the output data xsDataResultSPDCake = XSDataResultSPDCake() if (self.m_strOutputFilePath is not None): if (strOutputFileType == "PowderCIF"): import CIFfile cif = CIFfile.CIF() cif["_audit_creation_method"] = 'From 2-D detector using SPD and CIFfile' cif["_pd_meas_2theta_range_inc"] = str(pyfStep) cif["_pd_meas_2theta_range_max"] = str(pyfTthMax) cif["_pd_meas_2theta_range_min"] = str(pyfTthMin) cif["_pd_meas_number_of_points"] = str(pyiLength) cif["_pd_meas_scan_method"] = "fixed" cif["_pd_spec_description"] = pydHeader["title"] cif["_diffrn_radiation_wavelength"] = str( self.getDataInput().getWavelength().getValue()) cif["_pd_instr_dist_spec/detc"] = str(self.getDataInput( ).getSampleToDetectorDistance().getValue()) oneloop = [] #range( pyiLength ): for i in numpy.linspace(pyfTthMin, pyfTthMax, pyiLength): oneloop.append({"_pd_meas_intensity_total": str(XRPD(i))}) cif["loop_"] = [[["_pd_meas_intensity_total"], oneloop]] cif.saveCIF(self.m_strOutputFilePath) elif (strOutputFileType == "CHIPLOT"): f = open( os.path.join(self.getWorkingDirectory(), self.m_strOutputFilePath), "w") f.write( pydHeader["title"] + ": Angular Profile\nTwo-Theta Angle (degrees)\nIntensity (normalised)\n%i\n" % pyiLength) for i in numpy.linspace(pyfTthMin, pyfTthMax, pyiLength): f.write("%f\t%f\n" % (i, XRPD(i))) f.close() xsDataFile = XSDataFile() xsDataFile.setPath(XSDataString(self.m_strOutputFilePath)) xsDataResultSPDCake.setCakedFile(xsDataFile) self.setDataOutput(xsDataResultSPDCake)
def postProcess(self, _edObject=None): EDPluginExecProcessScript.postProcess(self) EDVerbose.DEBUG("EDPluginSPDCakev1_1.postProcess") xsDataInputSPDCake = self.getDataInput() strOutputFileType = xsDataInputSPDCake.getOutputFileType().getValue() # Determine the image file name without path and suffix strInputImageFilePath = xsDataInputSPDCake.getInputFile().getPath().getValue() strInputFileNameWithoutSuffix = os.path.splitext(EDUtilsFile.getBaseName(strInputImageFilePath))[0] self.strOutputFileSuffix = "data" if (strOutputFileType == "PowderCIF"): self.strOutputFileSuffix = "cif" elif (strOutputFileType == "CHIPLOT"): self.strOutputFileSuffix = "chi" strOutputFileName = strInputFileNameWithoutSuffix + "." + self.strOutputFileSuffix if self.outputDir is None: self.m_strOutputFilePath = os.path.join(self.getWorkingDirectory(), strOutputFileName) else: self.m_strOutputFilePath = os.path.join(self.outputDir, strOutputFileName) PyStrCakeFilePrefix = os.path.splitext(os.path.split(strInputImageFilePath)[1])[0] ################################################################ #### Do some manipulation of the output image ############## ################################################################ EDFCakeFile = fabio.open(os.path.join(self.getWorkingDirectory(), PyStrCakeFilePrefix + ".azim.edf")) npaData = EDFCakeFile.data pydHeader = EDFCakeFile.header pyfPixSize = float(pydHeader["PSize_1"].split()[0]) pyfDist = float(pydHeader["SampleDistance"].split()[0]) EDVerbose.DEBUG("Calculation done with PixSize=%s, distance= %s" % (pydHeader["PSize_1"], pydHeader["SampleDistance"])) pyiNbAzimBin, pyiLength = npaData.shape nplInt = npaData.reshape((pyiLength)) nplTth = numpy.degrees(numpy.arctan(numpy.linspace(0.5 * pyfPixSize / pyfDist, (pyiLength - 0.5) * pyfPixSize / pyfDist , pyiLength,))) #for the description of the +0.5 term, please refer to http://www.esrf.fr/computing/scientific/SAXS/doc/SaxsKeywords/SaxsKeywords.pdf page 23 ######################################Debugging####################### f = open(os.path.join(self.getWorkingDirectory(), "original.dat"), "w") for i in range(pyiLength): f.write("%f\t%f\n" % (nplTth[i], nplInt[i])) f.close() ##############################end Debugging############################ XRPD = lambda tth: numpy.interp(tth, nplTth, nplInt, left=0, right=0) pyfTthMin = nplTth[0] pyfTthMax = nplTth[-1] pyfStep = (pyfTthMax - pyfTthMin) / (pyiLength - 1) ########### Remove large files to prevent disk saturation when not in debug mode ################### if not EDVerbose.isVerboseDebug(): os.remove(os.path.join(self.getWorkingDirectory(), PyStrCakeFilePrefix + ".cor.edf")) os.remove(os.path.join(self.getWorkingDirectory(), PyStrCakeFilePrefix + ".azim.edf")) # # Create the output data xsDataResultSPDCake = XSDataResultSPDCake() if (self.m_strOutputFilePath is not None): if (strOutputFileType == "PowderCIF"): import CIFfile cif = CIFfile.CIF() cif[ "_audit_creation_method" ] = 'From 2-D detector using SPD and CIFfile' cif[ "_pd_meas_2theta_range_inc" ] = str(pyfStep) cif[ "_pd_meas_2theta_range_max" ] = str(pyfTthMax) cif[ "_pd_meas_2theta_range_min" ] = str(pyfTthMin) cif[ "_pd_meas_number_of_points" ] = str(pyiLength) cif[ "_pd_meas_scan_method" ] = "fixed" cif[ "_pd_spec_description" ] = pydHeader["title"] cif["_diffrn_radiation_wavelength"] = str(self.getDataInput().getWavelength().getValue()) cif["_pd_instr_dist_spec/detc"] = str(self.getDataInput().getSampleToDetectorDistance().getValue()) oneloop = [] #range( pyiLength ): for i in numpy.linspace(pyfTthMin, pyfTthMax, pyiLength): oneloop.append({ "_pd_meas_intensity_total" : str(XRPD(i)) }) cif["loop_"] = [ [ ["_pd_meas_intensity_total"], oneloop ] ] cif.saveCIF(self.m_strOutputFilePath) elif (strOutputFileType == "CHIPLOT"): f = open(os.path.join(self.getWorkingDirectory(), self.m_strOutputFilePath), "w") f.write(pydHeader["title"] + ": Angular Profile\nTwo-Theta Angle (degrees)\nIntensity (normalised)\n%i\n" % pyiLength) for i in numpy.linspace(pyfTthMin, pyfTthMax, pyiLength): f.write("%f\t%f\n" % (i, XRPD(i))) f.close() xsDataFile = XSDataFile() xsDataFile.setPath(XSDataString(self.m_strOutputFilePath)) xsDataResultSPDCake.setCakedFile(xsDataFile) self.setDataOutput(xsDataResultSPDCake)