def process(self, _edObject=None): EDPluginControl.process(self) self.DEBUG("EDPluginControlH5ToCBFv1_0.process") imageNumber = self.dataInput.imageNumber.value if self.dataInput.hdf5ImageNumber is None: hdf5ImageNumber = imageNumber else: hdf5ImageNumber = self.dataInput.hdf5ImageNumber.value if self.dataInput.ispybDataCollection is None: xsDataInputRetrieveDataCollection = XSDataInputRetrieveDataCollection( ) xsDataImage = XSDataImage(self.dataInput.hdf5File.path) xsDataInputRetrieveDataCollection.image = xsDataImage self.edPluginISPyBRetrieveDataCollection.dataInput = xsDataInputRetrieveDataCollection self.edPluginISPyBRetrieveDataCollection.executeSynchronous() xsDataResultRetrieveDataCollection = self.edPluginISPyBRetrieveDataCollection.dataOutput dataCollection = xsDataResultRetrieveDataCollection.dataCollection else: dataCollection = self.dataInput.ispybDataCollection if dataCollection is not None: if dataCollection.overlap is None: overlap = 0.0 else: overlap = dataCollection.overlap axisStart = dataCollection.axisStart oscillationRange = dataCollection.axisRange axisStartNew = axisStart - (overlap + oscillationRange) * (imageNumber - 1) dataCollection.axisStart = axisStartNew xsDataISPyBDataCollection = XSDataISPyBDataCollection.parseString( dataCollection.marshal()) else: xsDataISPyBDataCollection = None xsDataInputH5ToCBF = XSDataInputH5ToCBF() xsDataInputH5ToCBF.hdf5File = self.dataInput.hdf5File xsDataInputH5ToCBF.imageNumber = self.dataInput.imageNumber xsDataInputH5ToCBF.hdf5ImageNumber = XSDataInteger(hdf5ImageNumber) xsDataInputH5ToCBF.dataCollection = xsDataISPyBDataCollection xsDataInputH5ToCBF.forcedOutputDirectory = self.dataInput.forcedOutputDirectory self.edPluginEDPluginH5ToCBF.dataInput = xsDataInputH5ToCBF self.edPluginEDPluginH5ToCBF.executeSynchronous() if self.edPluginEDPluginH5ToCBF.dataOutput is not None: self.dataOutput.outputCBFFile = self.edPluginEDPluginH5ToCBF.dataOutput.outputCBFFile if dataCollection is not None: self.dataOutput.ispybDataCollection = XSDataISPyBDataCollection.parseString( dataCollection.marshal())
def process(self, _edObject=None): EDPluginControl.process(self) self.DEBUG("EDPluginControlH5ToCBFv1_0.process") imageNumber = self.dataInput.imageNumber.value if self.dataInput.hdf5ImageNumber is None: hdf5ImageNumber = imageNumber else: hdf5ImageNumber = self.dataInput.hdf5ImageNumber.value if self.dataInput.ispybDataCollection is None: xsDataInputRetrieveDataCollection = XSDataInputRetrieveDataCollection() xsDataImage = XSDataImage(self.dataInput.hdf5File.path) xsDataInputRetrieveDataCollection.image = xsDataImage self.edPluginISPyBRetrieveDataCollection.dataInput = xsDataInputRetrieveDataCollection self.edPluginISPyBRetrieveDataCollection.executeSynchronous() xsDataResultRetrieveDataCollection = self.edPluginISPyBRetrieveDataCollection.dataOutput dataCollection = xsDataResultRetrieveDataCollection.dataCollection else: dataCollection = self.dataInput.ispybDataCollection if dataCollection is not None: if dataCollection.overlap is None: overlap = 0.0 else: overlap = dataCollection.overlap axisStart = dataCollection.axisStart oscillationRange = dataCollection.axisRange axisStartNew = axisStart - (overlap + oscillationRange) * (imageNumber - 1) dataCollection.axisStart = axisStartNew xsDataISPyBDataCollection = XSDataISPyBDataCollection.parseString(dataCollection.marshal()) else: xsDataISPyBDataCollection = None xsDataInputH5ToCBF = XSDataInputH5ToCBF() xsDataInputH5ToCBF.hdf5File = self.dataInput.hdf5File xsDataInputH5ToCBF.imageNumber = self.dataInput.imageNumber xsDataInputH5ToCBF.hdf5ImageNumber = XSDataInteger(hdf5ImageNumber) xsDataInputH5ToCBF.dataCollection = xsDataISPyBDataCollection xsDataInputH5ToCBF.forcedOutputDirectory = self.dataInput.forcedOutputDirectory self.edPluginEDPluginH5ToCBF.dataInput = xsDataInputH5ToCBF self.edPluginEDPluginH5ToCBF.executeSynchronous() if self.edPluginEDPluginH5ToCBF.dataOutput is not None: self.dataOutput.outputCBFFile = self.edPluginEDPluginH5ToCBF.dataOutput.outputCBFFile if dataCollection is not None: self.dataOutput.ispybDataCollection = XSDataISPyBDataCollection.parseString(dataCollection.marshal())
def postProcess(self, _edObject=None): EDPluginControl.postProcess(self) self.DEBUG("EDPluginControlDozorv1_0.postProcess") # Write a file to be used with ISPyB or GNUPLOT only if data collection id in input dataCollectionId = None if self.dataInput.dataCollectionId is None and len(self.dataInput.image) > 0: # Only try to obtain data collection id if at the ESRF and path starts with "/data" if EDUtilsPath.isESRF() and self.dataInput.image[0].path.value.startswith("/data"): xsDataInputRetrieveDataCollection = XSDataInputRetrieveDataCollection() xsDataInputRetrieveDataCollection.image = XSDataImage(self.dataInput.image[0].path) edPluginISPyBRetrieveDataCollection = self.loadPlugin("EDPluginISPyBRetrieveDataCollectionv1_4") edPluginISPyBRetrieveDataCollection.dataInput = xsDataInputRetrieveDataCollection edPluginISPyBRetrieveDataCollection.executeSynchronous() xsDataResultRetrieveDataCollection = edPluginISPyBRetrieveDataCollection.dataOutput if xsDataResultRetrieveDataCollection is not None: dataCollection = xsDataResultRetrieveDataCollection.dataCollection if dataCollection is not None: dataCollectionId = dataCollection.dataCollectionId elif self.dataInput.dataCollectionId is not None: dataCollectionId = self.dataInput.dataCollectionId.value if dataCollectionId is not None: minImageNumber = None maxImageNumber = None minAngle = None maxAngle = None minDozorValue = None maxDozorValue = None minResolution = None maxResolution = None dozorPlotFileName = "dozor_{0}.png".format(dataCollectionId) dozorCsvFileName = "dozor_{0}.csv".format(dataCollectionId) with open(os.path.join(self.getWorkingDirectory(), dozorCsvFileName), "w") as gnuplotFile: gnuplotFile.write("# Data directory: {0}\n".format(self.directory)) gnuplotFile.write("# File template: {0}\n".format(self.template.replace("%04d", "####"))) gnuplotFile.write("# {0:>9s}{1:>16s}{2:>16s}{3:>16s}{4:>16s}{5:>16s}\n".format("'Image no'", "'Angle'", "'No of spots'", "'Main score (*10)'", "'Spot score'", "'Visible res.'", )) for imageDozor in self.dataOutput.imageDozor: gnuplotFile.write("{0:10d},{1:15.3f},{2:15d},{3:15.3f},{4:15.3f},{5:15.3f}\n".format(imageDozor.number.value, imageDozor.angle.value, imageDozor.spotsNumOf.value, 10 * imageDozor.mainScore.value, imageDozor.spotScore.value, imageDozor.visibleResolution.value, )) if minImageNumber is None or minImageNumber > imageDozor.number.value: minImageNumber = imageDozor.number.value minAngle = imageDozor.angle.value if maxImageNumber is None or maxImageNumber < imageDozor.number.value: maxImageNumber = imageDozor.number.value maxAngle = imageDozor.angle.value if minDozorValue is None or minDozorValue > imageDozor.mainScore.value: minDozorValue = imageDozor.spotScore.value if maxDozorValue is None or maxDozorValue < imageDozor.mainScore.value: maxDozorValue = imageDozor.spotScore.value # Min resolution: the higher the value the lower the resolution if minResolution is None or minResolution < imageDozor.visibleResolution.value: # Disregard resolution worse than 10.0 if imageDozor.visibleResolution.value < 10.0: minResolution = imageDozor.visibleResolution.value # Max resolution: the lower the number the better the resolution if maxResolution is None or maxResolution > imageDozor.visibleResolution.value: maxResolution = imageDozor.visibleResolution.value xtics = "" if minImageNumber is not None and minImageNumber == maxImageNumber: minAngle -= 1.0 maxAngle += 1.0 noImages = maxImageNumber - minImageNumber + 1 if noImages <= 4: minImageNumber -= 0.1 maxImageNumber += 0.1 deltaAngle = maxAngle - minAngle minAngle -= deltaAngle * 0.1 / noImages maxAngle += deltaAngle * 0.1 / noImages xtics = "1" if maxResolution is None or maxResolution > 0.8: maxResolution = 0.8 else: maxResolution = int(maxResolution * 10.0) / 10.0 if minResolution is None or minResolution < 4.5: minResolution = 4.5 else: minResolution = int(minResolution * 10.0) / 10.0 + 1 if maxDozorValue < 0.001 and minDozorValue < 0.001: yscale = "set yrange [-0.5:0.5]\n set ytics 1" else: yscale = "set autoscale y" gnuplotFile.close() gnuplotScript = \ """# set terminal png set output '{dozorPlotFileName}' set title '{title}' set grid x2 y2 set xlabel 'Image number' set x2label 'Angle (degrees)' set y2label 'Resolution (A)' set ylabel 'Number of spots / Dozor score (*10)' set xtics {xtics} nomirror set x2tics set ytics nomirror set y2tics set xrange [{minImageNumber}:{maxImageNumber}] set x2range [{minAngle}:{maxAngle}] {yscale} set y2range [{minResolution}:{maxResolution}] set key below plot '{dozorCsvFileName}' using 1:3 title 'Number of spots' axes x1y1 with points linetype rgb 'goldenrod' pointtype 7 pointsize 1.5, \ '{dozorCsvFileName}' using 1:4 title 'Dozor score' axes x1y1 with points linetype 3 pointtype 7 pointsize 1.5, \ '{dozorCsvFileName}' using 1:6 title 'Visible resolution' axes x1y2 with points linetype 1 pointtype 7 pointsize 1.5 """.format(title=self.template.replace("%04d", "####"), dozorPlotFileName=dozorPlotFileName, dozorCsvFileName=dozorCsvFileName, minImageNumber=minImageNumber, maxImageNumber=maxImageNumber, minAngle=minAngle, maxAngle=maxAngle, minResolution=minResolution, maxResolution=maxResolution, xtics=xtics, yscale=yscale, ) pathGnuplotScript = os.path.join(self.getWorkingDirectory(), "gnuplot.sh") data_file = open(pathGnuplotScript, "w") data_file.write(gnuplotScript) data_file.close() oldCwd = os.getcwd() os.chdir(self.getWorkingDirectory()) os.system("{0} {1}".format(self.gnuplot, pathGnuplotScript)) os.chdir(oldCwd) self.dataOutput.dozorPlot = XSDataFile(XSDataString(os.path.join(self.getWorkingDirectory(), dozorPlotFileName))) if self.dataInput.processDirectory is not None: processDirectory = self.dataInput.processDirectory.path.value else: processDirectory = os.path.join(self.directory.replace("RAW_DATA", "PROCESSED_DATA"), "DozorPlot") resultsDirectory = os.path.join(processDirectory, "results") dozorPlotResultPath = os.path.join(resultsDirectory, dozorPlotFileName) dozorCsvResultPath = os.path.join(resultsDirectory, dozorCsvFileName) try: if not os.path.exists(resultsDirectory): os.makedirs(resultsDirectory, 0o755) shutil.copy(os.path.join(self.getWorkingDirectory(), dozorPlotFileName), dozorPlotResultPath) shutil.copy(os.path.join(self.getWorkingDirectory(), dozorCsvFileName), dozorCsvResultPath) except: self.warning("Couldn't copy files to results directory: {0}".format(resultsDirectory)) try: # Create paths on pyarch dozorPlotPyarchPath = EDHandlerESRFPyarchv1_0.createPyarchFilePath(dozorPlotResultPath) dozorCsvPyarchPath = EDHandlerESRFPyarchv1_0.createPyarchFilePath(dozorCsvResultPath) if not os.path.exists(os.path.dirname(dozorPlotPyarchPath)): os.makedirs(os.path.dirname(dozorPlotPyarchPath), 0o755) shutil.copy(dozorPlotResultPath, dozorPlotPyarchPath) shutil.copy(dozorCsvResultPath, dozorCsvPyarchPath) # Upload to data collection xsDataInputISPyBSetImageQualityIndicatorsPlot = XSDataInputISPyBSetImageQualityIndicatorsPlot() xsDataInputISPyBSetImageQualityIndicatorsPlot.dataCollectionId = XSDataInteger(dataCollectionId) xsDataInputISPyBSetImageQualityIndicatorsPlot.imageQualityIndicatorsPlotPath = XSDataString(dozorPlotPyarchPath) xsDataInputISPyBSetImageQualityIndicatorsPlot.imageQualityIndicatorsCSVPath = XSDataString(dozorCsvPyarchPath) EDPluginISPyBSetImageQualityIndicatorsPlot = self.loadPlugin("EDPluginISPyBSetImageQualityIndicatorsPlotv1_4") EDPluginISPyBSetImageQualityIndicatorsPlot.dataInput = xsDataInputISPyBSetImageQualityIndicatorsPlot EDPluginISPyBSetImageQualityIndicatorsPlot.executeSynchronous() except: self.warning("Couldn't copy files to pyarch: {0}".format(dozorPlotPyarchPath)) self.sendMessageToMXCuBE("Processing finished", "info") self.setStatusToMXCuBE("Success")