Exemplo n.º 1
0
    def __init__(self,
                 dbname,
                 beamline_gpfs_path,
                 username,
                 pulses_per_deg=360000,
                 topic="qas-processing",
                 bootstrap_servers=['cmb01:9092', 'cmb02:9092'],
                 *args,
                 **kwargs):
        # these can't be pickled
        self.logger = get_logger()
        self.logger.info("Begin scan processor")
        db = Broker.named(dbname)
        # need to register handlers
        db.reg.register_handler('PIZZABOX_AN_FILE_TXT',
                                PizzaBoxAnHandlerTxt,
                                overwrite=True)
        db.reg.register_handler('PIZZABOX_ENC_FILE_TXT',
                                PizzaBoxEncHandlerTxt,
                                overwrite=True)
        db.reg.register_handler('PIZZABOX_DI_FILE_TXT',
                                PizzaBoxDIHandlerTxt,
                                overwrite=True)

        db_analysis = Broker.named('qas-analysis')
        # Set up isstools parsers

        # TODO: fix pulses per deg
        gen_parser = xasdata.XASdataGeneric(pulses_per_deg, db, db_analysis)
        xia_parser = xiaparser.xiaparser()

        self.gen_parser = gen_parser
        self.xia_parser = xia_parser
        self.db = db
        self.md = {}
        self.root_path = Path(beamline_gpfs_path)
        self.user_data_path = Path(beamline_gpfs_path) / Path('users')
        self.xia_data_path = Path(beamline_gpfs_path) / Path('xia_files')
        self.uid = pwd.getpwnam(username).pw_uid
        self.gid = grp.getgrnam(username).gr_gid

        # TODO : move this in a separate function? (Julien)
        #context = zmq.Context()
        #self.sender = context.socket(zmq.PUSH)
        self.publisher = kafka.KafkaProducer(
            bootstrap_servers=bootstrap_servers)
        self.topic = topic

        # by default we send to srv2
        self.logger.info("Sending request to server")
Exemplo n.º 2
0
    def __init__(self,
                 dbname,
                 beamline_gpfs_path,
                 username,
                 pulses_per_deg=360000,
                 mono_name='hhm_theta',
                 topic="iss-analysis",
                 bootstrap_servers=['cmb01:9092', 'cmb02:9092'],
                 *args,
                 **kwargs):
        # these can't be pickled
        self.logger = get_logger()
        self.logger.info("Begin scan processor")
        db = Broker.named(dbname)
        db_analysis = Broker.named('iss-analysis')
        # Set up isstools parsers

        # TODO: fix pulses per deg
        gen_parser = xasdata.XASdataGeneric(pulses_per_deg,
                                            db,
                                            db_analysis,
                                            mono_name=mono_name)
        xia_parser = xiaparser.xiaparser()

        self.gen_parser = gen_parser
        self.xia_parser = xia_parser
        self.db = db
        self.md = {}
        self.root_path = Path(beamline_gpfs_path)
        self.user_data_path = Path(beamline_gpfs_path) / Path('User Data')
        self.xia_data_path = Path(beamline_gpfs_path) / Path('xia_files')
        # TODO : fix string creation
        self.logger.debug("setting xia path: {}".format(self.xia_data_path))
        self.logger.debug("setting user data path: {}".format(
            self.user_data_path))
        self.uid = pwd.getpwnam(username).pw_uid
        self.gid = grp.getgrnam(username).gr_gid

        # TODO : move this in a separate function? (Julien)
        #context = zmq.Context()
        #self.sender = context.socket(zmq.PUSH)
        self.publisher = kafka.KafkaProducer(
            bootstrap_servers=bootstrap_servers)
        self.topic = topic

        # by default we send to srv2
        self.logger.info("Sending request to server")
Exemplo n.º 3
0
    def __init__(self,
                 plan_funcs,
                 db,
                 shutters,
                 adc_list,
                 enc_list,
                 xia,
                 html_log_func,
                 parent_gui,
                 *args, **kwargs):

        super().__init__(*args, **kwargs)
        self.setupUi(self)
        self.addCanvas()

        self.plan_funcs = plan_funcs
        self.plan_funcs_names = [plan.__name__ for plan in plan_funcs]
        self.db = db
        if self.db is None:
            self.run_start.setEnabled(False)

        self.shutters = shutters
        self.adc_list = adc_list
        self.enc_list = enc_list
        self.xia = xia
        self.html_log_func = html_log_func
        self.parent_gui = parent_gui

        self.filepaths = []
        self.xia_parser = xiaparser.xiaparser()

        self.run_type.addItems(self.plan_funcs_names)
        self.run_start.clicked.connect(self.run_scan)

        self.pushButton_scantype_help.clicked.connect(self.show_scan_help)

        self.run_type.currentIndexChanged.connect(self.populateParams)

        # List with uids of scans created in the "run" mode:
        self.run_mode_uids = []

        self.params1 = []
        self.params2 = []
        self.params3 = []
        if len(self.plan_funcs) != 0:
            self.populateParams(0)
        snapshots_path = log_path / Path('snapshots')
        ProcessingRequester.create_dir(snapshots_path)

        return user_data_path

    def get_new_filepath(filepath):
        if op.exists(Path(filepath)):
            if filepath[-5:] == '.hdf5':
                filepath = filepath[:-5]
            iterator = 2

            while True:
                new_filepath = f'{filepath}-{iterator}.hdf5'
                if not op.isfile(new_filepath):
                    return new_filepath
                iterator += 1
        return filepath

    def create_dir(path):
        if not op.exists(path):
            os.makedirs(path)
            call(['setfacl', '-m', 'g:iss-staff:rwx', path])
            call(['chmod', '770', path])


gen_parser = xasdata.XASdataGeneric(hhm.pulses_per_deg, db, db_analysis)
xia_parser = xiaparser.xiaparser()

processor = ProcessingRequester(db, sender)
#processor_subscribe_id = RE.subscribe(processor)
Exemplo n.º 5
0
    def __init__(self,
                 xia_list=[],
                 *args, **kwargs):

        super().__init__(*args, **kwargs)
        self.setupUi(self)
        self.addCanvas()

        self.xia_list = xia_list
        self.xia_parser = xiaparser.xiaparser()
        self.xia_graphs_names = []
        self.xia_graphs_labels = []
        self.xia_handles = []



        self.xia = self.xia_list[0]
        self.xia_channels = [int(mca.split('mca')[1]) for mca in self.xia.read_attrs]
        self.xia_tog_channels = []

        self.xia.mca_max_energy.subscribe(self.update_xia_params)
        self.xia.real_time.subscribe(self.update_xia_params)
        self.xia.real_time_rb.subscribe(self.update_xia_params)
        self.edit_xia_acq_time.returnPressed.connect(self.update_xia_acqtime_pv)
        self.edit_xia_energy_range.returnPressed.connect(self.update_xia_energyrange_pv)
        self.push_gain_matching.clicked.connect(self.run_gain_matching)

        self.push_run_xia_measurement.clicked.connect(self.update_xia_rois)
        self.push_run_xia_measurement.clicked.connect(self.start_xia_spectra)
        if self.xia.connected:
            max_en = self.xia.mca_max_energy.value
            energies = np.linspace(0, max_en, 2048)
    
            self.roi_colors = []
            for mult in range(4):
                self.roi_colors.append((.4 + (.2 * mult), 0, 0))
                self.roi_colors.append((0, .4 + (.2 * mult), 0))
                self.roi_colors.append((0, 0, .4 + (.2 * mult)))
    
            for roi in range(12):
                low = getattr(self.xia, "mca1.roi{}".format(roi)).low.value
                high = getattr(self.xia, "mca1.roi{}".format(roi)).high.value
                if low > 0:
                    getattr(self, 'edit_roi_from_{}'.format(roi)).setText('{:.0f}'.format(
                        np.floor(energies[getattr(self.xia, "mca1.roi{}".format(roi)).low.value] * 1000)))
                else:
                    getattr(self, 'edit_roi_from_{}'.format(roi)).setText('{:.0f}'.format(low))
                if high > 0:
                    getattr(self, 'edit_roi_to_{}'.format(roi)).setText('{:.0f}'.format(
                        np.floor(energies[getattr(self.xia, "mca1.roi{}".format(roi)).high.value] * 1000)))
                else:
                    getattr(self, 'edit_roi_to_{}'.format(roi)).setText('{:.0f}'.format(high))
    
                label = getattr(self.xia, "mca1.roi{}".format(roi)).label.value
                getattr(self, 'edit_roi_name_{}'.format(roi)).setText(label)
    
                getattr(self, 'edit_roi_from_{}'.format(roi)).returnPressed.connect(self.update_xia_rois)
                getattr(self, 'edit_roi_to_{}'.format(roi)).returnPressed.connect(self.update_xia_rois)
                getattr(self, 'edit_roi_name_{}'.format(roi)).returnPressed.connect(self.update_xia_rois)
    
    
            for channel in self.xia_channels:
                getattr(self, "checkBox_gm_ch{}".format(channel)).setEnabled(True)
                getattr(self.xia, "mca{}".format(channel)).array.subscribe(self.update_xia_graph)
                getattr(self, "checkBox_gm_ch{}".format(channel)).toggled.connect(self.toggle_xia_checkbox)
            self.push_checkall_xia.clicked.connect(self.toggle_xia_all)
    
            if hasattr(self.xia, 'input_trigger'):
                if self.xia.input_trigger is not None:
                    self.xia.input_trigger.unit_sel.put(1)  # ms, not us
Exemplo n.º 6
0
# Set up a Broker.
from databroker import Broker
db = Broker.named('iss')
db_analysis = Broker.named('iss-analysis')

from databroker.assets.handlers_base import HandlerBase

# Set up isstools parsers
from isstools.xiaparser import xiaparser
from isstools.xasdata import xasdata
gen_parser = xasdata.XASdataGeneric(360000, db, db_analysis)
xia_parser = xiaparser.xiaparser()

# Import other stuff
import socket
from pathlib import Path
import os
import os.path as op
from subprocess import call
import json
import pickle
import pandas as pd
import numpy as np
import pwd
import grp

# Set up zeromq sockets
import zmq
context = zmq.Context()
machine_name = socket.gethostname()