Ejemplo n.º 1
0
def quantity(description, min=0.001, max=1, step=0.00001, value=0.032):
    quantity_item_layout = widgets.Layout(display='flex', flex_flow='row')

    quantity_label = widgets.Label(description,
                                   layout=widgets.Layout(flex='1 1 auto',
                                                         width='auto'))
    quantity_slider = widgets.FloatSlider(readout=False,
                                          min=min,
                                          max=max,
                                          step=step,
                                          value=value,
                                          layout=widgets.Layout(
                                              flex='10 1 auto', width='auto'))

    quantity_text = widgets.BoundedFloatText(
        min=min,
        max=max,
        step=step,
        value=value,
        readout_format='.6f',
        layout=widgets.Layout(flex='1 1 auto', width='auto'))

    widgets.link((quantity_slider, 'value'), (quantity_text, 'value'))
    quantity = widgets.HBox([quantity_label, quantity_slider, quantity_text],
                            layout=widgets.Layout(display='flex',
                                                  width='100%'))
    return quantity, quantity_slider, quantity_text
Ejemplo n.º 2
0
    def _init_vectorfield_widgets(self):
        self.length_factor_wid = FloatText(description='Length factor',
                                           value=self.length_factor)
        self.width_wid = IntSlider(description='Width',
                                   min=1,
                                   max=10,
                                   value=self.width)
        self.percentage_vectors_wid = FloatSlider(
            description='Nb vectors',
            step=0.01,
            min=0.0,
            max=1.0,
            value=self.percentage_vectors,
            readout_format='.2%')
        self.distribution_wid = ToggleButtons(description='Distribution',
                                              options=['ordered', 'random'],
                                              value=self.distribution)

        # Check if it's a volumetric mesh
        block = self
        while not isinstance(block, DataBlock):
            block = block._parent_block
        if len(block.mesh.tetrahedrons) != 0:
            self.mode_wid = ToggleButtons(description='Mode',
                                          options=['volume', 'surface'],
                                          value=self.mode)

            link((self, 'mode'), (self.mode_wid, 'value'))

        link((self, 'length_factor'), (self.length_factor_wid, 'value'))
        link((self, 'width'), (self.width_wid, 'value'))
        link((self, 'percentage_vectors'),
             (self.percentage_vectors_wid, 'value'))
        link((self, 'distribution'), (self.distribution_wid, 'value'))
Ejemplo n.º 3
0
    def _init_vectorfield_widgets(self):
        self.length_factor_wid = FloatText(description='Length factor',
                                           value=self.length_factor)
        self.width_wid = IntSlider(description='Width',
                                   min=1,
                                   max=10,
                                   value=self.width)
        self.percentage_vectors_wid = FloatSlider(
            description='Nb vectors',
            step=0.01,
            min=0.0,
            max=1.0,
            value=self.percentage_vectors,
            readout_format='.2%')
        self.distribution_wid = ToggleButtons(description='Distribution',
                                              options=['ordered', 'random'],
                                              value=self.distribution)
        self.mode_wid = ToggleButtons(description='Mode',
                                      options=['volume', 'surface'],
                                      value=self.mode)

        link((self, 'length_factor'), (self.length_factor_wid, 'value'))
        link((self, 'width'), (self.width_wid, 'value'))
        link((self, 'percentage_vectors'),
             (self.percentage_vectors_wid, 'value'))
        link((self, 'distribution'), (self.distribution_wid, 'value'))
        link((self, 'mode'), (self.mode_wid, 'value'))
Ejemplo n.º 4
0
 def _axes(self, change):
     new = change['new']
     children = []
     sliders = {}
     for axis in new:
         name = axis.label
         if name in self.current:
             rec = self.current[name]
             slider = rec['slider']
             sliders[name] = rec
             del self.current[name]
         else:
             slider = UnboundedFloatSlider(value=axis.len, min=0, max=200)
             l1 = link((slider, 'value'), (axis, 'len'))
             l2 = link((axis, 'label'), (slider, 'description'))
             # axis.observe(self.update, names=['len'])
             check = Checkbox(value=False)
             l3 = link((check, 'value'), (slider, 'disabled'))
             box = HBox(children=[check, slider])
             sliders[name] = dict(slider=slider,
                                  links=[l1, l2, l3],
                                  axis=axis)
         children.append(box)
     # disconnect
     for rec in self.current.values():
         for l in rec.links:
             l.unlink()
     # set new values
     self.current = sliders
     self.children = children
Ejemplo n.º 5
0
    def create_tools(self):
        # super(Plot2dSliced, self).create_tools()
        self.z_slice_slider = widgets.IntSlider(value=self.z_slice,
                                                min=0,
                                                max=self.z_shape - 1)
        # self.add_control_widget(self.z_slice_slider)
        self.z_slice_slider.observe(self._z_slice_changed, "value")
        self.observe(self._z_slice_changed, "z_slice")

        dz = self.z_max_extreme - self.z_min_extreme

        self.z_range_slider = widgets.FloatRangeSlider(
            min=min(self.z_min, self.z_min_extreme),
            value=[self.z_min, self.z_max],
            max=max(self.z_max, self.z_max_extreme),
            step=dz / 1000)
        self.z_range_slider.observe(self._z_range_changed_, names=["value"])
        # self.observe(self.z_range_slider, "z_min")

        self.z_control = widgets.VBox(
            [self.z_slice_slider, self.z_range_slider])
        self.add_control_widget(self.z_control)

        if self.controls_selection:
            self.widget_z_select = widgets.Checkbox(
                description='select z range', value=self.z_select)
            widgets.link((self, 'z_select'), (self.widget_z_select, 'value'))
            self.add_control_widget(self.widget_z_select)
Ejemplo n.º 6
0
def wi2():
    style = {'description_width': 'initial'}
    #Interface configuration
    w42 = wi.FloatSlider(value = 0.05, min = 0, max = 1, step = 0.05, 
                         description='Plateau/maximum intensity [%]:')
    w43 = wi.IntSlider(value = 0.1, min = 0, max = 3000, step = 100, description='Onset [ms]:')
    w44 = wi.IntSlider(value = 0.1, min = 0, max = 6000, step = 100, description='Plateau on [ms]:')
    w45 = wi.IntSlider(value = 6000, min = 0, max = 6000, step = 100, description='Plateau off [ms]:')
    w46 = wi.IntSlider(value = 6000, min = 0, max = 6000, step = 100, 
                       description='Offset [ms]:', style = style)
    w47 = wi.FloatSlider(value = 0.5, min = 0, max = 2, step = 0.1, description='Frequency [Hz]:')
    w48 = wi.IntSlider(value = 6000, min = 1000, max = 40000, step = 500, 
                       description='Duration [ms]:', style = style)
    w49 = wi.IntSlider(value = 20000, min = 15000, max = 40000, step = 1000, description='Sampling [Hz]:')
    w40 = wi.RadioButtons(options = ['Trapezoidal', 'Sinusoidal'], description = 'Modulation:', style = style)
    ui = wi.VBox([w49,w48,w42,w40,w43,w44,w45,w46,w47])
    ws = {"intensity": w42, "t0": w43, "t1": w44, "t2": w45, "t3": w46, "freq_sin": w47,
          "sample_time": w49, "sim_time": w48, "mode": w40}
    l11 = wi.link((w48, 'value'), (w44, 'max'))
    l12 = wi.link((w48, 'value'), (w45, 'max'))
    l12 = wi.link((w48, 'value'), (w46, 'max'))
    l12 = wi.link((w48, 'value'), (w43, 'max'))
    
    ui.children[0].layout = wi.Layout(width= '350px')
    for i in ui.children:
        i.layout = wi.Layout(width = '320px')
        i.style = style
        i.continuous_update = False
    return ws, ui
Ejemplo n.º 7
0
def link_islicer(*args):
    '''links islicers IntSlider widgets'''
    linked = [(widg, 'value') for widg in args]
    # link pair-wise
    pairs = [(linked[i + 1], linked[i]) for i in range(len(linked) - 1)]
    for pair in pairs:
        widgets.link(*pair)
Ejemplo n.º 8
0
    def __init__(self, options, *args, **kwargs):
        """Created a Multi-select widget

        Parameters
        ----------
        options : Sequence[str]
            The options to show in the multi-select widget.
        """

        super().__init__([])

        self.options = [str(option) for option in options]
        self.multi_select = widgets.SelectMultiple(
            options=self.options, description="Label:"
        )
        widgets.link((self, "options"), (self.multi_select, "options"))
        widgets.link((self, "value"), (self.multi_select, "value"))

        self.hints = defaultdict(widgets.Output)

        self.children = [
            self.multi_select,
            widgets.HBox(
                children=[self.hints[option] for option in self.value],
                layout=widgets.Layout(flex_flow="row wrap"),
            ),
        ]
Ejemplo n.º 9
0
        def update_quadrature_controls(change):
            new_wf_type = change['new']
            old_wf_type = change['old']
            if new_wf_type == 'Gaussian Sine' or new_wf_type == 'Gaussian Cosine':
                self.quadrature_hbox.children = self.q_gaussian_sine_cosine_controls
            elif new_wf_type == 'Gaussian' or new_wf_type == 'Gaussian Derivative':
                self.quadrature_hbox.children = self.q_gaussian_controls
            elif new_wf_type == 'Gaussian Square':
                self.quadrature_hbox.children = self.q_gaussian_square_controls
            elif new_wf_type == 'DRAG':
                self.quadrature_hbox.children = self.q_drag_controls
                self.in_phase_hbox.children, self.i_wf_dd.value = self.i_drag_controls, 'DRAG'
                self.drag_links += [
                    widgets.link((self.q_sigma_sldr, 'value'),
                                 (self.i_sigma_sldr, 'value')),
                    widgets.link((self.q_amp_sldr, 'value'),
                                 (self.i_amp_sldr, 'value')),
                ]

            if old_wf_type == 'DRAG':
                if self.drag_links is not None and len(self.drag_links) > 0:
                    for link in self.drag_links:
                        link.unlink()
                    self.drag_links = []
                    self.i_wf_dd.value = 'Gaussian'
Ejemplo n.º 10
0
    def __init__(self, flows, **kwargs):
        super().__init__(1, 3, grid_gap="10px", **kwargs)

        self._selector = ipywidgets.Select(
            layout=ipywidgets.Layout(height="100%", width="initial")
        )
        self._flow_widget = WorkflowWidget(layout=ipywidgets.Layout(flex="1 0 auto"))
        self._vg_widget = VersionGraftWidget(layout=ipywidgets.Layout(flex="1 0 auto"))

        self.flows = flows

        ipywidgets.link((self._selector, "value"), (self, "selected_id"))
        ipywidgets.link((self._flow_widget, "version"), (self, "selected_version"))
        traitlets.dlink(
            (self._selector, "value"),
            (self._flow_widget, "flow"),
            transform=lambda flow_id: self._flows_lookup.get(flow_id, None),
        )
        traitlets.dlink((self._flow_widget, "current_vg"), (self._vg_widget, "vg"))

        self._flow_widget.observe(
            lambda change: self.set_trait("current_flow", change["new"]), names="flow"
        )
        self._flow_widget.observe(
            lambda change: self.set_trait("current_vg", change["new"]),
            names="current_vg",
        )

        self[0, 0] = ipywidgets.VBox(
            children=[ipywidgets.HTML("<h2>Workflows</h2>"), self._selector],
            layout=ipywidgets.Layout(flex="1 0 auto"),
        )

        self[0, 1] = self._flow_widget
        self[0, 2] = self._vg_widget
Ejemplo n.º 11
0
    def _init_colormapping_widgets(self):
        self.colormap_wid = Dropdown(
            description='Colormap',
            options=['viridis', 'plasma', 'magma', 'inferno'],
            value=self.colormap
        )
        self.colormap_wid.layout.width = 'fit-content'

        min, max = self._get_component_min_max(
            self.input_data, self.input_components[0])

        self.colormapslider_wid = FloatRangeSlider(
            value=[self.colormap_min, self.colormap_max],
            min=min,
            max=max,
            description="Colormap bounds"
        )

        def on_range_change(change):
            self.colormap_min = change['new'][0]
            self.colormap_max = change['new'][1]

        self.colormapslider_wid.observe(on_range_change, 'value')

        link((self.colormap_wid, 'value'), (self, 'colormap'))
Ejemplo n.º 12
0
    def create_widgets(self):
        widget_visible = widgets.Checkbox(description='visible',
                                          value=self.state.visible)
        link((self.state, 'visible'), (widget_visible, 'value'))
        link((self.state, 'visible'), (self.scatter.material, 'visible'))

        self.widget_marker = widgets.ToggleButtons(
            options=['sphere', 'box', 'diamond'])
        widgets.link((self.scatter, 'geo'), (self.widget_marker, 'value'))

        self.widget_size = glue_jupyter.widgets.Size(state=self.state)
        self.widget_color = glue_jupyter.widgets.Color(state=self.state)

        # vector/quivers
        self.widget_vector = widgets.Checkbox(description='show vectors',
                                              value=self.state.vector_visible)

        helper = self.state.vx_att_helper
        self.widget_vector_x = widgets.Dropdown(
            options=[k.label for k in helper.choices],
            value=self.state.vx_att,
            description='vx')
        link_component_id_to_select_widget(self.state, 'vx_att',
                                           self.widget_vector_x)

        helper = self.state.vy_att_helper
        self.widget_vector_y = widgets.Dropdown(
            options=[k.label for k in helper.choices],
            value=self.state.vy_att,
            description='vy')
        link_component_id_to_select_widget(self.state, 'vy_att',
                                           self.widget_vector_y)

        helper = self.state.vz_att_helper
        self.widget_vector_z = widgets.Dropdown(
            options=[k.label for k in helper.choices],
            value=self.state.vz_att,
            description='vz')
        link_component_id_to_select_widget(self.state, 'vz_att',
                                           self.widget_vector_z)

        on_change([(self.state, 'vector_visible', 'vx_att', 'vy_att', 'vz_att')
                   ])(self._update_quiver)
        link((self.state, 'vector_visible'), (self.widget_vector, 'value'))
        link((self.state, 'vector_visible'), (self.quiver, 'visible'))
        dlink((self.widget_vector, 'value'),
              (self.widget_vector_x.layout, 'display'), lambda value: None
              if value else 'none')
        dlink((self.widget_vector, 'value'),
              (self.widget_vector_y.layout, 'display'), lambda value: None
              if value else 'none')
        dlink((self.widget_vector, 'value'),
              (self.widget_vector_z.layout, 'display'), lambda value: None
              if value else 'none')

        return widgets.VBox([
            widget_visible, self.widget_marker, self.widget_size,
            self.widget_color, self.widget_vector, self.widget_vector_x,
            self.widget_vector_y, self.widget_vector_z
        ])
Ejemplo n.º 13
0
    def __init__(
        self,
        classes=["MISC", "PER", "LOC", "ORG"],
        text="Lorem ipsum",
        data=[],
        button_width="5em",
        snap_to_word_boundary=True,
    ):
        """A tagging widget to annotate tokens inside text.

        Parameters
        ----------
        classes : list, optional
            The classes of entities to annotate, by default
            ["MISC", "PER", "LOC", "ORG"]
        text : str, optional
            The text to display, by default "Lorem ipsum"
        data : list, optional
            If you have entity annotations for this text already, by default []
        button_width : str, optional
            A valid HTML width string, by default "5em"
        snap_to_word_boundary : bool
            Whether or not the widget should expand selections to the word
            boundaries. For most languages, this should be left True, but some
            languages are based off single characters (e.g. traditional
            mandarin).
        """
        super().__init__()
        self.text_widget = TextTaggerCore(
            text=text,
            classes=classes,
            entity_spans=data,
            snap_to_word_boundary=snap_to_word_boundary,
        )
        self.class_selector = widgets.ToggleButtons(
            options=classes,
            description="Class to tag:",
            style=widgets.ToggleButtonsStyle(button_width=button_width),
        )
        widgets.link(
            (self.class_selector, "value"),
            (self.text_widget, "selected_class"),
        )
        widgets.link((self, "data"), (self.text_widget, "entity_spans"))
        self.children = (self.text_widget, self.class_selector)

        self.children = (
            self.text_widget,
            self.class_selector,
            widgets.HBox(
                [self.undo_button, self.skip_button, self.submit_button],
                layout={
                    "align_items": "stretch",
                    "justify_content": "flex-end",
                    "flex_flow": "row wrap",
                },
            ),
            self.event_watcher,
        )
        self.__undo_in_process = False
Ejemplo n.º 14
0
    def __init__(self, **kwargs):
        # Create description label
        self.description_label = widgets.Label(
            value=kwargs.get("description", ""))
        widgets.link((self.description_label, "value"), (self, "description"))

        # Create widgets
        value_trait = self.traits()["value"]
        ctx = kwargs["ctx"]
        self.widgets = ctx.create_widgets_for_model_cls(
            ctx.resolve(value_trait.klass))

        # Create box container for widgets
        self.widgets_container = widgets.GridBox(
            list(self.widgets.values()), layout={"flex_flow": "column"})
        self._links = []

        self._logger = ctx.logger

        shared_trait_names = self.class_traits().keys() & self.widgets.keys()
        if shared_trait_names:
            raise ValueError(
                f"Traits {shared_trait_names} clash with builtin widget trait names"
            )

        super().__init__(
            children=[
                self.description_label,
                self.widgets_container,
            ],
            **kwargs,
        )
Ejemplo n.º 15
0
    def __init__(self, **kwargs):
        self.message_area = ipw.Output()
        self.workchain_settings = WorkChainSettings()
        self.kpoints_settings = KpointSettings()
        self.pseudo_family_selector = PseudoFamilySelector()
        self.codes_selector = CodeSettings()
        self.resources_config = ResourceSelectionWidget()

        self.set_trait("builder_parameters",
                       self._default_builder_parameters())
        self._setup_builder_parameters_update()

        self.codes_selector.pw.observe(self._update_state, "selected_code")
        self.codes_selector.pw.observe(self._set_num_mpi_tasks_to_default,
                                       "selected_code")

        self.tab = ipw.Tab(
            children=[
                self.workchain_settings,
            ],
            layout=ipw.Layout(min_height="250px"),
        )

        self.tab.set_title(0, "Workflow")

        self.submit_button = ipw.Button(
            description="Submit",
            tooltip="Submit the calculation with the selected parameters.",
            icon="play",
            button_style="success",
            layout=ipw.Layout(width="auto", flex="1 1 auto"),
            disabled=True,
        )

        self.submit_button.on_click(self._on_submit_button_clicked)

        self.expert_mode_control = ipw.ToggleButton(
            description="Expert mode",
            tooltip="Activate Expert mode for access to advanced settings.",
            value=True,
        )
        ipw.link((self, "expert_mode"), (self.expert_mode_control, "value"))

        self._update_builder_parameters()

        self.builder_parameters_view = ipw.HTML(layout=ipw.Layout(
            width="auto"))
        ipw.dlink(
            (self, "builder_parameters"),
            (self.builder_parameters_view, "value"),
            transform=lambda p: '<pre style="line-height: 100%">' + pformat(
                p, indent=2, width=200) + "</pre>",
        )

        super().__init__(children=[
            self.message_area,
            self.tab,
            ipw.HBox([self.submit_button, self.expert_mode_control]),
        ])
Ejemplo n.º 16
0
    def setup_controls(self):
        down = ipywidgets.Button(icon="arrow-down",
                layout=ipywidgets.Layout(width='40px'))
        up = ipywidgets.Button(icon="arrow-up",
                layout=ipywidgets.Layout(width='40px'))
        right = ipywidgets.Button(icon="arrow-right",
                layout=ipywidgets.Layout(width='40px')
                )
        left = ipywidgets.Button(icon="arrow-left",
                layout=ipywidgets.Layout(width='40px')
                )
        zoom_start = 1./(self.view_width[0])
        zoom = ipywidgets.FloatSlider(min=0.1, max=10, step=0.1,
                value=zoom_start,
                description="Zoom")
        is_log = ipywidgets.Checkbox(value=False, description="Log colorscale")
        colormaps = ipywidgets.Dropdown(
                options=list(self.colormaps.cmaps.keys()),
                description="colormap",
                value = "viridis")
        min_val = ipywidgets.BoundedFloatText(description="lower colorbar bound:",
                value=self.val.min(), min=self.val.min(), max=self.val.max())
        max_val = ipywidgets.BoundedFloatText(description="upper colorbar bound:",
                value=self.val.max(), min=self.val.min(), max=self.val.max())
        minmax = ipywidgets.FloatRangeSlider(min=self.val.min(), max=self.val.max())


        down.on_click(self.on_ydownclick)
        up.on_click(self.on_yupclick)
        right.on_click(self.on_xrightclick)
        left.on_click(self.on_xleftclick)
        zoom.observe(self.on_zoom, names='value')
        # These can be jslinked, so we will do so.
        ipywidgets.jslink((is_log, 'value'), (self.colormaps, 'is_log'))
        ipywidgets.jslink((min_val, 'value'), (self.colormaps, 'min_val'))
        ipywidgets.jslink((max_val, 'value'), (self.colormaps, 'max_val'))
        # This one seemingly cannot be.
        ipywidgets.link((colormaps, 'value'), (self.colormaps, 'map_name'))

        sides = ipywidgets.HBox([left,right],
                layout=ipywidgets.Layout(justify_content='space-between',
                    width='122px'))
        nav_buttons = ipywidgets.VBox([up, sides, down],
                layout=ipywidgets.Layout(
                    align_items='center',
                    width='150px'))

        all_navigation = ipywidgets.VBox([nav_buttons, zoom],
                layout=ipywidgets.Layout(align_items='center')
                )
        all_normalizers = ipywidgets.VBox([is_log,
                colormaps, min_val, max_val],
                layout=ipywidgets.Layout(align_items='center')
                )
        accordion = ipywidgets.Accordion(children=[all_navigation,
            all_normalizers])
        accordion.set_title(0, 'navigation')
        accordion.set_title(1, 'colormap controls')
        return accordion
Ejemplo n.º 17
0
            def joint_player(self):
                # no player for static view
                static = True
                for a in self.arg:
                    if not a.static:
                        static = False
                if static:
                    return

                # compute timeline
                timeline = []
                for v in self.arg:
                    p = v.ctrl.widgets["player"]
                    if p.timeline is not None:
                        timeline = timeline + p.timeline
                    timeline = list(set(timeline))
                    timeline.sort()
                self.timeline = timeline

                # init widgets
                self.player = widgets.Play(value=0, min=0,
                                           max=len(timeline) - 1,
                                           interval=150)
                self.slider = widgets.SelectionSlider(value=timeline[0],
                                                      options=timeline)
                self.speed = widgets.Dropdown(
                    options=[("1", 250), ("2", 200), ("3", 150), ("4", 100),
                             ("5", 50)],
                    value=150,
                    description="Speed:",
                    layout=widgets.Layout(
                        width="100px"
                    ),
                    style={
                        "description_width": "45px"
                    }
                )

                def on_slider_change(change):
                    t = change.new
                    self.player.value = self.timeline.index(t)
                    for v in self.arg:
                        p = v.ctrl.widgets["player"]
                        if p.slider is not None and t in p.slider.options:
                            p.slider.value = t

                self.slider.observe(on_slider_change, names="value")

                def on_player_change(change):
                    t = self.timeline[change.new]
                    self.slider.value = t
                    for v in self.arg:
                        p = v.ctrl.widgets["player"]
                        if p.slider is not None and t in p.slider.options:
                            p.slider.value = t

                self.player.observe(on_player_change, names="value")

                widgets.link((self.speed, "value"), (self.player, "interval"))
Ejemplo n.º 18
0
 def _make_slider_input(self, label, description, min_val, max_val):
     label_widget = Label(description)
     slider = widgets.IntSlider(
         continuous_update=True, min=min_val, max=max_val, readout=False
     )
     self._input[label] = IntText(continuous_update=True, layout={"width": "80px"})
     widgets.link((self._input[label], "value"), (slider, "value"))
     return HBox([label_widget, slider, self._input[label]])
Ejemplo n.º 19
0
def wi12(muscle_force):
    style = {'description_width': 'initial'}
    wi120 = wi.Checkbox(value = True, description = 'Add standard deviation', 
                        layout = wi.Layout(width = '400px'), style = style)
    wi122 = wi.Checkbox(value = True, description = 'Add Spectrogram', 
                        layout = wi.Layout(width = '400px'), style = style)
    wi123 = wi.Dropdown(options = ['boxcar', 'hamming', 'hann'], value = 'hann', 
                        layout = wi.Layout(width = '400px'),
                        style = style, description = 'Window Type:')
    wi124 = wi.IntSlider(value = 2000, min = 2, max = 5000, step = 5, 
                         layout = wi.Layout(width = '400px'),style = style,
                         description = 'Window length [ms]:')
    wi125 = wi.IntSlider(value = 60, min = 1, max = 2500, step = 5, 
                         layout = wi.Layout(width = '400px'),style = style,
                         description = 'Window overlap [ms]:')
    wi126 = wi.Checkbox(value = False, description = 'Add Welch \' s periodogram',
                        layout = wi.Layout(width = '400px'), style = style)
    wi127 = wi.Dropdown(options = ['boxcar', 'hamming', 'hann'], value = 'hann', 
                        layout = wi.Layout(width = '400px'),
                        style = style, description = 'Window Type:')
    wi128 = wi.IntSlider(value =2000, min = 2, max = 5000, step = 5, 
                         layout = wi.Layout(width = '400px'), style = style,
                         description = 'Window length [ms]:')
    wi129 = wi.IntSlider(value = 60, min = 0, max = 2500, step = 5, 
                         layout = wi.Layout(width = '400px'), style = style,
                         description = 'Window overlap [ms]:')
    wi1210 = wi.FloatRangeSlider(value = [0,muscle_force.t[-1]], min = 0, 
                                 max = muscle_force.t[-1], step = 50, 
                                 layout = wi.Layout(width = '600px'),
                                 style = style, description = 'Analysis interval [ms]')
    wi1211 = wi.Checkbox(value = False, description = 'Add motor unit contribution', 
                         layout = wi.Layout(width = '400px'),style = style)
    wi1212 = wi.BoundedIntText(value = 1, min = 1, max = muscle_force.LR, step = 1, 
                               description = 'Motor unit Index #:',
                               style= style, layout=wi.Layout(width= '400px'))
    ws = {'add_rms': wi120, 'add_spec': wi122, 'spec_w': wi123, 'spec_w_size': wi124, 
          'spec_ol': wi125, 'add_welch': wi126, 'welch_w': wi127,
          'welch_w_size': wi128, 'welch_ol': wi129, 'a_interval': wi1210,
          'add_mu_c': wi1211, 'mu_index': wi1212}
    moving_average_acc2 = wi.VBox([wi120])
    spectrogram_acc2 = wi.VBox([wi122, wi123, wi124, wi125])
    welch_acc2 = wi.VBox([wi126, wi127, wi128, wi129])
    mu_c2 = wi.VBox([wi1211, wi1212])
    acc12 = wi.Tab(children = [moving_average_acc2, spectrogram_acc2, welch_acc2, mu_c2])
    acc12.set_title(0, 'Standard deviation')
    acc12.set_title(1, 'Spectrogram')
    acc12.set_title(2, 'Welch\'s Periodogram')
    acc12.set_title(3, 'Motor Unit Force')
    ui12 = wi.VBox([wi1210, acc12])
    l211 = wi.link((ui12.children[1].children[1].children[2], 'value'),
                   (ui12.children[1].children[1].children[3], 'max'))
    l212 = wi.link((ui12.children[1].children[1].children[3], 'value'),
                   (ui12.children[1].children[1].children[2], 'min'))
    l221 = wi.link((ui12.children[1].children[2].children[2], 'value'), 
                   (ui12.children[1].children[2].children[3], 'max'))
    l222 = wi.link((ui12.children[1].children[2].children[3], 'value'), 
                   (ui12.children[1].children[2].children[2], 'min'))
    return ui12, ws
Ejemplo n.º 20
0
    def __init__(self, light='light-1'):
        self.value = False
        self.button = ipw.ToggleButton(value=self.value)
        super(Switch, self).__init__()
        ipw.link((_lights[light], 'state'), (self, 'value'))

        self.description = 'Turn Light Off' if self.value else 'Turn Light On'
        self.button_style = 'danger' if self.value else 'success'
        self.observe(self._togglevalue, 'value')
Ejemplo n.º 21
0
def wi9(muscle_emg):
    style = {'description_width': 'initial'}
    wi110 = wi.Checkbox(value = True, description = 'Add moving average', 
                        layout = wi.Layout(width= '400px'), 
                        continuous_update = False, style = style)
    wi111 = wi.IntSlider(value = 100, min = 1, max = 500, layout = wi.Layout(width = '400px'),
                         style = style, continuous_update = False, 
                         description = 'Moving average window length [ms]:')
    wi112 = wi.Checkbox(value = True, description = 'Add Spectrogram', continuous_update = False,
                        layout = wi.Layout(width = '400px'),style = style)
    wi113 = wi.Dropdown(options = ['boxcar', 'hamming', 'hann'], value = 'hann', 
                        layout = wi.Layout(width = '400px'), style = style,
                        continuous_update = False,  description = 'Window Type:')
    wi114 = wi.IntSlider(value = 120, min = 2, max = 3000, layout = wi.Layout(width = '400px'),style = style,
                        continuous_update = False, description = 'Window length [ms]:')
    wi115 = wi.IntSlider(value = 60, min = 1, max = 1500, layout = wi.Layout(width = '400px'),style = style,
                        continuous_update = False, description = 'Window overlap [ms]:')
    wi116 = wi.Checkbox(value = False, description = 'Add Welch \' s periodogram',
                       continuous_update = False, layout = wi.Layout(width = '400px'),style = style)
    wi117 = wi.Dropdown(options = ['boxcar', 'hamming', 'hann'], value = 'hann', layout = wi.Layout(width = '400px'),
                       continuous_update = False, style = style, description = 'Window Type:')
    wi118 = wi.IntSlider(value = 120, min = 2, max = 3000, layout = wi.Layout(width = '400px'),style = style,
                        continuous_update = False, description = 'Window length [ms]:')
    wi119 = wi.IntSlider(value = 60, min = 1, max = 1500, layout = wi.Layout(width = '400px'),style = style,
                        continuous_update = False, description = 'Window overlap [ms]:')
    end = muscle_emg.t[-1]
    wi1110 = wi.FloatRangeSlider(value = [0, end], min = 0,
                                 max = end,step = 50, 
                                 layout = wi.Layout(width = '600px'),
                                 continuous_update = False, style = style, 
                                 description = 'Analysis interval [ms]')
    wi1111 = wi.Checkbox(value = False, description = 'Add Motor unit Contribution', layout = wi.Layout(width = '400px'),
                        continuous_update = False, style = style)
    wi1112 = wi.BoundedIntText(value = 1, min = 1, max = muscle_emg.LR, step = 1, description = 'Motor unit Index #:',
                              continuous_update = False, style = style, layout = wi.Layout(width = '400px'))
    ws11 = {'add_rms': wi110, 'rms_length': wi111, 'add_spec': wi112, 'spec_w': wi113,
        'spec_w_size': wi114, 'spec_ol': wi115, 'add_welch': wi116, 'welch_w': wi117,
        'welch_w_size': wi118, 'welch_ol': wi119, 'a_interval': wi1110, 'add_mu_cont': wi1111, 'mu_c_index': wi1112}
    mu_cont_acc = wi.VBox([wi1111, wi1112])
    moving_average_acc = wi.VBox([wi110, wi111])
    spectrogram_acc = wi.VBox([wi112, wi113, wi114, wi115])
    welch_acc = wi.VBox([wi116,wi117,wi118,wi119])
    acc11 = wi.Tab(children = [moving_average_acc, spectrogram_acc, welch_acc, mu_cont_acc])
    acc11.set_title(0, 'Moving average')
    acc11.set_title(1, 'Spectrogram')
    acc11.set_title(2, 'Welch\'s periodogram')
    acc11.set_title(3, 'Motor unit EMG')
    ui9 = wi.VBox([wi1110, acc11])
    l11 = wi.link((ui9.children[1].children[1].children[2], 'value'),
                  (ui9.children[1].children[1].children[3], 'max'))
    l12 = wi.link((ui9.children[1].children[1].children[3], 'value'),
                  (ui9.children[1].children[1].children[2], 'min'))
    l21 = wi.link((ui9.children[1].children[2].children[2], 'value'),
                  (ui9.children[1].children[2].children[3], 'max'))
    l22 = wi.link((ui9.children[1].children[2].children[3], 'value'),
                  (ui9.children[1].children[2].children[2], 'min'))
    return ui9, ws11
Ejemplo n.º 22
0
    def _init_isosurface_widgets(self):
        min, max = self._get_component_min_max(self.input_data,
                                               self.input_components[0])

        self.value_wid = FloatSlider(description='Value',
                                     min=min,
                                     max=max,
                                     value=self.value)

        link((self, 'value'), (self.value_wid, 'value'))
Ejemplo n.º 23
0
def setup_play_level(level, on_update, interval=1000, min=1, max=8):
    play = Play(interval=interval, min=min, max=max, step=1)
    progress = IntProgress(min=min, max=max, step=1)

    link((play, 'value'), (progress, 'value'))
    play.observe(on_update, 'value')

    canvas_dimensions = level.get_canvas_dimensions()
    layout = Layout(width=f'{canvas_dimensions[0]}px')
    return play, progress, layout
Ejemplo n.º 24
0
    def __init__(self, src=None, auto=True, x=None, y=None, **kwargs):
        super().__init__(**kwargs)
        self._filters = {}
        self.box = VBox()
        self._links = []
        self._group_filter = GroupUIFilter()
        self._trigger = Trigger(self._group_filter, func=self._apply_filter)
        self._filters = {}
        self._auto = auto
        self._auto_filter = None
        self.show_measure = False

        # setup controls
        self._ctrls = HBox()
        self._menu = widgets.Dropdown(
            options=self.options,
            description='Attribute:',
            value=self.attr,
            disabled=False,
        )

        self.x_slider = IntRangeSlider(min=0,
                                       max=1,
                                       value=(0, 1),
                                       description='Points:')
        self.y_slider = FloatRangeSlider(min=0,
                                         max=1,
                                         value=(0, 1),
                                         description='Persistence:',
                                         step=0.001)
        self._ctrls = HBox([self._menu, self.y_slider, self.x_slider])

        link((self, 'x_value'), (self.x_slider, 'value'))
        link((self, 'y_value'), (self.y_slider, 'value'))

        self._auto_filter = AttrFilter(attr=self._menu.value)
        if self._auto:
            self._group_filter.add(self._auto_filter, name='auto')
        widgets.link((self, 'attr'), (self._menu, 'value'))
        self.observe(self._auto_update, names=['attr'])

        # setup view
        self._links = [
            widgets.link((self, 'x'), (self.x_slider, 'value')),
            widgets.link((self, 'y'), (self.y_slider, 'value')),
        ]
        self._update_children()

        if src is not None:
            self.src = src
        if x is not None:
            self.x = x
        if y is not None:
            self.y = y
Ejemplo n.º 25
0
    def __init__(self, *args, **kwargs):

        # Create a dropdown widget
        self.ddw = FavunitDropdown()
        super().__init__(*args, **kwargs)

        # Link the favunits
        ipyw.link((self, "favunit"), (self.ddw, "value"))

        # Boxing widgets together
        self.children = [self.text, self.ddw]
Ejemplo n.º 26
0
    def _link_dropdown(self, dropdown, dim):
        def handle_dropdown_change(change):
            copy = self.input_components.copy()
            copy[dim] = change['new']
            self.input_components = copy
        dropdown.observe(handle_dropdown_change, names=['value'])

        def handle_input_change(change):
            dropdown.value = self.input_components[dim]
        self.observe(handle_input_change, names=['input_components'])

        link((dropdown, 'options'), (self, '_available_input_components'))
Ejemplo n.º 27
0
            def unit_player(self):
                # no player for static view
                if self.arg.static:
                    return

                # compute timeline
                layer, legend, profile = self.arg.get()
                temp_path = self.arg.temp_path
                file_list = self.arg.file_list
                timeline = [t.split(".")[0] for t in self.arg.file_list]
                timeline = [parser.parse(t) for t in timeline]
                self.timeline = timeline

                # init widgets
                self.player = widgets.Play(value=0, min=0,
                                           max=len(timeline) - 1,
                                           interval=150)
                self.slider = widgets.SelectionSlider(value=timeline[0],
                                                      options=timeline)
                self.speed = widgets.Dropdown(
                    options=[("1", 250), ("2", 200), ("3", 150), ("4", 100),
                             ("5", 50)],
                    value=150,
                    description="Speed:",
                    layout=widgets.Layout(
                        width="100px"
                    ),
                    style={
                        "description_width": "45px"
                    }
                )

                # slider change event
                def on_slider_change(change):
                    i = self.timeline.index(change.new)
                    self.player.value = i  # regarding change on player
                    img = os.path.join(temp_path, file_list[i])
                    layer.url = View.Layer.read_image(img)

                self.slider.observe(on_slider_change, names="value")

                # player change event
                def on_player_change(change):
                    t = self.timeline[change.new]
                    self.slider.value = t  # regarding change on slider
                    img = os.path.join(temp_path, file_list[change.new])
                    layer.url = View.Layer.read_image(img)

                self.player.observe(on_player_change, names="value")

                # speed change event
                widgets.link((self.speed, "value"), (self.player, "interval"))
Ejemplo n.º 28
0
    def _compose(self, change=None):

        self.options = [str(option) for option in self.options]
        if len(self.options) <= self.max_buttons:
            control_elements = widgets.HBox(
                [
                    widgets.Button(description=str(option))
                    for option in self.options
                ]
            )
            for button in control_elements.children:
                button.on_click(self._when_submitted)
        else:
            control_elements = widgets.HBox(
                [
                    widgets.Dropdown(
                        options=[str(option) for option in self.options],
                        description="Label:",
                    ),
                    widgets.Button(
                        description="Submit.",
                        tooltip="Submit label.",
                        button_style="success",
                    ),
                ]
            )
            widgets.link(
                (control_elements.children[0], "value"),
                (control_elements.children[1], "description"),
            )
            control_elements.children[1].on_click(self._when_submitted)
        sort_button = widgets.Button(description="Sort options", icon="sort")
        sort_button.on_click(self._sort_options)
        if self.other_option:
            other_widget = widgets.Text(
                value="",
                description="Other:",
                placeholder="Hit enter to submit.",
            )
            other_widget.on_submit(self._when_submitted)
            self.children = [
                control_elements,
                widgets.HBox(
                    [other_widget, sort_button],
                    layout=widgets.Layout(
                        justify_content="space-between"
                    ),
                ),
            ]
        else:
            self.children = [control_elements, widgets.HBox([sort_button])]
Ejemplo n.º 29
0
    def __init__(self, map):
        lonlat = LonLatInput(
            model=map.center,
            layout=widgets.Layout(width="initial"),
            style={"description_width": "initial"},
        )
        widgets.link((map, "center"), (lonlat, "model"))

        zoom_label = widgets.Label(
            value="Zoom:", layout=widgets.Layout(width="initial")
        )
        zoom = widgets.BoundedIntText(
            value=map.zoom,
            layout=widgets.Layout(width="3em"),
            min=map.min_zoom,
            max=map.max_zoom,
            step=1,
        )
        widgets.link((map, "zoom"), (zoom, "value"))
        widgets.link((map, "min_zoom"), (zoom, "min"))
        widgets.link((map, "max_zoom"), (zoom, "max"))

        super(PositionController, self).__init__(children=(lonlat, zoom_label, zoom))

        self.layout.overflow = "hidden"
        self.layout.flex = "0 0 auto"
        self.layout.padding = "2px 0"
Ejemplo n.º 30
0
    def __init__(self, view=None, **kwargs):
        if view:
            self.viewName = view

        self.offsetSlider = FloatSlider(description='Offset')

        self.updateImage()

        self._updateOffsetRange()
        self.l1 = link((self.offsetSlider, 'value'), (self, 'offset'))
        self.l2 = link((self, 'offsetMin'), (self.offsetSlider, 'min'))
        self.l3 = link((self, 'offsetMax'), (self.offsetSlider, 'max'))

        super().__init__(**kwargs)