def main(argv):
    # Create an OptionParser for reading optional parameters
    parser = OptionParser(version='0.10')
    parser.prog = 'Model Runner Plots Test'

    print 'Running ' + parser.prog + ' ' + parser.version

    options, args = parser.parse_args(argv)

    log = False

    # Use a hardcoded value for the input filename, probably adding in an option argument later
    # for more flexibility
    filename = 'output_test/BigHorn_Temperature.txt'

    # Create the data frames and plots from the input file
    (df, df_closest_fit) = ModelRunnerPlots.create_dataframes(filename, log)
    # Get the plot and create a matplotlib figure.

    df_plot = ModelRunnerPlots.create_line_plot('Temperature', 'Temperature in Farenheit', df=df, log=log, value_vars=list(df.columns - ['year']))
    df_plot.savefig('graph_test.png', format='png')

    # Create our GUI componenets.  Note, the data frame and plot must be created beforehand for the GUI to work properly.
    root = Tkinter.Tk()
    root.title(parser.prog + ' ' + parser.version)
    root.grid()

    model_runner_gui = ModelRunnerGraphGUI.GraphFrame(root, df=df, plot=df_plot)
    model_runner_gui.set_grid()

    # Run the window main loop
    root.mainloop()
Ejemplo n.º 2
0
def create_plots(output_files_list, log, gui_frame=None):
    print('Number of plots in output: ' + str(len(output_files_list)))

    for output_file_and_job in output_files_list:
        output_file = output_file_and_job[0]
        # NOTE: Skip files with "Avg" in the filename.  The problem occurs when creating line graphs with intervals like:
        # 1950-1959, 1951-1960, 1952-1961, etc.  This is because the y-value is a range associated with a discrete range of data,
        # but not a continuous range.  Would a bar chart be more applicable?
        if output_file.find('Avg') != -1:
            print('Could not find the output file!')
            continue

        if log:
            logging.info('Creating plots for file: ' + output_file)
        else:
            print('Creating plots for file: ' + output_file)

        #(df, df_closest_fit) = ModelRunnerPlots.create_dataframes(output_file, log)
        datatype = output_file[output_file.rindex('_')+1:output_file.rindex('.')]
        df = ModelRunnerPlots.create_dataframes(output_file, datatype, log)
        plot_title = create_plot_title(output_file, log)
        window_title = None
        if len(output_file_and_job) == 2:
            window_title = create_plot_title(output_file, log) + ': ' + output_file_and_job[1]
        else:
            window_title = plot_title

        if log:
            logging.info('Plot Title: ' + plot_title)

        all_plot = ModelRunnerPlots.create_line_plot(plot_title, get_plot_y_label(output_file, log), df, log, value_vars=list(df.columns - ['year']))
        #closest_fit_plot = ModelRunnerPlots.create_line_plot(create_plot_title(output_file, log) + ' Closest Fit', get_plot_y_label(output_file, log), df_closest_fit, log, value_vars=list(df_closest_fit.columns - ['year']))

        # Create two instances of graph windows for each graph
        if gui_frame != None:
            print('Creating plots!')
            #plot_title = create_plot_title(output_file, log)
            y_label = get_plot_y_label(output_file, log)
            #all_plot_gui = ModelRunnerGraphGUI.GraphWindow(parent=None, df=df, plot=all_plot, plot_title=plot_title, y_label=y_label)
            #closest_fit_plot_gui = ModelRunnerGraphGUI.GraphWindow(parent=None, df=df_closest_fit, plot=closest_fit_plot, plot_title=plot_title + ' Closest Fit', y_label=y_label)
            gui_frame.add_plot({'df': df, 'plot': all_plot, 'plot_title': plot_title, 'y_label': y_label, 'window_title': window_title, 'output_file': output_file})
            #print 'Adding plots'

        # Or, just save the files if a GUI is not being used
        else:
            print('Just outputting image files!')
            plot_base_fname = output_file[0:output_file.rindex('.')]
            all_plot_fname = plot_base_fname + '_all_plot.png'
            all_plot.savefig(all_plot_fname, format='png')
            if log:
                logging.info('Created a plot file of all output columns called ' + all_plot_fname)

            closest_fit_plot_fname = plot_base_fname + '_closest_fit_plot.png'
            closest_fit_plot.savefig(closest_fit_plot_fname, format='png')
            if log:
                logging.info('Created a plot file of the best fitting output called ' + closest_fit_plot_fname)
Ejemplo n.º 3
0
    def __init__(self, parent, paned_window, **kwargs):
        Frame.__init__(self, paned_window)
        self.parent = parent

        self.df_column_frame = ScrolledFrame(self, vertflex='expand')

        self.graph_frame = ScrolledFrame(self, horizflex='expand', vertflex='expand')
        self.plot_figure = kwargs['plot'] if 'plot' in kwargs else None

        self.plot_title = kwargs['plot_title'] if 'plot_title' in kwargs else 'Line Plot'
        self.y_label = kwargs['y_label'] if 'y_label' in kwargs else 'y'
        self.df = kwargs['df'] if 'df' in kwargs else DataFrame() # If the dataframe wasn't passed in, then create an empty dataframe

        plot_selected_avg = ModelRunnerPlots.get_avg_plot(self.plot_title, self.y_label, self.df, None)
        self.plot_figure = plot_selected_avg
        self.graph_canvas = FigureCanvasTkAgg(plot_selected_avg, master=self.graph_frame.interior())

        self.col_list = list()

        for col in self.df.columns:
            if col != 'year' and 'Average' not in col:
                col_var = IntVar()
                col_var.set(0)
                col_checkbox = Checkbutton(self.df_column_frame.interior(), text=col, variable=col_var, command=self.on_col_check)
                self.col_list.append([col_var, col_checkbox, col])

        avg_dataframe, dataframe = ModelRunnerPlots.find_avg_dataframe(self.df)
        for col in avg_dataframe.columns:
            if col != 'year':
                col_var = IntVar()
                col_var.set(0)
                col_checkbox = Checkbutton(self.df_column_frame.interior(), text=col, variable=col_var, command=self.on_col_check)
                self.col_list.append([col_var, col_checkbox, col])

        self.log_filename_frame = Frame(self)
        self.log_label = Label(self.log_filename_frame, text='Logfile: ' + kwargs['log_filename']) if 'log_filename' in kwargs else None

        self.button_frame = Frame(self)
        self.close_button = Button(self.button_frame, text='Close', command=self.on_close)
        self.save_button = Button(self.button_frame, text='Save', command=self.on_save)
Ejemplo n.º 4
0
    def on_col_check(self):
        # Based upon what is checked, a new plot should be created
        value_vars = list()

        for col in self.col_list:
            if col[0].get() == 1:
                #print col[2] + ' is checked'
                value_vars.append(col[2])
            else:
                pass
                #print col[2] + ' is not checked'

        plot_selected = ModelRunnerPlots.create_line_plot(self.plot_title, self.y_label, self.df, None, value_vars=value_vars)
        #if len(value_vars) == 0:
            #plot_selected = ModelRunnerPlots.get_avg_plot(self.plot_title, self.y_label, self.df, None)
        plt.close(self.plot_figure)
	try:
        	self.graph_canvas.get_tk_widget().grid_remove()
		self.graph_canvas = FigureCanvasTkAgg(plot_selected, master=self.graph_frame.interior())
        	self.graph_canvas.get_tk_widget().grid(row=0, column=1, sticky=Tkinter.N + Tkinter.S + Tkinter.E + Tkinter.W)
	except AttributeError:
		pass
        
        self.plot_figure = plot_selected
Ejemplo n.º 5
0
def create_plots(output_files_list, log, gui_frame=None):
    # print 'Number of plots in output: ' + str(len(output_files_list))

    for output_file_and_job in output_files_list:
        output_file = output_file_and_job[0]
        # NOTE: Skip files with "Avg" in the filename.  The problem occurs when creating line graphs with intervals like:
        # 1950-1959, 1951-1960, 1952-1961, etc.  This is because the y-value is a range associated with a discrete range of data,
        # but not a continuous range.  Would a bar chart be more applicable?
        if output_file.find("Avg") != -1:
            continue

        if log:
            logging.info("Creating plots for file: " + output_file)
        else:
            print ("Creating plots for file: " + output_file)

        # (df, df_closest_fit) = ModelRunnerPlots.create_dataframes(output_file, log)
        datatype = output_file[output_file.rindex("_") + 1 : output_file.rindex(".")]
        df = ModelRunnerPlots.create_dataframes(output_file, datatype, log)
        plot_title = create_plot_title(output_file, log)
        window_title = None
        if len(output_file_and_job) == 2:
            window_title = create_plot_title(output_file, log) + ": " + output_file_and_job[1]
        else:
            window_title = plot_title

        if log:
            logging.info("Plot Title: " + plot_title)

        all_plot = ModelRunnerPlots.create_line_plot(
            plot_title, get_plot_y_label(output_file, log), df, log, value_vars=list(df.columns - ["year"])
        )
        # closest_fit_plot = ModelRunnerPlots.create_line_plot(create_plot_title(output_file, log) + ' Closest Fit', get_plot_y_label(output_file, log), df_closest_fit, log, value_vars=list(df_closest_fit.columns - ['year']))

        # Create two instances of graph windows for each graph
        if gui_frame != None:
            # plot_title = create_plot_title(output_file, log)
            y_label = get_plot_y_label(output_file, log)
            # all_plot_gui = ModelRunnerGraphGUI.GraphWindow(parent=None, df=df, plot=all_plot, plot_title=plot_title, y_label=y_label)
            # closest_fit_plot_gui = ModelRunnerGraphGUI.GraphWindow(parent=None, df=df_closest_fit, plot=closest_fit_plot, plot_title=plot_title + ' Closest Fit', y_label=y_label)
            gui_frame.add_plot(
                {
                    "df": df,
                    "plot": all_plot,
                    "plot_title": plot_title,
                    "y_label": y_label,
                    "window_title": window_title,
                    "output_file": output_file,
                }
            )
            # print 'Adding plots'

        # Or, just save the files if a GUI is not being used
        else:
            plot_base_fname = output_file[0 : output_file.rindex(".")]
            all_plot_fname = plot_base_fname + "_all_plot.png"
            all_plot.savefig(all_plot_fname, format="png")
            if log:
                logging.info("Created a plot file of all output columns called " + all_plot_fname)

            closest_fit_plot_fname = plot_base_fname + "_closest_fit_plot.png"
            closest_fit_plot.savefig(closest_fit_plot_fname, format="png")
            if log:
                logging.info("Created a plot file of the best fitting output called " + closest_fit_plot_fname)