-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix field names in diag_parser.py and add example script (#2667)
Make sure np.genfromtxt() doesn't mess with the field names, add an example script that plots mass fractions over time from species_diag.out, and add a note to the docs. Co-authored-by: Alexander Smith <[email protected]>
- Loading branch information
1 parent
3a54bef
commit 8c34694
Showing
3 changed files
with
62 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env python3 | ||
import sys | ||
|
||
import matplotlib as mpl | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
from cycler import cycler | ||
from numpy.lib import recfunctions as rfn | ||
|
||
from diag_parser import deduplicate, read_diag_file | ||
|
||
data = deduplicate(read_diag_file(sys.argv[1])) | ||
|
||
mass_columns = [name for name in rfn.get_names(data.dtype) if name.startswith("Mass ")] | ||
|
||
# compute the total mass in the domain | ||
total_mass = rfn.apply_along_fields(np.sum, data[mass_columns]) | ||
|
||
# cycle through colors then line styles | ||
plt.rcParams["axes.prop_cycle"] = ( | ||
cycler(linestyle=["-", "--"]) * mpl.rcParamsDefault["axes.prop_cycle"] | ||
) | ||
|
||
plt.figure(figsize=(19.20, 10.80)) | ||
for col in mass_columns: | ||
plt.plot(data["TIME"], data[col] / total_mass, label=col.removeprefix("Mass ")) | ||
plt.xlabel("Time (s)") | ||
plt.ylabel("Mass fraction") | ||
# plt.xscale("log") | ||
plt.yscale("log") | ||
|
||
# put the legend to the right of the plot, not overlapping | ||
plt.legend(loc="center left", bbox_to_anchor=(1, 0.5)) | ||
|
||
plt.tight_layout() | ||
plt.savefig("massfrac_plot.png") |