3 from __future__
import print_function
6 import matplotlib.pyplot
as plt
11 parser = argparse.ArgumentParser(description=
"Plot field profiles")
12 parser.add_argument(
"output_dir", help=
"directory containing output file")
13 args = parser.parse_args()
14 return args.output_dir
17 profiles_data = np.genfromtxt(profile_file, names=
True)
19 fields = [f
for f
in profiles_data.dtype.names
20 if (f !=
"perturbation" and f !=
"rho")]
21 perturbations = {
int(i): profiles_data[profiles_data[
"perturbation"] == i]
22 for i
in np.unique(profiles_data[
"perturbation"])}
25 output_file = os.path.join(output_dir,
"{}_{}.png".format(prefix, f))
26 fig, ax = plt.subplots()
28 for p
in perturbations:
29 ax.plot(perturbations[p][
"rho"], perturbations[p][f],
30 label=
"perturbation {:d}".format(p))
34 plt.legend(numpoints = 1)
36 plt.savefig(output_file)
40 action_data = np.genfromtxt(action_file, names=
True)
41 output_file = os.path.join(output_dir,
"{}.png".format(prefix))
43 fig, ax = plt.subplots()
45 ax.plot(action_data[
"perturbation"], action_data[
"action"],
"bo")
47 ax.set_xlabel(
"perturbation")
48 ax.set_ylabel(
"action")
50 plt.savefig(output_file)
55 field_profiles_file = os.path.join(output_dir,
"field_profiles.txt")
56 corrections_file = os.path.join(output_dir,
"perturbations.txt")
57 action_file = os.path.join(output_dir,
"action.txt")
59 if os.path.exists(field_profiles_file):
60 plot_profiles(field_profiles_file, output_dir,
"field_profiles")
62 raise IOError(
"Field profiles file '" + field_profiles_file
65 if os.path.exists(corrections_file):
68 raise IOError(
"Perturbations/corrections file '" + corrections_file
71 if os.path.exists(action_file):
74 raise IOError(
"Action file '" + action_file +
"' not found!")
def plot_profiles(profile_file, output_dir, prefix)
def parse_cmd_line_args()
def plot_action(action_file, output_dir, prefix)