def plot_single_mass_fraction_vs_property(file, prop, species, **keyword_parameters): root = etree.parse(file).getroot() props = wn_xml.get_properties_in_zones(root, [prop]) m = wn_xml.get_mass_fractions_in_zones(root, species) x = np.array(map(float, props[prop])) if ('xfactor' in keyword_parameters): x /= float(keyword_parameters['xfactor']) plp.set_plot_params(plt, keyword_parameters) if ('use_latex_names' in keyword_parameters): if (keyword_parameters['use_latex_names'] == 'yes'): plt.ylabel('X(' + wn_utilities.get_latex_names([species])[species] + ')') for my_species in species: y = np.array(map(float, m[my_species])) plt.plot(x, y) plt.show()
def plot_group_mass_fractions_vs_property(file, group, prop, species, **keyword_parameters): plp.set_plot_params(mpl, keyword_parameters) fig = plt.figure() x = [] y = [] l = [] latex_names = [] props = wn_h5.get_group_properties_in_zones(file, group, [prop]) m = wn_h5.get_group_mass_fractions(file, group) nuclide_data = wn_h5.get_nuclide_data_hash(file) if ('xfactor' in keyword_parameters): xfactor = keyword_parameters['xfactor'] else: xfactor = 1 x = np.array(map(float, props[prop])) / xfactor if ('use_latex_names' in keyword_parameters): if (keyword_parameters['use_latex_names'] == 'yes'): laxtex_names = wn_utilities.get_latex_names(species) iy = 0 for sp in species: y = np.array(map(float, m[:, nuclide_data[sp]['index']])) if (len(latex_names) != 0): lab = latex_names[sp] else: lab = sp l.append(plt.plot(x, y, label=lab)) if (len(species) != 1): plt.legend(loc='upper right', prop={'size': 14}) if ('ylabel' not in keyword_parameters): if (len(species) != 1): plt.ylabel('Mass Fraction') else: if (len(latex_names) == 0): plt.ylabel('X(' + species[0] + ')') else: plt.ylabel('X(' + latex_names[species[0]] + ')') if ('xlabel' not in keyword_parameters): plt.xlabel(prop) plp.apply_class_methods(plt, keyword_parameters) plt.show()
def plot_zone_mass_fractions_vs_property(file, zone, prop, species, **keyword_parameters): plp.set_plot_params(mpl, keyword_parameters) fig = plt.figure() x = [] y = [] l = [] latex_names = [] props = wn_h5.get_zone_properties_in_groups(file, zone, [prop]) m = wn_h5.get_zone_nuclide_mass_fractions_in_groups(file, zone, species) if ('xfactor' in keyword_parameters): xfactor = keyword_parameters['xfactor'] else: xfactor = 1 x = np.array(map(float, props[prop])) / xfactor if ('use_latex_names' in keyword_parameters): if (keyword_parameters['use_latex_names'] == 'yes'): latex_names = wn_utilities.get_latex_names(species) for i in range(len(species)): y = np.array(list(map(float, m[species[i]]))) if (len(latex_names) != 0): lab = latex_names[species[i]] else: lab = species[i] l.append(plt.plot(x, y, label=lab)) if (len(species) != 1): plt.legend(loc='upper left', prop={'size': 14}) if ('ylabel' not in keyword_parameters): if (len(species) != 1): plt.ylabel('Mass Fraction') else: if (len(latex_names) == 0): plt.ylabel('X(' + species[0] + ')') else: plt.ylabel('X(' + latex_names[species[0]] + ')') if ('xlabel' not in keyword_parameters): plt.xlabel(prop) plp.apply_class_methods(plt, keyword_parameters) plt.show()
def plot_mass_fractions_vs_property(file, prop, species, **keyword_parameters): plp.set_plot_params(mpl, keyword_parameters) fig = plt.figure() x = [] y = [] l = [] latex_names = [] root = etree.parse(file).getroot() props = wn_xml.get_properties_in_zones(root, [prop]) x = np.array(list(map(float, props[prop]))) if ('xfactor' in keyword_parameters): x /= float(keyword_parameters['xfactor']) m = wn_xml.get_mass_fractions_in_zones(root, species) if ('use_latex_names' in keyword_parameters): if (keyword_parameters['use_latex_names'] == 'yes'): latex_names = wn_utilities.get_latex_names(species) for i in range(len(species)): y = np.array(list(map(float, m[species[i]]))) if (len(latex_names) != 0): lab = latex_names[species[i]] else: lab = species[i] l.append(plt.plot(x, y, label=lab)) if ('ylabel' not in keyword_parameters): if (len(species) != 1): plt.ylabel('Mass Fraction') else: if (len(latex_names) == 0): plt.ylabel('X(' + species[0] + ')') else: plt.ylabel('X(' + latex_names[species[0]] + ')') if len(species) != 1: plt.legend() if ('xlabel' not in keyword_parameters): plt.xlabel(prop) plp.apply_class_methods(plt, keyword_parameters) plt.show()
def plot_mass_fractions(file, species, **keyword_parameters): plp.set_plot_params(mpl, keyword_parameters) fig = plt.figure() y = [] l = [] latex_names = [] root = etree.parse(file).getroot() m = wn_xml.get_mass_fractions_in_zones(root, species) if ('use_latex_names' in keyword_parameters): if (keyword_parameters['use_latex_names'] == 'yes'): latex_names = wn_utilities.get_latex_names(species) for i in range(len(species)): y = np.array(list(map(float, m[species[i]]))) if (len(latex_names) != 0): lab = latex_names[species[i]] else: lab = species[i] l.append(plt.plot(y, label=lab)) # if( len( species ) != 1 ): # plt.legend(loc='upper right', prop={'size':14}) if ('ylabel' not in keyword_parameters): if (len(species) != 1): plt.ylabel('Mass Fraction') else: if (len(latex_names) == 0): plt.ylabel('X(' + species[0] + ')') else: plt.ylabel('X(' + latex_names[species[0]] + ')') if ('xlabel' not in keyword_parameters): plt.xlabel('step') plp.apply_class_methods(plt, keyword_parameters) plt.show()
def plot_single_mass_fraction_vs_property_in_files(files, prop, species, **keyword_parameters): plp.set_plot_params(plt, keyword_parameters) if ('legend_labels' in keyword_parameters): if (len(keyword_parameters['legend_labels']) != len(files)): print("Invalid legend labels for input files.") exit(1) fig = plt.figure() roots = [] x = [] y = [] l = [] for file in files: roots.append(etree.parse(file).getroot()) for i in range(len(roots)): props = wn_xml.get_properties_in_zones(roots[i], [prop]) x = np.array(list(map(float, props[prop]))) if ('xfactor' in keyword_parameters): x /= float(keyword_parameters['xfactor']) m = wn_xml.get_mass_fractions_in_zones(roots[i], [species]) y = np.array(list(map(float, m[species]))) if ('legend_labels' in keyword_parameters): ll, = plt.plot(x, y, label=keyword_parameters['legend_labels'][i]) else: ll, = plt.plot(x, y) l.append(ll) plp.apply_class_methods(plt, keyword_parameters) if ('use_latex_names' in keyword_parameters): if (keyword_parameters['use_latex_names'] == 'yes'): plt.ylabel('X(' + wn_utilities.get_latex_names([species])[species] + ')') plt.show()
def plot_single_mass_fraction_vs_property(file, zone, prop, species, **keyword_parameters): props = wn_h5.get_zone_properties_in_groups(file, zone, [prop]) m = wn_h5.get_zone_nuclide_mass_fractions_in_groups(file, zone, [species]) if ('xfactor' in keyword_parameters): xfactor = keyword_parameters['xfactor'] else: xfactor = 1 x = np.array(map(float, props[prop])) / xfactor y = np.array(map(float, m[species])) plp.set_plot_params(plt, keyword_parameters) if ('use_latex_names' in keyword_parameters): if (keyword_parameters['use_latex_names'] == 'yes'): plt.ylabel('X(' + wn_utilities.get_latex_names([species])[species] + ')') plt.plot(x, y) plt.show()
def movie_mass_fractions_vs_property(file, movie_name, prop, species, **keyword_parameters): import matplotlib.animation as manimation FFMpegWriter = manimation.writers['ffmpeg'] metadata = dict(title='Movie Test', artist='Matplotlib', comment='Movie support!') if ('fps' in keyword_parameters): fps = keyword_parameters['fps'] else: fps = 15 writer = FFMpegWriter(fps=fps, metadata=metadata) ts_factor = {'yr': 3.15e7, 'kyr': 3.15e10, 'Myr': 3.15e13} fig = plt.figure() groups = wn_h5.get_iterable_groups(file) nuclide_data = wn_h5.get_nuclide_data_hash(file) plp.set_plot_params(plt, keyword_parameters) names = wu.get_latex_names(species) l = {} for name in names: l[name], = plt.plot([], [], label=name) legend = plt.legend(loc='upper center', shadow=True) with writer.saving(fig, movie_name, 200): for group in groups: m = wn_h5.get_group_mass_fractions(file, group) t = wn_h5.get_group_properties_in_zones(file, group, ['time']) tt = float(t['time'][0]) title_str = "time (s) = %7.2e" % tt if ('time_scale' in keyword_parameters): title_str = \ "time (" + keyword_parameters['time_scale'] + ") = %7.2e" \ % (tt / ts_factor[keyword_parameters['time_scale']] ) plt.title(title_str) if prop == '': x = np.linspace(0, len(m[:, 0]) - 1, len(m[:, 0])) else: props = wn_h5.get_group_properties_in_zones( file, group, [prop]) if ('xfactor' in keyword_parameters): xfactor = keyword_parameters['xfactor'] else: xfactor = 1 x = np.array(map(float, props[prop])) / xfactor for sp in species: y = np.array(map(float, m[:, nuclide_data[sp]['index']])) l[sp].set_data(x, y) writer.grab_frame()