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

changed name of function

parent cbcc519d
No related branches found
No related tags found
No related merge requests found
......@@ -8,12 +8,14 @@ import json
import textwrap
import binary_c_python_api
from mergedict import ConfigDict
from mergedict import MergeDict
class SumDict(MergeDict):
@MergeDict.dispatch(float)
def merge_float(this, other):
return this + other
# import unicode
class Decoder(json.JSONDecoder):
"""
......@@ -47,6 +49,8 @@ class Decoder(json.JSONDecoder):
else:
return o
####
# Evolution functions
def test_return_persistent_data_memaddr():
output = binary_c_python_api.return_persistent_data_memaddr("")
......@@ -132,6 +136,8 @@ def ensemble_output():
print(json.dumps(json_1, indent=4))
print("took {}s to decode".format(stop-start))
def adding_ensemble_output():
m1 = 2 # Msun
m2 = 0.1 # Msun
......@@ -166,6 +172,9 @@ def adding_ensemble_output():
json_1 = json.loads(ensemble_jsons_1[0][len("ENSEMBLE_JSON "):], cls=Decoder)
json_2 = json.loads(ensemble_jsons_2[0][len("ENSEMBLE_JSON "):], cls=Decoder)
# test_1_total_dict = SumDict(json_1)
# test_1_total_dict.merge(json_2)
with open("json_1.json", 'w') as f:
f.write(json.dumps(json_1, indent=4))
with open("json_2.json", 'w') as f:
......@@ -267,14 +276,41 @@ def test_free_and_json_output():
print(textwrap.indent(str(json_output_by_freeing), "\t"))
def full_output():
m1 = 15.0 # Msun
m2 = 14.0 # Msun
separation = 0 # 0 = ignored, use period
orbital_period = 453000000000.0 # days
eccentricity = 0.0
metallicity = 0.02
max_evolution_time = 15000
argstring_1 = "binary_c M_1 {0:g} M_2 {1:g} separation {2:g} orbital_period {3:g} eccentricity {4:g} metallicity {5:g} max_evolution_time {6:g} ensemble 1 ensemble_defer 0".format(
m1,
m2,
separation,
orbital_period,
eccentricity,
metallicity,
max_evolution_time,
)
output_1 = binary_c_python_api.run_system(argstring=argstring_1)
ensemble_jsons_1 = [line for line in output_1.splitlines() if line.startswith("ENSEMBLE_JSON")]
start = time.time()
json_1 = json.loads(ensemble_jsons_1[0][len("ENSEMBLE_JSON "):], cls=Decoder)
stop = time.time()
print("took {}s to decode".format(stop-start))
with open("json_full_ensemble.json", 'w') as f:
f.write(json.dumps(json_1, indent=4))
####
if __name__ == "__main__":
# test_return_persistent_data_memaddr()
# test_passing_persistent_data_to_run_system()
# ensemble_output()
adding_ensemble_output()
# test_free_and_json_output()
\ No newline at end of file
# adding_ensemble_output()
# test_free_and_json_output()
full_output()
\ 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