Esempio n. 1
0
def test_hwo():
    from QtImport import *
    import time
    hwr_directory = os.environ['MXCUBE_XML_PATH']
    print 'hwr_directory', hwr_directory
    print 'abs.path hwr_directory', os.path.abspath(hwr_directory)
    from HardwareRepository.HardwareRepository import HardwareRepository
    hwr = HardwareRepository(os.path.abspath(hwr_directory))
    hwr.connect()

    hwo = hwr.getHardwareObject('/singleton_objects/limavideo')

    print 'Image dimensions: ', hwo.get_image_dimensions()
    print 'Live Mode: ', hwo.get_video_live()

    app = QApplication([])

    win = QMainWindow()
    lab = QLabel("toto")

    print "Image dimensions: ", hwo.get_image_dimensions()
    hwo.set_video_live(True)
    hwo.set_exposure_time(0.05)
    time.sleep(1)

    qimg = hwo.get_new_image()
    px = QPixmap(qimg)

    px = px.scaled(QSize(px.width() * 0.5, px.height() * 0.5))

    lab.setPixmap(px)
    win.setCentralWidget(lab)
    win.show()
    app.exec_()
    def init(self):
        if self.hasObject('connection_parameters'):
            self._connection_parameters.update(
                self['connection_parameters'].getProperties())
        if self.hasObject('ssh_options'):
            # We are running through ssh - so we need python_address
            # If not, we stick to default, which is localhost (127.0.0.1)
            self._connection_parameters['python_address'] = socket.gethostname(
            )

        locations = next(
            self.getObjects('directory_locations')).getProperties()
        paths = self.software_paths
        props = self.java_properties
        dd = next(self.getObjects('software_paths')).getProperties()
        for tag, val in dd.items():
            val2 = val.format(**locations)
            if not os.path.isabs(val2):
                val2 = HardwareRepository().findInRepository(val)
                if val2 is None:
                    raise ValueError("File path %s not recognised" % val)
            paths[tag] = props[tag] = val2
        dd = next(self.getObjects('software_properties')).getProperties()
        for tag, val in dd.items():
            val2 = val.format(**locations)
            if not os.path.isabs(val2):
                val2 = HardwareRepository().findInRepository(val)
                if val2 is None:
                    raise ValueError("File path %s not recognised" % val)
            paths[tag] = props[tag] = val2
        #
        pp = props['co.gphl.wf.bin'] = paths['GPHL_INSTALLATION']
        paths['BDG_home'] = paths.get('co.gphl.wf.bdg_licence_dir') or pp
Esempio n. 3
0
    def get_default_characterisation_parameters(self):
        """
        :returns: A CharacterisationsParameters object with default parameters.
        """
        input_fname = self.data_analysis_hwobj.edna_default_file
        hwr_dir = HardwareRepository().getHardwareRepositoryPath()

        with open(os.path.join(hwr_dir, input_fname), 'r') as f:
            edna_default_input = ''.join(f.readlines())

        edna_input = XSDataInputMXCuBE.parseString(edna_default_input)
        diff_plan = edna_input.getDiffractionPlan()
        #edna_beam = edna_input.getExperimentalCondition().getBeam()
        edna_sample = edna_input.getSample()
        char_params = queue_model_objects.CharacterisationParameters()
        char_params.experiment_type = queue_model_enumerables.EXPERIMENT_TYPE.OSC

        # Optimisation parameters
        char_params.use_aimed_resolution = False
        char_params.aimed_resolution = diff_plan.getAimedResolution().getValue(
        )
        char_params.use_aimed_multiplicity = False
        #char_params.aimed_multiplicity = diff_plan.getAimedMultiplicity().getValue()
        char_params.aimed_i_sigma = diff_plan.getAimedIOverSigmaAtHighestResolution(
        ).getValue()
        char_params.aimed_completness = diff_plan.getAimedCompleteness(
        ).getValue()
        char_params.strategy_complexity = 0
        char_params.induce_burn = False
        char_params.use_permitted_rotation = False
        char_params.permitted_phi_start = 0.0
        char_params.permitted_phi_end = 360
        char_params.low_res_pass_strat = False

        # Crystal
        char_params.max_crystal_vdim = edna_sample.getSize().getY().getValue()
        char_params.min_crystal_vdim = edna_sample.getSize().getZ().getValue()
        char_params.max_crystal_vphi = 90
        char_params.min_crystal_vphi = 0.0
        char_params.space_group = ""

        # Characterisation type
        char_params.use_min_dose = True
        char_params.use_min_time = False
        char_params.min_dose = 30.0
        char_params.min_time = 0.0
        char_params.account_rad_damage = True
        char_params.auto_res = True
        char_params.opt_sad = False
        char_params.sad_res = 0.5
        char_params.determine_rad_params = False
        char_params.burn_osc_start = 0.0
        char_params.burn_osc_interval = 3

        # Radiation damage model
        char_params.rad_suscept = edna_sample.getSusceptibility().getValue()
        char_params.beta = 1
        char_params.gamma = 0.06

        return char_params
Esempio n. 4
0
    def init(self):
        self.collect_obj = self.getObjectByRole("collect")
        self.start_edna_command = self.getProperty("edna_command")
        self.edna_default_file = self.getProperty("edna_default_file")
        hwr_dir = HardwareRepository().getHardwareRepositoryPath()

        with open(os.path.join(hwr_dir, self.edna_default_file), 'r') as f:
            self.edna_default_input = ''.join(f.readlines())
 def init(self):
     self.collect_obj = self.getObjectByRole("collect")
     self.start_edna_command = self.getProperty("edna_command")
     self.edna_default_file = self.getProperty("edna_default_file")
     fp = HardwareRepository().findInRepository(self.edna_default_file)
     if fp is None:
         raise ValueError("File %s not found in repository" %
                          self.edna_default_file)
     with open(fp, 'r') as f:
         self.edna_default_input = ''.join(f.readlines())
def test_hwo():
    from QtImport import *
    import time

    hwr_directory = os.environ["MXCUBE_XML_PATH"]
    print "hwr_directory", hwr_directory
    print "abs.path hwr_directory", os.path.abspath(hwr_directory)
    from HardwareRepository.HardwareRepository import HardwareRepository

    hwr = HardwareRepository(os.path.abspath(hwr_directory))
    hwr.connect()

    hwo = hwr.getHardwareObject("/singleton_objects/limavideo")

    print "Image dimensions: ", hwo.get_image_dimensions()
    print "Live Mode: ", hwo.get_video_live()

    app = QApplication([])

    win = QMainWindow()
    lab = QLabel("toto")

    print "Image dimensions: ", hwo.get_image_dimensions()
    hwo.set_video_live(True)
    hwo.set_exposure_time(0.05)
    time.sleep(1)

    qimg = hwo.get_new_image()
    px = QPixmap(qimg)

    px = px.scaled(QSize(px.width() * 0.5, px.height() * 0.5))

    lab.setPixmap(px)
    win.setCentralWidget(lab)
    win.show()
    app.exec_()
    def data_collection_hook(self):
        """Spawns data emulation using gphl simcal"""

        data_collect_parameters = self.current_dc_parameters

        logging.getLogger('HWR').debug("Emulator: nominal position "
            + ', '.join('%s=%s' % (tt)
                        for tt in sorted(data_collect_parameters['motors'].items())
                        if tt[1] is not None)
        )

        logging.getLogger('HWR').debug("Emulator:  actual position "
             + ', '.join('%s=%s' % tt
                         for tt in sorted(self.diffractometer_hwobj.get_positions().items())
                         if tt[1] is not None)
        )

        # Done here as there are what-happens-first conflicts
        # if you put it in init
        bl_setup_hwobj = HardwareRepository().getHardwareObject(
            'beamline-setup'
        )
        if self.gphl_workflow_hwobj is None:
            self.gphl_workflow_hwobj = bl_setup_hwobj.gphl_workflow_hwobj
        if not self.gphl_workflow_hwobj:
            raise ValueError("Emulator requires GPhL workflow installation")
        if self.gphl_connection_hwobj is None:
            self.gphl_connection_hwobj = bl_setup_hwobj.gphl_connection_hwobj
        if not self.gphl_connection_hwobj:
            raise ValueError("Emulator requires GPhL connection installation")

        # Get program locations
        simcal_executive = self.gphl_connection_hwobj.get_executable('simcal')
        # Get environmental variables
        envs = {'BDG_home':
                    self.gphl_connection_hwobj.software_paths['BDG_home'],
                'GPHL_INSTALLATION':
                    self.gphl_connection_hwobj.software_paths['GPHL_INSTALLATION']
                }
        for tag, val in self['environment_variables'].getProperties().items():
            envs[str(tag)] = str(val)

        # get crystal data
        sample_name = self.getProperty('default_sample_name')
        sample = self.sample_changer_hwobj.getLoadedSample()
        if sample:
            ss = sample.getName()
            if ss and ss.startswith(self.TEST_SAMPLE_PREFIX):
                sample_name  = ss[len(self.TEST_SAMPLE_PREFIX):]

        sample_dir = self.gphl_connection_hwobj.software_paths.get(
            'gphl_test_samples'
        )
        if not sample_dir:
            raise ValueError(
                "Emulator requires gphl_test_samples dir specified"
            )
        sample_dir = os.path.join(sample_dir, sample_name)
        if not os.path.isdir(sample_dir):
            raise ValueError(
                "Sample data directory %s does not exist" % sample_dir
            )
        crystal_file = os.path.join(sample_dir, 'crystal.nml')
        if not os.path.isfile(crystal_file):
            raise ValueError(
                "Emulator crystal data file %s does not exist" % crystal_file
            )
        # in spite of the simcal_crystal_list name this returns an OrderdDict
        crystal_data = f90nml.read(crystal_file)['simcal_crystal_list']

        input_data = self._get_simcal_input(data_collect_parameters,
                                            crystal_data)

        # NB outfile is the echo output of the input file;
        # image files templates are set in the input file
        file_info = data_collect_parameters['fileinfo']
        if not os.path.exists(file_info['directory']):
            os.makedirs(file_info['directory'])
        if not os.path.exists(file_info['directory']):
            os.makedirs(file_info['directory'])
        infile = os.path.join(file_info['directory'],
                              'simcal_in_%s.nml' % self._counter)

        f90nml.write(input_data, infile, force=True)
        outfile = os.path.join(file_info['directory'],
                               'simcal_out_%s.nml' % self._counter)
        logfile = os.path.join(file_info['directory'],
                               'simcal_log_%s.txt' % self._counter)
        self._counter += 1
        hklfile = os.path.join(sample_dir, 'sample.hkli')
        if not os.path.isfile(hklfile):
            raise ValueError(
                "Emulator hkli file %s does not exist" % hklfile
            )
        command_list = [simcal_executive, '--input', infile, '--output', outfile,
                        '--hkl', hklfile]

        for tag, val in self['simcal_options'].getProperties().items():
            command_list.extend(ConvertUtils.command_option(tag, val,
                                                            prefix='--'))
        logging.getLogger('HWR').info("Executing command: %s" % command_list)
        logging.getLogger('HWR').info("Executing environment: %s"
                                      % sorted(envs.items()))


        fp1 = open(logfile, 'w')
        fp2 = subprocess.STDOUT
        # resource.setrlimit(resource.RLIMIT_STACK, (-1,-1))

        try:
            running_process = subprocess.Popen(command_list, stdout=fp1,
                                               stderr=fp2, env=envs)
        except:
            logging.getLogger('HWR').error('Error in spawning workflow application')
            raise
        finally:
            fp1.close()

        # This does waiting, so we want to collect the result afterwards
        super(CollectEmulator, self).data_collection_hook()

        logging.getLogger('HWR').info(
            'Waiting for simcal collection emulation.'
        )
        # NBNB TODO put in time-out, somehow
        if running_process is not None:
            return_code = running_process.wait()
            if return_code:
                raise RuntimeError("simcal process terminated with return code %s"
                                   % return_code)
            else:
                logging.getLogger('HWR').info(
                    'Simcal collection emulation successful'
                )

        return
Esempio n. 8
0
    def init(self):

        self.synchrotron_name = self.getProperty('synchrotron_name')
        self.beamline_name = self.getProperty('beamline_name')
        self.endstation_name = self.getProperty('endstation_name').lower()

        self.suffix = self["file_info"].getProperty('file_suffix')
        self.template = self["file_info"].getProperty('file_template')

        # Override directory names, if parameter_override_file exists.
        # Intended to allow resetting directories in mock mode,
        # while keeping the session/xml used for the mocked beamline.
        override_file = HardwareRepository().findInRepository(
            parameter_override_file
        )
        logging.getLogger('HWR').info('Reading override directory names from %s' % override_file)
        if override_file:
            parameters =  ET.parse(override_file).getroot()
            for elem in parameters:
                tag = elem.tag
                if tag in ('base_directory', 'processed_data_base_directory',
                           'archive_base_directory'):
                    val = elem.text.strip()
                    if val is not None:
                        self["file_info"].setProperty(tag, val)

        base_directory = self["file_info"].\
                              getProperty('base_directory')

        base_process_directory = self["file_info"].\
            getProperty('processed_data_base_directory')

        base_archive_directory = self['file_info'].\
            getProperty('archive_base_directory')

        raw_folder = self["file_info"].\
            getProperty('raw_data_folder_name')

        if raw_folder is None or (not raw_folder.strip()):
            raw_folder = Session.default_raw_data_folder 

        process_folder = self["file_info"].\
            getProperty('processed_data_folder_name')

        archive_folder = self['file_info'].\
            getProperty('archive_folder')

        try:
            inhouse_proposals = self["inhouse_users"]["proposal"]
            for prop in inhouse_proposals:
                self.in_house_users.append((prop.getProperty('code'),
                                            str(prop.getProperty('number'))))
        except KeyError:
            pass

        email_extension = self.getProperty('email_extension')
        if email_extension:
            self.email_extension = email_extension
        else:
            try:
                domain = socket.getfqdn().split('.')
                self.email_extension = '.'.join((domain[-2], domain[-1]))
            except (TypeError, IndexError):
                pass

        archive_base_directory = self['file_info'].getProperty('archive_base_directory')
        if archive_base_directory:
            queue_model_objects.PathTemplate.set_archive_path(archive_base_directory,
                                                              self['file_info'].getProperty('archive_folder'))

        self.set_base_data_directories( base_directory, 
                                        base_process_directory, 
                                        base_archive_directory, 
                                        raw_folder=raw_folder, 
                                        process_folder=process_folder, 
                                        archive_folder=archive_folder)

        precision = self.default_precision
                
        try:
            precision = eval(self["file_info"].getProperty('precision', self.default_precision))
        except:
            pass

        queue_model_objects.PathTemplate.set_precision(precision)