示例#1
0
def get_navigation_sliders_group(obj):
    """Raises a windows with sliders to control the index of DataAxis

    Parameters
    ----------
    obj : list of DataAxis instances

    """
    axis_group_args = []
    context = {}

    def get_axis_label(axis):
        return (axis.name if axis.name != t.Undefined
                else f"Axis {axis.index_in_axes_manager}")

    for i, axis in enumerate(obj):
        axis_group_args.append(tui.Item(f'axis{i}.value',
                                        label=get_axis_label(axis),
                                        editor=tui.RangeEditor(
                                                low_name=f'axis{i}.low_value',
                                                high_name=f'axis{i}.high_value',
                                                label_width=28,
                                                format='%i',
                                                mode='auto')))
        context[f'axis{i}'] = axis

    axis_group = tui.Group(*axis_group_args,
                           show_border=False,)

    return axis_group, context
示例#2
0
def get_axis_group(n, navigate, label='', attribs=[], **kwargs):
    group_args = [
        tui.Item(f'axis{n}.name'),
        tui.Item(f'axis{n}.size', style='readonly'),
        tui.Item(f'axis{n}.index_in_array', style='readonly'),
        tui.Item(f'axis{n}.low_index', style='readonly'),
        tui.Item(f'axis{n}.high_index', style='readonly'),
        tui.Item(f'axis{n}.units'),
    ]
    cal_args = [ ]
    if 'is_binned' in attribs:
        group_args.append(tui.Item(f'axis{n}.is_binned'))
    if navigate:
        group_args.extend([
            tui.Item(f'axis{n}.index', editor=tui.RangeEditor(
                                                low_name=f'axis{n}.low_index',
                                                high_name=f'axis{n}.high_index',
                                                label_width=28,
                                                format_str='%i',
                                                mode='auto')),
            tui.Item(f'axis{n}.value', style='readonly', format_str='%5g'), ])
    if 'scale' in attribs:
        cal_args.extend([
            tui.Item(f'axis{n}.scale'),
            tui.Item(f'axis{n}.offset'), ])
    if '_expression' in attribs:
        cal_args.extend([
            tui.Item(f'axis{n}._expression', style='readonly'), ])
        for j in range(len(kwargs['parameters_list'])):
            p = kwargs['parameters_list'][j]
            cal_args.extend([
                tui.Item(f'axis{n}.{p}', label=p), ])
        if 'xscale' in kwargs.keys():
            cal_args.extend([
                tui.Item(f'axis{n}.x.scale', label='x scale'),
                tui.Item(f'axis{n}.x.offset', label='x offset'), ])

    if cal_args == [ ]:
        group = tui.Group(
            tui.Group(*group_args,
                      show_border=True,),
            label=label,
            show_border=True,)
    else:
        group = tui.Group(
            tui.Group(*group_args,
                      show_border=True,),
            tui.Group(*cal_args,
                      label='Calibration', show_border=True, ),
            label=label,
            show_border=True,)
    return group
示例#3
0
class SavGolFilter(Filter):
    order = tr.Range(1, 10)
    window_size = tr.Int(5)

    @tr.on_trait_change('order, window_size')
    def update(self):
        ws = (self.window_size / 2) * 2 + 1
        y = self.d[:, self.chan]
        self.yf = dv.savitzky_golay(y, ws, self.order)
        self.replot = True

    range_edit = ui.RangeEditor(low_name='order', high=51)
    view_window_size = ui.Item('window_size', editor=range_edit)
    traits_view = ui.View(['order', view_window_size])
示例#4
0
class FilterTool(tr.HasTraits):
    data = tr.Array
    max_chans = tr.Int
    t = tr.Array
    channel = tr.Int
    filter_type = tr.Enum(filter_dict.keys())
    filter = tr.Instance(Filter)
    _ds = tr.Instance(ch.ArrayPlotData)
    _plot = tr.Instance(ch.Plot)

    def _max_chans_default(self):
        return int(self.data.shape[1] - 1)

    def _filter_default(self):
        return SvdFilter(t=self.t, d=self.data)

    def __ds_default(self):
        return ch.ArrayPlotData(t=self.t,
                                y=self.data[:, self.channel],
                                yf=self.filter.yf)

    def __plot_default(self):
        pl = ch.Plot(self._ds)
        pl.plot(('t', 'y'), color='black')
        pl.plot(('t', 'yf'), color='red', line_width=1.2)
        return pl

    @tr.on_trait_change('filter.replot')
    def replot(self):
        self._ds.set_data('yf', self.filter.yf)

    def _channel_changed(self):
        self._ds.set_data('y', self.data[:, self.channel])
        self.filter.chan = int(self.channel)
        self.replot()

    def _filter_type_changed(self, value):
        self.filter = filter_dict[value](t=self.t, d=self.data)

    plot_item = ui.Item('_plot', editor=en.ComponentEditor(), show_label=False)

    ch_item = ui.Item('channel',
                      editor=ui.RangeEditor(low=0,
                                            high_name='max_chans',
                                            is_float=False))
    settings_group = ui.VGroup([ch_item, 'filter_type', '@filter'])

    traits_view = ui.View(ui.HGroup([plot_item, settings_group]))
 def edit_traits(self, comp, buttons=True):
     try:
         items = [tu.Item('name'), tu.Item('active')]
         for p in comp.parameters:
             name = '.'.join(('object', p.name))
             p_label = p.name.replace('_', ' ').capitalize()
             vi = tu.Item(name + '.value',
                          label=p_label,
                          editor=tu.RangeEditor(low_name=name + '.bmin',
                                                high_name=name + '.bmax'))
             items.extend((vi, tu.Item(name + '.free')))
         view = tu.View(*items,
                        handler=ComponentEditorHandler(),
                        buttons=tu.OKCancelButtons if buttons else [],
                        default_button=tu.OKButton,
                        kind='live',
                        resizable=True)
         comp.edit_traits(view=view)
     except AttributeError:
         pass
示例#6
0
def create_model_plot(sources, handler=None, metadata=None):
    """Create the plot window

    Parameters
    ----------

    """
    if not isinstance(sources, (list)):
        stop("*** error: sources must be list of files")

    def genrunid(path):
        return os.path.splitext(os.path.basename(path))[0]

    if metadata is not None:
        stop("*** error: call create_view directly")
        metadata.plot.configure_traits(view=view)
        return

    if [source for source in sources if F_EVALDB in os.path.basename(source)]:
        if len(sources) > 1:
            stop(
                "*** error: only one source allowed with {0}".format(F_EVALDB))
        source = sources[0]
        if not os.path.isfile(source):
            stop("*** error: {0}: no such file".format(source))
        filepaths, variables = readtabular(source)
        runid = genrunid(filepaths[0])

    else:
        filepaths = []
        for source in sources:
            if not os.path.isfile(source):
                logerr("{0}: {1}: no such file".format(iam, source))
                continue
            fname, fext = os.path.splitext(source)
            if fext not in L_REC_EXT:
                logerr("{0}: unrecognized file extension".format(source))
                continue
            filepaths.append(source)
        if logerr():
            stop("***error: stopping due to previous errors")
        variables = [""] * len(filepaths)
        runid = ("Material Model Laboratory"
                 if len(filepaths) > 1 else genrunid(filepaths[0]))

    view = tuiapi.View(tuiapi.HSplit(
        tuiapi.VGroup(
            tuiapi.Item('Multi_Select', show_label=False),
            tuiapi.Item('Change_Axis', show_label=False),
            tuiapi.Item('Reset_Zoom', show_label=False),
            tuiapi.Item('Reload_Data', show_label=False),
            tuiapi.Item('Print_to_PDF', show_label=False),
            tuiapi.VGroup(tuiapi.HGroup(
                tuiapi.Item("X_Scale",
                            label="X Scale",
                            editor=tuiapi.TextEditor(multi_line=False)),
                tuiapi.Item("Y_Scale",
                            label="Y Scale",
                            editor=tuiapi.TextEditor(multi_line=False))),
                          show_border=True),
            tuiapi.VGroup(tuiapi.HGroup(
                tuiapi.Item('Load_Overlay', show_label=False, springy=True),
                tuiapi.Item('Close_Overlay', show_label=False, springy=True),
            ),
                          tuiapi.Item('Single_Select_Overlay_Files',
                                      show_label=False,
                                      resizable=False),
                          show_border=True)),
        tuiapi.VGroup(
            tuiapi.Item('Plot_Data',
                        show_label=False,
                        width=800,
                        height=568,
                        springy=True,
                        resizable=True),
            tuiapi.Item('Step',
                        editor=tuiapi.RangeEditor(low_name='low_step',
                                                  high_name='high_step',
                                                  format='%d',
                                                  label_width=28,
                                                  mode='slider')),
        )),
                       style='custom',
                       width=1124,
                       height=868,
                       resizable=True,
                       title=runid)

    main_window = ModelPlot(filepaths=filepaths, file_variables=variables)
    main_window.configure_traits(view=view, handler=handler)
    return main_window
示例#7
0
def image_constast_editor_traitsui(obj, **kwargs):
    from traitsui.qt4.extra.bounds_editor import BoundsEditor

    # format has been deprecated in Release 7.3.0, replaced by format_str
    # https://github.com/enthought/traitsui/pull/1684
    # Remove and simplify when minimum traitsui version is 7.3.0
    FORMAT_STR = 'format' if Version(traitsui.__version__) < Version('7.0.0') \
        else 'format_str'

    def get_format_dict(formatting):
        return {FORMAT_STR: formatting}

    view = tu.View(tu.Group(tu.Item(
        'ss_left_value',
        label='Min',
        show_label=True,
        style='readonly',
        format_str='%5g',
    ),
                            tu.Item(
                                'ss_right_value',
                                label='Max',
                                show_label=True,
                                style='readonly',
                                format_str='%5g',
                            ),
                            show_border=True),
                   tu.Group(
                       tu.Item(
                           'auto',
                           label='Auto',
                           show_label=True,
                       ),
                       tu.Item('vmin_percentile',
                               label='vmin/vmax percentile',
                               editor=BoundsEditor(
                                   low_name='vmin_percentile',
                                   high_name='vmax_percentile',
                                   **get_format_dict('%.2f'),
                               )),
                       show_border=True,
                   ),
                   tu.Group(
                       tu.Item(
                           'bins',
                           label='Bins',
                           show_label=True,
                       ),
                       tu.Item(
                           'norm',
                           label='Norm',
                           show_label=True,
                       ),
                       tu.Item(
                           'gamma',
                           label='Gamma',
                           show_label=True,
                           visible_when='norm == "Power"',
                           editor=tu.RangeEditor(
                               low=0.1,
                               high=3.,
                               mode="slider",
                               **get_format_dict('%.2f'),
                           ),
                       ),
                       tu.Item(
                           'linthresh',
                           label='Linear threshold',
                           show_label=True,
                           visible_when='norm == "Symlog"',
                           editor=tu.RangeEditor(
                               low=0.01,
                               high=1.,
                               mode="slider",
                               **get_format_dict('%.2f'),
                           ),
                       ),
                       tu.Item(
                           'linscale',
                           label='Linear scale',
                           show_label=True,
                           visible_when='norm == "Symlog"',
                           editor=tu.RangeEditor(
                               low=0.,
                               high=10.,
                               mode="slider",
                               **get_format_dict('%.2f'),
                           ),
                       ),
                       show_border=True,
                   ),
                   tu.Item('_'),
                   handler=ImageContrastHandler,
                   buttons=[
                       OKButton,
                       HelpButton,
                       OurApplyButton,
                       OurResetButton,
                   ],
                   title='Constrast adjustment tool',
                   resizable=True)
    return obj, {"view": view}
示例#8
0
    plot = IndDiffEVLinePlot(res.expl_var_y, title='Explained variance in Y')
    return plot


no_view = _traitsui.View()


prefmap_view = _traitsui.View(
    _traitsui.Item('int_ext_mapping', style='custom', label='Mapping'),
    _traitsui.Item('prefmap_method', style='custom', label='Method'),
    _traitsui.Item('standardise_x', label='Standardise X',
                   style='custom', show_label=True),
    _traitsui.Item('standardise_y', label='Standardise Y',
                   style='custom', show_label=True),
    _traitsui.Item('calc_n_pc',
                   editor=_traitsui.RangeEditor(
                       low_name='min_pc', high_name='max_pc', mode='auto'),
                   style='simple',
                   label='PC to calc:'),
    title='Prefmap settings',
)


prefmap_nodes = [
    _traitsui.TreeNode(
        node_for=[PrefmapController],
        label='name',
        children='',
        view=prefmap_view,
        menu=[]),
    _traitsui.TreeNode(
        node_for=[PrefmapController],
示例#9
0
def image_constast_editor_traitsui(obj, **kwargs):
    from traitsui.qt4.extra.bounds_editor import BoundsEditor

    view = tu.View(tu.Group(tu.Item(
        'ss_left_value',
        label='Min',
        show_label=True,
        style='readonly',
        format_str='%5g',
    ),
                            tu.Item(
                                'ss_right_value',
                                label='Max',
                                show_label=True,
                                style='readonly',
                                format_str='%5g',
                            ),
                            show_border=True),
                   tu.Group(
                       tu.Item(
                           'auto',
                           label='Auto',
                           show_label=True,
                       ),
                       tu.Item('vmin_percentile',
                               label='vmin/vmax percentile',
                               editor=BoundsEditor(low_name='vmin_percentile',
                                                   high_name='vmax_percentile',
                                                   format='%.2f')),
                       show_border=True,
                   ),
                   tu.Group(
                       tu.Item(
                           'bins',
                           label='Bins',
                           show_label=True,
                       ),
                       tu.Item(
                           'norm',
                           label='Norm',
                           show_label=True,
                       ),
                       tu.Item(
                           'gamma',
                           label='Gamma',
                           show_label=True,
                           visible_when='norm == "Power"',
                           editor=tu.RangeEditor(low=0.1,
                                                 high=3.,
                                                 format='%.3f',
                                                 mode="slider"),
                       ),
                       tu.Item(
                           'linthresh',
                           label='Linear threshold',
                           show_label=True,
                           visible_when='norm == "Symlog"',
                           editor=tu.RangeEditor(low=0.01,
                                                 high=1.,
                                                 format='%.3f',
                                                 mode="slider"),
                       ),
                       tu.Item(
                           'linscale',
                           label='Linear scale',
                           show_label=True,
                           visible_when='norm == "Symlog"',
                           editor=tu.RangeEditor(low=0.,
                                                 high=10.,
                                                 format='%.3f',
                                                 mode="slider"),
                       ),
                       show_border=True,
                   ),
                   tu.Item('_'),
                   handler=ImageContrastHandler,
                   buttons=[
                       OKButton,
                       HelpButton,
                       OurApplyButton,
                       OurResetButton,
                   ],
                   title='Constrast adjustment tool',
                   resizable=True)
    return obj, {"view": view}