Beispiel #1
0
    def characterise(self, edna_input):
        process_directory_path = edna_input.process_directory
        
        # if there is no data collection id, the id will be a random number
        # this is to give a unique number to the EDNA input and result files;
        # something more clever might be done to give a more significant
        # name, if there is no dc id.
        try:
            dc_id = edna_input.getDataCollectionId().getValue()
        except:
            dc_id = id(edna_input)
        
        if hasattr(edna_input, "process_directory"):
            edna_input_file = os.path.join(process_directory_path,"EDNAInput_%s.xml" % dc_id)
            edna_input.exportToFile(edna_input_file)
            edna_results_file = os.path.join(process_directory_path, "EDNAOutput_%s.xml" % dc_id)

            if not os.path.isdir(process_directory_path):
                os.makedirs(path)
        else:
            raise RuntimeError, "No process directory specified in edna_input"

        logging.getLogger("queue_exec").info("Starting EDNA using xml file %r", edna_input_file)

        edna_processing_thread = EdnaProcessingThread(self.start_edna_command, \
                                                      edna_input_file, \
                                                      edna_results_file,\
                                                      process_directory_path)
        self.processing_done_event = edna_processing_thread.start()
        self.processing_done_event.wait()
        
        self.result = XSDataResultMXCuBE.parseFile(edna_results_file)
        
        return self.result
Beispiel #2
0
    def characterise(self, edna_input):
        path = edna_input.process_directory

        # if there is no data collection id, the id will be a random number
        # this is to give a unique number to the EDNA input and result files;
        # something more clever might be done to give a more significant
        # name, if there is no dc id.
        try:
            dc_id = edna_input.getDataCollectionId().getValue()
        except:
            dc_id = id(edna_input)

        if hasattr(edna_input, "process_directory"):
            edna_input_file = os.path.join(path, "EDNAInput_%s.xml" % dc_id)
            edna_input.exportToFile(edna_input_file)
            edna_results_file = os.path.join(path, "EDNAOutput_%s.xml" % dc_id)

            if not os.path.isdir(path):
                os.makedirs(path)
        else:
            raise RuntimeError("No process directory specified in edna_input")

        msg = "Starting EDNA using xml file %r", edna_input_file
        logging.getLogger("queue_exec").info(msg)

        edna_processing_thread = \
          EdnaProcessingThread(self.start_edna_command, edna_input_file,
                               edna_results_file, path)

        self.processing_done_event = edna_processing_thread.start()
        self.processing_done_event.wait()
        self.result = XSDataResultMXCuBE.parseFile(edna_results_file)

        return self.result
    def get_result(self):

        jobstatus = self.job.status

        # outname = self.input_file.replace("Input", "Output")
        # outfile = os.path.join( self.edna_directory, outname)

        logging.getLogger("HWR").debug("Job / state is COMPLETED")
        logging.getLogger("HWR").debug("  job status dump: %s" % jobstatus)
        logging.getLogger("HWR").debug("  looking for file: %s" %
                                       self.results_file)

        if os.path.exists(self.results_file):
            # job_output = open(outfile).read()
            # logging.getLogger("HWR").debug("     EDNA results file found. loading it")
            # open(self.results_file, "w").write(job_output)
            logging.getLogger("HWR").debug("     EDNA results file found 2")
            result = XSDataResultMXCuBE.parseFile(self.results_file)
            logging.getLogger("HWR").debug("     EDNA results file found 3")
            logging.getLogger("HWR").debug(
                "EDNA Result loaded from file / result is=%s" %
                str(type(result)))
        else:
            logging.getLogger("HWR").debug(
                "EDNA Job finished without success / cannot find output file ")
            result = ""

        return result
    def get_result(self):

        jobstatus = self.job.status

        # outname = self.input_file.replace("Input", "Output")
        # outfile = os.path.join( self.edna_directory, outname)

        logging.getLogger("HWR").debug("Job / state is COMPLETED")
        logging.getLogger("HWR").debug("  job status dump: %s" % jobstatus)
        logging.getLogger("HWR").debug("  looking for file: %s" % self.results_file)

        if os.path.exists(self.results_file):
            # job_output = open(outfile).read()
            # logging.getLogger("HWR").debug("     EDNA results file found. loading it")
            # open(self.results_file, "w").write(job_output)
            logging.getLogger("HWR").debug("     EDNA results file found 2")
            result = XSDataResultMXCuBE.parseFile(self.results_file)
            logging.getLogger("HWR").debug("     EDNA results file found 3")
            logging.getLogger("HWR").debug(
                "EDNA Result loaded from file / result is=%s" % str(type(result))
            )
        else:
            logging.getLogger("HWR").debug(
                "EDNA Job finished without success / cannot find output file "
            )
            result = ""

        return result
Beispiel #5
0
 def workflow_state_changed(self, new_state):
     logging.debug('%s: new workflow state is %r', self.name(), new_state)
     if type(new_state) == types.ListType or type(new_state) == types.TupleType:
         new_state = str(new_state[0])
     try:
         actor = self.workflow.current_actor.getValue()
         self.refresh_workflow_state(new_state, actor)
     except:
         self.info_label.setText('Lost connection with workflow engine')
     if new_state == "ON" and self.previous_workflow_state == "RUNNING":
         # workflow finished, open the output file and use an EDNACaracterize method to
         # continue the work
         if self.workflow_output_file is not None and os.path.exists(self.workflow_output_file):
             logging.debug('Workflow finished, sending the results to %r', self.edna)
             logging.debug('Workflow file is %s', self.workflow_output_file)
             try:
                 data = XSDataResultMXCuBE.parseFile(self.workflow_output_file)
                 self.edna.readEDNAResults(data.getCharacterisationResult(), self.workflow_output_file,
                                           self.beamline_params['directory'], self.beamline_params['prefix'],
                                           int(self.beamline_params['run_number']),
                                           process_dir=self.process_dir, do_inducedraddam=False)
                 logging.debug('Results sent')
             except:
                 logging.debug('Malformed or empty results file')
         else:
             logging.debug('Workflow finished, no result file')
         # then remove the current widget with the parameters
         if self.params_widget is not None:
             self.layout().removeChild(self.params_widget)
     self.previous_workflow_state = new_state
Beispiel #6
0
 def workflow_state_changed(self, new_state):
     logging.debug('%s: new workflow state is %r', self.name(), new_state)
     if type(new_state) == list or type(new_state) == tuple:
         new_state = str(new_state[0])
     if new_state == "ON" and self.previous_workflow_state == "RUNNING":
         # workflow finished, open the output file and use an EDNACaracterize method to
         # continue the work
         if self.workflow_output_file is not None and os.path.exists(
                 self.workflow_output_file):
             logging.debug('Workflow finished, sending the results to %r',
                           self.edna)
             logging.debug('Workflow file is %s', self.workflow_output_file)
             try:
                 data = XSDataResultMXCuBE.parseFile(
                     self.workflow_output_file)
                 self.edna.readEDNAResults(
                     data.getCharacterisationResult(),
                     self.workflow_output_file,
                     self.beamline_params['directory'],
                     self.beamline_params['prefix'],
                     int(self.beamline_params['run_number']),
                     process_dir=self.process_dir,
                     do_inducedraddam=False)
                 logging.debug('Results sent')
             except:
                 logging.debug('Malformed or empty results file')
         else:
             logging.debug('Workflow finished, no result file')
         # then remove the current widget with the parameters
         if self.params_widget is not None:
             self.layout().removeChild(self.params_widget)
     self.previous_workflow_state = new_state
Beispiel #7
0
 def reallyGetEDNAResults(edna_process_id=edna_process_id, edna_results_file=edna_results_file, storage_dict={"i":0}):
     storage_dict["i"]+=1
     if storage_dict["i"]>=3:
       logging.getLogger().error("Timeout: cannot open EDNA results file (%s)", edna_results_file)
       self.EDNAWaitResultsTimers[edna_process_id].stop()
       del self.EDNAWaitResultsTimers[edna_process_id]
       del self.imagePathProperties[edna_process_id]
     else:
       results = XSDataResultMXCuBE.parseFile(edna_results_file)
       self.EDNAWaitResultsTimers[edna_process_id].stop()
       del self.EDNAWaitResultsTimers[edna_process_id]
       imagePrefix = self.imagePathProperties[edna_process_id]["imagePrefix"]
       imageDir = self.imagePathProperties[edna_process_id]["imageDir"]
       lRunN = self.imagePathProperties[edna_process_id]["lRunN"] 
       del self.imagePathProperties[edna_process_id]
       try:
           html_path = results.htmlPage.path.value
           self.emit('newEDNAHTML', (html_path, imagePrefix, lRunN))
       except:
           logging.getLogger().exception('EDNACharacterize: no html in results')
          
       try:
           screening_id = results.getScreeningId().getValue()
       except:
           screening_id = None 
       self.readEDNAResults(results.getCharacterisationResult(), edna_results_file, imageDir,
                            imagePrefix, lRunN, screeningId = screening_id)
Beispiel #8
0
 def workflow_state_changed(self, new_state):
     logging.debug("%s: new workflow state is %r", self.name(), new_state)
     if isinstance(new_state, types.ListType) or isinstance(
         new_state, types.TupleType
     ):
         new_state = str(new_state[0])
     if new_state == "ON" and self.previous_workflow_state == "RUNNING":
         # workflow finished, open the output file and use an EDNACaracterize method to
         # continue the work
         if self.workflow_output_file is not None and os.path.exists(
             self.workflow_output_file
         ):
             logging.debug("Workflow finished, sending the results to %r", self.edna)
             logging.debug("Workflow file is %s", self.workflow_output_file)
             try:
                 data = XSDataResultMXCuBE.parseFile(self.workflow_output_file)
                 self.edna.readEDNAResults(
                     data.getCharacterisationResult(),
                     self.workflow_output_file,
                     self.beamline_params["directory"],
                     self.beamline_params["prefix"],
                     int(self.beamline_params["run_number"]),
                     process_dir=self.process_dir,
                     do_inducedraddam=False,
                 )
                 logging.debug("Results sent")
             except BaseException:
                 logging.debug("Malformed or empty results file")
         else:
             logging.debug("Workflow finished, no result file")
         # then remove the current widget with the parameters
         if self.params_widget is not None:
             self.layout().removeChild(self.params_widget)
     self.previous_workflow_state = new_state
Beispiel #9
0
 def workflow_state_changed(self, new_state):
     logging.debug("%s: new workflow state is %r", self.name(), new_state)
     if isinstance(new_state, types.ListType) or isinstance(
             new_state, types.TupleType):
         new_state = str(new_state[0])
     if new_state == "ON" and self.previous_workflow_state == "RUNNING":
         # workflow finished, open the output file and use an EDNACaracterize method to
         # continue the work
         if self.workflow_output_file is not None and os.path.exists(
                 self.workflow_output_file):
             logging.debug("Workflow finished, sending the results to %r",
                           self.edna)
             logging.debug("Workflow file is %s", self.workflow_output_file)
             try:
                 data = XSDataResultMXCuBE.parseFile(
                     self.workflow_output_file)
                 self.edna.readEDNAResults(
                     data.getCharacterisationResult(),
                     self.workflow_output_file,
                     self.beamline_params["directory"],
                     self.beamline_params["prefix"],
                     int(self.beamline_params["run_number"]),
                     process_dir=self.process_dir,
                     do_inducedraddam=False,
                 )
                 logging.debug("Results sent")
             except BaseException:
                 logging.debug("Malformed or empty results file")
         else:
             logging.debug("Workflow finished, no result file")
         # then remove the current widget with the parameters
         if self.params_widget is not None:
             self.layout().removeChild(self.params_widget)
     self.previous_workflow_state = new_state
Beispiel #10
0
    def characterise(self, edna_input):

        # if there is no data collection id, the id will be a random number
        # this is to give a unique number to the EDNA input and result files;
        # something more clever might be done to give a more significant
        # name, if there is no dc id.
        try:
            dc_id = edna_input.getDataCollectionId().getValue()
        except:
            dc_id = id(edna_input)

        for dataSet in edna_input.dataSet:
            for imageFile in dataSet.imageFile:
                firstImage = imageFile.path.value
                break

        self.edna_processing_thread = None
        listImageName = os.path.basename(firstImage).split("_")
        prefix = "_".join(listImageName[:-2])
        run_number = listImageName[-2]
        i = 1

        if hasattr(edna_input, "process_directory"):
            edna_directory = os.path.join(
                edna_input.process_directory,
                "characterisation_%s_run%s_%d" % (prefix, run_number, i))
            while os.path.exists(edna_directory):
                i += 1
                edna_directory = os.path.join(
                    edna_input.process_directory,
                    "characterisation_%s_run%s_%d" % (prefix, run_number, i))
            os.makedirs(edna_directory)
        else:
            raise RuntimeError("No process directory specified in edna_input")

        edna_input_file = os.path.join(edna_directory,
                                       "EDNAInput_%s.xml" % dc_id)
        edna_input.exportToFile(edna_input_file)
        edna_results_file = os.path.join(edna_directory,
                                         "EDNAOutput_%s.xml" % dc_id)

        msg = "Starting EDNA using xml file %r", edna_input_file
        logging.getLogger("queue_exec").info(msg)

        self.edna_processing_thread = \
          EdnaProcessingThread(self.start_edna_command, edna_input_file,
                               edna_results_file, edna_directory)

        self.processing_done_event = self.edna_processing_thread.start()
        self.processing_done_event.wait()
        self.result = None
        if os.path.exists(edna_results_file):
            self.result = XSDataResultMXCuBE.parseFile(edna_results_file)

        return self.result
    def _run_edna(self, input_file, results_file, process_directory):
        """Starts EDNA"""
        msg = "Starting EDNA characterisation using xml file %s" % input_file
        logging.getLogger("queue_exec").info(msg)

        args = (self.start_edna_command, input_file, results_file, process_directory)
        subprocess.call("%s %s %s %s" % args, shell=True)

        self.result = None
        if os.path.exists(results_file):
            self.result = XSDataResultMXCuBE.parseFile(results_file)

        return self.result
    def run_edna(self, input_file, results_file, process_directory):

        msg = "Starting EDNA characterisation using xml file %s" % input_file
        logging.getLogger("queue_exec").info(msg)

        args = (self.start_edna_command, input_file, results_file, process_directory)
        subprocess.call("%s %s %s %s" % args, shell=True)

        self.result = None
        if os.path.exists(results_file):
            self.result = XSDataResultMXCuBE.parseFile(results_file)

        return self.result
    def characterise(self, edna_input):

        # if there is no data collection id, the id will be a random number
        # this is to give a unique number to the EDNA input and result files;
        # something more clever might be done to give a more significant
        # name, if there is no dc id.
        try:
            dc_id = edna_input.getDataCollectionId().getValue()
        except:
            dc_id = id(edna_input)

        for dataSet in edna_input.dataSet:
            for imageFile in dataSet.imageFile:
                firstImage = imageFile.path.value
                break

        self.edna_processing_thread = None
        listImageName = os.path.basename(firstImage).split("_")
        prefix = "_".join(listImageName[:-2])
        run_number = listImageName[-2]
        i = 1

        if hasattr(edna_input, "process_directory"):
            edna_directory = os.path.join(edna_input.process_directory, "characterisation_%s_run%s_%d" % (prefix, run_number, i))
            while os.path.exists(edna_directory):
                i += 1
                edna_directory = os.path.join(edna_input.process_directory, "characterisation_%s_run%s_%d" % (prefix, run_number, i))
            os.makedirs(edna_directory)
        else:
            raise RuntimeError("No process directory specified in edna_input")

        edna_input_file = os.path.join(edna_directory, "EDNAInput_%s.xml" % dc_id)
        edna_input.exportToFile(edna_input_file)
        edna_results_file = os.path.join(edna_directory, "EDNAOutput_%s.xml" % dc_id)

        msg = "Starting EDNA using xml file %r", edna_input_file
        logging.getLogger("queue_exec").info(msg)

        self.edna_processing_thread = \
          EdnaProcessingThread(self.start_edna_command, edna_input_file,
                               edna_results_file, edna_directory)

        self.processing_done_event = self.edna_processing_thread.start()
        self.processing_done_event.wait()
        self.result = None
        if os.path.exists(edna_results_file):
            self.result = XSDataResultMXCuBE.parseFile(edna_results_file)
    
        return self.result
Beispiel #14
0
    def get_result(self, state):
        if state == "COMPLETED": 
            outfile = os.path.join( self.edna_directory, "ControlInterfaceToMXCuBEv1_3_dataOutput.xml")

            logging.getLogger("HWR").debug("Job / state is COMPLETED")
            logging.getLogger("HWR").debug("  looking for file: %s" % outfile)
            if os.path.exists(outfile):
                job_output = open(outfile).read()
                open(self.results_file, "w").write(job_output)
                result = XSDataResultMXCuBE.parseFile(self.results_file)
            else:
                logging.getLogger("HWR").debug("EDNA Job finished without success / cannot find output file ") 
                result = ""
        else:
            logging.getLogger("HWR").debug("EDNA Job finished without success / state was %s" % (job.state))
            result = ""
        
        return result
    def get_result(self, state):
        if state == "COMPLETED":
            outfile = os.path.join(
                self.edna_directory, "ControlInterfaceToMXCuBEv1_3_dataOutput.xml"
            )

            logging.getLogger("HWR").debug("Job / state is COMPLETED")
            logging.getLogger("HWR").debug("  looking for file: %s" % outfile)
            if os.path.exists(outfile):
                job_output = open(outfile).read()
                open(self.results_file, "w").write(job_output)
                result = XSDataResultMXCuBE.parseFile(self.results_file)
            else:
                logging.getLogger("HWR").debug(
                    "EDNA Job finished without success / cannot find output file "
                )
                result = ""
        else:
            logging.getLogger("HWR").debug(
                "EDNA Job finished without success / state was %s" % (job.state)
            )
            result = ""

        return result