def simulation_data(istart): pathname = os.path.abspath(os.getcwd()) dat = isdf.use_sdf(istart, pathname) extent = np.shape(dat.Fluid_Temperature_electron.data) cs = int(extent[1] * 0.5) temp = dat.Fluid_Temperature_electron.data#[:,cs] x = dat.Grid_Grid_mid.data[0]#[:,cs] return x, temp
def plot_multi(): """ """ sdf_num = 10 search_string = str(sdf_num).zfill(4)+'.sdf' pathname = os.path.abspath(os.getcwd()) print('From directory:') print(pathname) sub_dir = sorted(glob.glob1(pathname, '*')) plt.figure() fig_labels = ["arithmetic", "harmonic $\delta = 0.1$", "harmonic $\delta = 0.01$", "harmonic $\delta = 0.001$"] fig_symbols = ["","x",".","+"] fig_colour = ["r","g","b","m"] fig_line = ["-","None","None","None"] for idir in range(0, len(sub_dir)): print('We have imported from directories:') print(sub_dir[idir]) current_dir_ap = pathname + '/' + sub_dir[idir] dat = isdf.use_sdf(sdf_num, current_dir_ap) extent = np.shape(dat.Fluid_Temperature_electron.data) cs = int(extent[1] * 0.5) temp = dat.Fluid_Temperature_electron.data[:,cs] x = dat.Grid_Grid_mid.data[0][:,cs] plt.plot(x, temp, label = fig_labels[idir], color = fig_colour[idir], marker = fig_symbols[idir], linestyle = fig_line[idir]) plt.title("Non-linear heatwave travelling into cold medium") plt.xlabel("Distance (arbitrary)") plt.ylabel("Temperature (arbitrary)") plt.legend() plt.show()
def data_and_plot(sdf_num, fig, ax1, cax1, fig2, ax2, ax3, parameters): """This routine is called from menu.py and is a wrapper for calls to data collection the plotting routines. The dat file is created with all the data from the sdf file. """ print_string = 'Processing file {:4d}'.format(sdf_num) \ + ' of {:4d}'.format(parameters.iend) + ' ' sys.stdout.write('\r' + print_string) sys.stdout.flush() data_struct = data_structure() data_struct.data = [None] * parameters.num_dir for num in range(0, parameters.num_dir): if parameters.movie: parameters.sdf_num = sdf_num parameters.sdf_num2 = sdf_num else: if num == 0: sdf_num = parameters.sdf_num else: sdf_num = parameters.sdf_num2 if parameters.apply_comparison[num]: if os.path.isdir(parameters.entry_comparison[num]): #print("Data loaded from: " + parameters.entry_comparison[num] + " to " + num) data_struct.data[num] = isdf.use_sdf(sdf_num, parameters.entry_comparison[num], use_analysis = parameters.use_analysis, istart = parameters.istart) else: parameters.apply_comparison[num] = False print() print("Warning: " + parameters.entry_comparison[num] + " is not a directory") snapshot(fig, ax1, cax1, parameters = parameters, data = data_struct) lineout(fig2, ax2, ax3, parameters = parameters, data = data_struct) return parameters, data_struct
def __init__(self, app, use_analysis, user_istart, user_iend): """This function is only called on creation of the class and initialises the tkinter menu. First setup is done including importing data needed for initialising menu controls from sdf files, then the figures are initialised to be populated later, the tkinter objects are setup. """ self.app = app self.parameters = op.plot_parameters() self.data_struct = op.data_structure() self.parameters.use_analysis = use_analysis app.title("Time history GUI") app.geometry('450x200+10+10') plt.ion() plt.close('all') self.cross_section = 1 # find sdf files and count self.parameters.pathname = os.path.abspath(os.getcwd()) runs = glob.glob1(self.parameters.pathname, "*.sdf") self.parameters.istart, self.parameters.iend, self.parameters.sdf_num \ = sdf_counter(runs, user_istart, user_iend) # initial data import, needed for variable selection combo box data = isdf.use_sdf(self.parameters.sdf_num, self.parameters.pathname, use_analysis=self.parameters.use_analysis, istart=self.parameters.istart) self.data_struct.data = isdf.get_data_all(data, self.parameters.istart, self.parameters.iend, self.parameters.pathname, self.parameters.use_analysis, self.cross_section) # create empty figures aspc = 1.2 self.fig = plt.figure(num=1, figsize=(8 * aspc, 8), facecolor='white') move_figure(self.fig, 700, 10) self.ax1 = self.fig.add_axes([0.15, 0.14, 0.6, 0.6 * aspc]) self.cax1 = self.fig.add_axes([0.8, 0.14, 0.05, 0.6 * aspc]) self.fig2 = plt.figure(num=2, figsize=(6, 6), facecolor='white') move_figure(self.fig2, 10, 1000) self.ax2 = plt.axes() self.ax3 = op.empty_lineout(self.fig2, self.ax2) control_row = 0 # Combo box - variable self.labelTop_combo1 = tk.Label(app, text="Select variable:") self.labelTop_combo1.grid(column=0, row=control_row) self.combo1 = ttk.Combobox(app, values=data.variables) self.combo1.bind("<<ComboboxSelected>>", self.callbackFunc) self.combo1.current(0) self.combo1.grid(column=1, row=control_row) control_row += 1 # Combo box - time variable self.labelTop_combo2 = tk.Label(app, text="Select time variable:") self.labelTop_combo2.grid(column=0, row=control_row) self.combo2 = ttk.Combobox(app, values=data.variables_time) self.combo2.bind("<<ComboboxSelected>>", self.callbackFunc) self.combo2.current(0) self.combo2.grid(column=1, row=control_row) control_row += 1 # Combo box - grid choice grid_list = ['default', 'initial', 'cell number'] self.labelTop_combo3 = tk.Label(app, text="Select a grid:") self.labelTop_combo3.grid(column=0, row=control_row) self.combo3 = ttk.Combobox(app, values=grid_list) self.combo3.bind("<<ComboboxSelected>>", self.callbackFunc1) self.combo3.current(0) self.combo3.grid(column=1, row=control_row) control_row += 1 # slider - scale colour self.label_slider1 = tk.Label(app, text="Colourbar scale:") self.label_slider1.grid(column=0, row=control_row) self.slider1 = tk.Scale(app, from_=-10, to=0, tickinterval=100, orient=tk.HORIZONTAL, command=self.callbackFunc, length=200, resolution=0.01) self.slider1.set(0) self.slider1.grid(column=1, row=control_row) control_row += 1 # button - reset button self.reset_button = tk.Button(app, text="Reset zoom") self.reset_axis_variable = tk.BooleanVar(app) self.reset_axis_variable.set(True) self.reset_button.grid(column=0, row=control_row) control_row += 1 # button - exit self.exit_button = tk.Button(app, text="Exit", command=self.exit_gui) self.exit_button.grid(column=0, row=control_row) control_row += 1 self.reset_button.bind("<Button-1>", self.callbackFunc1)
def __init__(self, app, use_analysis, user_istart, user_iend): self.app = app self.parameters = op.plot_parameters() self.parameters.use_analysis = use_analysis app.title("Snapshot GUI") app.geometry('500x400+10+10') plt.ion() plt.close('all') self.parameters.pathname, runs, self.parameters.dir_list, \ self.parameters.num_dir, self.parameters.parent_dir = find_sdf_files() self.parameters.istart, self.parameters.iend, self.parameters.sdf_num = \ sdf_counter(runs, user_istart, user_iend) # initial data import, needed for variable selection combo box data = isdf.use_sdf(self.parameters.sdf_num, self.parameters.pathname, use_analysis=self.parameters.use_analysis, istart=self.parameters.istart) # create empty figures aspc = 1.2 self.fig = plt.figure(num=1, figsize=(8 * aspc, 8), facecolor='white') move_figure(self.fig, 700, 10) self.ax1 = self.fig.add_axes([0.15, 0.14, 0.6, 0.6 * aspc]) self.cax1 = self.fig.add_axes([0.8, 0.14, 0.05, 0.6 * aspc]) #self.ax1.set_aspect('equal', 'box') self.fig2 = plt.figure(num=2, figsize=(6, 6), facecolor='white') move_figure(self.fig2, 10, 1050) self.ax2 = plt.axes() self.ax3 = op.empty_lineout(self.fig2, self.ax2) setattr(self.ax2, "loc_cell_track", 0) control_row = 0 # slider - time self.label_slider1 = tk.Label(app, text="Select sdf number:") self.label_slider1.grid(column=0, row=control_row) self.slider1 = tk.Scale(app, from_=self.parameters.istart, to=self.parameters.iend, tickinterval=100, orient=tk.HORIZONTAL, command=self.callbackFunc, length=300, resolution=1.0) self.slider1.grid(column=1, row=control_row) self.slider1.set(self.parameters.istart) control_row += 1 # slider - time for comparison data self.label_slider2 = tk.Label(app, text="Offset comparison file:") self.label_slider2.grid(column=0, row=control_row) self.label_slider2.grid_remove() self.slider2 = tk.Scale(app, from_=self.parameters.istart, to=self.parameters.iend, tickinterval=100, orient=tk.HORIZONTAL, command=self.callbackFunc, length=300, resolution=1.0) self.slider2.set(self.parameters.istart) self.slider2.grid(column=1, row=control_row) self.slider2.grid_remove() control_row += 1 # Combo box - variable 1 self.labelTop_combo1 = tk.Label(app, text="Select variable 1:") self.labelTop_combo1.grid(column=0, row=control_row) self.combo1 = ttk.Combobox(app, values=data.variables) self.combo1.grid(column=1, row=control_row) self.combo1.current(0) control_row += 1 # Combo box - variable 2 self.labelTop_combo2 = tk.Label(app, text="Select variable 2:") self.labelTop_combo2.grid(column=0, row=control_row) self.labelTop_combo2.grid_remove() self.combo2 = ttk.Combobox(app, values=data.variables) self.combo2.grid(column=1, row=control_row) self.combo2.current(0) self.combo2.grid_remove() control_row += 1 # check box - grid self.grid_variable = tk.BooleanVar(app) self.grid_button = tk.Checkbutton(app, text="grid", variable=self.grid_variable, onvalue=True, offvalue=False) self.grid_button.deselect() self.grid_button.grid(column=0, row=control_row) # button - save fig as pdf self.print_button = tk.Button(app, text="Save .pdf", command=self.save_pdf) self.print_button.grid(column=1, row=control_row) control_row += 1 # check box - polar coordinates self.polar_variable = tk.BooleanVar(app) self.polar_button = tk.Checkbutton(app, text="polar coordinates", variable=self.polar_variable, onvalue=True, offvalue=False) self.polar_button.deselect() self.polar_button.grid(column=0, row=control_row) # button - reset button self.reset_button = tk.Button(app, text="Reset zoom") self.reset_axis_variable = tk.BooleanVar(app) self.reset_axis_variable.set(True) self.reset_button.grid(column=1, row=control_row) control_row += 1 # check box - anisotropies self.anisotropies_variable = tk.BooleanVar(app) self.anisotropies_button = \ tk.Checkbutton(app, text="View anisotropies", variable=self.anisotropies_variable, onvalue=True, offvalue=False) self.anisotropies_button.deselect() self.anisotropies_button.grid(column=0, row=control_row) # button - exit self.exit_button = tk.Button(app, text="Exit", command=self.exit_gui) self.exit_button.grid(column=1, row=control_row) control_row += 1 # check box - Logarithm self.log_variable = tk.BooleanVar(app) self.log_button = tk.Checkbutton(app, text="Take log_10", variable=self.log_variable, onvalue=True, offvalue=False) self.log_button.deselect() self.log_button.grid(column=0, row=control_row) # button - save video self.video_button = tk.Button(app, text="Save video", command=self.save_video) self.video_button.grid(column=1, row=control_row) control_row += 1 # Combo box - surface tracking self.label_combo_surf = tk.Label(app, text="Select a surface to track:") self.label_combo_surf.grid(column=0, row=control_row) data.track_surfaces.insert(0, 'None') self.combo_surf = ttk.Combobox(app, values=data.track_surfaces) self.combo_surf.current(0) self.combo_surf.grid(column=1, row=control_row) control_row += 1 # Entry - Change cbar scale max self.apply_scale_max = tk.BooleanVar(app) self.scale_max_check = tk.Checkbutton(app, text="Apply max scaling", variable=self.apply_scale_max, onvalue=True, offvalue=False) self.scale_max_check.deselect() self.scale_max_check.grid(column=0, row=control_row) self.entry_scale_max = tk.Entry(app) self.entry_scale_max.insert(0, "1.0") self.entry_scale_max.grid(column=1, row=control_row) control_row += 1 # Entry - Change cbar scale min self.apply_scale_min = tk.BooleanVar(app) self.scale_min_check = tk.Checkbutton(app, text="Apply min scaling", variable=self.apply_scale_min, onvalue=True, offvalue=False) self.scale_min_check.deselect() self.scale_min_check.grid(column=0, row=control_row) self.entry_scale_min = tk.Entry(app) self.entry_scale_min.insert(0, "0.0") self.entry_scale_min.grid(column=1, row=control_row) control_row += 1 # check box - plot rays? self.rays_variable = tk.BooleanVar(app) self.rays_button = tk.Checkbutton(app, text="Show rays", variable=self.rays_variable, onvalue=True, offvalue=False) self.rays_button.deselect() self.rays_button.grid(column=0, row=control_row) # check box - plot all rays? self.all_rays_variable = tk.BooleanVar(app) self.all_rays_button = tk.Checkbutton(app, text="All rays?", variable=self.all_rays_variable, onvalue=True, offvalue=False) self.all_rays_button.deselect() self.all_rays_button.grid(column=1, row=control_row) self.all_rays_button.grid_remove() control_row += 1 # slider - ray selecter self.label_slider3 = tk.Label(app, text="Which rays to plot:") self.label_slider3.grid(column=0, row=control_row) self.label_slider3.grid_remove() self.slider3 = tk.Scale(app, from_=1, to=1000, tickinterval=100, orient=tk.HORIZONTAL, command=self.update_ray, length=300, resolution=1.0) self.slider3.set(1) self.slider3.grid(column=1, row=control_row) self.slider3.grid_remove() control_row += 1 # Entry - Plot second file self.parameters.apply_comparison = [False] * self.parameters.num_dir self.parameters.apply_comparison[0] = True self.parameters.entry_comparison = [None] * self.parameters.num_dir self.parameters.entry_comparison[0] = self.parameters.pathname self.apply_comparison = [None] * (self.parameters.num_dir - 1) self.comparison_check = [None] * (self.parameters.num_dir - 1) self.entry_comparison = [None] * (self.parameters.num_dir - 1) for num in range(0, self.parameters.num_dir - 1): self.apply_comparison[num] = tk.BooleanVar(app) self.comparison_check[num] = tk.Checkbutton( app, text="Apply Comparison" + " from file ->", variable=self.apply_comparison[num], onvalue=True, offvalue=False) self.comparison_check[num].deselect() self.comparison_check[num].grid(column=0, row=control_row) self.entry_comparison[num] = tk.Entry(app) self.entry_comparison[num].insert( 0, self.parameters.parent_dir + '/' + self.parameters.dir_list[num + 1]) self.entry_comparison[num].grid(column=1, row=control_row) control_row += 1 # Entry - Cross section self.y_dir_cross_section = tk.BooleanVar(app) self.cross_section_check = tk.Checkbutton( app, text="Cross section X/Y, location:", variable=self.y_dir_cross_section, onvalue=True, offvalue=False) self.cross_section_check.deselect() self.cross_section_check.grid(column=0, row=control_row) self.entry_cross_section = tk.Entry(app) self.entry_cross_section.insert(0, "1") self.entry_cross_section.grid(column=1, row=control_row) control_row += 1 # check box - show legend self.legend_variable = tk.BooleanVar(app) self.legend_button = tk.Checkbutton(app, text="Show legend", variable=self.legend_variable, onvalue=True, offvalue=False) self.legend_button.deselect() self.legend_button.grid(column=0, row=control_row) self.parameters.line_labels = [None] * self.parameters.num_dir self.entry_line = [None] * self.parameters.num_dir for num in range(0, self.parameters.num_dir): self.parameters.line_labels[num] = self.parameters.dir_list[num] self.entry_line[num] = tk.Entry(app) self.entry_line[num].insert(0, self.parameters.dir_list[num]) self.entry_line[num].grid(column=1, row=control_row) control_row += 1 # Bindings self.app.bind('<Left>', self.left_key) self.app.bind('<Right>', self.right_key) self.app.bind('<Up>', self.up_key) self.app.bind('<Down>', self.down_key) self.combo1.bind("<<ComboboxSelected>>", self.show_variable_combo) self.combo2.bind("<<ComboboxSelected>>", self.callbackFunc) self.grid_button.bind("<ButtonRelease-1>", self.callbackFunc) self.polar_button.bind("<ButtonRelease-1>", self.callbackFunc1) self.anisotropies_button.bind("<ButtonRelease-1>", self.callbackFunc) self.log_button.bind("<ButtonRelease-1>", self.callbackFunc1) self.reset_button.bind("<Button-1>", self.callbackFunc1) self.combo_surf.bind("<<ComboboxSelected>>", self.callbackFunc) self.scale_max_check.bind("<ButtonRelease-1>", self.callbackFunc) self.scale_min_check.bind("<ButtonRelease-1>", self.callbackFunc) self.rays_button.bind("<ButtonRelease-1>", self.show_ray_slider) self.all_rays_button.bind("<ButtonRelease-1>", self.show_ray_slider) for num in range(0, self.parameters.num_dir - 1): self.comparison_check[num].bind("<ButtonRelease-1>", self.hide_slider) self.legend_button.bind("<ButtonRelease-1>", self.callbackFunc) self.cross_section_check.bind("<ButtonRelease-1>", self.callbackFunc1)