def test_annotations():
    @annotate(n=10, f=widgets.FloatTextWidget())
    def f(n, f):
        pass

    c = interactive(f)
    check_widgets(
        c,
        n=dict(
            cls=widgets.IntSliderWidget,
            value=10,
        ),
        f=dict(cls=widgets.FloatTextWidget, ),
    )
Exemple #2
0
    def _fill_constants_widgets(self):
        """Fills up the constants widget with the current constants symbols
        and values."""

        for sym, init_val in self._system.constants.items():

            desc = latex(sym, mode='inline')

            if ipython_less_than_3:
                text_widget = widgets.FloatTextWidget(value=init_val,
                                                      description=desc)
            else:
                text_widget = widgets.FloatText(value=init_val,
                                                description=desc)

            self._constants_text_widgets[sym] = text_widget
Exemple #3
0
    def display_ipython(self):
        """
        Method to display the visualization inside the 
        Ipython notebook. It is only supported by IPython
        versions>=2.0.0
        
        """

        self.create_static_html(silent=True)
        self._widget_dict = OrderedDict()
        self.container = widgets.ContainerWidget()
        components = []
        for var, init_val in \
            zip(self.constant_variables, self.constant_values):
            self._widget_dict[str(var)] = widgets.FloatTextWidget(
                value=init_val, description=str(var))
            components.append(self._widget_dict[str(var)])

        self.button = widgets.ButtonWidget(description="Rerun Simulations")

        def button_click(clicked):
            self.button.add_class('disabled')
            self.button.description = 'Rerunning Simulation ...'
            self.constant_values = []
            for i in self._widget_dict.values():
                self.constant_values.append(i.value)
            if self.system is not None:
                #update system constants
                self.system.constants = dict(
                    zip(self.system.constants, self.constant_values))
                self.generate_visualization_json_system(self.system)
            else:
                self.generate_visualization_json(
                    self.dynamic_variables,
                    self.constant_variables,
                    self.dynamic_values,
                    self.constant_values,
                    fps=self.fps,
                    outfile_prefix=self.outfile_prefix)
            self.create_static_html(overwrite=True, silent=True)
            js = 'jQuery("#json-input").val("{}");'.format(
                'static/' + self.scene_json_file)
            display(Javascript(js))
            display(Javascript('jQuery("#simulation-load").click()'))
            self.button.remove_class('disabled')

            self.button.description = 'Rerun Simulation'

        self.button.on_click(button_click)
        #components.append(button)
        html_file = open("static/index_ipython.html")
        self.html_widget = widgets.HTMLWidget(value=html_file.read().format(
            load_url='static/' + self.scene_json_file))
        self.container.children = components
        self.container.set_css({
            "max-height": "10em",
            "overflow-y": "scroll",
            "display": "block"
        })
        self.html_widget.set_css({"display": "block", "float": "left"})
        display(self.container)
        display(self.button)
        display(self.html_widget)
        self.button.add_class('btn-info')
Exemple #4
0
def modeAnalyzerGrowth(myDMD_Uy,
                       k=(0, 100),
                       m=(0, 500),
                       vmin=-0.1,
                       vmax=0.1,
                       xscale='log',
                       min_norm=3.0,
                       min_abs=0.0003,
                       component=0,
                       extent=None):
    def plotTime(k, m, sorting, vmin=vmin, vmax=vmax, plotSpectrum=True):
        idx_pos, idx_neg, f = myDMD_Uy.getFrqSortedIdx()

        normList = myDMD_Uy.result['mode_norms']
        stabList = np.absolute(myDMD_Uy.result['ritz_vals'])

        fig = plt.figure(figsize=(15, 5))
        gs = gridspec.GridSpec(1, 5)
        ax1 = plt.subplot(gs[0, 0])
        ax2 = plt.subplot(gs[0, 1])
        ax3 = plt.subplot(gs[0, 2])
        ax4 = plt.subplot(gs[0, 3:5])

        #idx=[myDMD_Uy.getIdxforFrq(65.0)]

        if sorting == 0:
            idx_sel = myDMD_Uy.getFilteredIndex(min_norm=min_norm,
                                                min_abs=min_abs)[::-1]
            idx_sel = [idx for idx in idx_pos if idx in idx_sel]
            idx = [idx_sel[m]]

        elif sorting == 1:
            #idx=[myDMD_Uy.getGrowthSortedIdx()[::-1][m]]
            idx_norm = np.argsort(normList)[::-1]
            idx_sel = idx_norm

            #idx=[idx_stab[m]]
            idx = [idx_norm[m]]
        elif sorting == 2:
            idx_stab = np.argsort(np.abs(np.log(stabList)))
            idx_sel = idx_stab
            idx = [idx_stab[m]]
        elif sorting == 3:
            idx_none = np.linspace(0, len(normList), len(normList) + 1)
            idx_sel = idx_none
            print idx_sel
            idx = [idx_none[m]]
        elif sorting == 4:
            idx_sel = myDMD_Uy.getFilteredIndex(min_norm=min_norm,
                                                min_abs=min_abs)[::-1]
            idx = [idx_sel[m]]

        #idx=[idx_pos[m]]
        out = myDMD_Uy.reconstructDMD(k=k, idx=idx)
        if len(out.shape) > 2:
            out = out[component]
        ax1.imshow(np.real(out), vmin=vmin, vmax=vmax, extent=extent)
        ax1.set_title(str(idx[0]))
        #md=myDMD_Uy.getMode(idx[0],component=component)
        md = myDMD_Uy.getMode(idx[0], component=component)
        print md.shape
        if len(md.shape) > 2:
            md = md[component]

        ax2.imshow(np.real(md) / np.linalg.norm(md),
                   vmin=vmin,
                   vmax=vmax,
                   extent=extent)
        ax2.grid()
        ax3.imshow(np.imag(md) / np.linalg.norm(md),
                   vmin=vmin,
                   vmax=vmax,
                   extent=extent)
        ax3.grid()

        if (plotSpectrum):
            f1 = np.abs(myDMD_Uy.getFrq(idx[0]))
            #ax4.plot(f,normList)
            flist = myDMD_Uy.getFrqList()
            if sorting == 4 or sorting == 0:
                DecompositionPlotting.plotGrowth(myDMD_Uy,
                                                 ax4,
                                                 k,
                                                 idx=idx_sel[::-1],
                                                 dt=myDMD_Uy.result['dt'])
            else:
                #DecompositionPlotting.plotGrowth(myDMD_Uy,ax4,k,idx=idx_sel[::-1])
                DecompositionPlotting.plotGrowth(myDMD_Uy,
                                                 ax4,
                                                 k,
                                                 dt=myDMD_Uy.result['dt'])
            ritz_sel = np.log(myDMD_Uy.result['ritz_vals'][idx[0]]**
                              k) / myDMD_Uy.result['dt']
            ax4.plot(
                np.imag(ritz_sel) / (2.0 * np.pi), np.real(ritz_sel), 'rx')
            #ax4.plot(flist[idx_pos],10*np.log10(stabList[idx_pos]))
            #ax4.plot(flist[idx_pos[m]],10*np.log10(stabList[idx_pos[m]]),'ro')

            #ax4.plot(f1,myDMD_Uy.result['mode_norms'][idx[0]],'ro')
            #print f1,myDMD_Uy.result['mode_norms'][idx[0]]
            #ax4.set_xscale(xscale)
            #ax4.set_yscale('log')
            ax4.grid()
            ax4.set_title(
                str(np.round(f1, 5)) + r' Hz |$\lambda$|=' +
                str(np.round(myDMD_Uy.getEigAbs()[idx[0]], 6)) +
                r' |$\phi$| ' + str(np.round(normList[idx[0]], 2)))
        plt.show()

    kw = widgets.IntSliderWidget()
    kw.min = k[0]
    kw.max = k[1]
    kw.value = 1

    mw = widgets.IntSliderWidget()
    mw.min = m[0]
    mw.max = m[1]
    mw.value = 0
    sw = widgets.Dropdown(options={
        'Frequency': 0,
        'Norm': 1,
        'Growth': 2,
        'None': 3,
        'Importance': 4
    })
    #sw.values={'Frequency':0,'Norm':1,'Growth':2,'None':3,'Importance':4}
    ws = widgets.interaction.interactive(
        plotTime,
        k=kw,
        m=mw,
        vmin=widgets.FloatTextWidget(value=vmin),
        vmax=widgets.FloatTextWidget(value=vmax),
        plotSpectrum=True,
        sorting=sw)

    return ws
Exemple #5
0
def modeAnalyzer(myDMD_Uy,
                 k=(0, 100),
                 m=(0, 500),
                 vmin=-0.1,
                 vmax=0.1,
                 xscale='log'):
    def plotTime(k, m, vmin=vmin, vmax=vmax, plotSpectrum=True, magSort=True):
        idx_pos, idx_neg, f = myDMD_Uy.getFrqSortedIdx()
        normList = myDMD_Uy.result['mode_norms']
        stabList = np.absolute(myDMD_Uy.result['ritz_vals'])

        fig = plt.figure(figsize=(15, 5))
        gs = gridspec.GridSpec(1, 5)
        ax1 = plt.subplot(gs[0, 0])
        ax2 = plt.subplot(gs[0, 1])
        ax3 = plt.subplot(gs[0, 2])
        ax4 = plt.subplot(gs[0, 3:5])

        #idx=[myDMD_Uy.getIdxforFrq(65.0)]
        if magSort:
            #idx=[myDMD_Uy.getGrowthSortedIdx()[::-1][m]]
            idx_stab = np.argsort(stabList**k)[::-1]
            idx_norm = np.argsort(normList)[::-1]

            #idx=[idx_stab[m]]
            idx = [idx_norm[m]]
        else:
            #idx_pos,idx_neg,fc=myDMD_Uy.getFrqSortedIdx()
            idx = [idx_pos[m]]

        #idx=[idx_pos[m]]

        out = myDMD_Uy.reconstructDMD(k=k, idx=idx_stab[1:])

        ax1.imshow(np.real(out), vmin=vmin, vmax=vmax)
        ax1.set_title(str(idx[0]))
        md = myDMD_Uy.getMode(idx[0])

        ax2.imshow(np.real(md), vmin=vmin, vmax=vmax)

        ax3.imshow(np.imag(md), vmin=vmin, vmax=vmax)

        if (plotSpectrum):
            f1 = np.abs(myDMD_Uy.getFrq(idx[0]))
            #ax4.plot(f,normList)
            flist = myDMD_Uy.getFrqList()
            DecompositionPlotting.plotEigenvals(myDMD_Uy, ax4, k)
            ritz_sel = myDMD_Uy.result['ritz_vals'][idx[0]]**k
            ax4.plot(np.real(ritz_sel), np.imag(ritz_sel), 'rx')
            #ax4.plot(flist[idx_pos],10*np.log10(stabList[idx_pos]))
            #ax4.plot(flist[idx_pos[m]],10*np.log10(stabList[idx_pos[m]]),'ro')

            #ax4.plot(f1,myDMD_Uy.result['mode_norms'][idx[0]],'ro')
            #print f1,myDMD_Uy.result['mode_norms'][idx[0]]
            #ax4.set_xscale(xscale)
            #ax4.set_yscale('log')
            ax4.set_title(
                str(f1) + r' Hz |$\lambda$|=' +
                str(myDMD_Uy.getEigAbs()[idx[0]]))
        plt.show()

    kw = widgets.IntSliderWidget()
    kw.min = k[0]
    kw.max = k[1]
    kw.value = 1

    mw = widgets.IntSliderWidget()
    mw.min = m[0]
    mw.max = m[1]
    mw.value = 0

    ws = widgets.interaction.interactive(
        plotTime,
        k=kw,
        m=mw,
        vmin=widgets.FloatTextWidget(value=vmin),
        vmax=widgets.FloatTextWidget(value=vmax),
        plotSpectrum=True,
        magSort=True)

    return ws