コード例 #1
0
def test_list_tuple_3_int():
    with nt.assert_raises(ValueError):
        c = interactive(f, tup=(1, 2, 0))
    with nt.assert_raises(ValueError):
        c = interactive(f, tup=(1, 2, -1))
    for min, max, step in [(0, 2, 1), (1, 10, 2), (1, 100, 2), (-5, 5, 4), (-100, -20, 4)]:
        c = interactive(f, tup=(min, max, step), lis=[min, max, step])
        nt.assert_equal(len(c.children), 2)
        d = dict(cls=widgets.IntSlider, min=min, max=max, step=step, readout=True)
        check_widgets(c, tup=d, lis=d)
コード例 #2
0
def test_list_tuple_2_float():
    with nt.assert_raises(ValueError):
        c = interactive(f, tup=(1.0, 1.0))
    with nt.assert_raises(ValueError):
        c = interactive(f, tup=(0.5, -0.5))
    for min, max in [(0.5, 1.5), (1.1, 10.2), (1, 2.2), (-5.0, 5), (-20, -19.0)]:
        c = interactive(f, tup=(min, max), lis=[min, max])
        nt.assert_equal(len(c.children), 2)
        d = dict(cls=widgets.FloatSlider, min=min, max=max, step=0.1, readout=True)
        check_widgets(c, tup=d, lis=d)
コード例 #3
0
ファイル: FEM3loop.py プロジェクト: Pbellive/gpgLabs
def interactfem3loop():

    S = 4.
    ht = 1.
    xmin = -10.
    xmax = 10.
    zmax = 10.
    # xmin = lambda dx: -40.*dx
    # xmax = lambda dx: 40.*dx

    fem3loopwrap = lambda L,R,yc,xc,zc,dincl,ddecl,f,dx,showDataPts: fem3loop(L,R,-yc,xc,zc,dincl,ddecl,S,ht,f,xmin,xmax,dx,showDataPts)

    Q = interactive(fem3loopwrap,
        L = FloatSlider(min=0.00,max=0.20,step=0.01,value=0.10),
        R = FloatSlider(min=0.0,max=20000.,step=1000.,value=2000.),
        xc = FloatSlider(min=-10.,max=10.,step=1.,value=0.0),
        yc = FloatSlider(min=-10.,max=10.,step=1.,value=0.0),
        zc = FloatSlider(min=0.,max=zmax,step=0.5,value=1.),
        dincl = FloatSlider(min=-90.,max=90.,step=1.,value=0.),
        ddecl = FloatSlider(min=0.,max=180.,step=1.,value=90.),
        f = FloatSlider(min=10.,max=19990.,step=10.,value=10000.),
        dx = FloatSlider(min=0.25,max=5.,step=0.25,value=0.25),
        showDataPts = Checkbox(value=False)
        )

    return Q
コード例 #4
0
def test_default_out_of_bounds():
    @annotate(f=(0, 10.), h={'a': 1}, j=['hi', 'there'])
    def f(f='hi', h=5, j='other'):
        pass

    c = interactive(f)
    check_widgets(
        c,
        f=dict(
            cls=widgets.FloatSlider,
            value=5.,
        ),
        h=dict(
            cls=widgets.Dropdown,
            values={'a': 1},
            value=1,
        ),
        j=dict(
            cls=widgets.Dropdown,
            values={
                'hi': 'hi',
                'there': 'there'
            },
            value='hi',
        ),
    )
コード例 #5
0
ファイル: test_interaction.py プロジェクト: qiqisteve/ipython
def test_default_out_of_bounds():
    @annotate(f=(0, 10.), h={'a': 1}, j=['hi', 'there'])
    def f(f='hi', h=5, j='other'):
        pass

    c = interactive(f)
    check_widgets(
        c,
        f=dict(
            cls=widgets.FloatSliderWidget,
            value=5.,
        ),
        h=dict(
            cls=widgets.DropdownWidget,
            values={'a': 1},
            value=1,
        ),
        j=dict(
            cls=widgets.DropdownWidget,
            values={
                'hi': 'hi',
                'there': 'there'
            },
            value='hi',
        ),
    )
コード例 #6
0
def test_list_tuple_3_int():
    with nt.assert_raises(ValueError):
        c = interactive(f, tup=(1,2,0))
    with nt.assert_raises(ValueError):
        c = interactive(f, tup=(1,2,-1))
    for min, max, step in [ (0,2,1), (1,10,2), (1,100,2), (-5,5,4), (-100,-20,4) ]:
        c = interactive(f, tup=(min, max, step), lis=[min, max, step])
        nt.assert_equal(len(c.children), 2)
        d = dict(
            cls=widgets.IntSlider,
            min=min,
            max=max,
            step=step,
            readout=True,
        )
        check_widgets(c, tup=d, lis=d)
コード例 #7
0
def display_columns(df):
    """
    Display the columns of df in a SelectMultiple widget and print the code
    representing the list of selected columns.
    """
    dt = list(df.dtypes.items())
    column_display = [f"{c} ({str(t)})" for c, t in dt]
    column = [c for c, t in dt]
    w = widgets.SelectMultiple(options=list(zip(column_display, column)))
    h = widgets.BoundedIntText(value=5, min=1, max=len(df))

    def print_columns(columns=None, head=5):
        if columns is None:
            return
        else:
            inner = map(lambda t: '"' + str(t) + '"', columns)
            print(f"cols_selected = [{', '.join(inner)}]")
            print()
            if len(columns) == 0:
                return
            try:
                display(df[list(columns)].head(head).style)
            except AttributeError:
                pass

    return interactive(print_columns, columns=w, head=h)
コード例 #8
0
def test_interact_manual_nocall():
    callcount = 0
    def calltest(testarg):
        callcount += 1
    c = interactive(calltest, testarg=5, __manual=True)
    c.children[0].value = 10
    nt.assert_equal(callcount, 0)
コード例 #9
0
ファイル: twerk.py プロジェクト: olgabot/twerk
 def pick_soft_threshold(self):
     w = interactive(self._soft_threshold,
                     method=('spearman', 'pearson', 'kendall'),
               power=widgets.IntSliderWidget(min=0, max=100, step=2,
                                             value=10),
               signed=True)
     display(w)
コード例 #10
0
ファイル: twerk.py プロジェクト: olgabot/twerk
 def pick_hard_threshold(self):
     w = interactive(self._soft_threshold,
                     method=('spearman', 'pearson', 'kendall'),
                     power=widgets.FloatSliderWidget(min=0, max=.99,
                                                     step=.01, value=0.5),
                     signed=True)
     display(w)
コード例 #11
0
def InteractLogs(d2=50,
                 d3=100,
                 rho1=2300,
                 rho2=2300,
                 rho3=2300,
                 v1=500,
                 v2=1000,
                 v3=1500):
    logs = interactive(plotLogsInteract,
                       d2=FloatSlider(min=0., max=100., step=5, value=d2),
                       d3=FloatSlider(min=100., max=200., step=5, value=d3),
                       rho1=FloatSlider(min=2000.,
                                        max=5000.,
                                        step=50.,
                                        value=rho1),
                       rho2=FloatSlider(min=2000.,
                                        max=5000.,
                                        step=50.,
                                        value=rho2),
                       rho3=FloatSlider(min=2000.,
                                        max=5000.,
                                        step=50.,
                                        value=rho3),
                       v1=FloatSlider(min=300., max=4000., step=50., value=v1),
                       v2=FloatSlider(min=300., max=4000., step=50., value=v2),
                       v3=FloatSlider(min=300., max=4000., step=50., value=v3))
    return logs
コード例 #12
0
def test_priority():
    @annotate(annotate="annotate", kwarg="annotate")
    def f(kwarg="default", annotate="default", default="default"):
        pass

    c = interactive(f, kwarg="kwarg")
    check_widgets(c, kwarg=dict(cls=widgets.Text, value="kwarg"), annotate=dict(cls=widgets.Text, value="annotate"))
コード例 #13
0
def test_list_tuple_2_int():
    with nt.assert_raises(ValueError):
        c = interactive(f, tup=(1, 1))
    with nt.assert_raises(ValueError):
        c = interactive(f, tup=(1, -1))
    for min, max in [(0, 1), (1, 10), (1, 2), (-5, 5), (-20, -19)]:
        c = interactive(f, tup=(min, max), lis=[min, max])
        nt.assert_equal(len(c.children), 3)
        d = dict(
            cls=widgets.IntSlider,
            min=min,
            max=max,
            step=1,
            readout=True,
        )
        check_widgets(c, tup=d, lis=d)
コード例 #14
0
def TrajectorySliderView(traj, frame=0, **kwargs):
    """IPython notebook widget for viewing trajectories in the browser with
    an interactiver slider.

    Parameters
    ----------
    traj : Trajectory
        Trajectory for which you want the viewer.
    frame : int, default=0
        Frame to set the slider to by default
    kwargs : string
        See TrajectoryView for all available options.

    See Also
    --------
    TrajectoryView: IPython notebook widget for displaying trajectories in the
    browser with WebGL.
    """
    widget = TrajectoryView(traj, frame=frame, **kwargs)

    def slide(frame):
        widget.frame = frame

    s = IntSlider(min=0, max=traj.n_frames - 1, value=frame)
    slider = interactive(slide, frame=s)
    
    container = Box()
    container.children = [widget, slider] 

    return container
コード例 #15
0
def test_list_tuple_2_float():
    with nt.assert_raises(ValueError):
        c = interactive(f, tup=(1.0, 1.0))
    with nt.assert_raises(ValueError):
        c = interactive(f, tup=(0.5, -0.5))
    for min, max in [(0.5, 1.5), (1.1, 10.2), (1, 2.2), (-5., 5), (-20, -19.)]:
        c = interactive(f, tup=(min, max), lis=[min, max])
        nt.assert_equal(len(c.children), 3)
        d = dict(
            cls=widgets.FloatSlider,
            min=min,
            max=max,
            step=.1,
            readout=True,
        )
        check_widgets(c, tup=d, lis=d)
コード例 #16
0
def test_list_tuple_str():
    values = ['hello', 'there', 'guy']
    first = values[0]
    c = interactive(f, tup=tuple(values), lis=list(values))
    nt.assert_equal(len(c.children), 3)
    d = dict(cls=widgets.Dropdown, value=first, values=values)
    check_widgets(c, tup=d, lis=d)
コード例 #17
0
def test_default_values():
    @annotate(n=10, f=(0, 10.), g=5, h={'a': 1, 'b': 2}, j=['hi', 'there'])
    def f(n, f=4.5, g=1, h=2, j='there'):
        pass

    c = interactive(f)
    check_widgets(
        c,
        n=dict(
            cls=widgets.IntSlider,
            value=10,
        ),
        f=dict(
            cls=widgets.FloatSlider,
            value=4.5,
        ),
        g=dict(
            cls=widgets.IntSlider,
            value=5,
        ),
        h=dict(cls=widgets.Dropdown, values={
            'a': 1,
            'b': 2
        }, value=2),
        j=dict(cls=widgets.Dropdown, values=['hi', 'there'], value='there'),
    )
コード例 #18
0
def test_list_tuple_str():
    values = ["hello", "there", "guy"]
    first = values[0]
    c = interactive(f, tup=tuple(values), lis=list(values))
    nt.assert_equal(len(c.children), 2)
    d = dict(cls=widgets.Dropdown, value=first, values=values)
    check_widgets(c, tup=d, lis=d)
コード例 #19
0
ファイル: test_interaction.py プロジェクト: Emaasit/ipython
def test_interact_manual_nocall():
    callcount = 0
    def calltest(testarg):
        callcount += 1
    c = interactive(calltest, testarg=5, __manual=True)
    c.children[0].value = 10
    nt.assert_equal(callcount, 0)
コード例 #20
0
ファイル: ResponseFct.py プロジェクト: waterstar2010/gpgLabs
def interactive_responseFct():
    app = interactive(
        plot_ResponseFct,
        h_boom=FloatSlider(min=h_boom,
                           max=h_boom_max,
                           step=0.1,
                           value=h_boom,
                           continuous_update=False),
        h_1=FloatSlider(min=0.,
                        max=zmax,
                        value=0.1,
                        step=0.1,
                        continuous_update=False),
        sigma_1=FloatSlider(min=sigmin,
                            max=sigmax,
                            value=sigmin,
                            step=sigmin,
                            continuous_update=False),
        sigma_2=FloatSlider(min=sigmin,
                            max=sigmax,
                            value=sigmin,
                            step=sigmin,
                            continuous_update=False),
        orientation=ToggleButtons(options=['vertical', 'horizontal']))
    return app
コード例 #21
0
def makeinteract3diagrams(v, z):
    Q = interactive(lambda x0, dx: view3diagrams(
        x0, dx, v1=v[0], v2=v[1], v3=v[2], z1=z[0], z2=z[1]),
                    x0=IntSlider(min=0, max=10, step=1, value=4),
                    dx=IntSlider(min=0, max=20, step=1, value=4))

    return Q
コード例 #22
0
def test_annotations():
    @annotate(n=10, f=widgets.FloatText())
    def f(n, f):
        pass

    c = interactive(f)
    check_widgets(c, n=dict(cls=widgets.IntSlider, value=10), f=dict(cls=widgets.FloatText))
コード例 #23
0
def makeinteractTXdiagram():
    Q = interactive(lambda x0, dx: viewTXdiagram(
        x0, dx, v1=v1, v2=v2, v3=v3, z1=z1, z2=z2),
                    x0=IntSlider(min=1, max=10, step=1, value=4),
                    dx=IntSlider(min=1, max=10, step=1, value=4))

    return Q
コード例 #24
0
ファイル: test_interaction.py プロジェクト: Emaasit/ipython
def test_list_tuple_2_int():
    with nt.assert_raises(ValueError):
        c = interactive(f, tup=(1,1))
    with nt.assert_raises(ValueError):
        c = interactive(f, tup=(1,-1))
    for min, max in [ (0,1), (1,10), (1,2), (-5,5), (-20,-19) ]:
        c = interactive(f, tup=(min, max), lis=[min, max])
        nt.assert_equal(len(c.children), 2)
        d = dict(
            cls=widgets.IntSlider,
            min=min,
            max=max,
            step=1,
            readout=True,
        )
        check_widgets(c, tup=d, lis=d)
コード例 #25
0
ファイル: test_interaction.py プロジェクト: Emaasit/ipython
def test_default_values():
    @annotate(n=10, f=(0, 10.), g=5, h={'a': 1, 'b': 2}, j=['hi', 'there'])
    def f(n, f=4.5, g=1, h=2, j='there'):
        pass
    
    c = interactive(f)
    check_widgets(c,
        n=dict(
            cls=widgets.IntSlider,
            value=10,
        ),
        f=dict(
            cls=widgets.FloatSlider,
            value=4.5,
        ),
        g=dict(
            cls=widgets.IntSlider,
            value=5,
        ),
        h=dict(
            cls=widgets.Dropdown,
            values={'a': 1, 'b': 2},
            value=2
        ),
        j=dict(
            cls=widgets.Dropdown,
            values={'hi':'hi', 'there':'there'},
            value='there'
        ),
    )
コード例 #26
0
def draw_2D_slice_notebook(self, p_vals, x_variable, y_variable,
                           range_x, range_y, slider_ranges,
                           image_container=None, **kwargs):
    plot_widget = interactive(make_2D_slice, ds=fixed(self), 
                              p_vals=fixed(p_vals),
                              x_variable=fixed(x_variable),
                              y_variable=fixed(y_variable), 
                              range_x=fixed(range_x),
                              range_y=fixed(range_y),
                              intersections={'Single':[1],
                                             'Single and Triple':[1,3],
                                             'Triple':[3],
                                             'All':range(1, 100)},
                              highlight=Text(value=''),
                              image_widget=fixed(image_container),
                              **{i:FloatSlider(min=log10(slider_ranges[i][0]),
                                                             max=log10(slider_ranges[i][1]),
                                                             step=log10(slider_ranges[i][1]/slider_ranges[i][0])/20,
                                                             value=log10(p_vals[i]))
                                                             for i in slider_ranges
                                                             }

                                 )
    make_2D_slice(ds=self, p_vals=p_vals,
                  x_variable=x_variable, y_variable=y_variable,
                  range_x=range_x, range_y=range_y, 
                  intersections=range(1, 100), image_widget=image_container, 
                  highlight='')
    return plot_widget
    
コード例 #27
0
ファイル: FEMpipe.py プロジェクト: geoStuff/gpgLabs
def interact_femPipe():
    Q = interactive(fempipeWidget,
                    alpha=FloatSlider(min=0.1, max=2., step=0.1, value=1.),
                    pipedepth=FloatSlider(min=0.5,
                                          max=4.0,
                                          step=0.1,
                                          value=1.0))
    return Q
コード例 #28
0
ファイル: test_interaction.py プロジェクト: Emaasit/ipython
def test_default_description():
    c = interactive(f, b='text')
    w = c.children[0]
    check_widget(w,
        cls=widgets.Text,
        value='text',
        description='b',
    )
コード例 #29
0
ファイル: test_interaction.py プロジェクト: Emaasit/ipython
def test_custom_description():
    c = interactive(f, b=widgets.Text(value='text', description='foo'))
    w = c.children[0]
    check_widget(w,
        cls=widgets.Text,
        value='text',
        description='foo',
    )
コード例 #30
0
ファイル: test_interaction.py プロジェクト: qiqisteve/ipython
def test_list_tuple_str():
    values = ['hello', 'there', 'guy']
    first = values[0]
    dvalues = OrderedDict((v, v) for v in values)
    c = interactive(f, tup=tuple(values), lis=list(values))
    nt.assert_equal(len(c.children), 2)
    d = dict(cls=widgets.DropdownWidget, value=first, values=dvalues)
    check_widgets(c, tup=d, lis=d)
コード例 #31
0
 def run_selector(self):
     '''
     Driver of interactive plotting of SMB util-service-point-id
     :return: Container widget with child indicating which util-service-point to plot
     '''
     smb_selection = SelectWidget(values=OrderedDict((str(id), id) for id in self.service_points))
     i = interactive(self.interactive_selector, SMB=smb_selection)
     return i
コード例 #32
0
ファイル: test_interaction.py プロジェクト: wyorgb/ipython
def test_custom_description():
    c = interactive(f, b=widgets.Text(value='text', description='foo'))
    w = c.children[0]
    check_widget(w,
        cls=widgets.Text,
        value='text',
        description='foo',
    )
コード例 #33
0
def test_default_description():
    c = interactive(f, b='text')
    w = c.children[0]
    check_widget(w,
        cls=widgets.Text,
        value='text',
        description='b',
    )
コード例 #34
0
def test_list_tuple_3_float():
    with nt.assert_raises(ValueError):
        c = interactive(f, tup=(1,2,0.0))
    with nt.assert_raises(ValueError):
        c = interactive(f, tup=(-1,-2,1.))
    with nt.assert_raises(ValueError):
        c = interactive(f, tup=(1,2.,-1.))
    for min, max, step in [ (0.,2,1), (1,10.,2), (1,100,2.), (-5.,5.,4), (-100,-20.,4.) ]:
        c = interactive(f, tup=(min, max, step), lis=[min, max, step])
        nt.assert_equal(len(c.children), 2)
        d = dict(
            cls=widgets.FloatSlider,
            min=min,
            max=max,
            step=step,
            readout=True,
        )
        check_widgets(c, tup=d, lis=d)
コード例 #35
0
def test_fixed():
    c = interactive(f, a=widgets.fixed(5), b='text')
    nt.assert_equal(len(c.children), 1)
    w = c.children[0]
    check_widget(w,
        cls=widgets.Text,
        value='text',
        description='b',
    )
コード例 #36
0
 def pick_hard_threshold(self):
     w = interactive(self._soft_threshold,
                     method=('spearman', 'pearson', 'kendall'),
                     power=widgets.FloatSliderWidget(min=0,
                                                     max=.99,
                                                     step=.01,
                                                     value=0.5),
                     signed=True)
     display(w)
コード例 #37
0
 def pick_soft_threshold(self):
     w = interactive(self._soft_threshold,
                     method=('spearman', 'pearson', 'kendall'),
                     power=widgets.IntSliderWidget(min=0,
                                                   max=100,
                                                   step=2,
                                                   value=10),
                     signed=True)
     display(w)
コード例 #38
0
ファイル: test_interaction.py プロジェクト: Emaasit/ipython
def test_single_value_bool():
    for a in (True, False):
        c = interactive(f, a=a)
        w = c.children[0]
        check_widget(w,
            cls=widgets.Checkbox,
            description='a',
            value=a,
        )
コード例 #39
0
ファイル: test_interaction.py プロジェクト: Emaasit/ipython
def test_list_tuple_3_float():
    with nt.assert_raises(ValueError):
        c = interactive(f, tup=(1,2,0.0))
    with nt.assert_raises(ValueError):
        c = interactive(f, tup=(-1,-2,1.))
    with nt.assert_raises(ValueError):
        c = interactive(f, tup=(1,2.,-1.))
    for min, max, step in [ (0.,2,1), (1,10.,2), (1,100,2.), (-5.,5.,4), (-100,-20.,4.) ]:
        c = interactive(f, tup=(min, max, step), lis=[min, max, step])
        nt.assert_equal(len(c.children), 2)
        d = dict(
            cls=widgets.FloatSlider,
            min=min,
            max=max,
            step=step,
            readout=True,
        )
        check_widgets(c, tup=d, lis=d)
コード例 #40
0
ファイル: test_interaction.py プロジェクト: Emaasit/ipython
def test_fixed():
    c = interactive(f, a=widgets.fixed(5), b='text')
    nt.assert_equal(len(c.children), 1)
    w = c.children[0]
    check_widget(w,
        cls=widgets.Text,
        value='text',
        description='b',
    )
コード例 #41
0
def test_single_value_bool():
    for a in (True, False):
        c = interactive(f, a=a)
        w = c.children[0]
        check_widget(w,
            cls=widgets.Checkbox,
            description='a',
            value=a,
        )
コード例 #42
0
def test_single_value_string():
    a = u'hello'
    c = interactive(f, a=a)
    w = c.children[0]
    check_widget(w,
        cls=widgets.Text,
        description='a',
        value=a,
    )
コード例 #43
0
ファイル: test_interaction.py プロジェクト: Emaasit/ipython
def test_single_value_string():
    a = u'hello'
    c = interactive(f, a=a)
    w = c.children[0]
    check_widget(w,
        cls=widgets.Text,
        description='a',
        value=a,
    )
コード例 #44
0
ファイル: SeisRefrac.py プロジェクト: Pbellive/gpgLabs
def makeinteractTXdiagram():
	v1 = 600.
	v2 = 1200. 
	v3 = 1700.
	z1, z2 = 5., 10.
	Q = interactive(lambda x0, dx: viewTXdiagram(x0, dx, v1=v1, v2=v2, v3=v3, z1=z1, z2=z2), 
	             x0=IntSlider(min=1, max=10, step=1, value=4),
	             dx=IntSlider(min=1, max=10, step=1,value=4))

	return Q
コード例 #45
0
ファイル: test_interaction.py プロジェクト: Emaasit/ipython
def test_list_tuple_invalid():
    for bad in [
        (),
        (5, 'hi'),
        ('hi', 5),
        ({},),
        (None,),
    ]:
        with nt.assert_raises(ValueError):
            print(bad) # because there is no custom message in assert_raises
            c = interactive(f, tup=bad)
コード例 #46
0
ファイル: SeisRefrac.py プロジェクト: Pbellive/gpgLabs
def makeinteractTXwigglediagram():
	v1 = 600.
	v2 = 1200. 
	v3 = 1700.
	z1, z2 = 5., 10.
	Q = interactive(lambda x0, dx, tI, v, Fit=False: viewWiggleTX(x0, dx, tI, v, Fit=Fit, v1=v1, v2=v2, v3=v3, z1=z1, z2=z2), 
	             x0=IntSlider(min=1, max=10, step=1, value=4),
	             dx=IntSlider(min=1, max=10, step=1,value=4),
				 tI=FloatSlider(min=0., max=0.25, step=0.0025,value=0.05),
				 v=FloatSlider(min=400, max=2000, step=50,value=1000.))
	return Q
コード例 #47
0
def test_list_tuple_invalid():
    for bad in [
        (),
        (5, 'hi'),
        ('hi', 5),
        ({}, ),
        (None, ),
    ]:
        with nt.assert_raises(ValueError):
            print(bad)  # because there is no custom message in assert_raises
            c = interactive(f, tup=bad)
コード例 #48
0
ファイル: interactive.py プロジェクト: westamine/gp
def setup_conditional_sampler(x, y, yerr, kernel):
    # Pre-compute a bunch of things for speed.
    xs = np.linspace(-6, 6, 300)
    rxx = x[:, None] - x[None, :]
    rss = xs[:, None] - xs[None, :]
    rxs = x[None, :] - xs[:, None]
    ye2 = yerr**2

    # Initialize at the least squares position.
    mu, _ = least_squares(x, y, yerr)

    # This function samples from the conditional distribution and
    # plots those samples.
    def sample_conditional(amp, ell, m=mu[0], b=mu[1]):
        np.random.seed(123)

        # Compute the covariance matrices.
        Kxx = kernel([amp, ell], rxx)
        Kxx[np.diag_indices_from(Kxx)] += ye2
        Kss = kernel([amp, ell], rss)
        Kxs = kernel([amp, ell], rxs)

        # Compute the residuals.
        resid = y - (m * x + b)
        model = m * xs + b
        a = np.linalg.solve(Kxx, resid)

        # Compute the likelihood.
        s, ld = np.linalg.slogdet(Kxx)
        ll = -0.5 * (np.dot(resid, a) + ld + len(x) * np.log(2 * np.pi))

        # Compute the predictive mean.
        mu = np.dot(Kxs, a) + model

        # Compute the predictive covariance.
        cov = Kss - np.dot(Kxs, np.linalg.solve(Kxx, Kxs.T))

        # Sample and display the results.
        y0 = np.random.multivariate_normal(mu, cov, 6)
        pl.errorbar(x, y, yerr=yerr, fmt=".k", capsize=0)
        pl.plot(xs, y0.T, "k", alpha=0.5)
        pl.plot(xs, m * xs + b, ":r")
        pl.ylim(-3, 3)
        pl.xlim(-6, 6)
        pl.title("lnlike = {0}".format(ll))

    w = interactive(sample_conditional,
                    amp=(1.0e-4, 2.0),
                    ell=(0.01, 3.0),
                    m=(-1.0, 5.0),
                    b=(-3.0, 3.0))
    display(w)

    return w
コード例 #49
0
def InteractLogs(d2=50, d3=100, rho1=2300, rho2=2300, rho3=2300, v1=500, v2=1000, v3=1500):
    logs = interactive(plotLogsInteract,
        d2  =FloatSlider(min = 0.   ,max = 100. ,step = 5  , value = d2  ),
        d3  =FloatSlider(min = 100. ,max = 200. ,step = 5  , value = d3  ),
        rho1=FloatSlider(min = 2000.,max = 5000.,step = 50., value = rho1),
        rho2=FloatSlider(min = 2000.,max = 5000.,step = 50., value = rho2),
        rho3=FloatSlider(min = 2000.,max = 5000.,step = 50., value = rho3),
        v1  =FloatSlider(min = 300. ,max = 4000.,step = 50., value = v1  ),
        v2  =FloatSlider(min = 300. ,max = 4000.,step = 50., value = v2  ),
        v3  =FloatSlider(min = 300. ,max = 4000.,step = 50., value = v3  ))
    return logs
コード例 #50
0
ファイル: viewer.py プロジェクト: Anhmike/pstats-view
    def interact(self):
        def _interact(count, field):
            self.view(count, field)

        display(
            interactive(
                _interact,
                count=IntSliderWidget(min=5,max=100,step=5,value=35),
                field=('cumtime', 'tottime', 'ncalls'),
            )
        )
コード例 #51
0
def test_list_tuple_str():
    values = ['hello', 'there', 'guy']
    first = values[0]
    c = interactive(f, tup=tuple(values), lis=list(values))
    nt.assert_equal(len(c.children), 3)
    d = dict(
        cls=widgets.Dropdown,
        value=first,
        options=values
    )
    check_widgets(c, tup=d, lis=d)
コード例 #52
0
def test_custom_description():
    d = {}

    def record_kwargs(**kwargs):
        d.clear()
        d.update(kwargs)

    c = interactive(record_kwargs, b=widgets.Text(value="text", description="foo"))
    w = c.children[0]
    check_widget(w, cls=widgets.Text, value="text", description="foo")
    w.value = "different text"
    nt.assert_equal(d, {"b": "different text"})
コード例 #53
0
ファイル: pylab_helpers.py プロジェクト: sandeep9373/Devel
def nb_set_fig_size():
    from IPython.html import widgets
    from IPython.display import display
    width, height = matplotlib.rcParams["figure.figsize"]
    width_slider = widgets.IntSlider(min=1, max=40, value=width)
    height_slider = widgets.IntSlider(min=1, max=40, value=height)
    def set_figsize(width, height):
        matplotlib.rcParams["figure.figsize"] = width, height
        matplotlib.pyplot.plot(numpy.sin(numpy.arange(100)))

    w = widgets.interactive(set_figsize,width=width_slider, height=height_slider)
    display(w)
コード例 #54
0
def makeinteractTXwigglediagram():
    v1 = 600.
    v2 = 1200.
    v3 = 1700.
    z1, z2 = 5., 10.
    Q = interactive(lambda x0, dx, tI, v, Fit=False: viewWiggleTX(
        x0, dx, tI, v, Fit=Fit, v1=v1, v2=v2, v3=v3, z1=z1, z2=z2),
                    x0=IntSlider(min=1, max=10, step=1, value=4),
                    dx=IntSlider(min=1, max=10, step=1, value=4),
                    tI=FloatSlider(min=0., max=0.25, step=0.0025, value=0.05),
                    v=FloatSlider(min=400, max=2000, step=50, value=1000.))
    return Q
コード例 #55
0
def InteractNosiy(noisyDataFile, noisyTimeFile):
    noisy = interactive(NoisyNMOWidget,
                        t0=FloatSlider(min=0.1,
                                       max=0.6,
                                       step=0.01,
                                       continuous_update=False),
                        v=FloatSlider(min=800.,
                                      max=2500.,
                                      step=100.,
                                      continuous_update=False),
                        syndat=fixed(noisyDataFile),
                        timdat=fixed(noisyTimeFile))
    return noisy
コード例 #56
0
def InteractClean(cleanDataFile, cleanTimeFile):
    clean = interactive(CleanNMOWidget,
                        t0=FloatSlider(min=0.2,
                                       max=0.8,
                                       step=0.01,
                                       continuous_update=False),
                        v=FloatSlider(min=1000.,
                                      max=5000.,
                                      step=100.,
                                      continuous_update=False),
                        syndat=fixed(cleanDataFile),
                        timdat=fixed(cleanTimeFile))
    return clean
コード例 #57
0
def test_single_value_dict():
    for d in [
        dict(a=5),
        dict(a=5, b='b', c=dict),
    ]:
        c = interactive(f, d=d)
        w = c.children[0]
        check_widget(w,
            cls=widgets.Dropdown,
            description='d',
            options=d,
            value=next(iter(d.values())),
        )
コード例 #58
0
def test_single_value_float():
    for a in (2.25, 1.0, -3.5):
        c = interactive(f, a=a)
        w = c.children[0]
        check_widget(w,
            cls=widgets.FloatSlider,
            description='a',
            value=a,
            min= -a if a > 0 else 3*a,
            max= 3*a if a > 0 else -a,
            step=0.1,
            readout=True,
        )
コード例 #59
0
def test_annotations():
    @annotate(n=10, f=widgets.FloatText())
    def f(n, f):
        pass

    c = interactive(f)
    check_widgets(
        c,
        n=dict(
            cls=widgets.IntSlider,
            value=10,
        ),
        f=dict(cls=widgets.FloatText, ),
    )