Пример #1
0
class TfComparer(Tool):
    name = "TfComparer"
    description = "Compare between two TargetCalib TFs."

    tf1_path = Unicode("", help="Path to the first tf file.").tag(config=True)
    tf2_path = Unicode("", help="Path to the second tf file.").tag(config=True)

    aliases = Dict(dict(
        tf1='TfComparer.tf1_path',
        tf2='TfComparer.tf2_path',
    ))
    classes = List([])

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.tfa1 = None
        self.tfa2 = None

    def setup(self):
        self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]"
        kwargs = dict(config=self.config, tool=self)

        self.tfa1 = TFApplier(**kwargs, tf_path=self.tf1_path)
        self.tfa2 = TFApplier(**kwargs, tf_path=self.tf2_path)

    def start(self):
        tf1 = self.tfa1.get_tf()[0]
        tf2 = self.tfa2.get_tf()[0]

        assert np.allclose(tf1, tf2)

    def finish(self):
        pass
Пример #2
0
    def setup(self):
        self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]"
        kwargs = dict(config=self.config, tool=self)

        self.tf = TFApplier(**kwargs)

        script = "plot_tf"
        self.p_tf = TFPlotter(**kwargs, shape="wide")
Пример #3
0
    def setup(self):
        self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]"
        kwargs = dict(config=self.config, tool=self)

        if (self.tfinput_path is None) != (self.vped_path is None):
            self.log.warn("Both tf_input and vped need to be supplied to "
                          "view the input TF array")

        self.tf = TFApplier(**kwargs)
        self.p_tfspread = TFSpread(**kwargs)
        self.p_tfselect = TFSelector(**kwargs)
        if self.tfinput_path and self.vped_path:
            self.p_tfinputspread = TFInputSpread(**kwargs)
            self.p_tfinputselect = TFInputSelector(**kwargs)
Пример #4
0
class PedestalBuilder(Tool):
    name = "PedestalBuilder"
    description = "Create the TargetCalib Pedestal file from waveforms"

    aliases = Dict(dict(tf='TFApplier.tf_path',
                        ))
    classes = List([TFApplier
                    ])

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.tf = None

        self.p_tf = None

    def setup(self):
        self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]"
        kwargs = dict(config=self.config, tool=self)

        self.tf = TFApplier(**kwargs)

        script = "plot_tf"
        self.p_tf = TFPlotter(**kwargs, shape="wide")

    def start(self):

        # Get TF
        tf, adc_min, adc_step = self.tf.get_tf()
        tf = np.array(tf)

        tm = 0
        tmpix = 0
        cell = 0

        self.p_tf.create(tf, adc_min, adc_step, tm, tmpix, cell)

    def finish(self):
        output_dir = join(dirname(self.tf.tf_path), "plot_tf")

        output_path = join(output_dir, "tf.pdf")
        self.p_tf.save(output_path)
Пример #5
0
class TargetCalibTFExplorer(Tool):
    name = "TargetCalibTFExplorer"
    description = "Plot the TargetCalib transfer function using bokeh"

    tfinput_path = Unicode(None,
                           allow_none=True,
                           help='Path to a numpy file containing the input '
                           'TF array').tag(config=True)
    vped_path = Unicode(None,
                        allow_none=True,
                        help='Path to a numpy file containing the vped '
                        'vector').tag(config=True)

    aliases = Dict(
        dict(
            tf='TFApplier.tf_path',
            tf_input='TargetCalibTFExplorer.tfinput_path',
            vped='TargetCalibTFExplorer.vped_path',
            # o='TargetCalibTFExplorer.output_dir'
        ))
    classes = List([TFApplier])

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.tf = None

        self.p_tfspread = None
        self.p_tfselect = None
        self.p_tfinputspread = None
        self.p_tfinputselect = None

        self.layout = None

    def setup(self):
        self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]"
        kwargs = dict(config=self.config, tool=self)

        if (self.tfinput_path is None) != (self.vped_path is None):
            self.log.warn("Both tf_input and vped need to be supplied to "
                          "view the input TF array")

        self.tf = TFApplier(**kwargs)
        self.p_tfspread = TFSpread(**kwargs)
        self.p_tfselect = TFSelector(**kwargs)
        if self.tfinput_path and self.vped_path:
            self.p_tfinputspread = TFInputSpread(**kwargs)
            self.p_tfinputselect = TFInputSelector(**kwargs)

    def start(self):
        # Get TF
        tf, adc_min, adc_step = self.tf.get_tf()

        # Get TF Input
        tf_input = None
        vped = None
        if self.tfinput_path and self.vped_path:
            self.log.info("Loading TF input array file: {}".format(
                self.tfinput_path))
            tf_input = np.load(self.tfinput_path)
            self.log.info("Loading Vped vector file: {}".format(
                self.vped_path))
            vped = np.load(self.vped_path)

        # # Dimensions
        # n_tm = tf.shape[0]
        # n_tmpix = tf.shape[1]
        # n_cells = tf.shape[2]
        # n_points = tf.shape[3]

        # # Convert tm and tmpix to pixel
        # tf_pix = np.empty((n_tm * n_tmpix, n_cells, n_points))
        # tm_str = []
        # for tm in range(n_tm):
        #     tm_str.append('{:.0f}'.format(tm))
        #     for tmpix in range(n_tmpix):
        #         pix = pixels.convert_tm_tmpix_to_pix(tm, tmpix)
        #         tf_pix[pix] = tf[tm, tmpix]

        # Create bokeh figures
        self.p_tfspread.create(tf, adc_min, adc_step)
        self.p_tfselect.create(tf, adc_min, adc_step)
        if tf_input is not None and vped is not None:
            self.p_tfinputspread.create(tf_input, vped)
            self.p_tfinputselect.create(tf_input, vped)

        # Get bokeh layouts
        l_tfspread = self.p_tfspread.layout
        l_tfselect = self.p_tfselect.layout
        l_tfinputspread = None
        l_tfinputselect = None
        if self.p_tfinputspread:
            l_tfinputspread = self.p_tfinputspread.layout
            l_tfinputselect = self.p_tfinputselect.layout

        # Get widgets

        # Layout
        layout_list = [[l_tfspread], [l_tfselect]]
        if l_tfinputspread:
            layout_list.append([l_tfinputspread])
        if l_tfinputselect:
            layout_list.append([l_tfinputselect])
        self.layout = layout(layout_list, sizing_mode="scale_width")

    def finish(self):
        fig_dir = join(dirname(self.tf.tf_path), "plot_tf")
        if not exists(fig_dir):
            self.log.info("Creating directory: {}".format(fig_dir))
            makedirs(fig_dir)

        path = join(fig_dir, 'tf.html')
        output_file(path)
        show(self.layout)
        self.log.info("Created bokeh figure: {}".format(path))

        curdoc().add_root(self.layout)
        curdoc().title = "Transfer Function"
Пример #6
0
    def setup(self):
        self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]"
        kwargs = dict(config=self.config, tool=self)

        self.tfa1 = TFApplier(**kwargs, tf_path=self.tf1_path)
        self.tfa2 = TFApplier(**kwargs, tf_path=self.tf2_path)
Пример #7
0
class PedestalBuilder(Tool):
    name = "PedestalBuilder"
    description = "Create the TargetCalib Pedestal file from waveforms"

    aliases = Dict(dict(tf='TFApplier.tf_path',
                        ))
    classes = List([TFApplier
                    ])

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.tf = None

        self.p_tf = None

    def setup(self):
        self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]"
        kwargs = dict(config=self.config, tool=self)

        self.tf = TFApplier(**kwargs)

        script = "plot_tf"
        self.p_tf = TFPlotter(**kwargs, shape="wide")
        self.p_low2dpix = TFLow2DPlotter(**kwargs, shape="wide")
        self.p_low2dpixgrad = TFLow2DPlotter(**kwargs, shape="wide")
        self.p_low2dcell = TFLow2DPlotter(**kwargs, shape="wide")
        self.p_low2dcellgrad = TFLow2DPlotter(**kwargs, shape="wide")

    def start(self):

        # Get TF
        tf, adc_min, adc_step = self.tf.get_tf()
        tf = np.array(tf)

        # Get TF Applied
        x_app = np.linspace(-500, 3500, 1000, dtype=np.float32)
        tf_app = np.zeros([*tf.shape[:3], x_app.size], dtype=np.float32)
        for tm in range(tf.shape[0]):
            for tmpix in range(tf.shape[1]):
                for cell in range(tf.shape[2]):
                    bp, r, c = get_bp_r_c(cell)
                    y_i = tf_app[tm, tmpix, cell]
                    self.tf.calibrator.ApplyArray(x_app, y_i, tm, tmpix, 0, cell)

        tm = 0
        tmpix = 0
        cell = 2

        self.p_tf.create(tf, adc_min, adc_step, tm, tmpix, cell)

        tf_pixmean = np.mean(tf_app, axis=2)
        x_range = [0, 200]
        y_range = [-10, 130]
        x_label = "ADC"
        y_label = "Amplitude (mV)"
        self.p_low2dpix.create(tf_pixmean, x_app, x_range, y_range, x_label, y_label)

        grad = np.gradient(tf_pixmean, x_app, axis=-1)
        x_range = [0, 200]
        y_range = [0, 1.6]
        x_label = "ADC"
        y_label = "TF Slope"
        self.p_low2dpixgrad.create(grad, x_app, x_range, y_range, x_label, y_label)

        tf_pix = tf_app[tm, tmpix]
        x_range = [0, 200]
        y_range = [-10, 130]
        x_label = "ADC"
        y_label = "Amplitude (mV)"
        self.p_low2dcell.create(tf_pix, x_app, x_range, y_range, x_label, y_label)

        grad = np.gradient(tf_pix, x_app, axis=-1)
        x_range = [0, 200]
        y_range = [0, 1.6]
        x_label = "ADC"
        y_label = "TF Slope"
        self.p_low2dcellgrad.create(grad, x_app, x_range, y_range, x_label, y_label)

    def finish(self):
        output_dir = join(dirname(self.tf.tf_path), "plot_tf")

        self.p_tf.save(join(output_dir, "tf.pdf"))
        self.p_low2dpix.save(join(output_dir, "low2dpix.pdf"))
        self.p_low2dpixgrad.save(join(output_dir, "low2dpixgrad.pdf"))
        self.p_low2dcell.save(join(output_dir, "low2dcell.pdf"))
        self.p_low2dcellgrad.save(join(output_dir, "low2dcellgrad.pdf"))