diff --git a/README.md b/README.md index 50a44cef3dbd530fc9129c2cde5596bf3cb362f5..90c0ef45261cea8c896a97825423970cdb9e86fb 100644 --- a/README.md +++ b/README.md @@ -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). +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 --------------------- -- ?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 - Use sphinx for auto generation of docs - Use queueing system/asynchronous task queue +- Make some parse-data that can be easily used +- Make some simple script to assign probabilities diff --git a/__pycache__/defaults.cpython-36.pyc b/__pycache__/defaults.cpython-36.pyc index 5e366ee6c1b3beae8fadebe63d1e7e413ff1ec67..16d2a1e2a2eebed842457dfebe2c60d92cc79c8d 100644 Binary files a/__pycache__/defaults.cpython-36.pyc and b/__pycache__/defaults.cpython-36.pyc differ diff --git a/build/temp.linux-x86_64-3.6/binary_c_python.o b/build/temp.linux-x86_64-3.6/binary_c_python.o index 931bef1273d1cdd3d3e69442b345fbdbaedc611c..ca9e7c36ab4089a52d0b5498471952e18df97964 100644 Binary files a/build/temp.linux-x86_64-3.6/binary_c_python.o and b/build/temp.linux-x86_64-3.6/binary_c_python.o differ diff --git a/examples/__init__.py b/examples/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/examples/full_evolution_with_plot.py b/examples/full_evolution_with_plot.py new file mode 100644 index 0000000000000000000000000000000000000000..02cf4fd511e78ba83a9a55abd5d965882c833b0f --- /dev/null +++ b/examples/full_evolution_with_plot.py @@ -0,0 +1,73 @@ +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 diff --git a/python_API_test.py b/python_API_test.py index bbba1d945e24ed8fd0df2c60dd33fcf2cea920f0..fb77ec234976cdeb13e76c336c7563842eb6c97d 100755 --- a/python_API_test.py +++ b/python_API_test.py @@ -7,8 +7,6 @@ import binary_c # module. ############################################################ - - def run_test_binary(): m1 = 15.0 # Msun m2 = 14.0 # Msun diff --git a/test_david.py b/test_david.py index dd375efd4e84ba32b7d9967a2207f1e720f913ea..99f0154fab215d539e1dcb5387c02948d5a85b13 100644 --- a/test_david.py +++ b/test_david.py @@ -1,6 +1,7 @@ #!/usr/bin/python3 import os import binary_c +import matplotlib.pyplot as plt from defaults import physics_defaults @@ -27,9 +28,9 @@ def run_test_binary(): # print ("Binary_c output:\n\n") print (output) - def run_simple_loop_binary(): # Some simple function with a loop + # This function assumes a single output line m2 = 14.0 # Msun separation = 0 # 0 = ignored, use period @@ -77,30 +78,6 @@ def run_simple_loop_binary(): print('zams_mass1:' ,initial_m1) print('time:', time) - - - - - - - - - - - - - - - - - - - - - - - - # print("Current binary_c object class functions: ") # print(dir(binary_c)) @@ -119,41 +96,4 @@ def run_simple_loop_binary(): # run_test_binary() # Test grid-like -# run_simple_loop_binary() - -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 +# run_simple_loop_binary() \ No newline at end of file diff --git a/utils/__pycache__/defaults.cpython-36.pyc b/utils/__pycache__/defaults.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d364497266246ceb5cb898c81ad256338ab74946 Binary files /dev/null and b/utils/__pycache__/defaults.cpython-36.pyc differ diff --git a/utils/__pycache__/functions.cpython-36.pyc b/utils/__pycache__/functions.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..16a46b9804ec090a27bc98609a51840fce995f10 Binary files /dev/null and b/utils/__pycache__/functions.cpython-36.pyc differ diff --git a/defaults.py b/utils/defaults.py similarity index 100% rename from defaults.py rename to utils/defaults.py diff --git a/utils/functions.py b/utils/functions.py new file mode 100644 index 0000000000000000000000000000000000000000..a116cd908ce120498b54d4c3764ec161bca63acf --- /dev/null +++ b/utils/functions.py @@ -0,0 +1,10 @@ +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 diff --git a/utils/stellar_types.py b/utils/stellar_types.py new file mode 100644 index 0000000000000000000000000000000000000000..8f947f28bca95043af541510d840b79429d1e6d1 --- /dev/null +++ b/utils/stellar_types.py @@ -0,0 +1,18 @@ +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