def testCheckParameters(self): xsDataInput = XSDataInputWaitFile() xsDataInput.setExpectedFile(XSDataFile(XSDataString("toto"))) xsDataInput.setExpectedSize(XSDataInteger(10)) edPluginWaitFile = self.createPlugin() edPluginWaitFile.setDataInput(xsDataInput) edPluginWaitFile.checkParameters()
def process(self, _edObject=None): EDPluginControl.process(self) self.DEBUG("EDPluginWaitMultiFile.process global time-out is set to: %s (default value)" % (self.getTimeOut())) self.setTimeInit() ################################################################################ # Initialize the accumulator with the query ################################################################################ xsdiAccumulator = XSDataInputAccumulator() xsdQuery = XSDataQuery() xsdQuery.setRemoveItems(XSDataBoolean(1)) xsdQuery.setItem(self.listXsdStrings) xsdiAccumulator.setQuery([xsdQuery]) edPluginAccumulator = self.loadPlugin(self.__strControlledPluginAccumulator) edPluginAccumulator.setDataInput(xsdiAccumulator) edPluginAccumulator.connectSUCCESS(self.doSuccessAccumulator) edPluginAccumulator.connectFAILURE(self.doFailureAccumulator) edPluginAccumulator.execute() for oneXSDImage in self.listXsdFiles: xsdiWaitFile = XSDataInputWaitFile() xsdiWaitFile.setExpectedFile(oneXSDImage) xsdiWaitFile.setExpectedSize(self.dataInput.expectedSize) xsdiWaitFile.setTimeOut(self.dataInput.timeOut) edPluginWaitFile = self.loadPlugin(self.__strControlledPluginWaitFile) edPluginWaitFile.setDataInput(xsdiWaitFile) edPluginWaitFile.connectSUCCESS(self.doSuccessWaitFile) edPluginWaitFile.connectFAILURE(self.doFailureWaitFile) edPluginWaitFile.execute()
def process(self, _edObject=None): EDPluginControl.process(self) EDVerbose.DEBUG("EDPluginBioSaxsAzimutIntv1_1.process") xsdiWaitFile = XSDataInputWaitFile( expectedFile=XSDataFile(self.dataInput.normalizedImage.path), expectedSize=self.dataInput.normalizedImageSize, timeOut=XSDataTime(30)) self.__edPluginWaitFile.setDataInput(xsdiWaitFile) self.__edPluginWaitFile.connectSUCCESS(self.doSuccessWaitFile) self.__edPluginWaitFile.connectFAILURE(self.doFailureWaitFile) self.__edPluginWaitFile.executeSynchronous() if not self.isFailure(): self.__edPluginSaxsGetMetadata.connectSUCCESS( self.doSuccessGetMetadata) self.__edPluginSaxsGetMetadata.connectFAILURE( self.doFailureGetMetadata) self.__edPluginSaxsGetMetadata.executeSynchronous() if not self.isFailure(): self.__edPluginSaxsAngle.connectSUCCESS(self.doSuccessSaxsAngle) self.__edPluginSaxsAngle.connectFAILURE(self.doFailureSaxsAngle) self.__edPluginSaxsAngle.executeSynchronous() if not self.isFailure(): self.__edPluginAsciiExport.connectSUCCESS( self.doSuccessAsciiExport) self.__edPluginAsciiExport.connectFAILURE( self.doFailureAsciiExport) self.__edPluginAsciiExport.executeSynchronous()
def process(self, _edObject=None): EDPluginControl.process(self) self.DEBUG("EDPluginBioSaxsNormalizev1_1.process") xsdiWaitFile = XSDataInputWaitFile(expectedFile=XSDataFile(self.xsdInput.rawImage.path), expectedSize=self.xsdInput.rawImageSize, timeOut=XSDataTime(value=30)) self.__edPluginExecWaitFile.setDataInput(xsdiWaitFile) self.__edPluginExecWaitFile.connectSUCCESS(self.doSuccessExecWaitFile) self.__edPluginExecWaitFile.connectFAILURE(self.doFailureExecWaitFile) self.__edPluginExecWaitFile.executeSynchronous() if self.isFailure(): return # Small Numpy processing: fabIn = fabio.open(self.strRawImage) if "time_of_day" in fabIn.header: self.dictOutputHeader["time_of_day"] = fabIn.header["time_of_day"] if "Mask" in self.dictOutputHeader: mask = self.getMask(self.dictOutputHeader["Mask"]) npaMaskedData = numpy.ma.masked_array(fabIn.data.astype("float32"), ((fabIn.data < 0) + (mask[:fabIn.dim2, :fabIn.dim1 ] < 0))) else: npaMaskedData = numpy.ma.masked_array(fabIn.data.astype("float32"), (fabIn.data < 0)) scale = self.dictOutputHeader["Normalization"] / self.dictOutputHeader["DiodeCurr"] self.dictOutputHeader["Dummy"] = str(self.dummy) self.dictOutputHeader["DDummy"] = "0.1" self.dictOutputHeader["EDF_DataBlockID"] = "1.Image.Psd" header_keys = self.dictOutputHeader.keys() header_keys.sort() fabioOut = fabio.edfimage.edfimage(header=self.dictOutputHeader, header_keys=header_keys, data=numpy.ma.filled(npaMaskedData * scale, float(self.dummy))) fabioOut.appendFrame(header={"Dummy": str(self.dummy), "DDummy":"0.1", "EDF_DataBlockID":"1.Image.Error"}, data=(numpy.ma.filled(npaMaskedData * (scale ** 2), float(self.dummy)))) fabioOut.write(self.strNormalizedImage) self.lstProcessLog.append("Normalized image by factor %.3f " % (scale))
def process(self, _edObject=None): EDPluginControl.process(self) self.DEBUG("EDPluginBioSaxsNormalizev1_0.process") xsdiWaitFile = XSDataInputWaitFile( expectedFile=XSDataFile(self.xsdInput.rawImage.path), expectedSize=self.xsdInput.rawImageSize, timeOut=XSDataTime(30)) self.__edPluginExecWaitFile.setDataInput(xsdiWaitFile) self.__edPluginExecWaitFile.connectSUCCESS(self.doSuccessExecWaitFile) self.__edPluginExecWaitFile.connectFAILURE(self.doFailureExecWaitFile) self.__edPluginExecWaitFile.executeSynchronous() if self.isFailure(): return self.__edPluginExecSaxsMac.connectSUCCESS(self.doSuccessExecSaxsMac) self.__edPluginExecSaxsMac.connectFAILURE(self.doFailureExecSaxsMac) self.__edPluginExecSaxsMac.executeSynchronous() if self.isFailure(): return self.__edPluginExecMetadata.connectSUCCESS(self.doSuccessExecMetadata) self.__edPluginExecMetadata.connectFAILURE(self.doFailureExecMetadata) self.__edPluginExecMetadata.executeSynchronous()
def process(self, _edObject=None): EDPluginControl.process(self) self.DEBUG("EDPluginBioSaxsAzimutIntv1_2.process") xsdiWaitFile = XSDataInputWaitFile( expectedFile=XSDataFile(self.dataInput.normalizedImage.path), expectedSize=self.dataInput.normalizedImageSize, timeOut=XSDataTime(30)) self.__edPluginWaitFile.setDataInput(xsdiWaitFile) self.__edPluginWaitFile.connectSUCCESS(self.doSuccessWaitFile) self.__edPluginWaitFile.connectFAILURE(self.doFailureWaitFile) self.__edPluginWaitFile.executeSynchronous() if not self.isFailure(): self.__edPluginSaxsGetMetadata.connectSUCCESS( self.doSuccessGetMetadata) self.__edPluginSaxsGetMetadata.connectFAILURE( self.doFailureGetMetadata) self.__edPluginSaxsGetMetadata.executeSynchronous() if not self.isFailure(): self.__edPluginSaxsAngle.connectSUCCESS(self.doSuccessSaxsAngle) self.__edPluginSaxsAngle.connectFAILURE(self.doFailureSaxsAngle) self.__edPluginSaxsAngle.executeSynchronous() if not self.isFailure(): self.write3ColumnAscii(self.integratedImage, self.integratedCurve) self.lstProcessLog.append( "Conversion to ascii: '%s' --> '%s'" % (self.integratedImage, self.integratedCurve)) self.xsdResult.setIntegratedCurve(self.dataInput.integratedCurve)
def process(self, _edObject=None): EDPluginControl.process(self) self.DEBUG("EDPluginBioSaxsToSASv1_0.process") self.__edPluginExecWait = self.loadPlugin(self.__strControlledPluginWait) self.__edPluginExecWait.dataInput = XSDataInputWaitFile(expectedSize=XSDataInteger(self.__class__.size), expectedFile=self.dataInput.subtractedCurve) self.__edPluginExecWait.connectSUCCESS(self.doSuccessExecWait) self.__edPluginExecWait.connectFAILURE(self.doFailureExecWait) self.__edPluginExecWait.executeSynchronous() if self.isFailure(): return Rg = None title = open(self.strInFile).readline() if title.startswith("#"): title = title[1:] if self.dataInput.firstPoint is not None: firstPoint = self.dataInput.firstPoint.value else: firstPoint = 0 for line in open(self.strInFile): if line.startswith("# AutoRg: Points"): try: firstPoint = int(line[16:].split()[0]) except Exception, error: self.WARNING("Unable to read first data point from line: %s %s" % (error, line)) firstPoint = 0 else: break elif line.startswith("# AutoRg: Quality:"): quality = float(line[18:].split("%")[0]) if quality < 1: self.warning("The quality of this dataset is very low (%.1f%%): garbage in garbage out !") elif line.startswith("# AutoRg: Rg ="): Rg = float(line[16:].split()[0])
def process(self, _edObject=None): EDPluginControl.process(self) EDVerbose.DEBUG("EDPluginBioSaxsAsciiExportv1_0.process") xsdiWaitFile = XSDataInputWaitFile() xsdiWaitFile.setExpectedFile(XSDataFile(self.dataInput.integratedImage.path)) xsdiWaitFile.setExpectedSize(XSDataInteger(8196)) # size of the header self.__edPluginWaitFile.setDataInput(xsdiWaitFile) self.__edPluginWaitFile.connectSUCCESS(self.doSuccessWaitFile) self.__edPluginWaitFile.connectFAILURE(self.doFailureWaitFile) self.__edPluginWaitFile.executeSynchronous() if not self.isFailure(): self.__edPluginSaxsGetMetadata.connectSUCCESS(self.doSucessGetMetadata) self.__edPluginSaxsGetMetadata.connectFAILURE(self.doFailureGetMetadata) self.__edPluginSaxsGetMetadata.executeSynchronous() if not self.isFailure(): self.__edPluginSaxsCurves.connectSUCCESS(self.doSuccessSaxsCurves) self.__edPluginSaxsCurves.connectFAILURE(self.doFailureSaxsCurves) self.__edPluginSaxsCurves.executeSynchronous()
def preProcess(self, _edObject=None): """ """ EDPluginControl.preProcess(self) self.DEBUG("EDPluginControlReadImageHeaderv10.preProcess") # First determine the type of image xsDataInputReadImageHeader = self.getDataInput() xsDataFileImage = xsDataInputReadImageHeader.getImage() self.strFileImagePath = xsDataFileImage.getPath().getValue() # Plugin for waiting for files self.edPluginExecWaitFile = self.loadPlugin(self.strPluginExecWaitFile) xsDataInputWaitFile = XSDataInputWaitFile() xsDataInputWaitFile.setExpectedFile( XSDataFile(XSDataString(self.strFileImagePath))) xsDataInputWaitFile.setExpectedSize(XSDataInteger(100000)) xsDataInputWaitFile.setTimeOut(XSDataTime(self.fWaitFileTimeOut)) self.edPluginExecWaitFile.setDataInput(xsDataInputWaitFile)
def preProcess(self, _edObject=None): """ """ EDPluginControl.preProcess(self) self.DEBUG("EDPluginControlReadImageHeaderv10.preProcess") # First determine the type of image xsDataInputReadImageHeader = self.getDataInput() xsDataFileImage = xsDataInputReadImageHeader.getImage() self.strFileImagePath = xsDataFileImage.getPath().getValue() # Plugin for waiting for files self.edPluginExecWaitFile = self.loadPlugin(self.strPluginExecWaitFile) xsDataInputWaitFile = XSDataInputWaitFile() xsDataInputWaitFile.setExpectedFile(XSDataFile(XSDataString(self.strFileImagePath))) xsDataInputWaitFile.setExpectedSize(XSDataInteger(100000)) xsDataInputWaitFile.setTimeOut(XSDataTime(self.fWaitFileTimeOut)) self.edPluginExecWaitFile.setDataInput(xsDataInputWaitFile)
def process(self, _edObject=None): EDPluginControl.process(self) self.DEBUG("EDPluginBioSaxsProcessOneFilev1_3.process") xsd = XSDataInputWaitFile(expectedFile=XSDataFile(XSDataString(self.rawImage)), expectedSize=self.rawImageSize, timeOut=XSDataTime(30)) self.__edPluginWaitFile.setDataInput(xsd) self.__edPluginWaitFile.connectSUCCESS(self.doSuccessWaitFile) self.__edPluginWaitFile.connectFAILURE(self.doFailureWaitFile) self.__edPluginWaitFile.executeSynchronous() if self.isFailure(): return q, I, std = self.integrate() I = self.normalize(I) std = self.normalize(std) self.write3ColumnAscii(q, I, std, self.integratedCurve)
def process(self, _edObject=None): EDPluginControl.process(self) EDVerbose.DEBUG("EDPluginControlDiffractionCTv1_2.process") #=============================================================================== # Wait File #=============================================================================== edPluginWaitFile = self.loadPlugin(self.strControlledPluginWait) xsdin = XSDataInputWaitFile() xsdin.setExpectedFile(self.xsDataFileInputImage) xsdin.setExpectedSize(XSDataInteger(self.iImageSize)) edPluginWaitFile.setDataInput(xsdin) edPluginWaitFile.connectSUCCESS(self.doSuccessWaitFile) edPluginWaitFile.connectFAILURE(self.doFailureWaitFile) edPluginWaitFile.executeSynchronous() #=============================================================================== # #ReadHeader #=============================================================================== edPluginReadHeader = self.loadPlugin(self.strControlledPluginReadHeader) # Set the input data for the read header plugin xsDataInputReadHeader = XSDataInputReadHeader() xsDataInputReadHeader.setInputFile(self.xsDataFileInputImage) edPluginReadHeader.setDataInput(xsDataInputReadHeader) edPluginReadHeader.connectSUCCESS(self.doSuccessReadHeader) edPluginReadHeader.connectFAILURE(self.doFailureReadHeader) edPluginReadHeader.executeSynchronous() ################################################################################ # Powder Integration ################################################################################ self.edPluginPowderIntegration.connectSUCCESS(self.doSuccessPowderIntegration) self.edPluginPowderIntegration.connectFAILURE(self.doFailurePowderIntegration) self.edPluginPowderIntegration.executeSynchronous() self.edPluginHDF5MapSpectra.connectSUCCESS(self.doSuccessWriteSinogram) self.edPluginHDF5MapSpectra.connectFAILURE(self.doFailureWriteSinogram) self.edPluginHDF5MapSpectra.execute() self.edPluginExportAsciiPowder.connectSUCCESS(self.doSuccessExportAsciiPowder) self.edPluginExportAsciiPowder.connectFAILURE(self.doFailureExportAsciiPowder) self.edPluginExportAsciiPowder.execute()
def process(self, _edObject=None): EDPluginControl.process(self) self.DEBUG("EDPluginBioSaxsProcessOneFilev1_6.process") xsd = XSDataInputWaitFile(expectedFile=XSDataFile(XSDataString(self.rawImage)), expectedSize=self.rawImageSize, timeOut=XSDataTime(30)) self.__edPluginWaitFile.setDataInput(xsd) self.__edPluginWaitFile.connectSUCCESS(self.doSuccessWaitFile) self.__edPluginWaitFile.connectFAILURE(self.doFailureWaitFile) self.__edPluginWaitFile.executeSynchronous() if self.isFailure(): return self.xsDataResult.sample = self.sample self.xsDataResult.experimentSetup = self.experimentSetup res = self.integrate() self.write3ColumnAscii(res, self.integratedCurve) self.xsDataResult.dataQ = EDUtilsArray.arrayToXSData(res.radial) self.xsDataResult.dataI = EDUtilsArray.arrayToXSData(res.intensity) self.xsDataResult.dataStdErr = EDUtilsArray.arrayToXSData(res.sigma)
def process(self, _edObject=None): EDPluginControl.process(self) EDVerbose.DEBUG("EDPluginBioSaxsAsciiExportv1_1.process") xsdiWaitFile = XSDataInputWaitFile() xsdiWaitFile.setExpectedFile(XSDataFile(self.dataInput.integratedImage.path)) xsdiWaitFile.setExpectedSize(XSDataInteger(8196)) #size of the header self.__edPluginWaitFile.setDataInput(xsdiWaitFile) self.__edPluginWaitFile.connectSUCCESS(self.doSuccessWaitFile) self.__edPluginWaitFile.connectFAILURE(self.doFailureWaitFile) self.__edPluginWaitFile.executeSynchronous() if not self.isFailure(): self.__edPluginSaxsGetMetadata.connectSUCCESS(self.doSucessGetMetadata) self.__edPluginSaxsGetMetadata.connectFAILURE(self.doFailureGetMetadata) self.__edPluginSaxsGetMetadata.executeSynchronous() if not self.isFailure(): self.__edPluginSaxsCurves.connectSUCCESS(self.doSuccessSaxsCurves) self.__edPluginSaxsCurves.connectFAILURE(self.doFailureSaxsCurves) self.__edPluginSaxsCurves.executeSynchronous()
def preProcess(self, _edObject=None): EDPluginControl.preProcess(self) self.DEBUG('EDPluginControlAutoproc.preProcess starting') self.DEBUG('failure state is currently {0}'.format(self.isFailure())) # for info to send to the autoproc stats server self.custom_stats = dict( creation_time=time.time(), processing_type='edna fastproc', datacollect_id=self.dataInput.data_collection_id.value, comments='running on {0}'.format(socket.gethostname())) data_in = self.dataInput xds_in = XSDataMinimalXdsIn() xds_in.input_file = data_in.input_file.path xds_in.spacegroup = data_in.spacegroup xds_in.unit_cell = data_in.unit_cell self.log_file_path = os.path.join(self.root_dir, 'stats.json') self.DEBUG('will log timing information to {0}'.format( self.log_file_path)) self.stats = dict() # Get the image prefix from the directory name # XXX: This is horrible try: self.image_prefix = '_'.join( os.path.basename(self.root_dir).split('_')[1:-1]) except Exception: self.image_prefix = '' self.results_dir = os.path.join(self.root_dir, 'results', 'fast_processing') try: os.makedirs(self.results_dir) except OSError: # it most likely exists pass # Copy the vanilla XDS input file to the results dir infile_dest = os.path.join(self.results_dir, self.image_prefix + '_input_XDS.INP') shutil.copy(self.dataInput.input_file.path.value, infile_dest) # Ensure the autoproc ids directory is there self.autoproc_ids_dir = os.path.join(self.results_dir, 'fastproc_integration_ids') try: os.makedirs(self.autoproc_ids_dir) except OSError: # it's there pass # we'll need the low res limit later on lowres = data_in.low_resolution_limit if lowres is not None: self.low_resolution_limit = lowres.value else: self.low_resolution_limit = 50 res_override = data_in.res_override if res_override is not None: self.res_override = res_override.value else: # XXX: default to 0? self.res_override = None # check the number of images (must be > 8) and get the first # image name to wait for. Also modify the XDS.INP file to # reflect these values, if specified conf = parse_xds_file(data_in.input_file.path.value) # Make the [XY]-GEO_CORR paths absolute if 'X-GEO_CORR=' in conf: xgeo = os.path.abspath( os.path.join(self.root_dir, conf['X-GEO_CORR='][0])) if not os.path.exists(xgeo): self.DEBUG( 'geometry file {0} does not exist, removing'.format(xgeo)) del conf['X-GEO_CORR='] else: conf['X-GEO_CORR='] = xgeo if 'Y-GEO_CORR=' in conf: ygeo = os.path.abspath( os.path.join(self.root_dir, conf['Y-GEO_CORR='][0])) if not os.path.exists(ygeo): self.DEBUG( 'geometry file {0} does not exist, removing'.format(ygeo)) del conf['Y-GEO_CORR='] else: conf['Y-GEO_CORR='] = ygeo dump_xds_file(data_in.input_file.path.value, conf) resrange = conf.get('INCLUDE_RESOLUTION_RANGE=') if resrange is not None: if self.low_resolution_limit is not None: resrange[0] = self.low_resolution_limit if self.res_override is not None: resrange[1] = self.res_override conf['INCLUDE_RESOLUTION_RANGE='] = resrange dump_xds_file(data_in.input_file.path.value, conf) data_range = conf.get('DATA_RANGE=') # we'll need that for the very last part ( file import ) self.data_range = data_range if data_range is not None: start_image = data_range[0] end_image = data_range[1] if end_image - start_image < 8: self.ERROR('there are fewer than 8 images, aborting') self.setFailure() return template = conf['NAME_TEMPLATE_OF_DATA_FRAMES='][0] self.DEBUG('template for images is {0}'.format(template)) # fix the path if it's not absolute if not os.path.isabs(template): self.DEBUG('file template {0} is not absolute'.format(template)) base_dir = os.path.abspath( os.path.dirname(data_in.input_file.path.value)) template = os.path.normpath(os.path.join(self.root_dir, template)) conf['NAME_TEMPLATE_OF_DATA_FRAMES='] = template self.DEBUG('file template fixed to {0}'.format(template)) self.DEBUG('dumping back the file to {0}'.format( data_in.input_file.path.value)) dump_xds_file(data_in.input_file.path.value, conf) first_image = _template_to_image(template, start_image) self.wait_file = self.loadPlugin('EDPluginWaitFile') waitfileinput = XSDataInputWaitFile() waitfileinput.expectedFile = XSDataFile() waitfileinput.expectedFile.path = XSDataString(first_image) waitfileinput.expectedSize = XSDataInteger(0) # we do not care timeout = XSDataTime() global WAIT_FOR_FRAME_TIMEOUT timeout.value = WAIT_FOR_FRAME_TIMEOUT waitfileinput.timeOut = timeout self.wait_file.dataInput = waitfileinput self.xds_first = self.loadPlugin("EDPluginControlRunXdsFastProc") self.xds_first.dataInput = xds_in self.generate = self.loadPlugin("EDPluginXDSGenerate") self.first_res_cutoff = self.loadPlugin("EDPluginResCutoff") self.res_cutoff_anom = self.loadPlugin("EDPluginResCutoff") self.res_cutoff_noanom = self.loadPlugin("EDPluginResCutoff") self.parse_xds_anom = self.loadPlugin("EDPluginParseXdsOutput") self.parse_xds_noanom = self.loadPlugin("EDPluginParseXdsOutput") self.xscale_generate = self.loadPlugin("EDPluginControlXscaleGenerate") self.store_autoproc_anom = self.loadPlugin( 'EDPluginISPyBStoreAutoProcv1_4') self.store_autoproc_noanom = self.loadPlugin( 'EDPluginISPyBStoreAutoProcv1_4') self.file_conversion = self.loadPlugin('EDPluginControlAutoprocImport') self.DEBUG('EDPluginControlAutoproc.preProcess finished')
def preProcess(self, _edObject = None): EDPluginControl.preProcess(self) self.DEBUG('EDPluginControlAutoproc.preProcess starting') self.DEBUG('failure state is currently {0}'.format(self.isFailure())) # for info to send to the autoproc stats server self.custom_stats = dict(creation_time=time.time(), processing_type='edna fastproc', datacollect_id=self.dataInput.data_collection_id.value, comments='running on {0}'.format(socket.gethostname())) data_in = self.dataInput xds_in = XSDataMinimalXdsIn() xds_in.input_file = data_in.input_file.path xds_in.spacegroup = data_in.spacegroup xds_in.unit_cell = data_in.unit_cell self.log_file_path = os.path.join(self.root_dir, 'stats.json') self.DEBUG('will log timing information to {0}'.format(self.log_file_path)) self.stats = dict() # Get the image prefix from the directory name # XXX: This is horrible try: self.image_prefix = '_'.join(os.path.basename(self.root_dir).split('_')[1:-1]) except Exception: self.image_prefix = '' self.results_dir = os.path.join(self.root_dir, 'results', 'fast_processing') try: os.makedirs(self.results_dir) except OSError: # it most likely exists pass # Copy the vanilla XDS input file to the results dir infile_dest = os.path.join(self.results_dir, self.image_prefix + '_input_XDS.INP') shutil.copy(self.dataInput.input_file.path.value, infile_dest) # Ensure the autoproc ids directory is there self.autoproc_ids_dir = os.path.join(self.results_dir, 'fastproc_integration_ids') try: os.makedirs(self.autoproc_ids_dir) except OSError: # it's there pass # we'll need the low res limit later on lowres = data_in.low_resolution_limit if lowres is not None: self.low_resolution_limit = lowres.value else: self.low_resolution_limit = 50 res_override = data_in.res_override if res_override is not None: self.res_override = res_override.value else: # XXX: default to 0? self.res_override = None # check the number of images (must be > 8) and get the first # image name to wait for. Also modify the XDS.INP file to # reflect these values, if specified conf = parse_xds_file(data_in.input_file.path.value) # Make the [XY]-GEO_CORR paths absolute if 'X-GEO_CORR=' in conf: xgeo = os.path.abspath(os.path.join(self.root_dir, conf['X-GEO_CORR='][0])) if not os.path.exists(xgeo): self.DEBUG('geometry file {0} does not exist, removing'.format(xgeo)) del conf['X-GEO_CORR='] else: conf['X-GEO_CORR='] = xgeo if 'Y-GEO_CORR=' in conf: ygeo = os.path.abspath(os.path.join(self.root_dir, conf['Y-GEO_CORR='][0])) if not os.path.exists(ygeo): self.DEBUG('geometry file {0} does not exist, removing'.format(ygeo)) del conf['Y-GEO_CORR='] else: conf['Y-GEO_CORR='] = ygeo dump_xds_file(data_in.input_file.path.value, conf) resrange = conf.get('INCLUDE_RESOLUTION_RANGE=') if resrange is not None: if self.low_resolution_limit is not None: resrange[0] = self.low_resolution_limit if self.res_override is not None: resrange[1] = self.res_override conf['INCLUDE_RESOLUTION_RANGE='] = resrange dump_xds_file(data_in.input_file.path.value, conf) data_range = conf.get('DATA_RANGE=') # we'll need that for the very last part ( file import ) self.data_range = data_range if data_range is not None: start_image = data_range[0] end_image = data_range[1] if end_image - start_image < 8: self.ERROR('there are fewer than 8 images, aborting') self.setFailure() return template = conf['NAME_TEMPLATE_OF_DATA_FRAMES='][0] self.DEBUG('template for images is {0}'.format(template)) # fix the path if it's not absolute if not os.path.isabs(template): self.DEBUG('file template {0} is not absolute'.format(template)) base_dir = os.path.abspath(os.path.dirname(data_in.input_file.path.value)) template = os.path.normpath(os.path.join(self.root_dir, template)) conf['NAME_TEMPLATE_OF_DATA_FRAMES=']=template self.DEBUG('file template fixed to {0}'.format(template)) self.DEBUG('dumping back the file to {0}'.format(data_in.input_file.path.value)) dump_xds_file(data_in.input_file.path.value, conf) first_image = _template_to_image(template, start_image) self.wait_file = self.loadPlugin('EDPluginWaitFile') waitfileinput = XSDataInputWaitFile() waitfileinput.expectedFile = XSDataFile() waitfileinput.expectedFile.path = XSDataString(first_image) waitfileinput.expectedSize = XSDataInteger(0) # we do not care timeout = XSDataTime() global WAIT_FOR_FRAME_TIMEOUT timeout.value = WAIT_FOR_FRAME_TIMEOUT waitfileinput.timeOut = timeout self.wait_file.dataInput = waitfileinput self.xds_first = self.loadPlugin("EDPluginControlRunXdsFastProc") self.xds_first.dataInput = xds_in self.generate = self.loadPlugin("EDPluginXDSGenerate") self.first_res_cutoff = self.loadPlugin("EDPluginResCutoff") self.res_cutoff_anom = self.loadPlugin("EDPluginResCutoff") self.res_cutoff_noanom = self.loadPlugin("EDPluginResCutoff") self.parse_xds_anom = self.loadPlugin("EDPluginParseXdsOutput") self.parse_xds_noanom = self.loadPlugin("EDPluginParseXdsOutput") self.xscale_generate = self.loadPlugin("EDPluginControlXscaleGenerate") self.store_autoproc_anom = self.loadPlugin('EDPluginISPyBStoreAutoProcv1_4') self.store_autoproc_noanom = self.loadPlugin('EDPluginISPyBStoreAutoProcv1_4') self.file_conversion = self.loadPlugin('EDPluginControlAutoprocImport') self.DEBUG('EDPluginControlAutoproc.preProcess finished')
def preProcess(self, _edObject=None): EDPluginControl.preProcess(self) EDVerbose.DEBUG("EDPluginControlPyarchThumbnailGeneratorv1_0.preProcess") # Check that the input image exists and is of the expected type strPathToDiffractionImage = self.getDataInput().getDiffractionImage().getPath().getValue() strImageFileNameExtension = os.path.splitext(strPathToDiffractionImage)[1] if not strImageFileNameExtension in [".img", ".marccd", ".mccd", ".cbf"]: print strImageFileNameExtension EDVerbose.error("Unknown image file name extension for pyarch thumbnail generator: %s" % strPathToDiffractionImage) self.setFailure() else: # Load the waitFile plugin xsDataInputWaitFile = XSDataInputWaitFile() xsDataInputWaitFile.setExpectedSize(XSDataInteger(self.__iExpectedSize)) xsDataInputWaitFile.setExpectedFile(self.getDataInput().getDiffractionImage()) if self.getDataInput().getWaitForFileTimeOut(): xsDataInputWaitFile.setTimeOut(self.getDataInput().getWaitForFileTimeOut()) self.__edPluginWaitFile = EDPluginWaitFile() self.__edPluginWaitFile.setDataInput(xsDataInputWaitFile) # Load the execution plugin self.__edPluginExecThumbnail = self.loadPlugin(self.__strExecThumbnailPluginName) xsDataInputExecThumbnail = XSDataInputExecThumbnail() xsDataInputExecThumbnail.setInputImagePath(self.getDataInput().getDiffractionImage()) xsDataInputExecThumbnail.setLevelsInvert(XSDataBoolean(True)) xsDataInputExecThumbnail.setLevelsMin(XSDataDoubleWithUnit(0.0)) xsDataDoubleWithUnitLevelsMax = XSDataDoubleWithUnit(99.95) xsDataDoubleWithUnitLevelsMax.setUnit(XSDataString("%")) xsDataInputExecThumbnail.setLevelsMax(xsDataDoubleWithUnitLevelsMax) xsDataInputExecThumbnail.setFilterDilatation([XSDataInteger(4)]) xsDataInputExecThumbnail.setLevelsColorize(XSDataBoolean(False)) xsDataInputExecThumbnail.setThumbHeight(XSDataInteger(1024)) xsDataInputExecThumbnail.setThumbWidth(XSDataInteger(1024)) xsDataInputExecThumbnail.setKeepRatio(XSDataBoolean(False)) # Output path strImageNameWithoutExt = os.path.basename(os.path.splitext(strPathToDiffractionImage)[0]) strImageDirname = os.path.dirname(strPathToDiffractionImage) if self.getDataInput().getForcedOutputDirectory(): strForcedOutputDirectory = self.getDataInput().getForcedOutputDirectory().getPath().getValue() if not os.access(strForcedOutputDirectory, os.W_OK): EDVerbose.error("Cannot write to forced output directory : %s" % strForcedOutputDirectory) self.setFailure() else: self.strOutputPathWithoutExtension = os.path.join(strForcedOutputDirectory, strImageNameWithoutExt) else: # Try to store in the ESRF pyarch directory strOutputDirname = EDHandlerESRFPyarchv1_0.createPyarchFilePath(strImageDirname) # Check that output pyarch path exists and is writeable: bIsOk = False if strOutputDirname: if not os.path.exists(strOutputDirname): # Try to create the directory try: os.makedirs(strOutputDirname) bIsOk = True except BaseException, e: EDVerbose.WARNING("Couldn't create the directory %s" % strOutputDirname) elif os.access(strOutputDirname, os.W_OK): bIsOk = True if not bIsOk: EDVerbose.warning("Cannot write to pyarch directory: %s" % strOutputDirname) strOutputDirname = tempfile.mkdtemp("", "EDPluginPyarchThumbnailv10_", "/tmp") EDVerbose.warning("Writing thumbnail images to: %s" % strOutputDirname) self.strOutputPathWithoutExtension = os.path.join(strOutputDirname, strImageNameWithoutExt) self.strOutputPath = os.path.join(self.strOutputPathWithoutExtension + ".jpeg") xsDataInputExecThumbnail.setOutputPath(XSDataFile(XSDataString(self.strOutputPath))) self.__edPluginExecThumbnail.setDataInput(xsDataInputExecThumbnail)
def process(self, _edPlugin=None): """ Executes the execution plugins """ EDPluginControl.process(self, _edPlugin) EDVerbose.DEBUG("EDPluginControlImageQualityIndicatorsv1_2.process") EDUtilsParallel.initializeNbThread() # Check if we should do indexing: bDoIndexing = False if self.dataInput.doIndexing is not None: if self.dataInput.doIndexing.value: bDoIndexing = True # Loop through all the incoming reference images listXSDataImage = self.dataInput.image xsDataInputWaitFile = XSDataInputWaitFile() self.xsDataResultControlImageQualityIndicators = XSDataResultControlImageQualityIndicators( ) listPlugin = [] for xsDataImage in listXSDataImage: if not os.path.exists(xsDataImage.path.value): self.screen("Waiting for image %s" % xsDataImage.path.value) self.edPluginWaitFile = self.loadPlugin( self.strPluginWaitFileName) xsDataInputWaitFile.expectedFile = XSDataFile(xsDataImage.path) xsDataInputWaitFile.setExpectedSize(XSDataInteger(100000)) xsDataInputWaitFile.setTimeOut( XSDataTime(self.fWaitFileTimeOut)) self.DEBUG("Wait file timeOut set to %f" % self.fWaitFileTimeOut) self.edPluginWaitFile.setDataInput(xsDataInputWaitFile) self.edPluginWaitFile.executeSynchronous() if not os.path.exists(xsDataImage.path.value): strError = "Time-out while waiting for image %s" % xsDataImage.path.value self.error(strError) self.addErrorMessage(strError) self.setFailure() else: if self.bUseThinClient: strPluginName = self.strPluginNameThinClient else: strPluginName = self.strPluginName edPluginPluginExecImageQualityIndicator = self.loadPlugin( strPluginName) listPlugin.append(edPluginPluginExecImageQualityIndicator) self.listPluginExecImageQualityIndicator.append( edPluginPluginExecImageQualityIndicator) xsDataInputDistlSignalStrength = XSDataInputDistlSignalStrength( ) xsDataInputDistlSignalStrength.setReferenceImage(xsDataImage) edPluginPluginExecImageQualityIndicator.setDataInput( xsDataInputDistlSignalStrength) edPluginPluginExecImageQualityIndicator.execute() listIndexing = [] # Synchronize all image quality indicator plugins and upload to ISPyB xsDataInputStoreListOfImageQualityIndicators = XSDataInputStoreListOfImageQualityIndicators( ) for edPluginPluginExecImageQualityIndicator in listPlugin: edPluginPluginExecImageQualityIndicator.synchronize() xsDataImageQualityIndicators = XSDataImageQualityIndicators.parseString( \ edPluginPluginExecImageQualityIndicator.dataOutput.imageQualityIndicators.marshal()) self.xsDataResultControlImageQualityIndicators.addImageQualityIndicators( xsDataImageQualityIndicators) xsDataISPyBImageQualityIndicators = \ XSDataISPyBImageQualityIndicators.parseString(xsDataImageQualityIndicators.marshal()) xsDataInputStoreListOfImageQualityIndicators.addImageQualityIndicators( xsDataISPyBImageQualityIndicators) # print xsDataInputStoreListOfImageQualityIndicators.marshal() self.edPluginISPyB = self.loadPlugin(self.strISPyBPluginName) self.edPluginISPyB.dataInput = xsDataInputStoreListOfImageQualityIndicators self.edPluginISPyB.execute() # if bDoIndexing: # Find the 5 most intensive images (TIS): listImage = [] listSorted = sorted( self.xsDataResultControlImageQualityIndicators. imageQualityIndicators, key=lambda imageQualityIndicators: imageQualityIndicators. totalIntegratedSignal.value) for xsDataResultControlImageQualityIndicator in listSorted[-5:]: if xsDataResultControlImageQualityIndicator.goodBraggCandidates.value > 30: xsDataInputReadImageHeader = XSDataInputReadImageHeader() xsDataInputReadImageHeader.image = XSDataFile( xsDataResultControlImageQualityIndicator.image.path) self.edPluginReadImageHeader = self.loadPlugin( self.strPluginReadImageHeaderName) self.edPluginReadImageHeader.dataInput = xsDataInputReadImageHeader self.edPluginReadImageHeader.executeSynchronous() xsDataResultReadImageHeader = self.edPluginReadImageHeader.dataOutput if xsDataResultReadImageHeader is not None: xsDataSubWedge = xsDataResultReadImageHeader.subWedge self.xsDataCollection = XSDataCollection() self.xsDataCollection.addSubWedge(xsDataSubWedge) xsDataIndexingInput = XSDataIndexingInput() xsDataIndexingInput.setDataCollection( self.xsDataCollection) xsDataMOSFLMIndexingInput = EDHandlerXSDataMOSFLMv10.generateXSDataMOSFLMInputIndexing( xsDataIndexingInput) edPluginMOSFLMIndexing = self.loadPlugin( self.strIndexingMOSFLMPluginName) self.listPluginMOSFLM.append([ edPluginMOSFLMIndexing, xsDataResultControlImageQualityIndicator ]) edPluginMOSFLMIndexing.setDataInput( xsDataMOSFLMIndexingInput) edPluginMOSFLMIndexing.execute() for tupleMOSFLM in self.listPluginMOSFLM: edPluginMOSFLMIndexing = tupleMOSFLM[0] xsDataResultControlImageQualityIndicator = tupleMOSFLM[1] edPluginMOSFLMIndexing.synchronize() if not edPluginMOSFLMIndexing.isFailure(): xsDataMOSFLMOutput = edPluginMOSFLMIndexing.dataOutput xsDataIndexingResult = EDHandlerXSDataMOSFLMv10.generateXSDataIndexingResult( xsDataMOSFLMOutput) selectedSolution = xsDataIndexingResult.selectedSolution if selectedSolution is not None: xsDataResultControlImageQualityIndicator.selectedIndexingSolution = selectedSolution
def process(self, _edPlugin=None): """ Executes the execution plugins """ EDPluginControl.process(self, _edPlugin) EDVerbose.DEBUG("EDPluginControlImageQualityIndicatorsv1_3.process") EDUtilsParallel.initializeNbThread() # Check if we should do indexing: bDoIndexing = False if self.dataInput.doIndexing is not None: if self.dataInput.doIndexing.value: bDoIndexing = True # Loop through all the incoming reference images listXSDataImage = self.dataInput.image xsDataInputWaitFile = XSDataInputWaitFile() self.xsDataResultControlImageQualityIndicators = XSDataResultControlImageQualityIndicators() listPlugin = [] for xsDataImage in listXSDataImage: if not os.path.exists(xsDataImage.path.value): self.screen("Waiting for image %s" % xsDataImage.path.value) self.edPluginWaitFile = self.loadPlugin(self.strPluginWaitFileName) xsDataInputWaitFile.expectedFile = XSDataFile(xsDataImage.path) xsDataInputWaitFile.setExpectedSize(XSDataInteger(100000)) xsDataInputWaitFile.setTimeOut(XSDataTime(self.fWaitFileTimeOut)) self.DEBUG("Wait file timeOut set to %f" % self.fWaitFileTimeOut) self.edPluginWaitFile.setDataInput(xsDataInputWaitFile) self.edPluginWaitFile.executeSynchronous() if not os.path.exists(xsDataImage.path.value): strError = "Time-out while waiting for image %s" % xsDataImage.path.value self.error(strError) self.addErrorMessage(strError) self.setFailure() else: if self.bUseThinClient: strPluginName = self.strPluginNameThinClient else: strPluginName = self.strPluginName edPluginPluginExecImageQualityIndicator = self.loadPlugin(strPluginName) self.listPluginExecImageQualityIndicator.append(edPluginPluginExecImageQualityIndicator) xsDataInputDistlSignalStrength = XSDataInputDistlSignalStrength() xsDataInputDistlSignalStrength.setReferenceImage(xsDataImage) edPluginPluginExecImageQualityIndicator.setDataInput(xsDataInputDistlSignalStrength) edPluginPluginExecImageQualityIndicator.execute() edPluginControlBackground3D = self.loadPlugin(self.strPluginNameControlBackground3D) listPlugin.append([edPluginPluginExecImageQualityIndicator, edPluginControlBackground3D]) xsDataInputControlBackground3D = XSDataInputControlBackground3D() xsDataInputControlBackground3D.addImage(XSDataFile(xsDataImage.path)) edPluginControlBackground3D.dataInput = xsDataInputControlBackground3D edPluginControlBackground3D.execute() listIndexing = [] # Synchronize all image quality indicator plugins and upload to ISPyB xsDataInputStoreListOfImageQualityIndicators = XSDataInputStoreListOfImageQualityIndicators() for pluginPair in listPlugin: edPluginPluginExecImageQualityIndicator = pluginPair[0] edPluginControlBackground3D = pluginPair[1] edPluginPluginExecImageQualityIndicator.synchronize() edPluginControlBackground3D.synchronize() xsDataImageQualityIndicators = XSDataImageQualityIndicators.parseString(\ edPluginPluginExecImageQualityIndicator.dataOutput.imageQualityIndicators.marshal()) if edPluginControlBackground3D.dataOutput.imageBackground != []: xsDataImageQualityIndicators.background3D_estimate = edPluginControlBackground3D.dataOutput.imageBackground[0].estimate self.xsDataResultControlImageQualityIndicators.addImageQualityIndicators(xsDataImageQualityIndicators) xsDataISPyBImageQualityIndicators = \ XSDataISPyBImageQualityIndicators.parseString(xsDataImageQualityIndicators.marshal()) xsDataInputStoreListOfImageQualityIndicators.addImageQualityIndicators(xsDataISPyBImageQualityIndicators) # print xsDataInputStoreListOfImageQualityIndicators.marshal() if self.dataInput.doUploadToIspyb is not None and self.dataInput.doUploadToIspyb.value: self.edPluginISPyB = self.loadPlugin(self.strISPyBPluginName) self.edPluginISPyB.dataInput = xsDataInputStoreListOfImageQualityIndicators self.edPluginISPyB.execute() # if bDoIndexing: # Find the 5 most intensive images (TIS): listImage = [] # Check that we have background3D_estimate from all images: has_background3D_estimate = True for imageQualityIndicators in self.xsDataResultControlImageQualityIndicators.imageQualityIndicators: if imageQualityIndicators.background3D_estimate is None: has_background3D_estimate = False if has_background3D_estimate: listSorted = sorted(self.xsDataResultControlImageQualityIndicators.imageQualityIndicators, key=lambda imageQualityIndicators: imageQualityIndicators.background3D_estimate.value) else: listSorted = sorted(self.xsDataResultControlImageQualityIndicators.imageQualityIndicators, key=lambda imageQualityIndicators: imageQualityIndicators.totalIntegratedSignal.value) for xsDataResultControlImageQualityIndicator in listSorted[-5:]: if xsDataResultControlImageQualityIndicator.goodBraggCandidates.value > 30: xsDataInputReadImageHeader = XSDataInputReadImageHeader() xsDataInputReadImageHeader.image = XSDataFile(xsDataResultControlImageQualityIndicator.image.path) self.edPluginReadImageHeader = self.loadPlugin(self.strPluginReadImageHeaderName) self.edPluginReadImageHeader.dataInput = xsDataInputReadImageHeader self.edPluginReadImageHeader.executeSynchronous() xsDataResultReadImageHeader = self.edPluginReadImageHeader.dataOutput if xsDataResultReadImageHeader is not None: xsDataSubWedge = xsDataResultReadImageHeader.subWedge self.xsDataCollection = XSDataCollection() self.xsDataCollection.addSubWedge(xsDataSubWedge) xsDataIndexingInput = XSDataIndexingInput() xsDataIndexingInput.setDataCollection(self.xsDataCollection) xsDataMOSFLMIndexingInput = EDHandlerXSDataMOSFLMv10.generateXSDataMOSFLMInputIndexing(xsDataIndexingInput) edPluginMOSFLMIndexing = self.loadPlugin(self.strIndexingMOSFLMPluginName) self.listPluginMOSFLM.append([edPluginMOSFLMIndexing, xsDataResultControlImageQualityIndicator]) edPluginMOSFLMIndexing.setDataInput(xsDataMOSFLMIndexingInput) edPluginMOSFLMIndexing.execute() for tupleMOSFLM in self.listPluginMOSFLM: edPluginMOSFLMIndexing = tupleMOSFLM[0] xsDataResultControlImageQualityIndicator = tupleMOSFLM[1] edPluginMOSFLMIndexing.synchronize() if not edPluginMOSFLMIndexing.isFailure(): xsDataMOSFLMOutput = edPluginMOSFLMIndexing.dataOutput xsDataIndexingResult = EDHandlerXSDataMOSFLMv10.generateXSDataIndexingResult(xsDataMOSFLMOutput) selectedSolution = xsDataIndexingResult.selectedSolution if selectedSolution is not None: xsDataResultControlImageQualityIndicator.selectedIndexingSolution = selectedSolution
def process(self, _edObject=None): EDPluginControl.process(self) self.DEBUG("EDPluginBioSaxsToSASv1_1.process") self.pluginWait = self.loadPlugin(self.cpWait) self.pluginWait.dataInput = XSDataInputWaitFile( expectedSize=XSDataInteger(self.__class__.size), expectedFile=self.inputFile) self.pluginWait.connectSUCCESS(self.doSuccessExecWait) self.pluginWait.connectFAILURE(self.doFailureExecWait) self.pluginWait.executeSynchronous() if self.isFailure(): return if self.gnomFile and os.path.exists(self.gnomFile): self.pluginModeling = self.loadPlugin(self.cpModeling) self.pluginModeling.dataInput = XSDataInputSaxsModeling( graphFormat=XSDataString("png"), gnomFile=XSDataFile(XSDataString(self.gnomFile))) elif self.strInFile and os.path.exists(self.strInFile): self.pluginModeling = self.loadPlugin(self.cpAnalysisModeling) self.pluginModeling.dataInput = XSDataInputSaxsAnalysisModeling( graphFormat=XSDataString("png"), scatterCurve=XSDataFile(XSDataString(self.strInFile))) else: self.error( "Neither gnomFile not subtractedCurve are present in the input datastructure" ) self.setFailure() return self.pluginModeling.connectSUCCESS(self.doSuccessExecSAS) self.pluginModeling.connectFAILURE(self.doFailureExecSAS) self.pluginModeling.executeSynchronous() ######################################################################## # Send to ISPyB ######################################################################## if self.dataInput.sample and self.dataInput.sample.login and \ self.dataInput.sample.passwd and self.dataInput.sample.measurementID and \ self.xsdIspybInput: self.addExecutiveSummaryLine("Registering to ISPyB") self.pluginISPyB = self.loadPlugin(self.cpISPyB) self.xsdIspybInput.sample = self.dataInput.sample self.pluginISPyB.dataInput = self.xsdIspybInput self.pluginISPyB.connectSUCCESS(self.doSuccessExecISPyB) self.pluginISPyB.connectFAILURE(self.doFailureExecISPyB) self.pluginISPyB.executeSynchronous() ######################################################################## # Move results ######################################################################## if self.dataInput.destinationDirectory is None: if self.strInFile is not None: outdir = os.path.join( os.path.dirname(os.path.dirname(self.strInFile)), "ednaSAS") else: #nothing specified outdir = os.path.join(os.path.dirname(os.getcwd()), "ednaSAS") else: outdir = self.dataInput.destinationDirectory.path.value if self.strInFile is not None: outdir = os.path.join( outdir, os.path.basename(os.path.splitext(self.strInFile)[0])) if not os.path.isdir(outdir): os.makedirs(outdir) self.outFile = os.path.join(outdir, "NoResults.html") self.pluginRsync = self.loadPlugin(self.cpRsync) self.pluginRsync.dataInput = XSDataInputRsync( source=XSDataFile(XSDataString(self.wd)), destination=XSDataFile(XSDataString(outdir)), options=XSDataString("-avx")) self.pluginRsync.connectSUCCESS(self.doSuccessExecRsync) self.pluginRsync.connectFAILURE(self.doFailureExecRsync) self.pluginRsync.executeSynchronous() # if no errors up to now, clean up scratch disk if not self.isFailure(): to_remove = self.pluginModeling.getWorkingDirectory() if os.path.isdir(to_remove): shutil.rmtree(to_remove)