Basics¶

make sure you have some data in your example_1k directory doing an nbody run. See examples README

Reading data from the main stdout file¶

If you've followed the examples README, the standard output was redirected into the file example_1k/1k.out.

Let's have a look at that file

In [ ]:
with open("example_1k/1k.out","r") as nb_stdout:
    for line in enumerate(nb_stdout):
        print(line[1])
        
# Careful, this will produce quite some output!

Lagrangian Radii¶

The main stdout file produces a lot of output. See the documentation for more information on what data can be pulled out from the main stdout file.

Let us now extract some data. If you e.g. search for RLAGR in the output file, you'll find multiple results like this, giving the Lagragian radii for different mass fractions, and even some more info. Let us now try to extract this data

TIME   M/MT:  1.00E-03  3.00E-03  5.00E-03  1.00E-02  [...]
0.0000D+00 RLAGR:   6.27E-02  1.00E-01  1.02E-01  [...]
0.0000D+00 AVMASS:  7.82E-04  5.23E-04  1.29E-03  [...]
0.0000D+00 NPARTC:         3         6         7  [...]
0.0000E+00 SIGR2:   3.62E-02  4.58E+03  1.44E+08  [...]
0.0000E+00 SIGT2:   7.10E-03  1.21E+03  3.84E+07  [...]
0.0000E+00 VROT:    2.89E-02  9.31E+00  1.03E+03  [...]

Reading the data¶

Start by importing some useful libraries

In [1]:
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import re
In [2]:
# initialize a pandas DataFrame
df = None

# work through the file
with open("example_1k/1k.out","r") as nb_stdout:
    for line in nb_stdout:
        # Match line where we get the mass fractions
        if re.search("TIME.*M/MT:", line):
            # Replace the multiple spaces by just one space
            line = re.sub("\s+", " ", line).strip()
            # After replacing the multiple spaces we can more easily split the line
            line = line.split(" ")
            # We'll now store our mass fractions as we'll later use them as columns
            cols = [float(i) for i in line[2:len(line)-1]] + [line[len(line)-1]]
            
            # create the DataFrame if it's not done yet
            if df is None:
                df = pd.DataFrame(columns=cols)
        # Match lines with lagragian radii
        elif re.search("RLAGR:", line):
            # Similarly prepare the line, for working with it
            line = re.sub("\s+", " ", line).strip()
            line = line.split(" ")
            
            # We need to replace D by E, since python can not handle D as exponential,
            # after that we set the row at time t by the following values
            df.loc[np.float64(line[0].replace("D","E"))] = np.float64(line[2:])

df         
Out[2]:
0.001 0.003 0.005 0.01 0.03 0.05 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 0.95 0.99 1.0 <RC
0.0 0.0627 0.1000 0.1020 0.1060 0.1580 0.2240 0.296 0.431 0.536 0.667 0.731 0.836 1.04 1.45 2.36 2.90 4.50 6.12 0.2910
1.0 0.0645 0.0831 0.0886 0.1050 0.1510 0.1980 0.243 0.391 0.534 0.624 0.813 0.924 1.04 1.45 2.51 2.87 4.93 6.28 0.1880
2.0 0.0907 0.1060 0.1420 0.1660 0.1960 0.2170 0.239 0.371 0.460 0.606 0.766 0.995 1.35 1.46 2.44 2.86 4.83 6.55 0.2890
3.0 0.0638 0.0784 0.0925 0.1020 0.1260 0.1390 0.273 0.336 0.485 0.643 0.785 1.010 1.35 1.61 2.58 3.02 4.46 6.72 0.2050
4.0 0.0956 0.0983 0.1100 0.1290 0.1350 0.1720 0.216 0.371 0.461 0.595 0.805 1.040 1.55 1.60 2.58 2.98 4.20 6.70 0.2000
5.0 0.0225 0.0411 0.0433 0.0439 0.0443 0.0480 0.162 0.321 0.490 0.668 0.898 1.150 1.34 1.74 2.38 2.97 4.50 6.69 0.0606
6.0 0.0337 0.0398 0.0586 0.0716 0.0737 0.0908 0.132 0.327 0.570 0.770 0.963 1.060 1.36 1.81 2.32 3.12 4.47 6.60 0.0901
7.0 0.0290 0.0346 0.0361 0.0476 0.0611 0.0656 0.153 0.313 0.538 0.657 0.811 1.040 1.35 1.89 2.48 3.35 5.07 6.70 0.0582
8.0 0.0492 0.0573 0.0642 0.0651 0.0722 0.0864 0.103 0.339 0.420 0.621 0.881 1.200 1.60 2.05 3.60 6.84 6.84 6.84 0.1070
9.0 0.0744 0.0855 0.0908 0.0922 0.0960 0.1050 0.136 0.366 0.475 0.697 0.952 1.270 1.58 2.21 3.75 8.11 8.11 8.11 0.1740
10.0 0.0144 0.0328 0.0354 0.0398 0.0413 0.0499 0.103 0.393 0.501 0.768 1.040 1.360 1.67 2.31 4.28 9.90 9.90 9.90 0.0445
11.0 0.0839 0.0990 0.1030 0.1200 0.1520 0.1580 0.202 0.320 0.651 0.860 1.080 1.490 1.84 2.54 4.73 11.60 11.60 11.60 0.2140
12.0 0.0668 0.0714 0.0783 0.1150 0.1180 0.1210 0.139 0.414 0.673 0.948 1.240 1.580 1.96 2.68 4.93 13.40 13.40 13.40 0.1300
13.0 0.0217 0.0266 0.0360 0.0454 0.0473 0.0667 0.112 0.353 0.657 1.020 1.340 1.750 2.12 2.79 5.35 15.00 15.00 15.00 0.0547
14.0 0.0694 0.1220 0.1250 0.1590 0.1650 0.2490 0.299 0.487 0.660 1.080 1.470 1.930 2.40 3.21 6.24 16.90 16.90 16.90 0.2980
15.0 0.0437 0.0695 0.1010 0.1350 0.1470 0.1590 0.273 0.588 0.819 1.160 1.550 2.010 2.59 3.56 6.89 18.60 18.60 18.60 0.1960
16.0 0.1140 0.1210 0.1260 0.1620 0.1650 0.1670 0.183 0.556 0.928 1.310 1.600 2.100 2.79 3.79 7.19 20.20 20.20 20.20 0.2310
17.0 0.1190 0.1490 0.1570 0.1600 0.1970 0.2030 0.275 0.637 0.846 1.330 1.730 2.150 2.94 4.09 7.96 21.90 21.90 21.90 0.3160
18.0 0.0900 0.1080 0.1530 0.1640 0.1640 0.1680 0.215 0.539 0.887 1.230 1.820 2.260 3.04 4.40 8.41 23.70 23.70 23.70 0.2390
19.0 0.0605 0.0647 0.0748 0.1020 0.1280 0.1410 0.190 0.424 0.857 1.250 1.720 2.330 3.20 4.95 15.70 25.30 25.30 25.30 0.1910
20.0 0.0439 0.0800 0.1140 0.1390 0.1620 0.1630 0.316 0.488 0.942 1.270 1.710 2.400 3.36 5.29 16.90 27.00 27.00 27.00 0.2630
21.0 0.0505 0.1080 0.1210 0.1360 0.1650 0.1950 0.324 0.517 0.896 1.250 1.700 2.340 3.34 5.41 18.00 18.00 18.00 18.00 0.2550
22.0 0.0604 0.0796 0.0816 0.0851 0.0887 0.1340 0.202 0.562 0.888 1.300 1.710 2.350 3.38 5.71 19.20 19.20 19.20 19.20 0.0877
23.0 0.0390 0.0877 0.1030 0.1240 0.1310 0.2320 0.261 0.567 0.902 1.270 1.740 2.410 3.41 5.85 21.10 21.10 21.10 21.10 0.1720
24.0 0.0492 0.0595 0.0726 0.0732 0.0843 0.1170 0.154 0.624 0.934 1.250 1.700 2.350 3.40 5.97 25.40 25.40 25.40 25.40 0.1070
25.0 0.0965 0.1030 0.1130 0.1300 0.1660 0.1780 0.226 0.564 0.877 1.330 1.700 2.260 3.44 6.20 23.20 23.20 23.20 23.20 0.1870
26.0 0.0945 0.0973 0.1340 0.1380 0.1430 0.1440 0.187 0.469 0.836 1.320 1.710 2.300 3.38 6.29 24.40 24.40 24.40 24.40 0.2170
27.0 0.0702 0.0890 0.1180 0.1440 0.1480 0.1920 0.223 0.511 0.855 1.220 1.630 2.310 3.54 6.58 25.70 25.70 25.70 25.70 0.2350
28.0 0.0335 0.0677 0.0794 0.0862 0.1020 0.1070 0.264 0.479 0.794 1.170 1.620 2.320 3.70 6.75 24.80 24.80 24.80 24.80 0.1300
29.0 0.0768 0.1020 0.1020 0.1030 0.1150 0.1180 0.160 0.525 0.828 1.110 1.640 2.290 3.71 7.01 25.80 25.80 25.80 25.80 0.1570
30.0 0.0211 0.0632 0.0891 0.0908 0.0919 0.0990 0.276 0.490 0.918 1.300 1.820 2.600 4.37 8.44 26.20 26.20 26.20 26.20 0.0881

Plotting¶

This is already a nice table, but let's plot the data

In [3]:
# We don't want it to get too messy, so let's only plot
# a few columns
COLS = [0.1, 0.3, 0.5, 0.9, 1.0]

# Prepare plot
fig = plt.figure(figsize=(9,6))
ax = fig.gca()

# plot
df[COLS].plot(ax=ax)

# make the plot a little bit nicer
ax.set_title(r"Lagragian Radii time evolution")
ax.set_xlabel(r"Time t [nbody units]")
ax.set_ylabel(r"R [nbody units]")
ax.grid()
ax.set_yscale("log")

Get more information¶

Let's get more info, we've only slightly modified the code to read the main output file. From the example output above we can also read not only RLAGR but also AVMASS, NPARTC, SIGR2, SIGT2, and VROT

In [4]:
# set lines to analyze
LINES_TO_READ = ["RLAGR", "AVMASS", "NPARTC", "SIGR2", "SIGT2", "VROT"]

# this time, just set the columns manually instead of letting
# the program figure it out for itself.
COLS = [0.001, 0.003, 0.005, 0.01, 0.03, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.95, 0.99, 1.0, '<RC']

# initialize dataframes to store results in
data = {data_type: pd.DataFrame(columns=COLS) for data_type in LINES_TO_READ}

# work through the file
with open("example_1k/1k.out","r") as nb_stdout:
    for line in nb_stdout:
        # work through all lines that should be read
        for data_type in LINES_TO_READ:
            # match lines with data type
            if re.search(data_type, line):
                # prepare the line, for working with it
                line = re.sub("\s+", " ", line).strip()
                line = line.split(" ")

                # We need to replace D by E, since python can not handle D as exponential,
                # after that we set the row at time t by the following values
                (data[data_type]).loc[np.float64(line[0].replace("D","E"))] = np.float64(line[2:])
                # stop loop cause each line can only have one data type
                break

data["VROT"]
Out[4]:
0.001 0.003 0.005 0.01 0.03 0.05 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 0.95 0.99 1.0 <RC
0.0 0.0289 9.31 1030.0 63400.0 2110000.0 4.210000e+07 3.760000e+08 1.880000e+09 6.250000e+09 1.520000e+10 2.850000e+10 4.730000e+10 6.750000e+10 8.430000e+10 9.370000e+10 9.840000e+10 9.940000e+10 9.940000e+10 -0.01920
1.0 0.5850 186.00 36100.0 1640000.0 53400000.0 1.040000e+09 1.010000e+10 5.070000e+10 1.530000e+11 3.810000e+11 7.460000e+11 1.130000e+12 1.620000e+12 2.020000e+12 2.230000e+12 2.350000e+12 2.370000e+12 2.370000e+12 0.11300
2.0 0.4590 129.00 24400.0 2280000.0 65000000.0 1.240000e+09 1.160000e+10 5.800000e+10 1.930000e+11 4.820000e+11 9.640000e+11 1.610000e+12 2.290000e+12 2.860000e+12 3.180000e+12 3.350000e+12 3.380000e+12 3.380000e+12 0.04530
3.0 -0.6950 -210.00 -41200.0 -3890000.0 -129000000.0 -2.100000e+09 -1.760000e+10 -8.780000e+10 -2.860000e+11 -7.140000e+11 -1.430000e+12 -2.380000e+12 -3.400000e+12 -4.150000e+12 -4.610000e+12 -4.850000e+12 -4.890000e+12 -4.890000e+12 0.18800
4.0 0.0804 16.70 3280.0 129000.0 3590000.0 7.150000e+07 6.220000e+08 3.000000e+09 9.990000e+09 2.500000e+10 4.970000e+10 8.290000e+10 1.060000e+11 1.320000e+11 1.420000e+11 1.490000e+11 1.500000e+11 1.500000e+11 -0.02580
5.0 0.9730 16.90 282.0 4680.0 77400.0 1.280000e+06 1.260000e+07 6.250000e+07 2.080000e+08 5.200000e+08 1.040000e+09 1.730000e+09 2.390000e+09 2.980000e+09 3.250000e+09 3.420000e+09 3.460000e+09 3.460000e+09 0.38300
6.0 0.2170 4.81 107.0 2360.0 51100.0 9.900000e+05 9.590000e+06 4.770000e+07 1.590000e+08 3.960000e+08 7.030000e+08 1.170000e+09 1.660000e+09 2.080000e+09 2.310000e+09 2.410000e+09 2.440000e+09 2.440000e+09 0.14800
7.0 1.4900 73.60 1150.0 17700.0 262000.0 3.580000e+06 2.990000e+07 1.490000e+08 4.950000e+08 1.130000e+09 2.260000e+09 3.770000e+09 5.370000e+09 6.460000e+09 7.160000e+09 7.540000e+09 7.610000e+09 7.620000e+09 -0.10300
8.0 1.4200 69.00 3260.0 148000.0 2250000.0 2.980000e+07 2.850000e+08 1.420000e+09 4.730000e+09 1.180000e+10 2.360000e+10 3.930000e+10 5.410000e+10 6.760000e+10 7.480000e+10 7.900000e+10 7.900000e+10 7.900000e+10 0.09440
9.0 -1.0300 -52.10 -2330.0 -35200.0 -528000.0 -7.880000e+06 -7.870000e+07 -3.930000e+08 -1.310000e+09 -3.260000e+09 -6.510000e+09 -1.080000e+10 -1.550000e+10 -1.940000e+10 -2.150000e+10 -2.280000e+10 -2.280000e+10 -2.280000e+10 0.01550
10.0 -1.1000 -17.10 -242.0 -3430.0 -39800.0 -4.560000e+05 -4.360000e+06 -1.920000e+07 -6.350000e+07 -1.590000e+08 -3.170000e+08 -5.260000e+08 -7.510000e+08 -9.390000e+08 -1.040000e+09 -1.100000e+09 -1.100000e+09 -1.100000e+09 -0.22900
11.0 -0.7730 -41.70 -2190.0 -109000.0 -2040000.0 -3.800000e+07 -2.990000e+08 -1.410000e+09 -4.620000e+09 -1.150000e+10 -2.290000e+10 -3.810000e+10 -5.440000e+10 -6.800000e+10 -7.550000e+10 -8.010000e+10 -8.010000e+10 -8.010000e+10 -0.07450
12.0 -0.5480 -12.30 -192.0 -2980.0 -45800.0 -6.990000e+05 -6.980000e+06 -3.400000e+07 -1.130000e+08 -2.820000e+08 -5.640000e+08 -9.380000e+08 -1.340000e+09 -1.660000e+09 -1.850000e+09 -1.960000e+09 -1.960000e+09 -1.960000e+09 0.00916
13.0 0.7580 12.50 135.0 1440.0 15100.0 1.570000e+05 1.290000e+06 6.460000e+06 2.150000e+07 5.360000e+07 1.070000e+08 1.780000e+08 2.470000e+08 3.080000e+08 3.410000e+08 3.620000e+08 3.620000e+08 3.620000e+08 0.05390
14.0 -0.5650 -149.00 -18600.0 -1510000.0 -45800000.0 -8.390000e+08 -8.210000e+09 -4.060000e+10 -1.340000e+11 -3.340000e+11 -6.690000e+11 -1.110000e+12 -1.550000e+12 -1.940000e+12 -2.160000e+12 -2.340000e+12 -2.340000e+12 -2.340000e+12 0.33300
15.0 -0.8930 -215.00 -40500.0 -1970000.0 -38500000.0 -7.510000e+08 -7.510000e+09 -3.750000e+10 -1.250000e+11 -3.110000e+11 -6.210000e+11 -1.030000e+12 -1.430000e+12 -1.790000e+12 -1.990000e+12 -2.160000e+12 -2.160000e+12 -2.160000e+12 -0.04920
16.0 0.5860 36.70 2250.0 48300.0 862000.0 1.510000e+07 1.510000e+08 7.510000e+08 2.500000e+09 6.250000e+09 1.250000e+10 2.080000e+10 2.850000e+10 3.550000e+10 3.940000e+10 4.270000e+10 4.270000e+10 4.270000e+10 0.03000
17.0 0.3820 35.40 3040.0 258000.0 8610000.0 1.660000e+08 1.500000e+09 7.300000e+09 2.420000e+10 6.040000e+10 1.200000e+11 2.000000e+11 2.760000e+11 3.440000e+11 3.820000e+11 4.140000e+11 4.140000e+11 4.140000e+11 -0.06340
18.0 -0.8680 -48.30 -1760.0 -37700.0 -752000.0 -1.470000e+07 -1.450000e+08 -7.170000e+08 -2.390000e+09 -5.950000e+09 -1.190000e+10 -1.980000e+10 -2.730000e+10 -3.410000e+10 -3.790000e+10 -4.100000e+10 -4.100000e+10 -4.100000e+10 0.01500
19.0 -0.0529 -2.31 -103.0 -3270.0 -59400.0 -1.070000e+06 -9.990000e+06 -4.990000e+07 -1.660000e+08 -4.150000e+08 -8.300000e+08 -1.380000e+09 -1.980000e+09 -2.460000e+09 -2.730000e+09 -3.030000e+09 -3.030000e+09 -3.030000e+09 -0.26500
20.0 -0.6970 -14.80 -296.0 -5780.0 -112000.0 -2.150000e+06 -2.070000e+07 -1.030000e+08 -3.450000e+08 -8.610000e+08 -1.710000e+09 -2.850000e+09 -4.070000e+09 -5.090000e+09 -5.650000e+09 -6.280000e+09 -6.280000e+09 -6.280000e+09 -0.09860
21.0 0.4180 25.40 1440.0 79700.0 2360000.0 3.160000e+07 3.150000e+08 1.570000e+09 5.220000e+09 1.310000e+10 2.610000e+10 4.330000e+10 6.180000e+10 7.720000e+10 8.580000e+10 8.580000e+10 8.580000e+10 8.580000e+10 0.03670
22.0 0.5000 30.50 1330.0 24900.0 362000.0 5.180000e+06 4.410000e+07 2.190000e+08 7.250000e+08 1.810000e+09 3.620000e+09 6.010000e+09 8.590000e+09 1.070000e+10 1.190000e+10 1.190000e+10 1.190000e+10 1.190000e+10 0.44100
23.0 0.5430 26.90 1180.0 50200.0 1290000.0 1.640000e+07 1.600000e+08 7.790000e+08 2.590000e+09 6.480000e+09 1.300000e+10 2.160000e+10 3.080000e+10 3.850000e+10 4.280000e+10 4.280000e+10 4.280000e+10 4.280000e+10 0.20600
24.0 0.4680 12.70 326.0 8030.0 143000.0 2.530000e+06 2.530000e+07 1.160000e+08 3.880000e+08 9.680000e+08 1.930000e+09 3.220000e+09 4.600000e+09 5.750000e+09 6.390000e+09 6.390000e+09 6.390000e+09 6.390000e+09 0.33700
25.0 -0.3010 -12.60 -318.0 -6890.0 -146000.0 -1.890000e+06 -1.860000e+07 -9.310000e+07 -3.100000e+08 -7.740000e+08 -1.550000e+09 -2.580000e+09 -3.680000e+09 -4.600000e+09 -5.160000e+09 -5.160000e+09 -5.160000e+09 -5.160000e+09 0.20400
26.0 -0.2350 -7.76 -171.0 -3690.0 -77000.0 -1.210000e+06 -1.150000e+07 -5.740000e+07 -1.910000e+08 -4.770000e+08 -9.480000e+08 -1.570000e+09 -2.240000e+09 -2.800000e+09 -3.150000e+09 -3.150000e+09 -3.150000e+09 -3.150000e+09 -0.02470
27.0 -0.6850 -43.40 -2690.0 -67900.0 -1230000.0 -2.210000e+07 -1.930000e+08 -9.620000e+08 -3.210000e+09 -8.010000e+09 -1.600000e+10 -2.670000e+10 -3.810000e+10 -4.760000e+10 -5.350000e+10 -5.350000e+10 -5.350000e+10 -5.350000e+10 -0.22200
28.0 -0.7710 -29.40 -706.0 -10900.0 -166000.0 -2.410000e+06 -2.390000e+07 -1.140000e+08 -3.810000e+08 -9.510000e+08 -1.900000e+09 -3.170000e+09 -4.520000e+09 -5.650000e+09 -6.370000e+09 -6.370000e+09 -6.370000e+09 -6.370000e+09 0.41800
29.0 0.4750 8.57 145.0 2210.0 33400.0 4.110000e+05 3.950000e+06 1.950000e+07 6.470000e+07 1.610000e+08 3.230000e+08 5.380000e+08 7.680000e+08 9.600000e+08 1.080000e+09 1.080000e+09 1.080000e+09 1.080000e+09 -0.12200
30.0 -1.0400 -31.80 -816.0 -20700.0 -330000.0 -5.220000e+06 -5.110000e+07 -2.540000e+08 -8.460000e+08 -2.110000e+09 -4.230000e+09 -7.040000e+09 -1.010000e+10 -1.250000e+10 -1.440000e+10 -1.440000e+10 -1.440000e+10 -1.440000e+10 0.15800

Plotting all the data¶

Now we've extracted more data: RLAGR,AVMASS, NPARTC, SIGR2, SIGT2, and VROT. Lets plot them!

In [5]:
# Allows us to loop
PLOT_DATA = ["RLAGR", "AVMASS", "NPARTC", "SIGR2", "SIGT2", "VROT"]

# just plot the following fewer cols
COLS = [0.1, 0.3, 0.5, 0.9, 1.0]

# initialize matplotlib figure
fig = plt.figure(figsize=(12,4*len(PLOT_DATA)/2))

for pdata in PLOT_DATA:
    ax = fig.add_subplot(int(len(PLOT_DATA)/2),2,PLOT_DATA.index(pdata) + 1)
    
    # Plot the data
    data[pdata][COLS].plot(ax=ax)
    
    ax.set_title(f"{pdata} time evolution")
    ax.set_xlabel(r"Time t [nbody units]")
    ax.set_ylabel(f"{pdata}")
    ax.grid()
    if pdata != "VROT":
        ax.set_yscale("log")
    
fig.tight_layout()

Energy from Adjust line¶

Looking at the main stdout file, you'll find the ADJUST lines, giving a lot of information about the energy. Let us extract it

ADJUST:  TIME    0.00000E+00  T[Myr]    0.00  Q 0.50  DE   0.000E+00 DELTA   0.000E+00 DETOT   0.000E+00 E  -2.502E-01 EKIN   2.500E-01 POT   5.000E-01 ETIDE  -1.505E-04 ETOT  -2.502E-01 EBIN   0.000E+00 EMERGE   0.000E+00 ESUB   0.000E+00 ECOLL   0.000E+00 EMDOT   0.000E+00 ECDOT   0.000E+00
In [6]:
# initialize a pandas DataFrame
df = None

# work through the file
with open("example_1k/1k.out","r") as nb_stdout:
    for line in nb_stdout:
        # Match line where we get the mass fractions
        line = line.replace("*****", " nan")
        if re.search("ADJUST:", line):
            # Replace the multiple spaces by just one space
            line = re.sub("\s+", " ", line).strip()
            # After replacing the multiple spaces we can more easily split the line
            line = line.split(" ")
            
            # load dataframe
            if df is None:
                cols = [line[i] for i in range(3, len(line), 2)]
                df = pd.DataFrame(columns=cols)
            
            # Assign new row
            idx = np.float64(line[2])
            df.loc[idx] = np.float64([line[i] for i in range(4, len(line), 2)])
df
Out[6]:
T[Myr] Q DE DELTA DETOT E EKIN POT ETIDE ETOT EBIN EMERGE ESUB ECOLL EMDOT ECDOT
0.0 0.00 0.50 0.000000e+00 0.000000e+00 0.000000e+00 -0.25020 0.2500 0.5000 -0.000150 -0.2502 0.0 0.0 0.0 0.0 0.000000 0.00000
1.0 0.61 0.52 -4.289000e-09 -1.150000e-09 -1.150000e-09 -0.25010 0.2681 0.5180 -0.000147 -0.2502 0.0 0.0 0.0 0.0 -0.000037 0.00000
2.0 1.22 0.52 3.077000e-07 8.276000e-08 8.161000e-08 -0.25000 0.2689 0.5188 -0.000147 -0.2502 0.0 0.0 0.0 0.0 -0.000108 0.00000
3.0 1.82 0.50 1.454000e-07 3.675000e-08 1.184000e-07 -0.25000 0.2528 0.5026 -0.000133 -0.2502 0.0 0.0 0.0 0.0 -0.000186 0.00000
4.0 2.43 0.49 -2.213000e-08 -5.530000e-09 1.128000e-07 -0.24990 0.2384 0.4882 -0.000116 -0.2502 0.0 0.0 0.0 0.0 -0.000266 0.00000
5.0 3.04 0.51 1.435000e-08 3.725000e-09 1.166000e-07 -0.24970 0.2596 0.5093 -0.000103 -0.2502 0.0 0.0 0.0 0.0 -0.000407 0.00000
6.0 3.65 0.49 -4.267000e-07 -1.065000e-07 1.005000e-08 -0.24960 0.2390 0.4885 -0.000095 -0.2502 0.0 0.0 0.0 0.0 -0.000585 0.00000
7.0 4.25 0.54 -2.492000e-07 -7.143000e-08 -6.138000e-08 -0.24930 0.2866 0.5358 -0.000093 -0.2502 0.0 0.0 0.0 0.0 -0.000873 0.00000
8.0 4.86 0.59 -3.167000e-05 -9.156000e-06 -9.217000e-06 -0.20360 0.2891 0.4926 -0.000097 -0.2502 0.0 0.0 0.0 0.0 -0.046590 0.00000
9.0 5.47 0.56 2.437000e-07 6.306000e-08 -9.154000e-06 -0.20040 0.2588 0.4591 -0.000107 -0.2510 0.0 0.0 0.0 0.0 -0.050590 0.00000
10.0 6.08 0.59 -2.767000e-07 -8.101000e-08 -9.235000e-06 -0.20030 0.2927 0.4929 -0.000117 -0.2510 0.0 0.0 0.0 0.0 -0.050670 0.00000
11.0 6.68 0.56 -1.728000e-06 -4.378000e-07 -9.673000e-06 -0.20020 0.2534 0.4535 -0.000126 -0.2510 0.0 0.0 0.0 0.0 -0.050760 0.00000
12.0 7.29 0.49 -2.645000e-06 -5.295000e-07 -1.020000e-05 -0.20020 0.1936 0.3936 -0.000139 -0.2510 0.0 0.0 0.0 0.0 -0.050820 0.00000
13.0 7.90 0.53 -3.416000e-06 -7.588000e-07 -1.096000e-05 -0.19760 0.2221 0.4196 -0.000153 -0.2510 0.0 0.0 0.0 0.0 -0.053340 0.00000
14.0 8.51 0.57 1.787000e-05 2.927000e-06 -8.034000e-06 -0.12560 0.1638 0.2892 -0.000172 -0.2510 0.0 0.0 0.0 0.0 -0.100300 -0.02502
15.0 9.11 0.53 -1.569000e-06 -2.244000e-07 -8.258000e-06 -0.12630 0.1430 0.2691 -0.000196 -0.2516 0.0 0.0 0.0 0.0 -0.100300 -0.02502
16.0 9.72 0.51 -2.265000e-08 -3.024000e-09 -8.261000e-06 -0.12630 0.1335 0.2596 -0.000222 -0.2516 0.0 0.0 0.0 0.0 -0.100300 -0.02502
17.0 10.33 0.48 -1.124000e-06 -1.420000e-07 -8.403000e-06 -0.12630 0.1177 0.2437 -0.000246 -0.2516 0.0 0.0 0.0 0.0 -0.100300 -0.02502
18.0 10.94 0.51 -3.468000e-07 -4.588000e-08 -8.449000e-06 -0.12620 0.1323 0.2582 -0.000269 -0.2516 0.0 0.0 0.0 0.0 -0.100400 -0.02502
19.0 11.55 0.90 -4.679000e-06 -1.085000e-06 -9.534000e-06 -0.02726 0.2319 0.2588 -0.000279 -0.2516 0.0 0.0 0.0 0.0 -0.105200 -0.11920
20.0 12.15 0.88 -1.770000e-06 -3.758000e-07 -9.910000e-06 -0.02867 0.2123 0.2407 -0.000273 -0.2531 0.0 0.0 0.0 0.0 -0.105200 -0.11920
21.0 12.76 0.88 5.916000e-08 1.267000e-08 -9.897000e-06 -0.02867 0.2142 0.2426 -0.000253 -0.2531 0.0 0.0 0.0 0.0 -0.105200 -0.11920
22.0 13.37 0.89 -6.677000e-08 -1.642000e-08 -9.914000e-06 -0.02891 0.2459 0.2746 -0.000214 -0.2533 0.0 0.0 0.0 0.0 -0.105200 -0.11920
23.0 13.98 0.88 -2.583000e-07 -5.569000e-08 -9.969000e-06 -0.02891 0.2156 0.2444 -0.000163 -0.2533 0.0 0.0 0.0 0.0 -0.105200 -0.11920
24.0 14.58 0.88 -2.134000e-06 -4.639000e-07 -1.043000e-05 -0.02891 0.2173 0.2461 -0.000101 -0.2533 0.0 0.0 0.0 0.0 -0.105200 -0.11920
25.0 15.19 0.88 -4.604000e-07 -1.038000e-07 -1.054000e-05 -0.02891 0.2255 0.2544 -0.000026 -0.2533 0.0 0.0 0.0 0.0 -0.105200 -0.11920
26.0 15.80 0.52 1.519000e-04 1.958000e-05 9.045000e-06 -0.11950 0.1289 0.2479 -0.000476 -0.3438 0.0 0.0 0.0 0.0 -0.105200 -0.11920
27.0 16.41 0.56 -8.827000e-07 -1.329000e-07 8.912000e-06 -0.11940 0.1505 0.2695 -0.000513 -0.3438 0.0 0.0 0.0 0.0 -0.105200 -0.11920
28.0 17.01 0.59 -7.261000e-06 -1.243000e-06 7.669000e-06 -0.11940 0.1711 0.2900 -0.000556 -0.3438 0.0 0.0 0.0 0.0 -0.105300 -0.11920
29.0 17.62 0.56 -6.132000e-07 -9.626000e-08 7.573000e-06 -0.12130 0.1570 0.2778 -0.000514 -0.3460 0.0 0.0 0.0 0.0 -0.105500 -0.11920
30.0 18.23 2.72 9.057000e-06 5.902000e-06 1.347000e-05 0.41300 0.6516 0.2379 -0.000662 -0.3460 0.0 0.0 0.0 0.0 -0.119300 -0.63980
In [7]:
# We don't want it to get too messy, so let's only plot
# a few columns
COLS = ["ETOT", "EKIN", "POT"]

# Prepare plot
fig = plt.figure(figsize=(9,6))
ax = fig.gca()

# plot
df[COLS].plot(ax=ax)

# make the plot a little bit nicer
ax.set_title(r"Energy evolution")
ax.set_xlabel(r"Time t [nbody units]")
ax.set_ylabel(r"Energy E [nbody units]")
ax.grid()
#ax.set_yscale("log")