|
1 | | -import numpy |
2 | | -from matplotlib import pyplot |
3 | | -from amuse.lab import * |
| 1 | +import numpy as np |
| 2 | +import matplotlib.pyplot as plt |
| 3 | +from amuse.units import units |
| 4 | + |
| 5 | +from amuse.examples.supernova_IIp_Lightcurve import Supernova_IIp |
4 | 6 |
|
5 | | -from prepare_figure import single_frame, figure_frame, set_tickmarks |
6 | | -from distinct_colours import get_distinct |
7 | | -from supernova_IIp_Lightcurve import Supernova_IIp |
8 | 7 |
|
9 | 8 | def read_supernova_irradiation_file(filename): |
10 | 9 | t = [] |
11 | 10 | Tmean = [] |
12 | 11 | Tmax = [] |
13 | 12 | for line in open(filename): |
14 | | - if 'Time' in line: |
| 13 | + if "Time" in line: |
15 | 14 | sl = line.split() |
16 | 15 | t.append(float(sl[1])) |
17 | | - if 'Temperature:' in line: |
| 16 | + if "Temperature:" in line: |
18 | 17 | sl = line.split() |
19 | 18 | Tmean.append(float(sl[3])) |
20 | 19 | Tmax.append(float(sl[1])) |
21 | | - return numpy.asarray(t, dtype="float"), Tmean, Tmax |
| 20 | + return np.asarray(t, dtype="float"), Tmean, Tmax |
| 21 | + |
22 | 22 |
|
23 | 23 | def read_Earthorbit(): |
24 | 24 | t = [] |
25 | 25 | e = [] |
26 | 26 | a = [] |
27 | | - tmax = 1.e+6 |
28 | | - for line in open('Eart_Orbit_Eps-3.data'): |
29 | | - if '#' not in line: |
| 27 | + tmax = 1.0e6 |
| 28 | + for line in open("Eart_Orbit_Eps-3.data"): |
| 29 | + if "#" not in line: |
30 | 30 | sl = line.split() |
31 | 31 | t.append(float(sl[0])) |
32 | 32 | a.append(float(sl[1])) |
33 | 33 | e.append(float(sl[2])) |
34 | | - if t[-1]>tmax: |
| 34 | + if t[-1] > tmax: |
35 | 35 | break |
36 | | - return t, a, e |
| 36 | + return t, a, e |
| 37 | + |
37 | 38 |
|
38 | | -if __name__ in ('__main__', '__plot__'): |
39 | | - to = 50|units.day |
| 39 | +def plot_supernova_IIp_and_disk_temperature(): |
| 40 | + to = 50 | units.day |
40 | 41 |
|
41 | | - t_offset = to + (((0.15|units.parsec)/(1|units.lightyear)) | units.yr) |
42 | | - filename = 'SN10a.R0.15.i15.data' |
| 42 | + t_offset = to + (((0.15 | units.parsec) / (1 | units.lightyear)) | units.yr) |
| 43 | + filename = "SN10a.R0.15.i15.data" |
43 | 44 | time, Tmean, Tmax = read_supernova_irradiation_file(filename) |
44 | 45 | time += t_offset.value_in(units.day) |
45 | 46 |
|
46 | | - t_offset = to + (((0.3|units.parsec)/(1|units.lightyear)) | units.yr) |
47 | | - filename = 'SN11aof.R0.3.i45.data' |
| 47 | + t_offset = to + (((0.3 | units.parsec) / (1 | units.lightyear)) | units.yr) |
| 48 | + filename = "SN11aof.R0.3.i45.data" |
48 | 49 | t3pc_N7, Tmean3pc_N7, Tmax3pc_N7 = read_supernova_irradiation_file(filename) |
49 | 50 | t3pc_N7 += t_offset.value_in(units.day) |
50 | 51 |
|
51 | | - t_offset = to + (((0.4|units.parsec)/(1|units.lightyear)) | units.yr) |
52 | | - filename = 'SN11aof.R0.4.i15.data' |
| 52 | + t_offset = to + (((0.4 | units.parsec) / (1 | units.lightyear)) | units.yr) |
| 53 | + filename = "SN11aof.R0.4.i15.data" |
53 | 54 | t3pc_N8, Tmean3pc_N8, Tmax3pc_N8 = read_supernova_irradiation_file(filename) |
54 | 55 | t3pc_N8 += t_offset.value_in(units.day) |
55 | 56 |
|
56 | 57 | PS1_11aof = Supernova_IIp("11aof", to) |
57 | | - t = 10**numpy.arange(-2, 3., 0.01) | units.day |
58 | | - L11aof = [] | units.erg/units.s |
| 58 | + t = 10 ** np.arange(-2, 3.0, 0.01) | units.day |
| 59 | + L11aof = [] | units.erg / units.s |
59 | 60 | for ti in t: |
60 | 61 | L11aof.append(PS1_11aof.luminosity_at_time(ti)) |
61 | | - L11aof = numpy.log10(L11aof.value_in(units.LSun)) |
| 62 | + L11aof = np.log10(L11aof.value_in(units.LSun)) |
62 | 63 |
|
63 | 64 | PS1_10a = Supernova_IIp("10a", to) |
64 | | - L10a = [] | units.erg/units.s |
| 65 | + L10a = [] | units.erg / units.s |
65 | 66 | for ti in t: |
66 | 67 | L10a.append(PS1_10a.luminosity_at_time(ti)) |
67 | | - L10a = numpy.log10(L10a.value_in(units.LSun)) |
68 | | - |
69 | | - from matplotlib import pyplot, rc |
| 68 | + L10a = np.log10(L10a.value_in(units.LSun)) |
| 69 | + |
70 | 70 | x_label = "$t$ [day]" |
71 | 71 | y_label = "L [L$_\odot$]" |
72 | | - figure = single_frame(x_label, y_label, xsize=14, ysize=10) |
73 | | - ax1 = pyplot.gca() |
74 | | - cols = get_distinct(4) |
75 | | - |
76 | | - font = {'size' : 20} |
77 | | - rc('font', **font) |
78 | | - ax1.plot(t.value_in(units.day), L11aof, ls='-', c=cols[0]) |
79 | | - ax1.plot(t.value_in(units.day), L10a, ls='--', c=cols[0]) |
80 | | - ax1.set_xlabel('time [day]') |
81 | | - ax1.set_ylabel('log$_{10}$(L/L$_\odot$)', color=cols[0]) |
| 72 | + figure = plt.figure() |
| 73 | + ax1 = figure.add_subplot(1, 1, 1) |
| 74 | + ax1.set_xlabel(x_label) |
| 75 | + ax1.set_ylabel(y_label) |
| 76 | + |
| 77 | + colors = plt.rcParams["axes.prop_cycle"].by_key()["color"] |
| 78 | + ax1.plot(t.value_in(units.day), L11aof, ls="-", c=colors[0]) |
| 79 | + ax1.plot(t.value_in(units.day), L10a, ls="--", c=colors[0]) |
| 80 | + ax1.set_xlabel("time [day]") |
| 81 | + ax1.set_ylabel("log$_{10}$(L/L$_\odot$)", color=colors[0]) |
82 | 82 | for tl in ax1.get_yticklabels(): |
83 | | - tl.set_color(cols[0]) |
| 83 | + tl.set_color(colors[0]) |
84 | 84 |
|
85 | 85 | ax2 = ax1.twinx() |
86 | | - ax2.plot(time, Tmean, cols[1], ls='--') |
87 | | - ax2.plot(t3pc_N7, Tmean3pc_N7, cols[1]) |
88 | | - ax2.plot(t3pc_N8, Tmean3pc_N8, cols[1], lw=4) |
89 | | - ax2.set_ylabel('mean temperature [K]', color=cols[1]) |
| 86 | + ax2.plot(time, Tmean, colors[1], ls="--") |
| 87 | + ax2.plot(t3pc_N7, Tmean3pc_N7, colors[1]) |
| 88 | + ax2.plot(t3pc_N8, Tmean3pc_N8, colors[1], lw=4) |
| 89 | + ax2.set_ylabel("mean temperature [K]", color=colors[1]) |
90 | 90 | for tl in ax2.get_yticklabels(): |
91 | | - tl.set_color(cols[1]) |
| 91 | + tl.set_color(colors[1]) |
92 | 92 |
|
93 | 93 | t_cooling = [950, 1061] |
94 | 94 | T_cooling = [1600, 800] |
95 | | - ax2.plot(t_cooling, T_cooling, cols[3], lw=1) |
96 | | - ax2.text(t_cooling[0]+20, T_cooling[0]-100, "cooling of 0.3 K/h", rotation=-76.5, color=cols[3]) |
97 | | - |
98 | | - pyplot.show() |
99 | | -# pyplot.savefig("supernova_IIp_and_disk_temperature") |
| 95 | + ax2.plot(t_cooling, T_cooling, colors[3], lw=1) |
| 96 | + ax2.text( |
| 97 | + t_cooling[0] + 20, |
| 98 | + T_cooling[0] - 100, |
| 99 | + "cooling of 0.3 K/h", |
| 100 | + rotation=-76.5, |
| 101 | + color=colors[3], |
| 102 | + ) |
| 103 | + |
| 104 | + plt.savefig("supernova_IIp_and_disk_temperature") |
| 105 | + |
| 106 | + |
| 107 | +def main(): |
| 108 | + plot_supernova_IIp_and_disk_temperature() |
| 109 | + |
100 | 110 |
|
| 111 | +if __name__ == "__main__": |
| 112 | + main() |
0 commit comments