BubbleProfiler  0.3.0
by Peter Athron, Csaba Balazs, Michael Bardsley, Andrew Fowlie, Dylan Harries & Graham White
make_plots.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from __future__ import print_function
4 
5 import argparse
6 import matplotlib.pyplot as plt
7 import numpy as np
8 import os
9 
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
15 
16 def plot_profiles(profile_file, output_dir, prefix):
17  profiles_data = np.genfromtxt(profile_file, names=True)
18 
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"])}
23 
24  for f in fields:
25  output_file = os.path.join(output_dir, "{}_{}.png".format(prefix, f))
26  fig, ax = plt.subplots()
27 
28  for p in perturbations:
29  ax.plot(perturbations[p]["rho"], perturbations[p][f],
30  label="perturbation {:d}".format(p))
31 
32  ax.set_xlabel("rho")
33  ax.set_ylabel(f)
34  plt.legend(numpoints = 1)
35 
36  plt.savefig(output_file)
37  plt.close(fig)
38 
39 def plot_action(action_file, output_dir, prefix):
40  action_data = np.genfromtxt(action_file, names=True)
41  output_file = os.path.join(output_dir, "{}.png".format(prefix))
42 
43  fig, ax = plt.subplots()
44 
45  ax.plot(action_data["perturbation"], action_data["action"], "bo")
46 
47  ax.set_xlabel("perturbation")
48  ax.set_ylabel("action")
49 
50  plt.savefig(output_file)
51  plt.close(fig)
52 
53 
54 output_dir = parse_cmd_line_args()
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")
58 
59 if os.path.exists(field_profiles_file):
60  plot_profiles(field_profiles_file, output_dir, "field_profiles")
61 else:
62  raise IOError("Field profiles file '" + field_profiles_file
63  + "' not found!")
64 
65 if os.path.exists(corrections_file):
66  plot_profiles(corrections_file, output_dir, "corrections")
67 else:
68  raise IOError("Perturbations/corrections file '" + corrections_file
69  + "' not found!")
70 
71 if os.path.exists(action_file):
72  plot_action(action_file, output_dir, "action")
73 else:
74  raise IOError("Action file '" + action_file + "' not found!")
def plot_profiles(profile_file, output_dir, prefix)
Definition: make_plots.py:16
def parse_cmd_line_args()
Definition: make_plots.py:10
def plot_action(action_file, output_dir, prefix)
Definition: make_plots.py:39