Skip to content
Snippets Groups Projects
Commit e29b6ecb authored by David Hendriks's avatar David Hendriks
Browse files

moved some files around and created examples directory containing some examples

parent 9a9a577e
No related branches found
No related tags found
No related merge requests found
...@@ -37,9 +37,16 @@ Then to test the Python module: ...@@ -37,9 +37,16 @@ Then to test the Python module:
``` ```
You will require whatever libraries with which binary_c was compiled, as well as the compiler with which Python was built (usually gcc, which is easily installed on most systems). You will require whatever libraries with which binary_c was compiled, as well as the compiler with which Python was built (usually gcc, which is easily installed on most systems).
If you want to be able to import the binary_c module correctly for child directories (or anywhere for that matter), execute or put the following code in your .bashrc/.zshrc:
```
export LD_LIBRARY_PATH=<full path to directory containing libbinary_c_api.so>
```
TODO TODO
--------------------- ---------------------
- ?Put the header and src files in a dedicated directory - ?Put the header and src files in a dedicated directory.
- ?Have the compiled files be written into build - ?Have the compiled files be written into build
- Use sphinx for auto generation of docs - Use sphinx for auto generation of docs
- Use queueing system/asynchronous task queue - Use queueing system/asynchronous task queue
- Make some parse-data that can be easily used
- Make some simple script to assign probabilities
No preview for this file type
No preview for this file type
import os, sys
import matplotlib.pyplot as plt
import binary_c
# Append root dir of this project to include functionality
sys.path.append(os.path.dirname(os.getcwd()))
from utils.defaults import physics_defaults
from utils.functions import create_arg_string
def example_with_loading_default_args():
"""
Example function loading the default physics args for a binary_c system. Got
it from the binary_grid2 perl module
This function works if binary_c is set to log something every timestep so that we can plot the evolution of a system
"""
# Load args
physics_args = physics_defaults.copy()
# Manually set M_1, M_2, orbital_period and separation values:
physics_args['M_1'] = 20
physics_args['M_2'] = 15
physics_args['separation'] = 0 # 0 = ignored, use period
physics_args['orbital_period'] = 4530.0
arg_string = create_arg_string(physics_args)
arg_string = f'binary_c {arg_string}'
buffer = ""
output = binary_c.run_binary(arg_string)
# Make some
results = {}
time_arr = []
mass_arr = []
mass_2_arr = []
# split output on newlines
for line in output.split('\n'):
# Skip any blank lines
if not line=='':
split_line = line.split()
header = split_line[0]
value_array = split_line[1:]
# Use parse data here:
if header=='TESTLOG':
# Add values to lists
time_arr.append(float(value_array[0]))
mass_arr.append(float(value_array[1]))
mass_2_arr.append(float(value_array[4]))
# Save in results dir
results['time'] = time_arr
results['mass'] = mass_arr
results['mass2'] = mass_2_arr
return results
results = example_with_loading_default_args()
# Plot some stuff
plt.plot(results['time'], results['mass'])
plt.plot(results['time'], results['mass2'])
plt.xscale('log')
plt.show()
\ No newline at end of file
...@@ -7,8 +7,6 @@ import binary_c ...@@ -7,8 +7,6 @@ import binary_c
# module. # module.
############################################################ ############################################################
def run_test_binary(): def run_test_binary():
m1 = 15.0 # Msun m1 = 15.0 # Msun
m2 = 14.0 # Msun m2 = 14.0 # Msun
......
#!/usr/bin/python3 #!/usr/bin/python3
import os import os
import binary_c import binary_c
import matplotlib.pyplot as plt
from defaults import physics_defaults from defaults import physics_defaults
...@@ -27,9 +28,9 @@ def run_test_binary(): ...@@ -27,9 +28,9 @@ def run_test_binary():
# print ("Binary_c output:\n\n") # print ("Binary_c output:\n\n")
print (output) print (output)
def run_simple_loop_binary(): def run_simple_loop_binary():
# Some simple function with a loop # Some simple function with a loop
# This function assumes a single output line
m2 = 14.0 # Msun m2 = 14.0 # Msun
separation = 0 # 0 = ignored, use period separation = 0 # 0 = ignored, use period
...@@ -77,30 +78,6 @@ def run_simple_loop_binary(): ...@@ -77,30 +78,6 @@ def run_simple_loop_binary():
print('zams_mass1:' ,initial_m1) print('zams_mass1:' ,initial_m1)
print('time:', time) print('time:', time)
# print("Current binary_c object class functions: ") # print("Current binary_c object class functions: ")
# print(dir(binary_c)) # print(dir(binary_c))
...@@ -119,41 +96,4 @@ def run_simple_loop_binary(): ...@@ -119,41 +96,4 @@ def run_simple_loop_binary():
# run_test_binary() # run_test_binary()
# Test grid-like # Test grid-like
# run_simple_loop_binary() # run_simple_loop_binary()
\ No newline at end of file
def create_arg_string(arg_dict):
"""
Function that creates the arg string
"""
arg_string = ''
for key in arg_dict.keys():
arg_string += f'{key} {arg_dict[key]} '
arg_string = arg_string.strip()
return arg_string
def example_with_loading_default_args():
"""
Example function loading the default physics args for a binary_c system. Got
it from the binary_grid2 perl module
"""
# Load args
physics_args = physics_defaults.copy()
# Manually set M_1, M_2, orbital_period and separation values:
physics_args['M_1'] = 20
physics_args['M_2'] = 15
physics_args['separation'] = 0 # 0 = ignored, use period
physics_args['orbital_period'] = 4530.0
arg_string = create_arg_string(physics_args)
arg_string = f'binary_c {arg_string}'
output = binary_c.run_binary(arg_string)
print (output)
example_with_loading_default_args()
\ No newline at end of file
File added
File added
File moved
def create_arg_string(arg_dict):
"""
Function that creates the arg string
"""
arg_string = ''
for key in arg_dict.keys():
arg_string += f'{key} {arg_dict[key]} '
arg_string = arg_string.strip()
return arg_string
\ No newline at end of file
stellar_type = {
0: 'low mass main sequence',
1: 'Main Sequence',
2: 'Hertzsprung Gap',
3: 'First Giant Branch',
4: 'Core Helium Burning',
5: 'Early Asymptotic Giant Branch',
6: 'Thermally Pulsing',
7: 'NAKED_MAIN_SEQUENCE_HELIUM_STAR',
8: 'NAKED_HELIUM_STAR_HERTZSPRUNG_GAP',
9: 'NAKED_HELIUM_STAR_GIANT_BRANCH',
10: 'HELIUM_WHITE_DWARF',
11: 'CARBON_OXYGEN_WHITE_DWARF',
12: 'OXYGEN_NEON_WHITE_DWARF',
13: 'NEUTRON_STAR',
14: 'BLACK_HOLE',
15: 'MASSLESS REMNANT'
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment