Ejemplo n.º 1
0
    def animate_plane(self, func_update, n_iter, shape, plane=Plane.XOY, last_coordinate_value=0.0,
                      field=Field.E, field_coord=Axis.X, norm=False,
                      value_limits=(None, None), interval=1
                     ):
        title = ("$|%s|$" % (field.value)) if norm else ("$%s%s$" %(field.value, field_coord.value))
        xlabel = plane.value[0].value
        ylabel = plane.value[1].value
        min_coords = (get_coord_value(self.min_coords, plane.value[0]), get_coord_value(self.min_coords, plane.value[1]))
        max_coords = (get_coord_value(self.max_coords, plane.value[0]), get_coord_value(self.max_coords, plane.value[1]))
        
        fig = plt.figure()
        ax, im = self.create_ax_plane_(fig, shape, title, xlabel, ylabel, min_coords, max_coords, value_limits)
        
        coords0 = np.linspace(min_coords[0], max_coords[0], shape[0])
        coords1 = np.linspace(min_coords[1], max_coords[1], shape[1])         

        fig.tight_layout()
                
        def animate_(i):
            if (i > n_iter):
                exit()
            func_update()
            fields = self.get_field_plane_((coords0, coords1), shape, plane, last_coordinate_value,
                self.generate_func_get_(field, field_coord, norm))
            im.set_array(fields)
            return im,   
    
        ani = animation.FuncAnimation(fig, animate_, interval=interval, blit=True)
        plt.show()  
Ejemplo n.º 2
0
 def save_plane_to_image(self, shape, plane=Plane.XOY, last_coordinate_value=0.0,
                         field=Field.E, field_coord=Axis.X, norm=False,
                         value_limits=(None, None),
                         name_picture="field.png"
                        ):
     title = ("$|%s|$" % (field.value)) if norm else ("$%s%s$" %(field.value, field_coord.value))
     xlabel = plane.value[0].value
     ylabel = plane.value[1].value
     min_coords = (get_coord_value(self.min_coords, plane.value[0]), get_coord_value(self.min_coords, plane.value[1]))
     max_coords = (get_coord_value(self.max_coords, plane.value[0]), get_coord_value(self.max_coords, plane.value[1]))
     
     fig = plt.figure()
     ax, im = self.create_ax_plane_(fig, shape, title, xlabel, ylabel, min_coords, max_coords, value_limits)
     
     coords0 = np.linspace(min_coords[0], max_coords[0], shape[0])
     coords1 = np.linspace(min_coords[1], max_coords[1], shape[1])         
     fields = self.get_field_plane_((coords0, coords1), shape, plane, last_coordinate_value,
         self.generate_func_get_(field, field_coord, norm))
         
     im.set_array(fields)
     
     fig.tight_layout()
     
     plt.savefig(os.path.join(self.dir, name_picture), dpi=self.dpi)
     plt.close(fig=fig)
Ejemplo n.º 3
0
 def animate_axis(self, func_update, n_iter, n_points, axis=Axis.X, last_coordinate_value=(0.0, 0.0),
                  field=Field.E, field_coord=Axis.X, norm=False, line_plot="-", label="",
                  y_limits=None, interval=10
                 ):
     ylabel = ("$|%s|$" % (field.value)) if norm else ("$%s%s$" %(field.value, field_coord.value))
     xlabel = axis.value
     title = ""
     min_coords = get_coord_value(self.min_coords, axis)
     max_coords = get_coord_value(self.max_coords, axis)
     
     fig = plt.figure()
     ax = self.create_ax_axis_(fig, title, xlabel, ylabel, min_coords, max_coords, y_limits)
     
     coords = np.linspace(min_coords, max_coords, n_points)
     fields = self.get_field_axis_(coords, n_points, axis, last_coordinate_value,
         self.generate_func_get_(field, field_coord, norm))
         
     line, = ax.plot(coords, fields, line_plot, label=label)
     
     fig.tight_layout()               
             
     def animate_(i):
         if (i > n_iter):
             exit()
         func_update()
         fields = self.get_field_axis_(coords, n_points, axis, last_coordinate_value,
             self.generate_func_get_(field, field_coord, norm))
         line.set_data(coords, fields)
         return line,   
 
     ani = animation.FuncAnimation(fig, animate_, interval=interval, blit=True)
     plt.show()   
Ejemplo n.º 4
0
 def save_axis_to_file(self, n_points, axis=Axis.X, last_coordinate_value=(0.0, 0.0),
                       field=Field.E, field_coord=Axis.X, norm=False,
                       name_file="field.csv"
                      ):
     min_coords = get_coord_value(self.min_coords, axis)
     max_coords = get_coord_value(self.max_coords, axis)
     coords = np.linspace(min_coords, max_coords, n_points)
     fields = self.get_field_axis_(coords, n_points, axis, last_coordinate_value,
         self.generate_func_get_(field, field_coord, norm))
         
     with open(os.path.join(self.dir, name_file), "w") as file:
         for ix in range(n_points):
             file.write("%f\n" % fields[ix])
Ejemplo n.º 5
0
 def save_plane_to_file(self, shape, plane=Plane.XOY, last_coordinate_value=0.0,
                        field=Field.E, field_coord=Axis.X, norm=False,
                        name_file="field.csv"
                       ):
     min_coords = (get_coord_value(self.min_coords, plane.value[0]), get_coord_value(self.min_coords, plane.value[1]))
     max_coords = (get_coord_value(self.max_coords, plane.value[0]), get_coord_value(self.max_coords, plane.value[1]))
     coords0 = np.linspace(min_coords[0], max_coords[0], shape[0])
     coords1 = np.linspace(min_coords[1], max_coords[1], shape[1])         
     fields = self.get_field_plane_((coords0, coords1), shape, plane, last_coordinate_value,
         self.generate_func_get_(field, field_coord, norm))
         
     with open(os.path.join(self.dir, name_file), "w") as file:
         for iy in range(shape[1]):
             for ix in range(shape[0]):
                 file.write("%f;" % fields[iy, ix])
             file.write("\n")
Ejemplo n.º 6
0
 def save_axis_to_image(self, n_points, axis=Axis.X, last_coordinate_value=(0.0, 0.0),
                        field=Field.E, field_coord=Axis.X, norm=False, line_plot="-", label="",
                        y_limits=None,
                        name_picture="field.png"
                       ):
     ylabel = ("$|%s|$" % (field.value)) if norm else ("$%s%s$" %(field.value, field_coord.value))
     xlabel = axis.value
     title = ""
     min_coords = get_coord_value(self.min_coords, axis)
     max_coords = get_coord_value(self.max_coords, axis)
     
     fig = plt.figure()
     ax = self.create_ax_axis_(fig, title, xlabel, ylabel, min_coords, max_coords, y_limits)
     
     coords = np.linspace(min_coords, max_coords, n_points)
     fields = self.get_field_axis_(coords, n_points, axis, last_coordinate_value,
         self.generate_func_get_(field, field_coord, norm))
         
     ax.plot(coords, fields, line_plot, label=label)
     
     fig.tight_layout()
             
     plt.savefig(os.path.join(self.dir, name_picture), dpi=self.dpi)
     plt.close(fig=fig)