Commit 30ce226b authored by David Hendriks's avatar David Hendriks
Browse files

updated functions and made some notebooks

parent c7eed139
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -3,3 +3,4 @@
binary_c_python_api.o
output/*
david_results/*
*.nfs*
+6 −0
Original line number Diff line number Diff line
@@ -98,6 +98,12 @@ def parse_output(output, selected_header):
                    value_dict[key] = val
                value_dicts.append(value_dict)

    if len(value_dicts)==0:
        print('Sorry, didnt find any line matching your header {}'.format(selected_header))
        return None



    keys = value_dicts[0].keys()

    # Construct final dict.
+97 −0
Original line number Diff line number Diff line
%% Cell type:code id: tags:

``` python
import os, sys, time

import matplotlib.pyplot as plt
from collections import defaultdict
import numpy as np
import pandas as pd

# sys.path.append('../')
import binary_c


from binaryc_python_utils.functions import create_arg_string, parse_output, run_system

result_dir = '../david_results/'
```

%% Cell type:markdown id: tags:

# Run binaryc command

%% Cell type:code id: tags:

``` python
start = time.time()
output = run_system(M_1=10, M_2=20, separation=0, orbital_period=100, max_evolution_time=15000)
result = parse_output(output, 'DAVID_BINARY_ANALYSIS')
stop = time.time()
print("Took {:.2f}s to run single system".format(stop-start))
print("The following keys are present in the results:\n{}".format(result.keys()))
```

%% Output

    Took 1.60s to run single system
    The following keys are present in the results:
    dict_keys(['t', 'mass_1', 'zams_mass_1', 'mass_2', 'zams_mass_2', 'stellar_type_1', 'prev_stellar_type_1', 'stellar_type_2', 'prev_stellar_type_2', 'radius_1', 'radius_2', 'roche_radius_1', 'roche_radius_2', 'core_mass_1', 'core_mass_2', 'luminosity_1', 'luminosity_2', 'omega_1', 'omega_2', 'metallicity', 'probability', 'separation', 'eccentricity', 'period', 'dtm', 'core_radius_1', 'core_radius_2', 'teff_1', 'teff_2', 'drdt_1', 'drdt_2', 'vwind_1', 'vwind_2', 'tm_1', 'tm_2', 'tn_1', 'tn_2', 'tkh_1', 'tk_2', 'angular_momentum_1', 'angular_momentum_2', 'he_core_mass_1', 'he_core_mass_2', 'CO_core_mass_1', 'CO_core_mass_2', 'GB_core_mass_1', 'GB_core_mass_2', 'v_eq_1', 'v_eq_2', 'v_eq_ratio_1', 'v_eq_ratio_2'])

%% Cell type:code id: tags:

``` python
```

%% Output

    18351949

%% Cell type:code id: tags:

``` python
# Cast the data into a dataframe.
df = pd.DataFrame.from_dict(result, dtype=np.float64)
#### Now do whatever you want with it:

# Get last change moment
last_st_1 = df['stellar_type_1'].unique()[-1]
last_stellar_type_change_time_1 = df[df.stellar_type_1==last_st_1]['t'].iloc[0]
last_st_2 = df['stellar_type_2'].unique()[-1]
last_stellar_type_change_time_2 = df[df.stellar_type_2==last_st_2]['t'].iloc[0]
last_change_time = last_stellar_type_change_time_1 if last_stellar_type_change_time_1>last_stellar_type_change_time_2 else last_stellar_type_change_time_2


# slice to get that last time
sliced_df = df[df.t < last_change_time] # Cut off late parts of evolution
```

%% Cell type:code id: tags:

``` python
plt.plot(sliced_df['t'], sliced_df['mass_1'], label='mass_1')
plt.plot(sliced_df['t'], sliced_df['mass_2'], label='mass_2')
plt.xlabel('Time (Myr)')
plt.ylabel('Radius (Rsol)')
# plt.yscale('log')
plt.legend()
plt.savefig(os.path.join(result_dir, 's'))
plt.show()
```

%% Output


%% Cell type:code id: tags:

``` python
plt.plot(sliced_df['t'], sliced_df['period'], label='period')
plt.plot(sliced_df['t'], sliced_df['mass_2'], label='mass_2')
plt.xlabel('Time (Myr)')
plt.ylabel('Radius (Rsol)')
# plt.yscale('log')
plt.legend()
plt.savefig(os.path.join(result_dir, 's'))
plt.show()
```
+10 −2

File changed.

Preview size limit exceeded, changes collapsed.

+184 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading