-
Notifications
You must be signed in to change notification settings - Fork 1
/
migration.py
executable file
·127 lines (87 loc) · 2.89 KB
/
migration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/python3
# Include all relevant packages and modules
import matplotlib.pyplot as plt
import numpy as np
import sys
from modules.params import Params
#------------------------------#
# Variables
#------------------------------#
# Look for using default flags (uses all default values)
params = Params(sys.argv)
# Directory paths
directory = params.get("dir")
# Number of files to use
starts = [p.strip() for p in params.get("starts").split(",")]
# Whether to plot all start points
plot_startpoints = params.get("plot_start")
# Whether to plot all end points
plot_endpoints = params.get("plot_end")
# Target radius line
target_radius = params.get("radius")
# Minimum Plot Y-Axis
min_yaxis = params.get("min_y")
# Units of body mass
planet_units = params.get("p_unit")
# Graph variables
title = params.get("title")
# The name of the file
filename = directory + params.get("file")
#------------------------------#
# Fix any variables if required
if directory[-1] != "/":
directory += "/"
# The list of all data files - AU distances
colors = []
data = {}
# Create the list of data
for start in starts:
# Attempt to get the data
try:
data[start] = np.loadtxt(directory + "{}.out".format(start))
except:
print("Missing data: %s%s.out" % (directory, start))
starts.remove(start)
# Create the plot
fig, ax = plt.subplots(figsize=(12, 6))
# Find min length of the data
min_idx = 1e10
for start in starts:
if len(data[start]) < min_idx:
min_idx = len(data[start])
# Plot each of the data points
for idx, start in enumerate(starts):
# Get data
d = data[start]
r_idx = len(d[0]) - 2
# Check for color exists
if idx < len(colors):
# Plot the graph with colors
ax.plot(d[:min_idx,0], d[:min_idx,r_idx], color = colors[idx], label= start + planet_units)
else:
# No color preference
ax.plot(d[:min_idx,0], d[:min_idx,r_idx], label = start + planet_units)
# Plot only one start point (if flagged)
if idx == 0 or plot_startpoints:
ax.text(d[0,0], d[0,r_idx],' {:.1f} AU'.format(d[0,r_idx]))
ax.plot(d[0,0], d[0,r_idx], 'o', color='black')
# Plot end points excluding one (if flagged)
if idx == 0 or plot_endpoints:
ax.text(d[min_idx - 1,0], d[min_idx - 1, r_idx],' {:.1f} AU'.format(d[min_idx - 1,r_idx]))
ax.plot(d[min_idx - 1,0], d[min_idx - 1, r_idx], 'o', color='black')
# Add final location
x = np.linspace(0, np.max(data[starts[-1]][:,0] * 1.1), 2)
y = x * 0 + target_radius
ax.plot(x, y, label='Target Radius: %s AU' % str(target_radius), color='black', linestyle='dashed')
# Set the limits
ax.set_ylim([min_yaxis, np.max(data[starts[-1]][:,r_idx]) * 1.1])
ax.set_xlim([0, np.max(data[starts[-1]][:min_idx,0]) * 1.1])
ax.set_ylabel('Orbitial Radius (AU)', fontsize=14)
ax.set_xlabel('Simulation Time (Myr)', fontsize=14)
# Show the plot
ax.legend()
ax.set_title(title, fontsize=16)
# Save the figure
fig.savefig(filename + ".pdf", bbox_inches='tight')
# Display the figure
plt.show()