def plot_op(): f.clf() a = f.add_subplot(111) #make sure selected material is available, if not found set to first material mat_found = False for mat in materials: if selected_ID.get() == mat: mat_found=True if mat_found == False: selected_ID.set(materials[0]) # get values associated with this ID from dictionary T_grid = table_key_dict["{0}_{1}".format("tgrid", selected_ID.get())] rho_grid = table_key_dict["{0}_{1}".format("rgrid", selected_ID.get())] hnu_grid = table_key_dict["{0}_{1}".format("hnugrid", selected_ID.get())] mgr_grid = table_key_dict["{0}_{1}".format("ramg", selected_ID.get())] mgp_grid = table_key_dict["{0}_{1}".format("pmg", selected_ID.get())] # scattering is only availabe with Rosseland weighting mgs_grid = table_key_dict["{0}_{1}".format("rsmg", selected_ID.get())] mgrt_grid = table_key_dict["{0}_{1}".format("rtmg", selected_ID.get())] # get interpolated opacity data for this temperature and density # first check to see if the data is valid (non-zero) mgr_valid = ip_reader.check_valid_data(mgr_grid) mgp_valid = ip_reader.check_valid_data(mgp_grid) mgs_valid = ip_reader.check_valid_data(mgs_grid) mgrt_valid = ip_reader.check_valid_data(mgrt_grid) name = selected_ID.get() print( \ "-------------------- BEGIN DATA PRINT FOR {0} --------------------"\ .format(name)) # if valid, interpolate data at target rho and target T if (mgr_valid): mgr_interp = ip_reader.interpolate_mg_opacity_data(T_grid, rho_grid, \ hnu_grid, mgr_grid, target_rho.get(), target_T.get(), \ "multigroup absorption Rosseland") if (mgp_valid): mgp_interp = ip_reader.interpolate_mg_opacity_data(T_grid, rho_grid, \ hnu_grid, mgp_grid, target_rho.get(), target_T.get(), \ "multigroup absorption Planckian") if (mgs_valid): mgs_interp = ip_reader.interpolate_mg_opacity_data(T_grid, rho_grid, \ hnu_grid, mgs_grid, target_rho.get(), target_T.get(), \ "multigroup scattering") if (mgrt_valid): mgrt_interp =ip_reader.interpolate_mg_opacity_data(T_grid, rho_grid, \ hnu_grid, mgrt_grid, target_rho.get(), target_T.get(), \ "total rosseland") print( \ "-------------------- END DATA PRINT FOR {0} --------------------"\ .format(name)) # plotting data arrays opr_data = [] # Rosseland absorption opp_data = [] # Planck absorption ops_data = [] # Rosseland scattering oprt_data = [] # Rosseland total hnu_data = [] # hnu plot data # add points to plotting data twice to get the bar structure and find max and min opacity min_opacity = 1.0e10 max_opacity = 0.0 for hnu_i, hnu in enumerate(hnu_grid[:-1]): hnu_data.append(hnu) hnu_data.append(hnu_grid[hnu_i+1]) if (mgr_valid): opr_data.append(mgr_interp[hnu_i]) opr_data.append(mgr_interp[hnu_i]) min_opacity = min([min(opr_data), min_opacity]) max_opacity = max([max(opr_data), max_opacity]) if (mgp_valid): opp_data.append(mgp_interp[hnu_i]) opp_data.append(mgp_interp[hnu_i]) min_opacity = min([min(opp_data), min_opacity]) max_opacity = max([max(opp_data), max_opacity]) if (mgs_valid): ops_data.append(mgs_interp[hnu_i]) ops_data.append(mgs_interp[hnu_i]) min_opacity = min([min(ops_data), min_opacity]) max_opacity = max([max(ops_data), max_opacity]) a.set_xscale('log') a.set_yscale('log') a.set_xlabel('hnu (keV)') a.set_ylabel('opacity (cm sq./g)') # use label for Planck or Rosseland if (op_type.get() == 1 and mgr_valid ): a.plot(hnu_data, opr_data, 'b-', label = "{0} Rosseland Absorption".format(name)) elif(op_type.get() == 2 and mgp_valid): a.plot(hnu_data, opp_data, 'g-', label = "{0} Planckian Absorption".format(name)) elif(op_type.get() == 3 and mgr_valid and mgp_valid): a.plot(hnu_data, opr_data, 'b-', label = "{0} Rosseland Absorption".format(name)) a.plot(hnu_data, opp_data, 'g-', label = "{0} Planckian Absorption".format(name)) else: if (not mgr_valid): print("ERROR: Invalid multigroup Rosseland absorption data (all zeros)") if (not mgp_valid): print("ERROR: Invalid multigroup Planckian absorption data (all zeros)") if (mgs_valid): a.plot(hnu_data, ops_data, 'r-', label = "{0} Rosseland Scattering".format(name)) else: print("ERROR: Invalid multigroup scattering data (all zeros)") a.legend(loc='best') a.set_xlim([0.9*min(hnu_grid), 1.1*max(hnu_grid)]) a.set_ylim([ 0.7*min_opacity, 1.3*max_opacity]) canvas.show() canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1)
# get interpolated opacity data for this temperature and density # first check to see if the data is valid (non-zero) mgr_valid = ip_reader.check_valid_data(mgr_grid) mgp_valid = ip_reader.check_valid_data(mgp_grid) mgs_valid = ip_reader.check_valid_data(mgs_grid) mgrt_valid = ip_reader.check_valid_data(mgrt_grid) name = selected_ID.get() print( \ "-------------------- BEGIN DATA PRINT FOR {0} ---------------------"\ .format(name)) print("Group structure for {0} groups:".format(len(hnu_grid)-1)) print(hnu_grid) # if valid, interpolate data at target rho and target T if (mgr_valid): mgr_interp = ip_reader.interpolate_mg_opacity_data(T_grid, rho_grid, hnu_grid, mgr_grid, \ target_rho.get(), target_T.get(), "multigroup absorption Rosseland") if (mgp_valid): mgp_interp = ip_reader.interpolate_mg_opacity_data(T_grid, rho_grid, hnu_grid, mgp_grid, \ target_rho.get(), target_T.get(), "multigroup absorption Planckian") if (mgs_valid): mgs_interp =ip_reader.interpolate_mg_opacity_data(T_grid, rho_grid, hnu_grid, mgs_grid, \ target_rho.get(), target_T.get(), "multigroup scattering") if (mgrt_valid): mgrt_interp =ip_reader.interpolate_mg_opacity_data(T_grid, rho_grid, hnu_grid, mgrt_grid, \ target_rho.get(), target_T.get(), "total rosseland") print( \ "-------------------- END DATA PRINT FOR {0} ---------------------"\ .format(name)) # plotting data arrays opr_data = [] # Rosseland absorption