def test_generateCommandLine(self): edPlugin = self.getPlugin() strInputXML = EDUtilsFile.readFile(os.path.join(self.strDataPath, "XSDataInputAutoPROC_reference.xml")) xsDataInput = XSDataInputAutoPROC.parseString(strInputXML) strCommandLine = edPlugin.generateCommandLine(xsDataInput) print(strCommandLine) EDAssert.equal("-B -xml -I /scisoft/pxsoft/data/AUTO_PROCESSING/id29/20130301/RAW_DATA/GaelleB/xtal5 -Id 1088454,/scisoft/pxsoft/data/AUTO_PROCESSING/id29/20130301/RAW_DATA/GaelleB/xtal5,xtal5w1_1_####.cbf,1,100 -R 5.0 2.0 -ANO", strCommandLine, "Reference data input")
def test_generateCommandLine(self): edPlugin = self.getPlugin() strInputXML1 = EDUtilsFile.readFile(os.path.join(self.strDataPath, "XSDataInputAutoPROC_reference.xml")) xsDataInput1 = XSDataInputAutoPROC.parseString(strInputXML1) strCommandLine1 = edPlugin.generateCommandLine(xsDataInput1) referenceCommandLine1 = "-B -xml -nthreads 12 -M ReportingInlined autoPROC_HIGHLIGHT=\"no\" -Id 1088454A,/scisoft/pxsoft/data/AUTO_PROCESSING/id29/20130301/RAW_DATA/GaelleB/xtal5,xtal5w1_1_####.cbf,1,50 -R 5.0 2.0" # print(strCommandLine1) EDAssert.equal(referenceCommandLine1, strCommandLine1, "Reference data input") # Symmetry input strInputXML2 = EDUtilsFile.readFile(os.path.join(self.strDataPath, "XSDataInputAutoPROC_symm.xml")) xsDataInput2 = XSDataInputAutoPROC.parseString(strInputXML2) strCommandLine2 = edPlugin.generateCommandLine(xsDataInput2) # print(strCommandLine2) referenceCommandLine2 = "-B -xml -nthreads 12 -M ReportingInlined autoPROC_HIGHLIGHT=\"no\" -Id 1088454A,/scisoft/pxsoft/data/AUTO_PROCESSING/id29/20130301/RAW_DATA/GaelleB/xtal5,xtal5w1_1_####.cbf,1,50 -R 5.0 2.0 symm=\"P1\" cell=\"52.4 78.7 79.4 90.0 89.8 109.4\"" # print(referenceCommandLine) EDAssert.equal(referenceCommandLine2, strCommandLine2, "Reference data input")
def process(self, _edObject=None): EDPluginControl.process(self) self.DEBUG('EDPluginControlAutoPROCv1_0.process starting') directory = None template = None imageNoStart = None imageNoEnd = None pathToStartImage = None pathToEndImage = None userName = os.environ["USER"] beamline = "unknown" proposal = "unknown" # If we have a data collection id, use it if self.dataInput.dataCollectionId is not None: # Recover the data collection from ISPyB xsDataInputRetrieveDataCollection = XSDataInputRetrieveDataCollection() identifier = str(self.dataInput.dataCollectionId.value) xsDataInputRetrieveDataCollection.dataCollectionId = self.dataInput.dataCollectionId self.edPluginRetrieveDataCollection.dataInput = xsDataInputRetrieveDataCollection self.edPluginRetrieveDataCollection.executeSynchronous() ispybDataCollection = self.edPluginRetrieveDataCollection.dataOutput.dataCollection directory = ispybDataCollection.imageDirectory template = ispybDataCollection.fileTemplate.replace("%04d", "####") imageNoStart = ispybDataCollection.startImageNumber imageNoEnd = imageNoStart + ispybDataCollection.numberOfImages - 1 # # DEBUG we set the end image to 20 in order to speed up things # self.warning("End image set to 20 (was {0})".format(imageNoEnd)) # imageNoEnd = 20 pathToStartImage = os.path.join(directory, ispybDataCollection.fileTemplate % imageNoStart) pathToEndImage = os.path.join(directory, ispybDataCollection.fileTemplate % imageNoEnd) else: identifier = str(int(time.time())) directory = self.dataInput.dirN.value template = self.dataInput.templateN.value imageNoStart = self.dataInput.fromN.value imageNoEnd = self.dataInput.toN.value fileTemplate = template.replace("####", "%04d") pathToStartImage = os.path.join(directory, fileTemplate % imageNoStart) pathToEndImage = os.path.join(directory, fileTemplate % imageNoEnd) # Try to get proposal from path if EDUtilsPath.isESRF(): listDirectory = directory.split(os.sep) try: if listDirectory[1] == "data": if listDirectory[2] == "visitor": beamline = listDirectory[4] proposal = listDirectory[3] else: beamline = listDirectory[2] proposal = listDirectory[4] except: beamline = "unknown" proposal = userName if imageNoEnd - imageNoStart < 8: error_message = "There are fewer than 8 images, aborting" self.addErrorMessage(error_message) self.ERROR(error_message) self.setFailure() return # Process directory if self.dataInput.processDirectory is not None: processDirectory = self.dataInput.processDirectory.path.value else: processDirectory = directory.replace("RAW_DATA", "PROCESSED_DATA") # Make results directory self.resultsDirectory = os.path.join(processDirectory, "results") if not os.path.exists(self.resultsDirectory): os.makedirs(self.resultsDirectory, 0755) # Create path to pyarch self.pyarchDirectory = EDHandlerESRFPyarchv1_0.createPyarchFilePath(self.resultsDirectory) self.pyarchDirectory = self.pyarchDirectory.replace('PROCESSED_DATA', 'RAW_DATA') if self.pyarchDirectory is not None and not os.path.exists(self.pyarchDirectory): os.makedirs(self.pyarchDirectory, 0755) # Determine pyarch prefix listPrefix = template.split("_") self.pyarchPrefix = "ap_{0}_run{1}".format(listPrefix[-3], listPrefix[-2]) isH5 = False if any(beamline in pathToStartImage for beamline in ["id23eh1", "id29"]): minSizeFirst = 6000000 minSizeLast = 6000000 elif any(beamline in pathToStartImage for beamline in ["id23eh2", "id30a1"]): minSizeFirst = 2000000 minSizeLast = 2000000 elif any(beamline in pathToStartImage for beamline in ["id30a3"]): minSizeFirst = 100000 minSizeLast = 100000 pathToStartImage = os.path.join(directory, self.eiger_template_to_image(template, imageNoStart)) pathToEndImage = os.path.join(directory, self.eiger_template_to_image(template, imageNoEnd)) isH5 = True else: minSizeFirst = 1000000 minSizeLast = 1000000 fWaitFileTimeout = 3600 # s xsDataInputMXWaitFileFirst = XSDataInputMXWaitFile() xsDataInputMXWaitFileFirst.file = XSDataFile(XSDataString(pathToStartImage)) xsDataInputMXWaitFileFirst.timeOut = XSDataTime(fWaitFileTimeout) self.edPluginWaitFileFirst.size = XSDataInteger(minSizeFirst) self.edPluginWaitFileFirst.dataInput = xsDataInputMXWaitFileFirst self.edPluginWaitFileFirst.executeSynchronous() if self.edPluginWaitFileFirst.dataOutput.timedOut.value: strWarningMessage = "Timeout after %d seconds waiting for the first image %s!" % (fWaitFileTimeout, pathToStartImage) self.addWarningMessage(strWarningMessage) self.WARNING(strWarningMessage) xsDataInputMXWaitFileLast = XSDataInputMXWaitFile() xsDataInputMXWaitFileLast.file = XSDataFile(XSDataString(pathToEndImage)) xsDataInputMXWaitFileLast.timeOut = XSDataTime(fWaitFileTimeout) self.edPluginWaitFileLast.size = XSDataInteger(minSizeLast) self.edPluginWaitFileLast.dataInput = xsDataInputMXWaitFileLast self.edPluginWaitFileLast.executeSynchronous() if self.edPluginWaitFileLast.dataOutput.timedOut.value: strErrorMessage = "Timeout after %d seconds waiting for the last image %s!" % (fWaitFileTimeout, pathToEndImage) self.addErrorMessage(strErrorMessage) self.ERROR(strErrorMessage) self.setFailure() # Prepare input to execution plugin xsDataInputAutoPROCAnom = XSDataInputAutoPROC() xsDataInputAutoPROCAnom.anomalous = XSDataBoolean(True) if self.doAnomAndNonanom: xsDataInputAutoPROCNoanom = XSDataInputAutoPROC() xsDataInputAutoPROCNoanom.anomalous = XSDataBoolean(False) xsDataAutoPROCIdentifier = XSDataAutoPROCIdentifier() xsDataAutoPROCIdentifier.idN = XSDataString(identifier) xsDataAutoPROCIdentifier.dirN = XSDataFile(XSDataString(directory)) xsDataAutoPROCIdentifier.templateN = XSDataString(template) xsDataAutoPROCIdentifier.fromN = XSDataInteger(imageNoStart) xsDataAutoPROCIdentifier.toN = XSDataInteger(imageNoEnd) xsDataInputAutoPROCAnom.addIdentifier(xsDataAutoPROCIdentifier) if self.doAnomAndNonanom: xsDataInputAutoPROCNoanom.addIdentifier(xsDataAutoPROCIdentifier.copy()) if isH5: masterFilePath = os.path.join(directory, self.eiger_template_to_master(template)) xsDataInputAutoPROCAnom.masterH5 = XSDataFile(XSDataString(masterFilePath)) if self.doAnomAndNonanom: xsDataInputAutoPROCNoanom.masterH5 = XSDataFile(XSDataString(masterFilePath)) timeStart = time.localtime() self.edPluginExecAutoPROCAnom.dataInput = xsDataInputAutoPROCAnom self.edPluginExecAutoPROCAnom.execute() if self.doAnomAndNonanom: self.edPluginExecAutoPROCNoanom.dataInput = xsDataInputAutoPROCNoanom self.edPluginExecAutoPROCNoanom.execute() self.edPluginExecAutoPROCAnom.synchronize() if self.doAnomAndNonanom: self.edPluginExecAutoPROCNoanom.synchronize() timeEnd = time.localtime() # Upload to ISPyB self.uploadToISPyB(self.edPluginExecAutoPROCAnom, True, proposal, timeStart, timeEnd) if self.doAnomAndNonanom: self.uploadToISPyB(self.edPluginExecAutoPROCNoanom, False, proposal, timeStart, timeEnd)
def process(self, _edObject=None): EDPluginControl.process(self) self.DEBUG('EDPluginControlAutoPROCv1_0.process starting') directory = None template = None imageNoStart = None imageNoEnd = None pathToStartImage = None pathToEndImage = None userName = os.environ["USER"] beamline = "unknown" proposal = "unknown" # If we have a data collection id, use it if self.dataInput.dataCollectionId is not None: # Recover the data collection from ISPyB xsDataInputRetrieveDataCollection = XSDataInputRetrieveDataCollection() identifier = str(self.dataInput.dataCollectionId.value) xsDataInputRetrieveDataCollection.dataCollectionId = self.dataInput.dataCollectionId self.edPluginRetrieveDataCollection.dataInput = xsDataInputRetrieveDataCollection self.edPluginRetrieveDataCollection.executeSynchronous() ispybDataCollection = self.edPluginRetrieveDataCollection.dataOutput.dataCollection directory = ispybDataCollection.imageDirectory if EDUtilsPath.isEMBL(): template = ispybDataCollection.fileTemplate.replace("%05d", "#" * 5) elif EDUtilsPath.isMAXIV(): template = ispybDataCollection.fileTemplate else: template = ispybDataCollection.fileTemplate.replace("%04d", "####") if self.dataInput.fromN is None: imageNoStart = ispybDataCollection.startImageNumber else: imageNoStart = self.dataInput.fromN.value if self.dataInput.toN is None: imageNoEnd = imageNoStart + ispybDataCollection.numberOfImages - 1 else: imageNoEnd = self.dataInput.toN.value # # DEBUG we set the end image to 20 in order to speed up things # self.warning("End image set to 20 (was {0})".format(imageNoEnd)) # imageNoEnd = 20 pathToStartImage = os.path.join(directory, ispybDataCollection.fileTemplate % imageNoStart) pathToEndImage = os.path.join(directory, ispybDataCollection.fileTemplate % imageNoEnd) else: identifier = str(int(time.time())) directory = self.dataInput.dirN.path.value template = self.dataInput.templateN.value imageNoStart = self.dataInput.fromN.value imageNoEnd = self.dataInput.toN.value if EDUtilsPath.isEMBL(): fileTemplate = template.replace("#####", "%05d") else: fileTemplate = template.replace("####", "%04d") pathToStartImage = os.path.join(directory, fileTemplate % imageNoStart) pathToEndImage = os.path.join(directory, fileTemplate % imageNoEnd) # Try to get proposal from path if EDUtilsPath.isESRF(): listDirectory = directory.split(os.sep) try: if listDirectory[1] == "data": if listDirectory[2] == "visitor": beamline = listDirectory[4] proposal = listDirectory[3] else: beamline = listDirectory[2] proposal = listDirectory[4] except: beamline = "unknown" proposal = userName if imageNoEnd - imageNoStart < 8: error_message = "There are fewer than 8 images, aborting" self.addErrorMessage(error_message) self.ERROR(error_message) self.setFailure() return # Process directory if self.dataInput.processDirectory is not None: processDirectory = self.dataInput.processDirectory.path.value else: processDirectory = directory.replace("RAW_DATA", "PROCESSED_DATA") # Make results directory if EDUtilsPath.isALBA(): _processDirectory = "_".join(pathToStartImage.split('_')[:-1]) from datetime import datetime _id = datetime.now().strftime('%Y%m%d_%H%M%S') self.resultsDirectory = os.path.join(_processDirectory, "autoPROC_%s" % _id) else: self.resultsDirectory = os.path.join(processDirectory, "results") if not os.path.exists(self.resultsDirectory): os.makedirs(self.resultsDirectory, 0o755) # Create path to pyarch if self.dataInput.reprocess is not None and self.dataInput.reprocess.value: self.pyarchDirectory = EDHandlerESRFPyarchv1_0.createPyarchReprocessDirectoryPath(beamline, "autoPROC", self.dataInput.dataCollectionId.value) else: self.pyarchDirectory = EDHandlerESRFPyarchv1_0.createPyarchFilePath(self.resultsDirectory) if self.pyarchDirectory is not None: self.pyarchDirectory = self.pyarchDirectory.replace('PROCESSED_DATA', 'RAW_DATA') if not os.path.exists(self.pyarchDirectory): try: os.makedirs(self.pyarchDirectory, 0o755) except: self.pyarchDirectory = None # The resultsDirectory is not used at ALBA (only pyarchDirectory) if EDUtilsPath.isALBA(): self.resultsDirectory = None # Determine pyarch prefix if EDUtilsPath.isALBA(): listPrefix = template.split("_") self.pyarchPrefix = "ap_{0}_{1}".format("_".join(listPrefix[:-2]), listPrefix[-2]) else: listPrefix = template.split("_") self.pyarchPrefix = "ap_{0}_run{1}".format(listPrefix[-3], listPrefix[-2]) isH5 = False if any(beamline in pathToStartImage for beamline in ["id30b"]): minSizeFirst = 6000000 minSizeLast = 6000000 elif any(beamline in pathToStartImage for beamline in ["id23eh2", "id30a1"]): minSizeFirst = 2000000 minSizeLast = 2000000 elif any(beamline in pathToStartImage for beamline in ["id23eh1", "id30a3"]): minSizeFirst = 100000 minSizeLast = 100000 pathToStartImage = os.path.join(directory, self.eiger_template_to_image(template, imageNoStart)) pathToEndImage = os.path.join(directory, self.eiger_template_to_image(template, imageNoEnd)) isH5 = True else: minSizeFirst = 1000000 minSizeLast = 1000000 if EDUtilsPath.isMAXIV(): minSizeFirst = 100000 minSizeLast = 100000 pathToStartImage = os.path.join(directory, self.eiger_template_to_image(template, imageNoStart)) pathToEndImage = os.path.join(directory, self.eiger_template_to_image(template, imageNoEnd)) isH5 = True if EDUtilsPath.isEMBL() or EDUtilsPath.isMAXIV(): fWaitFileTimeout = 60 # s else: fWaitFileTimeout = 3600 # s xsDataInputMXWaitFileFirst = XSDataInputMXWaitFile() xsDataInputMXWaitFileFirst.file = XSDataFile(XSDataString(pathToStartImage)) xsDataInputMXWaitFileFirst.timeOut = XSDataTime(fWaitFileTimeout) self.edPluginWaitFileFirst.size = XSDataInteger(minSizeFirst) self.edPluginWaitFileFirst.dataInput = xsDataInputMXWaitFileFirst self.edPluginWaitFileFirst.executeSynchronous() if self.edPluginWaitFileFirst.dataOutput.timedOut.value: strWarningMessage = "Timeout after %d seconds waiting for the first image %s!" % (fWaitFileTimeout, pathToStartImage) self.addWarningMessage(strWarningMessage) self.WARNING(strWarningMessage) xsDataInputMXWaitFileLast = XSDataInputMXWaitFile() xsDataInputMXWaitFileLast.file = XSDataFile(XSDataString(pathToEndImage)) xsDataInputMXWaitFileLast.timeOut = XSDataTime(fWaitFileTimeout) self.edPluginWaitFileLast.size = XSDataInteger(minSizeLast) self.edPluginWaitFileLast.dataInput = xsDataInputMXWaitFileLast self.edPluginWaitFileLast.executeSynchronous() if self.edPluginWaitFileLast.dataOutput.timedOut.value: strErrorMessage = "Timeout after %d seconds waiting for the last image %s!" % (fWaitFileTimeout, pathToEndImage) self.addErrorMessage(strErrorMessage) self.ERROR(strErrorMessage) self.setFailure() self.timeStart = time.localtime() if self.dataInput.dataCollectionId is not None: # Set ISPyB to running if self.doAnom: self.autoProcIntegrationIdAnom, self.autoProcProgramIdAnom = \ EDHandlerXSDataISPyBv1_4.setIspybToRunning(self, dataCollectionId=self.dataInput.dataCollectionId.value, processingCommandLine=self.processingCommandLine, processingPrograms=self.processingProgram, isAnom=True, timeStart=self.timeStart) self.autoProcIntegrationIdAnomStaraniso, self.autoProcProgramIdAnomStaraniso = \ EDHandlerXSDataISPyBv1_4.setIspybToRunning(self, dataCollectionId=self.dataInput.dataCollectionId.value, processingCommandLine=self.processingCommandLine, processingPrograms=self.processingProgramStaraniso, isAnom=True, timeStart=self.timeStart) if self.doNoanom: self.autoProcIntegrationIdNoanom, self.autoProcProgramIdNoanom = \ EDHandlerXSDataISPyBv1_4.setIspybToRunning(self, dataCollectionId=self.dataInput.dataCollectionId.value, processingCommandLine=self.processingCommandLine, processingPrograms=self.processingProgram, isAnom=False, timeStart=self.timeStart) self.autoProcIntegrationIdNoanomStaraniso, self.autoProcProgramIdNoanomStaraniso = \ EDHandlerXSDataISPyBv1_4.setIspybToRunning(self, dataCollectionId=self.dataInput.dataCollectionId.value, processingCommandLine=self.processingCommandLine, processingPrograms=self.processingProgramStaraniso, isAnom=False, timeStart=self.timeStart) # Prepare input to execution plugin if self.doAnom: xsDataInputAutoPROCAnom = XSDataInputAutoPROC() xsDataInputAutoPROCAnom.anomalous = XSDataBoolean(True) xsDataInputAutoPROCAnom.symm = self.dataInput.symm xsDataInputAutoPROCAnom.cell = self.dataInput.cell xsDataInputAutoPROCAnom.lowResolutionLimit = self.dataInput.lowResolutionLimit xsDataInputAutoPROCAnom.highResolutionLimit = self.dataInput.highResolutionLimit if self.doNoanom: xsDataInputAutoPROCNoanom = XSDataInputAutoPROC() xsDataInputAutoPROCNoanom.anomalous = XSDataBoolean(False) xsDataInputAutoPROCNoanom.symm = self.dataInput.symm xsDataInputAutoPROCNoanom.cell = self.dataInput.cell xsDataInputAutoPROCNoanom.lowResolutionLimit = self.dataInput.lowResolutionLimit xsDataInputAutoPROCNoanom.highResolutionLimit = self.dataInput.highResolutionLimit xsDataAutoPROCIdentifier = XSDataAutoPROCIdentifier() xsDataAutoPROCIdentifier.idN = XSDataString(identifier) xsDataAutoPROCIdentifier.dirN = XSDataFile(XSDataString(directory)) xsDataAutoPROCIdentifier.templateN = XSDataString(template) xsDataAutoPROCIdentifier.fromN = XSDataInteger(imageNoStart) xsDataAutoPROCIdentifier.toN = XSDataInteger(imageNoEnd) if self.doAnom: xsDataInputAutoPROCAnom.addIdentifier(xsDataAutoPROCIdentifier) if self.doNoanom: xsDataInputAutoPROCNoanom.addIdentifier(xsDataAutoPROCIdentifier.copy()) if isH5: masterFilePath = os.path.join(directory, self.eiger_template_to_master(template)) if self.doAnom: xsDataInputAutoPROCAnom.masterH5 = XSDataFile(XSDataString(masterFilePath)) if self.doNoanom: xsDataInputAutoPROCNoanom.masterH5 = XSDataFile(XSDataString(masterFilePath)) timeStart = time.localtime() if self.doAnom: self.edPluginExecAutoPROCAnom.dataInput = xsDataInputAutoPROCAnom self.edPluginExecAutoPROCAnom.execute() if self.doNoanom: self.edPluginExecAutoPROCNoanom.dataInput = xsDataInputAutoPROCNoanom self.edPluginExecAutoPROCNoanom.execute() if self.doAnom: self.edPluginExecAutoPROCAnom.synchronize() if self.doNoanom: self.edPluginExecAutoPROCNoanom.synchronize() timeEnd = time.localtime() # Upload to ISPyB if self.doAnom: self.uploadToISPyB(self.edPluginExecAutoPROCAnom, True, False, proposal, timeStart, timeEnd) self.uploadToISPyB(self.edPluginExecAutoPROCAnom, True, True, proposal, timeStart, timeEnd) if self.doNoanom: self.uploadToISPyB(self.edPluginExecAutoPROCNoanom, False, False, proposal, timeStart, timeEnd) self.uploadToISPyB(self.edPluginExecAutoPROCNoanom, False, True, proposal, timeStart, timeEnd)