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

Got the M&S grid inplace. Will not debug and make sure the numbers are correct

parent ed070c0e
No related branches found
No related tags found
No related merge requests found
...@@ -22,7 +22,7 @@ Tasks: ...@@ -22,7 +22,7 @@ Tasks:
import math import math
import numpy as np import numpy as np
from typing import Optional, Union from typing import Optional, Union
from binarycpython.utils.useful_funcs import calc_period_from_sep from binarycpython.utils.useful_funcs import calc_period_from_sep, calc_sep_from_period
### ###
# File containing probability distributions # File containing probability distributions
...@@ -1425,12 +1425,6 @@ def Moe_de_Stefano_2017_pdf(options): ...@@ -1425,12 +1425,6 @@ def Moe_de_Stefano_2017_pdf(options):
prob = [] # Value that we will return prob = [] # Value that we will return
# Separation of the inner binary
options['sep'] = calc_sep_from_period(options['M1'], options['M2'], options['P'])
# Total mass inner binary:
options['M1+M2'] = options['M1'] + options['M2']
multiplicity = options['multiplicity'] multiplicity = options['multiplicity']
if not options.get('multiplicity', None): if not options.get('multiplicity', None):
multiplicity = 1 multiplicity = 1
...@@ -1446,7 +1440,7 @@ def Moe_de_Stefano_2017_pdf(options): ...@@ -1446,7 +1440,7 @@ def Moe_de_Stefano_2017_pdf(options):
############################################################ ############################################################
# multiplicity fraction # multiplicity fraction
prob.append(Moe_de_Stefano_2017_multiplicity_fractions(opts)[multiplicity-1]) prob.append(Moe_de_Stefano_2017_multiplicity_fractions(options)[multiplicity-1])
############################################################ ############################################################
# always require an IMF for the primary star # always require an IMF for the primary star
...@@ -1458,6 +1452,13 @@ def Moe_de_Stefano_2017_pdf(options): ...@@ -1458,6 +1452,13 @@ def Moe_de_Stefano_2017_pdf(options):
prob.append(Kroupa2001(options['M1']) * options['M1']) prob.append(Kroupa2001(options['M1']) * options['M1'])
if(multiplicity >= 2): if(multiplicity >= 2):
# Separation of the inner binary
options['sep'] = calc_sep_from_period(options['M1'], options['M2'], options['P'])
# Total mass inner binary:
options['M1+M2'] = options['M1'] + options['M2']
# binary, triple or quadruple system # binary, triple or quadruple system
if not Moecache.get("rinterpolator_log10P", None): if not Moecache.get("rinterpolator_log10P", None):
Moecache['rinterpolator_log10P'] = py_rinterpolate.Rinterpolate( Moecache['rinterpolator_log10P'] = py_rinterpolate.Rinterpolate(
......
...@@ -1257,6 +1257,96 @@ def merge_dicts(dict_1: dict, dict_2: dict) -> dict: ...@@ -1257,6 +1257,96 @@ def merge_dicts(dict_1: dict, dict_2: dict) -> dict:
# #
return new_dict return new_dict
def update_dicts(dict_1: dict, dict_2: dict) -> dict:
"""
Function to update dict_1 with values of dict_2 in a recursive way.
Behaviour:
When dict keys are only present in one of either:
- we just add the content to the new dict
When dict keys are present in both, we decide based on the value types how to combine them:
- value of dict2 will be taken
Args:
dict_1: first dictionary
dict_2: second dictionary
Returns:
New dictionary with Updated values
"""
# Set up new dict
new_dict = {}
#
keys_1 = dict_1.keys()
keys_2 = dict_2.keys()
# Find overlapping keys of both dicts
overlapping_keys = set(keys_1).intersection(set(keys_2))
# Find the keys that are unique
unique_to_dict_1 = set(keys_1).difference(set(keys_2))
unique_to_dict_2 = set(keys_2).difference(set(keys_1))
# Add the unique keys to the new dict
for key in unique_to_dict_1:
# If these items are ints or floats, then just put them in
if isinstance(dict_1[key], (float, int)):
new_dict[key] = dict_1[key]
# Else, to be safe we should deepcopy them
else:
copy_dict = copy.deepcopy(dict_1[key])
new_dict[key] = copy_dict
for key in unique_to_dict_2:
# If these items are ints or floats, then just put them in
if isinstance(dict_2[key], (float, int)):
new_dict[key] = dict_2[key]
# Else, to be safe we should deepcopy them
else:
copy_dict = copy.deepcopy(dict_2[key])
new_dict[key] = copy_dict
# Go over the common keys:
for key in overlapping_keys:
# See whether the types are actually the same
if not type(dict_1[key]) is type(dict_2[key]):
# Exceptions:
if (type(dict_1[key]) in [int, float]) and (
type(dict_2[key]) in [int, float]
):
new_dict[key] = dict_2[key]
else:
print(
"Error key: {} value: {} type: {} and key: {} value: {} type: {} are not of the same type and cannot be merged".format(
key,
dict_1[key],
type(dict_1[key]),
key,
dict_2[key],
type(dict_2[key]),
)
)
raise ValueError
# Here we check for the cases that we want to explicitly catch. Ints will be added,
# floats will be added, lists will be appended (though that might change) and dicts will be
# dealt with by calling this function again.
else:
# dicts
if isinstance(dict_1[key], dict) and isinstance(dict_2[key], dict):
new_dict[key] = update_dicts(dict_1[key], dict_2[key])
else:
new_dict[key] = dict_2[key]
#
return new_dict
def extract_ensemble_json_from_string(binary_c_output: str) -> dict: def extract_ensemble_json_from_string(binary_c_output: str) -> dict:
""" """
......
This diff is collapsed.
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