Exemplo n.º 1
0
 def run(self, output_dir):
     model = models_index[self.model]('pt_BR')
     g = model.callback(**self.kwargs)
     t, y = self.nmethod(g, self.sample_time, self.total_time)
     fig = Figure(figsize=(8, 6), dpi=300)
     ax = fig.add_subplot(111, xlabel='Tempo (seg)', ylabel='Amplitude')
     ax.plot(t, y, label='Resposta ao Degrau')
     # generate the tuning line
     ident = Smith(t, y)
     t1, y1 = ident.tuning_line
     ax.plot(t1, y1, label='Reta de Sintonia')
     ax.annotate(
         '%.1f%% (p1)' % ident.point1, xy=(t1[1], y1[1]), xycoords='data',
         xytext=(t1[1]+(self.total_time/15.0), y1[1]),
         arrowprops=dict(facecolor='black', shrink=0.05),
     )
     ax.annotate(
         '%.1f%% (p2)' % ident.point2, xy=(t1[2], y1[2]), xycoords='data',
         xytext=(t1[2]+(self.total_time/15.0), y1[2]),
         arrowprops=dict(facecolor='black', shrink=0.05),
     )
     legend = []
     for arg in model.args:
         if arg in self.blacklist_args:
             continue
         legend.append('%s=%s' % (arg, self.kwargs[arg]))
     #ax.legend(loc='best', prop={'size': 'x-small'}, title='; '.join(legend))
     canvas = FigureCanvas(fig)
     filename = 'cap3_model%i_%i.eps' % (self.model, self.plot_id)
     canvas.print_eps(os.path.join(output_dir, filename))
Exemplo n.º 2
0
 def run(self, output_dir):
     model = models_index[self.model]('pt_BR')
     g = model.callback(**self.kwargs)
     t, y = self.nmethod(g, self.sample_time, self.total_time)
     fig = Figure(figsize=(8, 6), dpi=300)
     ax = fig.add_subplot(111, xlabel='Tempo (seg)', ylabel='Amplitude')
     ax.plot(t, y, label='Resposta ao Degrau')
     # generate the tuning line
     ident = Smith(t, y)
     t1, y1 = ident.tuning_line
     ax.plot(t1, y1, label='Reta de Sintonia')
     ax.annotate(
         '%.1f%% (p1)' % ident.point1,
         xy=(t1[1], y1[1]),
         xycoords='data',
         xytext=(t1[1] + (self.total_time / 15.0), y1[1]),
         arrowprops=dict(facecolor='black', shrink=0.05),
     )
     ax.annotate(
         '%.1f%% (p2)' % ident.point2,
         xy=(t1[2], y1[2]),
         xycoords='data',
         xytext=(t1[2] + (self.total_time / 15.0), y1[2]),
         arrowprops=dict(facecolor='black', shrink=0.05),
     )
     legend = []
     for arg in model.args:
         if arg in self.blacklist_args:
             continue
         legend.append('%s=%s' % (arg, self.kwargs[arg]))
     #ax.legend(loc='best', prop={'size': 'x-small'}, title='; '.join(legend))
     canvas = FigureCanvas(fig)
     filename = 'cap3_model%i_%i.eps' % (self.model, self.plot_id)
     canvas.print_eps(os.path.join(output_dir, filename))
Exemplo n.º 3
0
    def run(self, output_dir):
        model = models_index[self.model]('pt_BR')
        g = model.callback(**self.kwargs)
        t, y = self.nmethod(g, self.sample_time, self.total_time)
        fig = Figure(figsize=(8, 6), dpi=300)
        ax = fig.add_subplot(111, xlabel='Tempo (seg)', ylabel='Amplitude')
        ax.plot(t, y, label='Resposta ao Degrau')

        if self.kp is None or self.ki is None or self.kd is None:
            kp, ki, kd = ZieglerNichols(t, y, Smith).gains
        else:
            kp, ki, kd = self.kp, self.ki, self.kd

        if self.simulate:
            # transfer function of the PID controller
            g_ = tf([kd, kp, ki], [1, 0])
            my_g = (g_ * g).feedback_unit()

            # discretize the controlled system
            t1, y1 = self.nmethod(my_g, self.sample_time, self.total_time)
            ax.plot(t1, y1, label='Resposta ao Degrau Controlada')
        else:
            # generate the tuning line
            ident = Smith(t, y)
            t1, y1 = ident.tuning_line
            ax.plot(t1, y1, label='Reta de Sintonia')
            ax.annotate(
                '%.1f%%' % ident.point1,
                xy=(t1[1], y1[1]),
                xycoords='data',
                xytext=(t1[1] + (self.total_time / 15.0), y1[1]),
                arrowprops=dict(facecolor='black', shrink=0.05),
            )
            ax.annotate(
                '%.1f%%' % ident.point2,
                xy=(t1[2], y1[2]),
                xycoords='data',
                xytext=(t1[2] + (self.total_time / 15.0), y1[2]),
                arrowprops=dict(facecolor='black', shrink=0.05),
            )
        legend = []
        for arg in model.args:
            if arg in self.blacklist_args:
                continue
            legend.append('%s=%s' % (arg, self.kwargs[arg]))
        ax.legend(
            loc='best',
            prop={'size': 'x-small'},
            title='kp=%.1f; ki=%.1f; kd=%.1f;' % (kp, ki, kd),
        )
        canvas = FigureCanvas(fig)
        filename = 'cap4_model%i_%i.eps' % (self.model, self.plot_id)
        canvas.print_eps(os.path.join(output_dir, filename))
Exemplo n.º 4
0
 def run(self, output_dir):
     model = models_index[self.model]('pt_BR')
     g = model.callback(**self.kwargs)
     t, y = self.nmethod(g, self.sample_time, self.total_time)
     fig = Figure(figsize=(8, 6), dpi=300)
     ax = fig.add_subplot(111, xlabel='Tempo (seg)', ylabel='Amplitude')
     ax.plot(t, y, label='Resposta ao Degrau')
     legend = []
     for arg in model.args:
         if arg in self.blacklist_args:
             continue
         legend.append('%s=%s' % (arg, self.kwargs[arg]))
     ax.legend(loc='best', prop={'size': 'x-small'}, title='; '.join(legend))
     canvas = FigureCanvas(fig)
     filename = 'cap2_model%i_%i.eps' % (self.model, self.plot_id)
     canvas.print_eps(os.path.join(output_dir, filename))
Exemplo n.º 5
0
def save_as_eps(x, y, xlim, figsize, orientation):
    """Create and save an EPS file from plot data.

    :param x: (numpy ndarray)
    :param y: (numpy ndarray)
    :param xlim: (float, float) a tuple of
    (max chemical shift, min chemical shift)
    :param figsize: (float, float) a tuple of (plot width, plot height) in
    inches.
    :param orientation: 'landscape' or 'portrait'"""
    figure = _create_figure(x, y, xlim, figsize)
    backend = FigureCanvasPS(figure)
    filename = asksaveasfilename()
    if filename:
        if filename[-4:] != '.eps':
            filename += '.eps'
        backend.print_eps(filename, orientation=orientation)