Exemplo n.º 1
0
 def uploadReferenceFrame(self, entry):
     paths = entry.split(":")
     if len(paths) == 1 and os.path.isfile(paths[0]):
         obj = fabio.open(paths[0]).data
         EDVerbose.WARNING("Got reference frame %s via fabio" % entry)
         EDPluginControlAlignStackv1_0.addFrame(-1, obj)
         EDPluginAccumulatorv1_0.addItem(XSDataString("raw -001"))
         self.updateAttrRefImage(obj)
     elif len(paths) == 2 and os.path.isfile(paths[0]):
         hdf = h5py.File(paths[0])
         if paths[1] in hdf:
             obj = hdf[paths[1]]
             if obj.__class__.__name__ == "Group":
                 if self.REFERENCE_FRAME_NAME in obj:
                     data = obj[self.REFERENCE_FRAME_NAME][:]
                     EDPluginControlAlignStackv1_0.addFrame(-1, data)
                     EDPluginAccumulatorv1_0.addItem("raw -001")
                     self.updateAttrRefImage(data)
                 else:
                     EDVerbose.ERROR("HDF5: No '%s' in group %s from %s" % (self.REFERENCE_FRAME_NAME, paths[1], paths[0]))
             elif obj.__class__.__name__ == "Dataset":
                 data = obj[:]
                 EDPluginControlAlignStackv1_0.addFrame(-1, data)
                 EDPluginAccumulatorv1_0.addItem(XSDataString("raw -001"))
                 self.updateAttrRefImage(data)
         else:
             EDVerbose.ERROR("HDF5: No such internal path %s in %s" % (paths[1], paths[0]))
     else:
         EDVerbose.ERROR("No such entry %s" % entry)
Exemplo n.º 2
0
    def checkParameters(self):
        """
        Checks the mandatory parameters.
        """
        self.DEBUG("EDPluginControlAutoproc.checkParameters")
        self.checkMandatoryParameters(self.dataInput.previous_run_dir,
                                      "previous run directory not specified")
        self.checkMandatoryParameters(self.dataInput.resolution,
                                      "resolution not specified")
        # Now really check what we need
        path = os.path.abspath(self.dataInput.previous_run_dir.value)
        if not os.path.isdir(path):
            EDVerbose.ERROR('path given is not a directory')
            self.setFailure()
            return

        # we do not generate a REMOVE.HKL file for now
        to_link = ['INTEGRATE.HKL', #'REMOVE.HKL',
                   'X-CORRECTIONS.cbf', 'Y-CORRECTIONS.cbf']

        # we require it but the run xds plugin copies it to its WD so
        # no need to link it
        required = to_link + ['XDS.INP']

        # we'll use it in preprocess
        self._required = [os.path.join(path, f) for f in required]
        self._to_link =  [os.path.join(path, f) for f in to_link]

        for f in self._required:
            if not os.path.isfile(f):
                EDVerbose.ERROR('missing required file {0}'.format(f))
                self.setFailure()
                return
Exemplo n.º 3
0
    def checkParameters(self):
        """
        Checks the mandatory parameters.
        """
        self.DEBUG("EDPluginXscale.checkParameters")
        # do the data binding work...
        self.checkMandatoryParameters(self.dataInput.merge,
                                      'merge param not given')
        self.checkMandatoryParameters(self.dataInput.friedels_law,
                                      'friedel\'s law not given')
        self.checkMandatoryParameters(self.dataInput.xds_files,
                                      'no xds files input')
        self.checkMandatoryParameters(self.dataInput.unit_cell_constants,
                                      'unit cell constants not defined')
        self.checkMandatoryParameters(self.dataInput.sg_number,
                                      'space group not given')
        # bins explicitely not mandatory as we may want to run xscale
        # over the whole data if the detector is complete

        # now really check that stuff
        # the unit cell constants param should be 6 floats
        if len(self.dataInput.unit_cell_constants) != 6:
            EDVerbose.ERROR('the unit cell constants list should have 6 elements')
            EDVerbose.ERROR('i got {}'.format(len(self.dataInput.unit_cell_constants)))
            self.setFailure()
        # check existence of the input files
        for f in self.dataInput.xds_files:
            path = f.path.value
            if not os.path.isfile(path):
                EDVerbose.ERROR('missing input file {}'.format(path))
                self.setFailure()
                break
Exemplo n.º 4
0
    def checkParameters(self):
        """
        Checks the mandatory parameters.
        """
        input_file = self.dataInput.input_file
        if input_file is None:
            EDVerbose.ERROR('no xds input file given, giving up')
            self.setFailure()
            return

        input_file = input_file.value
        if not os.path.exists(input_file):
            EDVerbose.ERROR('the specified input file does not seem to exist,'
                            ' giving up')
            self.setFailure()
            return

        # we need to "fix" the input file so the SPOT_RANGE gets set
        # to a sensible value
        cfg = parse_xds_file(input_file)
        spot_range = _spot_range(cfg)
        if len(spot_range) != 0:
            cfg['SPOT_RANGE='] = spot_range

        #SECONDS is also set to 20
        cfg['SECONDS='] = 20
        dump_xds_file(input_file, cfg)
Exemplo n.º 5
0
 def copyHTMLDir(_strPathToHTMLDir, _strPathToPyarchDirectory):
     if not os.path.exists(_strPathToPyarchDirectory):
         try:
             os.mkdir(_strPathToPyarchDirectory)
         except:
             EDVerbose.WARNING(
                 "EDHandlerESRFPyarchv1_0.copyHTMLFilesAndDir: cannot create pyarch html directory %s"
                 % _strPathToPyarchDirectory)
             return
     elif not os.path.exists(_strPathToHTMLDir):
         EDVerbose.ERROR(
             "EDHandlerESRFPyarchv1_0.copyHTMLFilesAndDir: path to html directory does not exist: %s"
             % _strPathToHTMLDir)
     else:
         try:
             strPathToPyArchHtmlDirectory = os.path.join(
                 _strPathToPyarchDirectory, "index")
             if os.path.exists(strPathToPyArchHtmlDirectory):
                 shutil.rmtree(strPathToPyArchHtmlDirectory,
                               ignore_errors=True)
             shutil.copytree(_strPathToHTMLDir,
                             strPathToPyArchHtmlDirectory)
         except Exception, e:
             EDVerbose.ERROR(
                 "EDHandlerESRFPyarchv1_0.copyHTMLFilesAndDir: Exception caught: %r"
                 % e)
    def process(self, _edObject=None):
        EDPluginControl.process(self)
        self.DEBUG("EDPluginControlXscaleGeneratev1_0.process")

        # start all plugins
        for p in self.getListOfLoadedPlugin():
            p.execute()

        # wait for all the 4 XScale plugins to finish
        self.synchronizePlugins()

        # this is actually quite wrong but i discovered I had to parse
        # output from xscale too late so for now I'm going to do it
        # here
        self.xscale_anom_merged_parser = self.loadPlugin(
            "EDPluginParseXscaleOutputv1_0")
        parserinput = XSDataXscaleParsingInput()
        parserinput.lp_file = XSDataString(
            self.xscale_anom_merged.dataOutput.lp_file.value)
        self.xscale_anom_merged_parser.dataInput = parserinput

        self.xscale_anom_unmerged_parser = self.loadPlugin(
            "EDPluginParseXscaleOutputv1_0")
        parserinput = XSDataXscaleParsingInput()
        parserinput.lp_file = XSDataString(
            self.xscale_anom_unmerged.dataOutput.lp_file.value)
        self.xscale_anom_unmerged_parser.dataInput = parserinput

        self.xscale_noanom_merged_parser = self.loadPlugin(
            "EDPluginParseXscaleOutputv1_0")
        parserinput = XSDataXscaleParsingInput()
        parserinput.lp_file = XSDataString(
            self.xscale_noanom_merged.dataOutput.lp_file.value)
        self.xscale_noanom_merged_parser.dataInput = parserinput

        self.xscale_noanom_unmerged_parser = self.loadPlugin(
            "EDPluginParseXscaleOutputv1_0")
        parserinput = XSDataXscaleParsingInput()
        parserinput.lp_file = XSDataString(
            self.xscale_noanom_unmerged.dataOutput.lp_file.value)
        self.xscale_noanom_unmerged_parser.dataInput = parserinput

        # as if the previous horror was not enough, the parsing will
        # be done sequentially
        parsers = [
            self.xscale_anom_merged_parser, self.xscale_anom_unmerged_parser,
            self.xscale_noanom_merged_parser,
            self.xscale_noanom_unmerged_parser
        ]

        for p in parsers:
            p.executeSynchronous()
            if p.isFailure():
                # include the file it failed to parse to the msg
                EDVerbose.ERROR('parser {0} failed to parse file'.format(p))
                EDVerbose.ERROR('the input was {0}'.format(
                    p.dataInput.marshal()))
Exemplo n.º 7
0
    def preProcess(self, _edObject=None):
        EDPluginControl.preProcess(self)
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_2.preProcess")
        # Load the plugins
        self.__edPluginControlIndexingIndicators = self.loadPlugin(self.__strPluginControlIndexingIndicators, \
                                                                   "Indexing")
        self.__edPluginControlIndexingLabelit = self.loadPlugin(self.__strPluginControlIndexingLabelit, \
                                                                   "IndexingLabelit")
        self.__edPluginExecEvaluationIndexingMOSFLM = self.loadPlugin(self.__strPluginExecEvaluationIndexing, \
                                                                   "IndexingEvalualtionMOSFLM")
        self.__edPluginExecEvaluationIndexingLABELIT = self.loadPlugin(self.__strPluginExecEvaluationIndexing, \
                                                                   "IndexingEvalualtionLABELIT")
        self.__edPluginControlGeneratePrediction = self.loadPlugin(self.__strPluginControlGeneratePrediction, \
                                                                   "GeneratePrediction")
        self.__edPluginControlIntegration = self.loadPlugin(self.__strPluginControlIntegration, \
                                                            "Integration")
        self.__edPluginControlStrategy = self.loadPlugin(self.__strPluginControlStrategy, \
                                                         "Strategy")
        if (self.__edPluginControlIndexingIndicators is not None):
            EDVerbose.DEBUG("EDPluginControlCharacterisationv1_2.preProcess: " + self.__strPluginControlIndexingIndicators + " Found... setting Data Input")
            # create Data Input for indexing
            xsDataInputCharacterisation = self.getDataInput()
            self.__xsDataCollection = xsDataInputCharacterisation.getDataCollection()
            xsDataCrystal = None
            xsDataSubWedgeList = self.__xsDataCollection.getSubWedge()
            if ((xsDataSubWedgeList is None) or (xsDataSubWedgeList == [])):
                strError = "EDPluginControlCharacterisationv1_2.preProcess: No subwedges in input data."
                EDVerbose.ERROR(strError)
                self.setFailure()
            else:
                xsDataExperimentalCondition = xsDataSubWedgeList[0].getExperimentalCondition()

                # Fix for bug 431: if the flux is zero raise an error
                xsDataDoubleFlux = xsDataExperimentalCondition.getBeam().getFlux()
                if (xsDataDoubleFlux is not None):
                    if (xsDataDoubleFlux.getValue() < 0.1):
                        strErrorMessage = "Input flux is negative or close to zero. Execution of characterisation aborted."
                        EDVerbose.ERROR(strErrorMessage)
                        self.addErrorMessage("EDPluginControlCharacterisationv1_2.preProcess ERROR: " + strErrorMessage)
                        #self.addComment(strErrorMessage)
                        self.setFailure()

                xsDataDiffractionPlan = self.__xsDataCollection.getDiffractionPlan()
                xsDataStringForcedSpaceGroup = xsDataDiffractionPlan.getForcedSpaceGroup()
                if (xsDataStringForcedSpaceGroup is not None):
                    self.__xsDataCrystal = XSDataCrystal()
                    xsDataSpaceGroup = XSDataSpaceGroup()
                    xsDataSpaceGroup.setName(xsDataStringForcedSpaceGroup)
                    self.__xsDataCrystal.setSpaceGroup(xsDataSpaceGroup)

                self.__edPluginControlIndexingIndicators.setDataInput(self.__xsDataCollection, "dataCollection")
                if self.__xsDataCrystal is not None:
                    self.__edPluginControlIndexingIndicators.setDataInput(self.__xsDataCrystal, "crystal")

                # Populate characterisation object
                self.__xsDataResultCharacterisation = XSDataResultCharacterisation()
                self.__xsDataResultCharacterisation.setDataCollection(XSDataCollection.parseString(self.__xsDataCollection.marshal()))
Exemplo n.º 8
0
    def process(self, _edObject=None):
        EDPluginControl.process(self)
        self.DEBUG("EDPluginControlAutoproc.process")

        EDVerbose.DEBUG('first run w/ anom')

        self.xds_anom.executeSynchronous()
        if self.xds_anom.isFailure():
            EDVerbose.ERROR('xds failed when generating w/ anom')
            self.setFailure()
            return

        #Now backup the file
        mydir = os.path.abspath(self.getWorkingDirectory())
        xds_run_directory = self.xds_anom.getWorkingDirectory()
        xds_output = os.path.join(xds_run_directory, 'XDS_ASCII.HKL')
        output_anom = os.path.join(mydir, 'XDS_ANOM.HKL')
        copyfile(xds_output, output_anom)

        # since the original get_xds_stats uses the CORRECT.LP file we
        # need to backup it as well
        correct_lp = os.path.join(xds_run_directory, 'CORRECT.LP')
        correct_lp_anom = os.path.join(mydir, 'CORRECT_ANOM.LP')
        copyfile(correct_lp, correct_lp_anom)

        # now the second run, generate w/out anom
        EDVerbose.DEBUG('second run w/out anom')

        self.xds_noanom.executeSynchronous()

        if self.xds_noanom.isFailure():
            EDVerbose.ERROR('xds failed when generating w/out anom')
            self.setFailure()
            return

        #Now backup the file
        xds_run_directory = self.xds_anom.getWorkingDirectory()
        xds_output = os.path.join(xds_run_directory, 'XDS_ASCII.HKL')
        output_noanom = os.path.join(mydir, 'XDS_NOANOM.HKL')
        copyfile(xds_output, output_noanom)

        # since the original get_xds_stats uses the CORRECT.LP file we
        # need to backup it as well
        correct_lp = os.path.join(xds_run_directory, 'CORRECT.LP')
        correct_lp_noanom = os.path.join(mydir, 'CORRECT_NOANOM.LP')
        copyfile(correct_lp, correct_lp_noanom)

        # everything went fine
        data_output = XSDataXdsGenerateOutput()
        data_output.hkl_anom = XSDataString(output_anom)
        data_output.hkl_no_anom = XSDataString(output_noanom)
        data_output.correct_lp_no_anom = XSDataString(correct_lp_noanom)
        data_output.correct_lp_anom = XSDataString(correct_lp_anom)
        self.dataOutput = data_output
 def checkRMaxSearchParameters(self):
     if self.getDataInput().getRMaxSearchSettings() is not None:
         if self.getDataInput().getRMaxSearchSettings().getRMaxStart() is None:
             EDVerbose.ERROR("EDPluginControlSolutionScatteringv0_2.setRMaxSerachParameters rMaxStart is missing")
             self.setFailure()
         if self.getDataInput().getRMaxSearchSettings().getRMaxStop() is None:
             EDVerbose.ERROR("EDPluginControlSolutionScatteringv0_2.setRMaxSerachParameters rMaxStop is missing")
             self.setFailure()
         if self.getDataInput().getRMaxSearchSettings().getRMaxAbsTol() is None:
             EDVerbose.ERROR("EDPluginControlSolutionScatteringv0_2.setRMaxSerachParameters rMaxAbsTol is missing")
             self.setFailure()
         if self.getDataInput().getRMaxSearchSettings().getRMaxIntervals() is None:
             EDVerbose.ERROR("EDPluginControlSolutionScatteringv0_2.setRMaxSerachParameters rMaxIntervals is missing")
             self.setFailure()
Exemplo n.º 10
0
    def showMessage(_iLevel, _strMessage, _strFilename=None):
        """
        Class Method:
        Similar to logging module of python but for updating BioSaxsCube

        @param _iLevel: print level seems to be
                        4 for Errors
                        3 for Warnings
                        2 for Info
                        1
                        0
        @type _iLevel: int
        @param _strMessage: comment to be printed
        @type _strMessage: string
        @param _strFilename: the file related to the message (nothing to do with a logfile)
        @type _strFilename: string or None
        """

        if _iLevel == 4:
            EDVerbose.ERROR(_strMessage)
        elif _iLevel == 3:
            EDVerbose.WARNING(_strMessage)
        else:
            EDVerbose.screen(_strMessage)
#        else:
#            EDVerbose.DEBUG(_strMessage)

        if EDUtilsBioSaxs.specStatus is not None:
            currentStatus = EDUtilsBioSaxs.specStatus.value["reprocess"][
                "status"]  # must do this, since SpecClient is apparently returning a non-expected data structure
            i = currentStatus.rfind(",")
            # TB: This ,1 or ,0 suffix nonsense seems to be a hack to force Spec to signal a variable change to bsxcube
            if i == -1 or currentStatus[i + 1:] == "1":
                if _strFilename is None:
                    newStatus = "%s,%s,0" % (_iLevel, _strMessage)
                else:
                    newStatus = "%s,%s,%s,0" % (_iLevel, _strMessage,
                                                _strFilename)
            else:
                if _strFilename is None:
                    newStatus = "%s,%s,1" % (_iLevel, _strMessage)
                else:
                    newStatus = "%s,%s,%s,1" % (_iLevel, _strMessage,
                                                _strFilename)
            EDUtilsBioSaxs.specStatus.setValue(newStatus)

        if (EDUtilsBioSaxs.specAbort is not None) and (
                EDUtilsBioSaxs.specAbort.value["reprocess"]["abort"]) == "1":
            # must do this, since SpecClient is apparently returning a non-expected data structure
            EDVerbose.ERROR("Aborting data reprocess!")
Exemplo n.º 11
0
    def checkParameters(self):
        """
        Checks the mandatory parameters.
        """
        self.DEBUG("EDPluginExecMinimalXds.checkParameters")
        self.checkMandatoryParameters(self.dataInput, "Data Input is None")
        self.checkMandatoryParameters(self.dataInput.input_file,
                                      "No XDS input file given")

        # really look into the mandatory arg
        xds_input = os.path.abspath(self.dataInput.input_file.value)
        if not (os.path.exists(xds_input) and os.path.isfile(xds_input)):
            self.setFailure()

        # if we have a resolution it has to be a list of 2 XSDataFloat
        resrange = self.dataInput.resolution_range
        if resrange is not None and len(resrange) != 0:
            # a non specified list input parameter has a default value
            # of [], seriously???
            if len(resrange) != 2:
                EDVerbose.ERROR(
                    "resolution range must be 2 in length ({} given)".format(
                        resrange))
                self.setFailure()
                return
Exemplo n.º 12
0
 def getArray(cls, _inputObject):
     """
     Tries to retrieve a numpy array from an Image or from a shared array or an XSD object
     
     As this method returns a numpy array, this method works only on plateform where numpy is available.
     
     @param _inputObject: XSDataArray or XSDataImageExt or XSDataFile
     @return: numpy ndarray
     """
     npaOutput = None
     bError = False
     lstAttrObj = dir(_inputObject)
     if "array" in lstAttrObj and _inputObject.array is not None:
         npaOutput = cls.xsDataToArray(_inputObject.array)
     elif "shared" in lstAttrObj and _inputObject.shared is not None:
         npaOutput = EDShare[_inputObject.shared.value]
     elif "path" in lstAttrObj and (_inputObject.path
                                    is not None) and os.path.isfile(
                                        _inputObject.path.value):
         if bHaveFabio is True:
             try:
                 npaOutput = fabio.open(_inputObject.path.value).data
             except Exception:
                 bError = True
         else:
             bError = True
     elif "XSDataArray" in str(type(_inputObject)):
         npaOutput = cls.xsDataToArray(_inputObject)
     if bError is True:
         EDVerbose.ERROR(
             "EDUtilsArray.getArray works better on platform with numpy & fabio ... No solution found for you, sorry.%s%s "
             % (os.linesep, _inputObject.marshal()))
     return npaOutput
Exemplo n.º 13
0
 def doFailureIndexingLabelit(self, _edPlugin=None):
     EDVerbose.DEBUG("EDPluginControlCharacterisationv1_2.doFailureIndexingLabelit")
     self.addStatusMessage("Labelit: Indexing FAILURE.")
     if self.__xsDataResultCharacterisation is not None:
         self.setDataOutput(self.__xsDataResultCharacterisation)
     if self.__xsDataIndexingResultMOSFLM == None:
         strErrorMessage = "Execution of indexing with both MOSFLM and Labelit failed. Execution of characterisation aborted."
         EDVerbose.ERROR(strErrorMessage)
         self.addErrorMessage(strErrorMessage)
         self.generateExecutiveSummary(self)
         self.setFailure()
         if self.__strStatusMessage != None:
             self.setDataOutput(XSDataString(self.__strStatusMessage), "statusMessage")
             self.writeDataOutput()
     else:
         # Use the MOSFLM indexing results - even if it's P1
         self.__xsDataResultCharacterisation.setIndexingResult(self.__xsDataIndexingResultMOSFLM)
         xsDataCollection = self.__xsDataResultCharacterisation.getDataCollection()
         xsDataGeneratePredictionInput = XSDataGeneratePredictionInput()
         xsDataGeneratePredictionInput.setDataCollection(XSDataCollection.parseString(xsDataCollection.marshal()))
         xsDataGeneratePredictionInput.setSelectedIndexingSolution(XSDataIndexingSolutionSelected.parseString(self.__xsDataIndexingResultMOSFLM.getSelectedSolution().marshal()))
         self.__edPluginControlGeneratePrediction.setDataInput(xsDataGeneratePredictionInput)
         if self.__edPluginControlIndexingIndicators.hasDataOutput("indexingShortSummary"):
             self.__strCharacterisationShortSummary += self.__edPluginControlIndexingIndicators.getDataOutput("indexingShortSummary")[0].getValue()
         # Start the generation of prediction images - we synchronize in the post-process
         self.__edPluginControlGeneratePrediction.execute()
         # Then start the integration of the reference images
         self.indexingToIntegration()
Exemplo n.º 14
0
 def readHeaderPilatus6M(self, _strImageFileName):
     """
     Returns an dictionary with the contents of a Pilatus 6M CBF image header.
     """
     dictPilatus6M = None
     pyFile = None
     try:
         pyFile = open(_strImageFileName, "r")
     except:
         EDVerbose.ERROR("EDPluginExecReadImageHeaderPilatus6Mv10.readHeaderPilauts6M: couldn't open file: " + _strImageFileName)
         self.setFailure()
     if (pyFile != None):
         EDVerbose.DEBUG("EDPluginExecReadImageHeaderPilatus6Mv10.readHeaderPilauts6M: Reading header from image " + _strImageFileName)
         pyFile.seek(0, 0)
         bContinue = True
         iMax = 60
         iIndex = 0
         while bContinue:
             strLine = pyFile.readline()
             iIndex += 1
             if (strLine.find("_array_data.header_contents") != -1):
                 dictPilatus6M = {}
             if (strLine.find("_array_data.data") != -1) or iIndex > iMax:
                 bContinue = False
             if (dictPilatus6M != None) and (strLine[0] == "#"):
                 # Check for date
                 strTmp = strLine[2:].replace("\r\n", "")
                 if strLine[6] == "/" and strLine[10] == "/":
                     dictPilatus6M["DateTime"] = strTmp
                 else:
                     strKey = strTmp.split(" ")[0]
                     strValue = strTmp.replace(strKey, "")[1:]
                     dictPilatus6M[strKey] = strValue
         pyFile.close()
     return dictPilatus6M
Exemplo n.º 15
0
 def setSessionId(cls, idSession):
     """setter for session ID. Only valid if not yet set !!!!"""
     if cls._sessionId is None:
         cls._sessionId = idSession
     else:
         EDVerbose.ERROR(
             "You are not allowed to change the session ID !!!!")
Exemplo n.º 16
0
    def checkParameters(self):
        """
        Checks the mandatory parameters.
        """
        self.DEBUG("EDPluginControlAutoproc.checkParameters")
        self.checkMandatoryParameters(self.dataInput, "Data Input is None")
        self.checkMandatoryParameters(self.dataInput.input_file,
                                      "No XDS input file")

        # save the root path (where the initial xds.inp is) for later use
        self.root_dir = os.path.abspath(
            os.path.dirname(self.dataInput.input_file.path.value))

        # at least check for the xds input file existence before
        # trying to start anything even if the first xds run does it
        # anyway
        if not os.path.isfile(self.dataInput.input_file.path.value):
            EDVerbose.ERROR('the specified input file does not exist')
            self.setFailure()
            # setFailure does not prevent preProcess/process/etc from running
            raise Exception('EDNA FAILURE')
        else:
            # copy it to our dir and modify our input
            newpath = os.path.join(
                self.getWorkingDirectory(),
                os.path.basename(self.dataInput.input_file.path.value))
            shutil.copyfile(self.dataInput.input_file.path.value, newpath)
            self.dataInput.input_file.path = XSDataString(newpath)
Exemplo n.º 17
0
    def readFile(_strFileName):
        """
        Reads and returns the content of a file.
        @param _strFileName: Path to the file
        @return: String containing the contents of the file.
        """
        strContent = None
        try:
            # ## Guifre Cuni, 130507 ?!?!?! Possible bug here...
            # ## After some executions there may be an error because too much opened files...
            # ## It can be monitored with command watch "lsof -p $EDNA_TANGODS_PID"

            # ##strContent = open(_strFileName, "rb").read()
            if sys.version.startswith('3'):
                with open(_strFileName, "r", encoding="ISO-8859-1") as fd:
                    strContent = fd.read()
            else:
                with open(_strFileName, "rb") as fd:
                    strContent = fd.read()

        except Exception as e:
            strError = "EDUtilsFile.readFile: Reading %s: %s" % (_strFileName, str(e))
            EDVerbose.ERROR(strError)
            raise IOError(strError)
        return strContent
Exemplo n.º 18
0
 def preProcess(self):
     """
     Initialize the plugin to be launched
     """
     EDTestCasePlugin.preProcess(self)
     if(EDUtilsPath.EDNA_SITE == None):
         raise RuntimeError, "EDNA_SITE must be set"
     # Load the plugin that should be executed
     self._edPlugin = EDFactoryPluginStatic.loadPlugin(self.getPluginName())
     if(self._edPlugin is not None):
         for strInputDataKey in self._dictStrDataInputFiles.keys():
             if (type(self._dictStrDataInputFiles[ strInputDataKey ]) == types.ListType):
                 for strDataInputFile in self._dictStrDataInputFiles[ strInputDataKey ]:
                     strXMLData = self.readAndParseFile(strDataInputFile)
                     if (strInputDataKey == self._strDefaultInputDataKey):
                         self._edPlugin.setDataInput(strXMLData)
                     else:
                         self._edPlugin.setDataInput(strXMLData, strInputDataKey)
             else:
                 strXMLData = self.readAndParseFile(self._dictStrDataInputFiles[ strInputDataKey ])
                 if (strInputDataKey == self._strDefaultInputDataKey):
                     self._edPlugin.setDataInput(strXMLData)
                 else:
                     self._edPlugin.setDataInput(strXMLData, strInputDataKey)
         #self._edPlugin.setDataInput( self._strXMLData, "inputMXCuBE" )
     else:
         EDVerbose.ERROR("Cannot load plugin: %s" % self.getPluginName())
         raise RuntimeError
     self._edPlugin.setConfiguration(self.getPluginConfiguration())
Exemplo n.º 19
0
    def toXSD(
        _classXSData,
        _strObject,
    ):
        """Convert a string or possibly any object to an XSD object
        
        @param _classXSData: the XSDataClass to be forced into
        @type _classXSData: class derived from XSData
        @param _strObject: the string representation of a physical object like "1.54 A" 
        @type _strObject: string (floats are accepted)
        """
        xsd = _classXSData()
        if isinstance(_strObject, (unicode, str)):
            listWords = _strObject.split(None, 1)
            if len(listWords) > 0:
                try:
                    fValue = float(listWords[0])
                except Exception:
                    EDVerbose.ERROR(
                        "Trying to create XSData object from %s; fValue not a float !"
                        % _strObject)

                else:
                    xsd.setValue(fValue)
                    if len(listWords) == 2:
                        xsd.setUnit(XSDataString(listWords[1]))
            else:
                EDVerbose.WARNING("Trying to create XSData object from %s " %
                                  _strObject)
        elif isinstance(_strObject, (float, int)):
            xsd.setValue(_strObject)
        return xsd
Exemplo n.º 20
0
 def checkParticleShapeInput(self):
     particleShape = ['P', 'O', 'U']
     try:
         if self.getDataInput().getExpectedParticleShape().getValue(
         ) in range(3):
             self.__strParticleShape = particleShape[
                 self.getDataInput().getExpectedParticleShape().getValue()]
     except Exception:
         EDVerbose.ERROR("Using Unknown particle shape")
Exemplo n.º 21
0
def XMLerr(strXMLin):
    """
    This is an example of XMLerr function ... it prints only the name of the file created
    @param srXMLin: The XML string used to launch the job
    @type strXMLin: python string with the input XML
    @rtype: None
    @return: None     
    """
    EDVerbose.ERROR("Error in the processing of : %s%s" % (os.linesep, strXMLin))
Exemplo n.º 22
0
    def getDataChunk(cls, filename, h5path, indexes=None):
        """
        Write down to the disk the HDF5 file and close it.
        
        @param filename: path of the file to be created
        @type filename: string
        @param h5path: path to the dataset of the internal NeXus structure to be read and returned
        @type  h5path: string
        @param indexes: limit indexes of the data chunk to retrieve from the file, the size of the list should be the same as the dimension of the data block 
        @type indexes: string representing the list of lists of integer like "[ [1,5], [3,4], [7,9] ]"  
        @return: the piece of data wanted  
        @rtype: numpy array
        """
        npArray = None
        if filename in cls.__dictHDF5:
            h5file = cls.__dictHDF5[filename]
            try:
                dataset = h5file[h5path]
            except Exception:
                EDVerbose.ERROR(
                    "HDF5 getDataChunk: %s, no such data structure in file %s"
                    % (h5path, filename))
                raise
            if indexes is not None:
                try:
                    npArray = eval("dataset.value%s " % indexes)
                except NameError:
                    EDVerbose.ERROR(
                        "HDF5 getDataChunk: Malformed indexes for file %s, h5path %s, indexes %s. The dataset has this shape: "
                        % (filename, h5path, indexes))
                    raise
                except ValueError:
                    EDVerbose.ERROR(
                        "HDF5 getDataChunk: Out of range indexes for file %s, h5path %s, indexes %s. The dataset has this shape: "
                        % (filename, h5path, indexes))
                    raise
            else:  #return the whole dataset
                npArray = dataset.value

        else:
            EDVerbose.ERROR(
                "HDF5 getDataChunk: %s, no such file under control" % filename)
            raise
        return npArray
Exemplo n.º 23
0
def getFortranCompiler():
    import numpy.distutils.fcompiler
    compilerEXE = numpy.distutils.fcompiler.find_executable("g77")
    if compilerEXE is None:
        compilerEXE = numpy.distutils.fcompiler.find_executable("gfortran")
    if compilerEXE is None:
        compilerEXE = numpy.distutils.fcompiler.find_executable("g95")
    if compilerEXE is None:
        EDVerbose.ERROR("No Fortran compiler found among g77, gfortran, g95")
    return compilerEXE
Exemplo n.º 24
0
    def process(self, _edObject=None):
        EDPlugin.process(self)

        output = XSDataXscaleParsedOutput()

        # get all the file's contents, find where the info is and then
        # use helper functions to retrieve stuff and put it in the
        # data model
        try:
            f = open(self.dataInput.lp_file.value, 'r')
            lines = f.readlines()
        except IOError:
            EDVerbose.ERROR(
                'Could not open the specified XDS output file for reading')
            self.setFailure()
            return

        # look for the stats table
        info_begin = None
        info_end = None
        started = False
        for line_no, line in enumerate(lines):
            if line.find(
                    'LIMIT     OBSERVED  UNIQUE  POSSIBLE     OF DATA   observed  expected'
            ) != -1:
                # there's an empty line after the header
                info_begin = line_no + 2
            if info_begin is not None and line.find('total') != -1:
                # we're at the last table line
                info_end = line_no
                # stop here as there are some other lines containing
                # "total" later
                break
        if info_begin is None or info_end is None:
            EDVerbose.ERROR('could not find the completeness table')
            self.setFailure()
            return

        _extract_completeness_entries(lines[info_begin:info_end + 1], output)

        input_file = self.dataInput.lp_file.value
        output.xds_run_directory = XSDataString(os.path.dirname(input_file))
        self.dataOutput = output
Exemplo n.º 25
0
    def synchronize(self):
        """
        Wait for the thread to finish. Since the time out is used by
        e.g. EDPluginExecProcessScript we add an extra second in order
        to allow the subclasses to handle the time out - without this
        extra second it's the EDAction class who time-outs first.
        
        Note that this does not in any case add time to the execution,
        because the extra second is only used for time-outs. The method
        returns immediately once the thread has finished.
        """
        EDVerbose.DEBUG("EDAction.synchronize() for %s" % self.getName())
        #        fTimeOut = self.__fTimeOutInSeconds
        if self.__fTimeOutInSeconds is None:
            self.__fTimeOutInSeconds = self.__fDefaultTimeOutInSeconds

        #Wait for the thread to be started up to timeout
        if self.isStarted() == False:
            tStartWait = time.time()
            while self.isStarted() == False:
                time.sleep(1)
                if time.time() - tStartWait > self.__fTimeOutInSeconds:
                    self.__bIsTimeOut = True
                    strErrorMessage = "Timeout when waiting for %s to start!" % self.getClassName(
                    )
                    EDVerbose.DEBUG("EDAction.synchronize: " + strErrorMessage)
                    EDVerbose.ERROR(strErrorMessage)
                    self.setFailure()
                    return
        # We add an extra second in order to allow execution plugin to finish
        # which have the same timeout
        self.join(float(self.__fTimeOutInSeconds + 1))
        for fExtraTime in self.__lExtraTime:
            self.join(float(fExtraTime))
        if self.isAlive():
            # Timeout!
            self.__bIsTimeOut = True
            EDVerbose.DEBUG("EDAction.synchronize: Timeout!")
            strErrorMessage = "Timeout when waiting for %s to terminate." % self.getClassName(
            )
            EDVerbose.ERROR(strErrorMessage)
            self.setFailure()
Exemplo n.º 26
0
 def checkAbsTable(self):
     _pluginConfiguration = self.getConfiguration()
     _strAbsTable = EDConfiguration.getStringParamValue(
         _pluginConfiguration, 'absTable')
     if os.path.isfile(_strAbsTable):
         shutil.copy(_strAbsTable, self.getWorkingDirectory())
     else:
         EDVerbose.ERROR(
             "EDPluginExecAbsCalcv0_1.checkAbsTable Couldn't find abstable file"
         )
         self.setFailure()
Exemplo n.º 27
0
 def doFailureIndexingIndicators(self, _edPlugin=None):
     EDVerbose.DEBUG("EDPluginControlCharacterisationv1_2.doFailureIndexingIndicators")
     strErrorMessage = "Execution of Indexing and Indicators plugin failed. Execution of characterisation aborted."
     EDVerbose.ERROR(strErrorMessage)
     self.addErrorMessage(strErrorMessage)
     if self.__xsDataResultCharacterisation is not None:
         self.setDataOutput(self.__xsDataResultCharacterisation)
     self.setFailure()
     if self.__strStatusMessage != None:
         self.setDataOutput(XSDataString(self.__strStatusMessage), "statusMessage")
         self.writeDataOutput()
Exemplo n.º 28
0
 def error(self, strXMLin):
     """
     This is an example of XMLerr function ... it prints only the name of the file created
     @param srXMLin: The XML string used to launch the job
     @type strXMLin: python string with the input XML
     @rtype: None
     @return: None     
     """
     xsd = XSDataInputDiffractionCT.parseString(strXMLin)
     filename = xsd.getImage().getPath().getValue
     EDVerbose.ERROR("Error in the processing of: %s" % filename)
Exemplo n.º 29
0
 def getHDF5File(cls, filename):
     """
     Retieve a HDF5 file object from the cache
     
     @param filename: path of the file to be created
     @type filename: string
     """
     if filename in cls.__dictHDF5:
         return cls.__dictHDF5[filename]
     else:
         EDVerbose.ERROR("EDPluginHDF5.getHDF5File: No such file: %s" %
                         filename)
Exemplo n.º 30
0
 def failurePluginExecution(self, _edObject=None):
     """
     Method called when the execution of the plugin failed 
     """
     self.synchronizeOn()
     self.__status = EDJob.PLUGIN_STATE_FAILURE
     EDVerbose.screen("Plugin %s execution ended with failure" %
                      self.__jobId)
     self.synchronizeOff()
     try:
         self.__edSlotFAILURE.call(self.__jobId)
     except Exception:
         EDVerbose.ERROR("Error in execution of Failure call-back for %s" %
                         self.__jobId)
         EDVerbose.writeErrorTrace()
     try:
         self.__edSlotCallBack.call(self.__jobId)
     except Exception:
         EDVerbose.ERROR(
             "Error in execution of Common call-back (after failure) for %s"
             % self.__jobId)
         EDVerbose.writeErrorTrace()