Example #1
0
def start_fig_update(self):
    '''Mutates the matplotlib figure to show data. Takes data from 
    various input fields.'''

    self.status_text.SetLabel('Computing Field...')

    domain_x = (float(self.x1_input_field.GetValue()),float(self.x2_input_field.GetValue()))
    range_y = (float(self.y1_input_field.GetValue()),float(self.y2_input_field.GetValue()))
    plot_type= self.plot_type_selector.GetValue()
    vector_type = self.vector_drawing_selector.GetValue()
    field_type = self.field_type_selector.GetValue()

    xs, ys, cs = parse_dsl(self.input_text_ctrl.GetValue(),self.display_help_msg_callback)
    

    if xs == []:
        self.set_console_msg('Input cannot be empty!\
                             Update with "help" for commands')

    elif xs == None:
        pass

    elif GUI_CONSTANTS['Cache']==[domain_x,range_y,plot_type, field_type, self.input_text_ctrl.GetValue(),vector_type]:
        return

    elif GUI_CONSTANTS['Cache'][0:5]==[domain_x,range_y,plot_type, field_type, self.input_text_ctrl.GetValue()] and GUI_CONSTANTS['Cache'][5]!= vector_type:
        tmp = GUI_CONSTANTS['Field_Cache'][0:9]
        fig, X, Y, Xq, Yq, F, Fq, res, direc=\
        plot_on_fig(tmp[0],tmp[1],tmp[2],tmp[3],tmp[4],tmp[5],tmp[6],tmp[7],direc=vector_type)
        
        GUI_CONSTANTS['Cache'] = [domain_x,range_y,plot_type, field_type, self.input_text_ctrl.GetValue(), vector_type]
        GUI_CONSTANTS['Field_Cache'] = [fig, X, Y, Xq, Yq, F, Fq, res, direc]
        self.canvas.draw()
        return

    else:

        fig, X, Y, Xq, Yq, F, Fq, res, direc =\
        force_field(self.figure, plot_type, vector_type,
                    domain_x, range_y,xs,ys,cs,field_type, res = 100)

        self.canvas.draw()
        GUI_CONSTANTS['Cache'] = [domain_x,range_y,plot_type, field_type, self.input_text_ctrl.GetValue(), vector_type]
        GUI_CONSTANTS['Field_Cache'] = [fig, X, Y, Xq, Yq, F, Fq, res, direc]
        self.status_text.SetLabel('Render Finished')
Example #2
0
def force_field(fig, plot_type, vector_type, xd, yr, xs, ys, cs,
                 field_type, constant=-0.001, res=100):
    """
    Function takes '
    fig'(figure object) to plot to, the kind of 'plot_type' and vector_type',
    'xd' being a tuple with the domain of x, 'yr' being a tuple with the range of y,
    'res' as a float being the resolution in the x and y, and finally 'xs' and 'ys' as
    a list of arrays defining some blob.
    field_type is a string stating which calcuations to do (either Gravitational or Electric), constant is float
    dictating the overall constant of the blob (negative constants are abs() when using Gravitational)
    """
    if plot_type=='Vector with Contour':
        ## Calculate both meshgrids for vectors and contours

        ## Set up a meshgrid for calculating contours
        X = linspace(xd[0],xd[1], res)
        Y = linspace(yr[0], yr[1], res)
        X, Y = meshgrid(X,Y)

        ## Set up a meshgrid for calculating vectors
        Xq = linspace(xd[0],xd[1], res/5)
        Yq = linspace(yr[0], yr[1], res/5)
        Xq, Yq = meshgrid(Xq,Yq)

        ## Evaluate the meshgrid at point (X,Y) for contours
        F_x = test_force_x(X,Y,xs,ys,cs)
        F_y = test_force_y(X,Y,xs,ys,cs)
             
        ## Evaluate the meshgrid at point (X,Y) for vectors
        F_xq = test_force_x(Xq,Yq,xs,ys,cs)
        F_yq = test_force_y(Xq,Yq,xs,ys,cs)
        
        if field_type=='Gravitational':
            F_x = F_x*(6.67384e-11)*abs(constant)
            F_y = F_y*(6.67384e-11)*abs(constant)
            F_xq = F_xq*(6.67384e-11)*abs(constant)
            F_yq = F_yq*(6.67384e-11)*abs(constant)
        elif field_type=='Electric':
            F_x = F_x*(8.98755e9)*constant
            F_y = F_y*(8.98755e9)*constant
            F_xq = F_xq*(8.98755e9)*constant
            F_yq = F_yq*(8.98755e9)*constant

        F = (F_x,F_y)
        Fq = (F_xq,F_yq) 

        fig, X, Y, Xq, Yq, F, Fq, res, direc =\
        plot_on_fig(fig, X, Y, Xq, Yq, F, Fq, res, direc=vector_type)

    elif plot_type=='Contour Plot':
        ## Set up a meshgrid for calculating contours
        X = linspace(xd[0],xd[1], res)
        Y = linspace(yr[0], yr[1], res)
        X, Y = meshgrid(X,Y)

        ## Evaluate the meshgrid at point (X,Y) for contours
        F_x = test_force_x(X,Y,xs,ys,cs)
        F_y = test_force_y(X,Y,xs,ys,cs)
        
        if field_type=='Gravitational':
            F_x = F_x*(6.67384e-11)*abs(constant)
            F_y = F_y*(6.67384e-11)*abs(constant)
        elif field_type=='Electric':
            F_x = F_x*(8.98755e9)*constant
            F_y = F_y*(8.98755e9)*constant

        F = (F_x,F_y)

        fig, X, Y, Xq, Yq, F, Fq, res, direc=\
        plot_on_fig(fig, X, Y, None, None, F, None, res, direc=vector_type)

    elif plot_type=='Vector Field':
        ## Set up a meshgrid for calculating vectors
        Xq = linspace(xd[0],xd[1], res/5)
        Yq = linspace(yr[0], yr[1], res/5)
        Xq, Yq = meshgrid(Xq,Yq)
        
        ## Evaluate the meshgrid at point (X,Y) for vectors
        F_xq = test_force_x(Xq,Yq,xs,ys,cs)
        F_yq = test_force_y(Xq,Yq,xs,ys,cs)
        
        if field_type=='Gravitational':
            F_xq = F_xq*(6.67384e-11)*abs(constant)
            F_yq = F_yq*(6.67384e-11)*abs(constant)
        elif field_type=='Electric':
            F_xq = F_xq*(8.98755e9)*constant
            F_yq = F_yq*(8.98755e9)*constant

        Fq = (F_xq,F_yq)

        fig, X, Y, Xq, Yq, F, Fq, res, direc=\
        plot_on_fig(fig, None, None, Xq, Yq, None, Fq, res, direc=vector_type)
    return fig, X, Y, Xq, Yq, F, Fq, res, direc