Loading binarycpython/utils/distribution_functions.py +9 −8 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ Tasks: import math import numpy as np 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 Loading Loading @@ -1425,12 +1425,6 @@ def Moe_de_Stefano_2017_pdf(options): 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'] if not options.get('multiplicity', None): multiplicity = 1 Loading @@ -1446,7 +1440,7 @@ def Moe_de_Stefano_2017_pdf(options): ############################################################ # 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 Loading @@ -1458,6 +1452,13 @@ def Moe_de_Stefano_2017_pdf(options): prob.append(Kroupa2001(options['M1']) * options['M1']) 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 if not Moecache.get("rinterpolator_log10P", None): Moecache['rinterpolator_log10P'] = py_rinterpolate.Rinterpolate( Loading binarycpython/utils/functions.py +90 −0 Original line number Diff line number Diff line Loading @@ -1257,6 +1257,96 @@ def merge_dicts(dict_1: dict, dict_2: dict) -> 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: """ Loading binarycpython/utils/grid.py +155 −89 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
binarycpython/utils/distribution_functions.py +9 −8 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ Tasks: import math import numpy as np 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 Loading Loading @@ -1425,12 +1425,6 @@ def Moe_de_Stefano_2017_pdf(options): 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'] if not options.get('multiplicity', None): multiplicity = 1 Loading @@ -1446,7 +1440,7 @@ def Moe_de_Stefano_2017_pdf(options): ############################################################ # 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 Loading @@ -1458,6 +1452,13 @@ def Moe_de_Stefano_2017_pdf(options): prob.append(Kroupa2001(options['M1']) * options['M1']) 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 if not Moecache.get("rinterpolator_log10P", None): Moecache['rinterpolator_log10P'] = py_rinterpolate.Rinterpolate( Loading
binarycpython/utils/functions.py +90 −0 Original line number Diff line number Diff line Loading @@ -1257,6 +1257,96 @@ def merge_dicts(dict_1: dict, dict_2: dict) -> 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: """ Loading
binarycpython/utils/grid.py +155 −89 File changed.Preview size limit exceeded, changes collapsed. Show changes