Loading utils/defaults.py→binaryc_python_utils/defaults.py +0 −0 File moved. View file binaryc_python_utils/functions.py 0 → 100644 +84 −0 Original line number Diff line number Diff line import binary_c from collections import defaultdict from binaryc_python_utils.defaults import physics_defaults def create_arg_string(arg_dict): """ Function that creates the arg string """ arg_string = '' for key in arg_dict.keys(): arg_string += "{key} {value} ".format(key=key, value=arg_dict[key]) arg_string = arg_string.strip() return arg_string def run_system(**kwargs): """ Wrapper to run a system with settings """ # Load args physics_args = physics_defaults.copy() # For example # physics_args['M_1'] = 20 # physics_args['separation'] = 0 # 0 = ignored, use period # physics_args['orbital_period'] = 100000000000 # To make it single # Use kwarg value to override defaults and add new args for key in kwargs.keys(): physics_args[key] = kwargs[key] # Construct arguments string and final execution string arg_string = create_arg_string(physics_args) arg_string = f'binary_c {arg_string}' # Run it and get output buffer = "" output = binary_c.run_binary(arg_string) return output def parse_output(output, selected_header): """ Function that parses output of binaryc when it is construction like this: DAVID_SINGLE_ANALYSIS t=0 mass=20 You can give a 'selected_header' to catch any line that starts with that. Then the values will be put into a """ value_dicts = [] val_lists = [] # split output on newlines for i, line in enumerate(output.split('\n')): # Skip any blank lines if not line=='': split_line = line.split() # Select parts header = split_line[0] value_array = split_line[1:] # Catch line starting with selected header if header==selected_header: # print(value_array) # Make a dict value_dict = {} for el in value_array: key, val = el.split('=') value_dict[key] = val value_dicts.append(value_dict) keys = value_dicts[0].keys() # Construct final dict. final_values_dict = defaultdict(list) for value_dict in value_dicts: for key in keys: final_values_dict[key].append(value_dict[key]) return final_values_dict No newline at end of file utils/stellar_types.py→binaryc_python_utils/stellar_types.py +0 −0 File moved. View file examples/full_evolution_with_plot.py +0 −3 Original line number Diff line number Diff line Loading @@ -4,10 +4,7 @@ import matplotlib.pyplot as plt # Append root dir of this project to include functionality sys.path.append(os.path.dirname(os.getcwd())) import binary_c <<<<<<< HEAD ======= >>>>>>> 19cf329fcbd85a0dff06eaec60030d6bf3ebc0b0 from utils.defaults import physics_defaults from utils.functions import create_arg_string Loading tests_david/test_david.py +1 −1 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ import os import binary_c import matplotlib.pyplot as plt from utils.defaults import physics_defaults from binaryc_python_utils.defaults import physics_defaults ############################################################ # Test script to run a binary using the binary_c Python Loading Loading
binaryc_python_utils/functions.py 0 → 100644 +84 −0 Original line number Diff line number Diff line import binary_c from collections import defaultdict from binaryc_python_utils.defaults import physics_defaults def create_arg_string(arg_dict): """ Function that creates the arg string """ arg_string = '' for key in arg_dict.keys(): arg_string += "{key} {value} ".format(key=key, value=arg_dict[key]) arg_string = arg_string.strip() return arg_string def run_system(**kwargs): """ Wrapper to run a system with settings """ # Load args physics_args = physics_defaults.copy() # For example # physics_args['M_1'] = 20 # physics_args['separation'] = 0 # 0 = ignored, use period # physics_args['orbital_period'] = 100000000000 # To make it single # Use kwarg value to override defaults and add new args for key in kwargs.keys(): physics_args[key] = kwargs[key] # Construct arguments string and final execution string arg_string = create_arg_string(physics_args) arg_string = f'binary_c {arg_string}' # Run it and get output buffer = "" output = binary_c.run_binary(arg_string) return output def parse_output(output, selected_header): """ Function that parses output of binaryc when it is construction like this: DAVID_SINGLE_ANALYSIS t=0 mass=20 You can give a 'selected_header' to catch any line that starts with that. Then the values will be put into a """ value_dicts = [] val_lists = [] # split output on newlines for i, line in enumerate(output.split('\n')): # Skip any blank lines if not line=='': split_line = line.split() # Select parts header = split_line[0] value_array = split_line[1:] # Catch line starting with selected header if header==selected_header: # print(value_array) # Make a dict value_dict = {} for el in value_array: key, val = el.split('=') value_dict[key] = val value_dicts.append(value_dict) keys = value_dicts[0].keys() # Construct final dict. final_values_dict = defaultdict(list) for value_dict in value_dicts: for key in keys: final_values_dict[key].append(value_dict[key]) return final_values_dict No newline at end of file
examples/full_evolution_with_plot.py +0 −3 Original line number Diff line number Diff line Loading @@ -4,10 +4,7 @@ import matplotlib.pyplot as plt # Append root dir of this project to include functionality sys.path.append(os.path.dirname(os.getcwd())) import binary_c <<<<<<< HEAD ======= >>>>>>> 19cf329fcbd85a0dff06eaec60030d6bf3ebc0b0 from utils.defaults import physics_defaults from utils.functions import create_arg_string Loading
tests_david/test_david.py +1 −1 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ import os import binary_c import matplotlib.pyplot as plt from utils.defaults import physics_defaults from binaryc_python_utils.defaults import physics_defaults ############################################################ # Test script to run a binary using the binary_c Python Loading