Exemplo n.º 1
0
    def parse(self):
        """
        parse options from command line
        """
        parser = optparse.OptionParser()
        parser.add_option("-V", "--version", dest="version", action="store_true",
                          help="print version of the program and quit", metavar="FILE", default=False)
        parser.add_option("-v", "--verbose",
                          action="store_true", dest="debug", default=False,
                          help="switch to debug/verbose mode")
        parser.add_option("-m", "--mask", dest="mask",
                      help="file containing the mask (for image reconstruction)", default=None)
        parser.add_option("-M", "--mode", dest="mode",
                      help="Mode can be online/offline/all", default="offline")
        parser.add_option("-o", "--out", dest="output",
                      help="file for log", default=None)
        parser.add_option("-w", "--wavelength", dest="wavelength", type="float",
                      help="wavelength of the X-Ray beam in Angstrom", default=None)
        parser.add_option("-e", "--energy", dest="energy", type="float",
                      help="energy of the X-Ray beam in keV (hc=%skeV.A)" % self.hc, default=None)
        parser.add_option("-t", "--template", dest="template", type="str",
                      help="template XML file", default=None)
        parser.add_option("-n", "--nbcpu", dest="nbcpu", type="int",
                      help="template XML file", default=self.nbcpu)


        (options, args) = parser.parse_args()

        # Analyse aruments and options
        if options.version:
            print("BioSaxs Azimuthal integration version %s" % __version__)
            sys.exit(0)
        if options.debug:
            EDVerbose.setVerboseDebugOn()
            self.debug = True
        if options.output:
            EDVerbose.setLogFileName(options.output)
        if options.mask and os.path.isfile(options.mask):
            self.maskfile = options.mask
        if options.template and os.path.isfile(options.template):
            self.xml = open(options.template).read()
        if options.wavelength:
            self.wavelength = 1e-10 * options.wavelength
        elif options.energy:
            self.wavelength = 1e-10 * self.hc / options.energy
        if options.mode=="offline":
            self.mode = "offline"
            self.newerOnly = False
        elif options.mode=="online":
            self.mode = "dirwarch"
            self.newerOnly = True
        elif options.mode=="dirwatch":
            self.mode = "dirwarch"
            self.newerOnly = False
        self.cpu_sem = Semaphore(options.nbcpu)
        self.nbcpu = options.nbcpu
        self.dataFiles = [f for f in args if os.path.isfile(f)]
        if not self.dataFiles:
            raise RuntimeError("Please provide datafiles or read the --help")
Exemplo n.º 2
0
def runMXv1Pipeline():
    strLogFileName = os.path.join(returnWorkingDirectory(), "wsgi-server.log")
    EDVerbose.setLogFileName(strLogFileName)
    strInput = str(request['wsgi.input'].read(int(request['CONTENT_LENGTH'])))
    if strInput:
        # Take the parameters string, split off the title and run the bash script to generate the input char. XML  
        listParams = shlex.split(strInput)
        strComments = listParams[0]          # the 1st item
        strShortComments = listParams[1]     # the 2nd item
        strWorkingDir = listParams[2]        # the 3rd item
        strHTMLResultDir = listParams[3]     # the 4th item 
        
        os.chdir(strWorkingDir)
        
        strParamString = " ".join(listParams[4:])     # all but the first four items 
        edPluginMxv1ParamsToXML = EDFactoryPluginStatic.loadPlugin('EDPluginMxv1ParamsToXMLv1_0')
        edPluginMxv1ParamsToXML.setDataInput(XSDataString(strParamString), "paramString")
        edPluginMxv1ParamsToXML.executeSynchronous()
        xsDataFile = edPluginMxv1ParamsToXML.getDataOutput()

        # Read the XML and parse it into an object hierarchy        
        strXMLFile = xsDataFile.getPath().getValue()
        f = open(strXMLFile, 'r')
        xml = f.read()
        f.close()
        xsDataInputCharacterisation = XSDataInputCharacterisation.parseString(xml)

        # Run the MXv1 application pipeline
        edApplicationMXv1Characterisation = EDApplicationMXv1Characterisation(_strPluginName="EDPluginControlInterfacev1_2", \
                               _strConfigurationFileName=strConfigurationFilePath, \
                               _xsDataInputCharacterisation=xsDataInputCharacterisation, \
                               _strComments=strComments, \
                               _strShortComments=strShortComments)
        edApplicationMXv1Characterisation.execute()

        # Run the EDNA2HTML generator on the output from the MXv1 application 
        edPluginExecOutputHTML = EDFactoryPluginStatic.loadPlugin('EDPluginExecOutputHTMLv1_0')
        edPluginExecOutputHTML.setDataInput(XSDataString(strComments), "title")
        strWorkingDir = os.path.join(strWorkingDir, edApplicationMXv1Characterisation.getWorkingDir())
        edPluginExecOutputHTML.setDataInput(XSDataString(strWorkingDir), "workingDir")
        #strBaseDir = os.path.join(strHTMLResultDir, "edna")
        #edPluginExecOutputHTML.setDataInput(XSDataString(strBaseDir), "basename")
        edPluginExecOutputHTML.setDataInput(XSDataString(strHTMLResultDir), "basename")

        edPluginExecOutputHTML.executeSynchronous()
        
        strPathToHTMLFile = ""
        if (edPluginExecOutputHTML.hasDataOutput("htmlFile")):
            strPathToHTMLFile = edPluginExecOutputHTML.getDataOutput("htmlFile")[0].getPath().getValue()
        else:
            EDVerbose.ERROR("edna-mxv1-wsgi-server: edPluginExecOutputHTML has no dataOutput htmlFile!")
            
        if strPathToHTMLFile =="":
            EDVerbose.ERROR("edna-mxv1-wsgi-server: Returning empty string")
        return strPathToHTMLFile
    else:
        return strInput
Exemplo n.º 3
0
 def processCommandline(self):
     """
     This method is intended to be overridden by applications who
     would like to implement their own command line handling.
     
     This default method implements the following workflow:
         - Check for debug, verbose and log file command line options
     
     """
     EDVerbose.DEBUG("EDApplication.execute")
     EDVerbose.log(self.__edCommandLine.getCommandLine())
     self.processCommandLineDebugVerboseLogFile()
     # Determine the base directory
     if (self.__strBaseDir is None):
         self.processCommandLineBaseDirectory()
     # Set the name of the log file
     self.__strPathToLogFile = os.path.abspath(
         os.path.join(self.__strBaseDir, self.__strLogFileName))
     EDVerbose.setLogFileName(self.__strPathToLogFile)
     self.processCommandLineHelp()
     if (not self.__bIsFailure):
         self.processCommandLineVersion()
     if (not self.__bIsFailure):
         # Name of the plugin to be executed
         if (self.__strPluginName is None):
             self.processCommandLinePluginName()
         # Path to the input XML file
         if (self.__strDataInputFilePath is None):
             self.processCommandLineInputFilePath()
         # Path to the output XML file
         if (self.__strDataOutputFilePath is None):
             self.processCommandLineOutputFilePath()
         if (self.__bIsFailure):
             self.usage()
     if (not self.__bIsFailure):
         # If strConfigurationFileName is None, this means that it has not been given to the constructor\
         # It has been given by the command line\
         if (self.__strConfigurationFileName is None):
             self.__strConfigurationFileName = self.getCommandLineArgument(
                 EDApplication.CONFIGURATION_PARAM_LABEL)
Exemplo n.º 4
0
 def processCommandline(self):
     """
     This method is intended to be overridden by applications who
     would like to implement their own command line handling.
     
     This default method implements the following workflow:
         - Check for debug, verbose and log file command line options
     
     """
     EDVerbose.DEBUG("EDApplication.execute")
     EDVerbose.log(self.__edCommandLine.getCommandLine())
     self.processCommandLineDebugVerboseLogFile()
     # Determine the base directory
     if(self.__strBaseDir is None):
         self.processCommandLineBaseDirectory()
     # Set the name of the log file
     self.__strPathToLogFile = os.path.abspath(os.path.join(self.__strBaseDir, self.__strLogFileName))
     EDVerbose.setLogFileName(self.__strPathToLogFile)
     self.processCommandLineHelp()
     if (not self.__bIsFailure):
         self.processCommandLineVersion()
     if (not self.__bIsFailure):
         # Name of the plugin to be executed        
         if (self.__strPluginName is None):
             self.processCommandLinePluginName()
         # Path to the input XML file
         if (self.__strDataInputFilePath is None):
             self.processCommandLineInputFilePath()
         # Path to the output XML file
         if(self.__strDataOutputFilePath is None):
             self.processCommandLineOutputFilePath()
         if (self.__bIsFailure):
             self.usage()
     if (not self.__bIsFailure):
         # If strConfigurationFileName is None, this means that it has not been given to the constructor\
         # It has been given by the command line\
         if(self.__strConfigurationFileName is None):
             self.__strConfigurationFileName = self.getCommandLineArgument(EDApplication.CONFIGURATION_PARAM_LABEL)
Exemplo n.º 5
0
 def preProcess(self):
     """
     Scans the command line.
     """
     EDVerbose.DEBUG("EDTestLauncher.preProcess")
     edCommandLine = EDCommandLine(sys.argv)
     EDVerbose.log(self.getEdCommandLine().getCommandLine())
     self.processCommandLineDebugVerboseLogFile()
     bContinue = True
     strTestName = edCommandLine.getArgument(EDTestLauncher.TEST_LABEL)
     EDVerbose.DEBUG("EDTestLauncher.preProcess: test name = %r" % strTestName)
     if (strTestName is None):
         EDVerbose.screen("ERROR - no --test argument found")
         bContinue = False
     else:
         self.__edTestCase = EDUtilsTest.getFactoryPluginTest().loadPlugin(strTestName)
     if (bContinue):
         # Determine the base directory
         if(self.getBaseDir() is None):
             self.processCommandLineBaseDirectory()
         # Create the application working directory  
         strApplicationInstanceName = strTestName + "_" + time.strftime("%Y%m%d-%H%M%S", time.localtime())
         if(self.getWorkingDir() is None):
             self.setWorkingDir(strApplicationInstanceName)
         self.createApplicationWorkingDirectory()
         # Set the name of the log file
         EDVerbose.setLogFileName(os.path.join(self.getBaseDir(), strApplicationInstanceName + ".log"))
         # The check for --quiet and --DEBUG should ideally be placed elsewhere,
         # for example in EDApplication.
         if (edCommandLine.existCommand(EDTestLauncher.QUIET_LABEL)):
             EDVerbose.setVerboseOff()
             EDVerbose.setTestOff()
         if (edCommandLine.existCommand(EDApplication.DEBUG_PARAM_LABEL_1) or \
             edCommandLine.existCommand(EDApplication.DEBUG_PARAM_LABEL_2)):
             EDVerbose.setVerboseDebugOn()
             EDVerbose.DEBUG("EDTestLauncher.preProcess: Debug mode")
Exemplo n.º 6
0
if __name__ == '__main__':
    EDVerbose.setVerboseDebugOn()
    # Sleep a random time 0-2s in order to avoid problems if many instances started at the same time
    fSleepTime = random.random()*2.0
    EDVerbose.DEBUG("Sleeping for %.2f s" % fSleepTime)
    time.sleep(fSleepTime)
    # Popolate input data
    EDVerbose.screen("Starting id29_create_thumbnail")
    # If no arguments stop
    if len(sys.argv) <= 2:
        EDVerbose.screen("Usage: id29_create_thumbnail image_directory_path image1 [image2]" )
        sys.exit(1)
    EDVerbose.screen("Arguments: %r" % sys.argv)
    strPathToTempDir = tempfile.mkdtemp(prefix="id29_create_thumbnail_")
    os.chdir(strPathToTempDir)
    EDVerbose.setLogFileName(os.path.join(strPathToTempDir, "id29_create_thumbnail.log"))
    strImageDirectory = sys.argv[1]
    listImageName = sys.argv[2:]
    # Quick check if the two image names are the same. If they are launch the thumbnail generator only once
    if len(listImageName) == 2:
        if listImageName[0] == listImageName[1]:
            listImageName = [ listImageName[0] ]
    for strImageName in listImageName:
        xsDataInputPyarchThumbnailGenerator = XSDataInputPyarchThumbnailGenerator()
        xsDataInputPyarchThumbnailGenerator.setWaitForFileTimeOut(XSDataTime(1000))
        strImagePath = os.path.join(strImageDirectory, strImageName)
        xsDataInputPyarchThumbnailGenerator.setDiffractionImage(XSDataFile(XSDataString(strImagePath)))
        EDVerbose.screen("XML input for EDPluginControlPyarchThumbnailGeneratorv1_0: %s" % xsDataInputPyarchThumbnailGenerator.marshal())
        edPluginControlPyarchThumbnailGeneratorv1_0 = EDPluginControlPyarchThumbnailGeneratorv1_0()
        edPluginControlPyarchThumbnailGeneratorv1_0.setDataInput(xsDataInputPyarchThumbnailGenerator)
        edPluginControlPyarchThumbnailGeneratorv1_0.execute()
Exemplo n.º 7
0
from EDVerbose import EDVerbose
from EDFactoryPluginStatic import EDFactoryPluginStatic

from XSDataCommon import XSDataFile
from XSDataCommon import XSDataString
from XSDataCommon import XSDataInteger
from XSDataCommon import XSDataBoolean

EDFactoryPluginStatic.loadModule("XSDataGridScreeningv1_0")
from XSDataGridScreeningv1_0 import XSDataInputGridScreening

if __name__ == '__main__':
    strPathToTempDir = tempfile.mkdtemp(
        prefix="edna-image-quality-indicators_")
    os.chdir(strPathToTempDir)
    EDVerbose.setLogFileName(os.path.join(strPathToTempDir, "edna.log"))
    # Popolate input data
    EDVerbose.screen("Starting EDNA image quality indicators processing")
    EDVerbose.screen("Arguments: %r" % sys.argv)
    bVerbose = False
    bDebug = False
    listPaths = []
    for iIndex, strArg in enumerate(sys.argv[1:]):
        strarg = strArg.lower()
        if strarg == "--verbose":
            EDVerbose.setVerboseOn()
        elif strarg == "--debug":
            EDVerbose.setVerboseDebugOn()
        if os.path.exists(strArg):
            listPaths.append(os.path.abspath(strArg))
    for strPath in listPaths:
Exemplo n.º 8
0
from XSDataISPyBv1_4 import XSDataInputStoreAutoProc
from XSDataISPyBv1_4 import AutoProcContainer


def successAction(self, _edObject=None):
    EDVerbose.screen("XML data sucessfully stored in ISPyB")

def failureAction(self, _edObject=None):
    EDVerbose.ERROR("XML data not stored in ISPyB")

if __name__ == '__main__':
    strCwd = os.getcwd()
    strPathToTempDir = tempfile.mkdtemp(prefix="edna-autoproc2ispyb_")
    os.chdir(strPathToTempDir)
    EDVerbose.setVerboseOn()
    EDVerbose.setLogFileName(os.path.join(strPathToTempDir, "edna.log"))
    # Populate input data
    EDVerbose.DEBUG("Arguments: %r" % sys.argv)
    bVerbose = False
    bDebug = False
    listPaths = []
    for iIndex, strArg in enumerate(sys.argv[1:]):
        strarg = strArg.lower()
        if strarg == "--verbose":
            EDVerbose.setVerboseOn()
        elif strarg == "--debug":
            EDVerbose.setVerboseDebugOn()
        strArgPath = strArg
        if os.path.dirname(strArgPath) == "":
            strArgPath = os.path.join(strCwd, strArg)
        strArgPathAbsolute = os.path.abspath(strArgPath)
Exemplo n.º 9
0
 # Sleep a random time 0-2s in order to avoid problems if many instances started at the same time
 fSleepTime = random.random() * 2.0
 EDVerbose.DEBUG("Sleeping for %.2f s" % fSleepTime)
 time.sleep(fSleepTime)
 # Popolate input data
 EDVerbose.screen("Starting id29_create_thumbnail")
 # If no arguments stop
 if len(sys.argv) <= 2:
     EDVerbose.screen(
         "Usage: id29_create_thumbnail image_directory_path image1 [image2]"
     )
     sys.exit(1)
 EDVerbose.screen("Arguments: %r" % sys.argv)
 strPathToTempDir = tempfile.mkdtemp(prefix="id29_create_thumbnail_")
 os.chdir(strPathToTempDir)
 EDVerbose.setLogFileName(
     os.path.join(strPathToTempDir, "id29_create_thumbnail.log"))
 strImageDirectory = sys.argv[1]
 listImageName = sys.argv[2:]
 # Quick check if the two image names are the same. If they are launch the thumbnail generator only once
 if len(listImageName) == 2:
     if listImageName[0] == listImageName[1]:
         listImageName = [listImageName[0]]
 for strImageName in listImageName:
     xsDataInputPyarchThumbnailGenerator = XSDataInputPyarchThumbnailGenerator(
     )
     xsDataInputPyarchThumbnailGenerator.setWaitForFileTimeOut(
         XSDataTime(1000))
     strImagePath = os.path.join(strImageDirectory, strImageName)
     xsDataInputPyarchThumbnailGenerator.setDiffractionImage(
         XSDataFile(XSDataString(strImagePath)))
     EDVerbose.screen(
Exemplo n.º 10
0
def runEdnaPlugin(execPath, pluginName, isDebug, xml, additionalPaths=None):
    
    '''
    execPath     - path to run plugin in
    pluginName   - plugin name
    isDebug      - True if should run edna in debug mode
    xml          - xml input to edna
    additionalPaths - list of other python path locations
    
    You must set EDNA_HOME to use this method
    This method blocks until the EDJob has reached a final status
    
    '''

    if (not 'EDNA_HOME' in os.environ):
        raise Exception("Cannot locate EDNA_HOME. Please set before running Edna plugins.")
    
    if (not 'EDNA_SITE' in os.environ):
        raise Exception(" Please set EDNA_SITE before running Edna plugins.")

    '''
    Add edna to path
    '''
    ednaKernelPath = os.environ['EDNA_HOME']+"/kernel/src"
    sys.path.insert(0, ednaKernelPath)
    
    '''
    If there are any additional paths such as fabio, add these
    '''
    if (not additionalPaths is None and len(additionalPaths)>0):
        for path in additionalPaths:
            sys.path.append(path)
    
    os.chdir(execPath)
    from EDVerbose import EDVerbose
    if (isDebug):
        EDVerbose.setVerboseDebugOn()
    else:
        EDVerbose.setVerboseOn()            
        EDVerbose.setVerboseDebugOff()
        
    from EDJob import EDJob
    
    EDVerbose.setLogFileName(execPath+"/"+pluginName+".log")           
    
    edJob = EDJob(pluginName)
    edJob.setDataInput(xml)
    edJob.execute()
    edJob.synchronize() # In theory should mean that the following loop is not needed
    
    # Unhelpful way of waiting for EDJob to be finished
    # TODO Fix this in EDJob some time
    while(True):
        status = edJob.getStatus()
        if (status is None):
            time.sleep(0.2) # 200 ms
            continue
        
        if ("failure" == status):
            raise Exception("EDJob failed! ")
        
        if ("success" == status):
            break
    
    ret = edJob.getDataOutput()
    
    return str(ret)
Exemplo n.º 11
0
def runEdnaPlugin(execPath, pluginName, isDebug, xml, additionalPaths=None):
    '''
    execPath     - path to run plugin in
    pluginName   - plugin name
    isDebug      - True if should run edna in debug mode
    xml          - xml input to edna
    additionalPaths - list of other python path locations
    
    You must set EDNA_HOME to use this method
    This method blocks until the EDJob has reached a final status
    
    '''

    if (not 'EDNA_HOME' in os.environ):
        raise Exception(
            "Cannot locate EDNA_HOME. Please set before running Edna plugins.")

    if (not 'EDNA_SITE' in os.environ):
        raise Exception(" Please set EDNA_SITE before running Edna plugins.")
    '''
    Add edna to path
    '''
    ednaKernelPath = os.environ['EDNA_HOME'] + "/kernel/src"
    sys.path.insert(0, ednaKernelPath)
    '''
    If there are any additional paths such as fabio, add these
    '''
    if (not additionalPaths is None and len(additionalPaths) > 0):
        for path in additionalPaths:
            sys.path.append(path)

    os.chdir(execPath)
    from EDVerbose import EDVerbose
    if (isDebug):
        EDVerbose.setVerboseDebugOn()
    else:
        EDVerbose.setVerboseOn()
        EDVerbose.setVerboseDebugOff()

    from EDJob import EDJob

    EDVerbose.setLogFileName(execPath + "/" + pluginName + ".log")

    edJob = EDJob(pluginName)
    edJob.setDataInput(xml)
    edJob.execute()
    edJob.synchronize(
    )  # In theory should mean that the following loop is not needed

    # Unhelpful way of waiting for EDJob to be finished
    # TODO Fix this in EDJob some time
    while (True):
        status = edJob.getStatus()
        if (status is None):
            time.sleep(0.2)  # 200 ms
            continue

        if ("failure" == status):
            raise Exception("EDJob failed! ")

        if ("success" == status):
            break

    ret = edJob.getDataOutput()

    return str(ret)
Exemplo n.º 12
0
def runMXv1Pipeline():
    strLogFileName = os.path.join(returnWorkingDirectory(), "wsgi-server.log")
    EDVerbose.setLogFileName(strLogFileName)
    strInput = str(request['wsgi.input'].read(int(request['CONTENT_LENGTH'])))
    if strInput:
        # Take the parameters string, split off the title and run the bash script to generate the input char. XML
        listParams = shlex.split(strInput)
        strComments = listParams[0]  # the 1st item
        strShortComments = listParams[1]  # the 2nd item
        strWorkingDir = listParams[2]  # the 3rd item
        strHTMLResultDir = listParams[3]  # the 4th item

        os.chdir(strWorkingDir)

        strParamString = " ".join(
            listParams[4:])  # all but the first four items
        edPluginMxv1ParamsToXML = EDFactoryPluginStatic.loadPlugin(
            'EDPluginMxv1ParamsToXMLv1_0')
        edPluginMxv1ParamsToXML.setDataInput(XSDataString(strParamString),
                                             "paramString")
        edPluginMxv1ParamsToXML.executeSynchronous()
        xsDataFile = edPluginMxv1ParamsToXML.getDataOutput()

        # Read the XML and parse it into an object hierarchy
        strXMLFile = xsDataFile.getPath().getValue()
        f = open(strXMLFile, 'r')
        xml = f.read()
        f.close()
        xsDataInputCharacterisation = XSDataInputCharacterisation.parseString(
            xml)

        # Run the MXv1 application pipeline
        edApplicationMXv1Characterisation = EDApplicationMXv1Characterisation(_strPluginName="EDPluginControlInterfacev1_2", \
                               _strConfigurationFileName=strConfigurationFilePath, \
                               _xsDataInputCharacterisation=xsDataInputCharacterisation, \
                               _strComments=strComments, \
                               _strShortComments=strShortComments)
        edApplicationMXv1Characterisation.execute()

        # Run the EDNA2HTML generator on the output from the MXv1 application
        edPluginExecOutputHTML = EDFactoryPluginStatic.loadPlugin(
            'EDPluginExecOutputHTMLv1_0')
        edPluginExecOutputHTML.setDataInput(XSDataString(strComments), "title")
        strWorkingDir = os.path.join(
            strWorkingDir, edApplicationMXv1Characterisation.getWorkingDir())
        edPluginExecOutputHTML.setDataInput(XSDataString(strWorkingDir),
                                            "workingDir")
        #strBaseDir = os.path.join(strHTMLResultDir, "edna")
        #edPluginExecOutputHTML.setDataInput(XSDataString(strBaseDir), "basename")
        edPluginExecOutputHTML.setDataInput(XSDataString(strHTMLResultDir),
                                            "basename")

        edPluginExecOutputHTML.executeSynchronous()

        strPathToHTMLFile = ""
        if (edPluginExecOutputHTML.hasDataOutput("htmlFile")):
            strPathToHTMLFile = edPluginExecOutputHTML.getDataOutput(
                "htmlFile")[0].getPath().getValue()
        else:
            EDVerbose.ERROR(
                "edna-mxv1-wsgi-server: edPluginExecOutputHTML has no dataOutput htmlFile!"
            )

        if strPathToHTMLFile == "":
            EDVerbose.ERROR("edna-mxv1-wsgi-server: Returning empty string")
        return strPathToHTMLFile
    else:
        return strInput