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

fixed functionality for fetching default args via binaryc interface. making...

fixed functionality for fetching default args via binaryc interface. making some evolution plots now
parent f0d5a6a7
No related branches found
No related tags found
No related merge requests found
...@@ -7,7 +7,6 @@ def create_arg_string(arg_dict): ...@@ -7,7 +7,6 @@ def create_arg_string(arg_dict):
""" """
Function that creates the arg string Function that creates the arg string
""" """
arg_string = '' arg_string = ''
for key in arg_dict.keys(): for key in arg_dict.keys():
arg_string += "{key} {value} ".format(key=key, value=arg_dict[key]) arg_string += "{key} {value} ".format(key=key, value=arg_dict[key])
...@@ -27,17 +26,26 @@ def get_defaults(): ...@@ -27,17 +26,26 @@ def get_defaults():
key, value = default.split(' = ') key, value = default.split(' = ')
# Filter out NULLS (not compiled anyway) # Filter out NULLS (not compiled anyway)
if not value=='NULL': if not value in ['NULL', 'Function']:
default_dict[key] = value if not value=='':
default_dict[key] = value
return default_dict return default_dict
def get_arg_keys():
"""
Function that return the list of possible keys to give in the arg string
"""
return get_defaults().keys()
def run_system(**kwargs): def run_system(**kwargs):
""" """
Wrapper to run a system with settings Wrapper to run a system with settings
""" """
# Load default args # Load default args
physics_args = get_defaults() args = get_defaults()
# args = {}
# For example # For example
# physics_args['M_1'] = 20 # physics_args['M_1'] = 20
...@@ -46,11 +54,12 @@ def run_system(**kwargs): ...@@ -46,11 +54,12 @@ def run_system(**kwargs):
# Use kwarg value to override defaults and add new args # Use kwarg value to override defaults and add new args
for key in kwargs.keys(): for key in kwargs.keys():
physics_args[key] = kwargs[key] args[key] = kwargs[key]
# Construct arguments string and final execution string # Construct arguments string and final execution string
arg_string = create_arg_string(physics_args) arg_string = create_arg_string(args)
arg_string = f'binary_c {arg_string}' arg_string = f'binary_c {arg_string}'
# print(arg_string)
# Run it and get output # Run it and get output
buffer = "" buffer = ""
...@@ -58,7 +67,6 @@ def run_system(**kwargs): ...@@ -58,7 +67,6 @@ def run_system(**kwargs):
return output return output
def parse_output(output, selected_header): def parse_output(output, selected_header):
""" """
Function that parses output of binaryc when it is construction like this: Function that parses output of binaryc when it is construction like this:
...@@ -98,5 +106,4 @@ def parse_output(output, selected_header): ...@@ -98,5 +106,4 @@ def parse_output(output, selected_header):
for key in keys: for key in keys:
final_values_dict[key].append(value_dict[key]) final_values_dict[key].append(value_dict[key])
return final_values_dict return final_values_dict
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
david_results/s.png

17.4 KiB

...@@ -9,7 +9,6 @@ import pandas as pd ...@@ -9,7 +9,6 @@ import pandas as pd
import binary_c import binary_c
from binaryc_python_utils.defaults import physics_defaults
from binaryc_python_utils.functions import create_arg_string, parse_output, run_system from binaryc_python_utils.functions import create_arg_string, parse_output, run_system
""" """
...@@ -31,13 +30,15 @@ print("The following keys are present in the results:\n{}".format(result.keys()) ...@@ -31,13 +30,15 @@ print("The following keys are present in the results:\n{}".format(result.keys())
# Cast the data into a dataframe. # Cast the data into a dataframe.
df = pd.DataFrame.from_dict(result, dtype=np.float64) df = pd.DataFrame.from_dict(result, dtype=np.float64)
print(df)
sliced_df = df[df.t < 1000] # Cut off late parts of evolution
# sliced_df = df[df.t < 1000] # Cut off late parts of evolution
# print(sliced_df["t"]) # print(sliced_df["t"])
# plt.plot(sliced_df['t'], sliced_df['radius'])
# plt.xlabel('Time (Myr)')
# plt.ylabel('Radius (Rsol)')
# plt.show()
\ No newline at end of file plt.plot(sliced_df['omega'], sliced_df['radius'])
plt.xlabel('Time (Myr)')
plt.ylabel('omega (Rsol)')
plt.show()
\ 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