Loading binarycpython/utils/custom_logging_functions.py +2 −4 Original line number Diff line number Diff line Loading @@ -213,9 +213,7 @@ def return_compilation_dict(verbose=0): libs = defaults[ "libs" ] # = ($ENV{BINARY_GRID2_LIBS} // $defaults{libs}).' '.($ENV{BINARY_GRID2_EXTRALIBS}//''); ccflags = defaults[ "ccflags" ] # = $ENV{BINARY_GRID2_CCFLAGS} ccflags = defaults["ccflags"] # = $ENV{BINARY_GRID2_CCFLAGS} # // ($defaults{ccflags}) . ($ENV{BINARY_GRID2_EXTRACCFLAGS} // ''); # you must define _SEARCH_H to prevent it being loaded twice Loading binarycpython/utils/distribution_functions.py +44 −28 Original line number Diff line number Diff line Loading @@ -9,9 +9,7 @@ generate probability distributions for sampling populations import math import numpy as np from binarycpython.utils.useful_funcs import ( calc_period_from_sep, ) from binarycpython.utils.useful_funcs import calc_period_from_sep ### # File containing probability distributions Loading @@ -27,6 +25,8 @@ from binarycpython.utils.useful_funcs import ( LOG_LN_CONVERTER = 1.0 / math.log(10.0) distribution_constants = {} # To store the constants in def prepare_dict(global_dict, list_of_sub_keys): """ Function that makes sure that the global dict is prepared to have a value set there Loading @@ -44,7 +44,6 @@ def prepare_dict(global_dict, list_of_sub_keys): internal_dict_value = internal_dict_value[k] def flat(): """ Dummy distribution function that returns 1 Loading Loading @@ -517,6 +516,7 @@ def sana12(M1, M2, a, P, amin, amax, x0, x1, p): return res def Izzard2012_period_distribution(P, M1, log10Pmin=1): """ period distribution which interpolates between Loading Loading @@ -546,21 +546,27 @@ def Izzard2012_period_distribution(P, M1, log10Pmin=1): # Calculate the normalisations # need to normalize the distribution for this mass # (and perhaps secondary mass) prepare_dict(distribution_constants, ['Izzard2012', M1]) if not distribution_constants['Izzard2012'][M1].get(log10Pmin): distribution_constants['Izzard2012'][M1][log10Pmin] = 1 # To prevent this loop from going recursive prepare_dict(distribution_constants, ["Izzard2012", M1]) if not distribution_constants["Izzard2012"][M1].get(log10Pmin): distribution_constants["Izzard2012"][M1][ log10Pmin ] = 1 # To prevent this loop from going recursive N = 200.0 # Resolution for normalisation. I hope 1000 is enough dlP = (10.0 - log10Pmin) / N C = 0 # normalisation const. for lP in np.arange(log10Pmin, 10, dlP): C += dlP * Izzard2012_period_distribution(10 ** lP, M1, log10Pmin) distribution_constants["Izzard2012"][M1][log10Pmin] = 1.0 / C print( "Normalization constant for Izzard2012 M={} (log10Pmin={}) is\ {}\n".format( M1, log10Pmin, distribution_constants["Izzard2012"][M1][log10Pmin] ) ) distribution_constants['Izzard2012'][M1][log10Pmin] = 1.0/C; print("Normalization constant for Izzard2012 M={} (log10Pmin={}) is\ {}\n".format(M1, log10Pmin, distribution_constants['Izzard2012'][M1][log10Pmin])) lP = math.log10(P); # log period lP = math.log10(P) # log period # # fits mu = interpolate_in_mass_izzard2012(M1, -17.8, 5.03) Loading @@ -570,16 +576,24 @@ def Izzard2012_period_distribution(P, M1, log10Pmin=1): g = 1.0 / (1.0 + 1e-30 ** (lP - nu)) lPmu = lP - mu print("M={} ({}) P={} : mu={} sigma={} K={} nu={} norm=%g\n".format( Mwas, M1, P, mu, sigma, K, nu)) print( "M={} ({}) P={} : mu={} sigma={} K={} nu={} norm=%g\n".format( Mwas, M1, P, mu, sigma, K, nu ) ) # print "FUNC $distdata{Izzard2012}{$M}{$log10Pmin} * (exp(- (x-$mu)**2/(2.0*$sigma*$sigma) ) + $K/MAX(0.1,$lP)) * $g;\n"; if ((lP < log10Pmin) or (lP > 10.0)): if (lP < log10Pmin) or (lP > 10.0): return 0 else: return distribution_constants['Izzard2012'][M1][log10Pmin] * (math.exp(- lPmu * lPmu / (2.0 * sigma * sigma)) + K/max(0.1, lP)) * g; return ( distribution_constants["Izzard2012"][M1][log10Pmin] * (math.exp(-lPmu * lPmu / (2.0 * sigma * sigma)) + K / max(0.1, lP)) * g ) def interpolate_in_mass_izzard2012(M, high, low): """ Loading @@ -592,7 +606,9 @@ def interpolate_in_mass_izzard2012(M, high, low): log_interpolation = False if log_interpolation: return (high-low)/(math.log10(16.3)-math.log10(1.15)) * (math.log10(M)-math.log10(1.15)) + low return (high - low) / (math.log10(16.3) - math.log10(1.15)) * ( math.log10(M) - math.log10(1.15) ) + low else: return (high - low) / (16.3 - 1.15) * (M - 1.15) + low Loading binarycpython/utils/grid.py +46 −48 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ import argparse import importlib.util from pathos.helpers import mp as pathos_multiprocess # from pathos.multiprocessing import ProcessingPool as Pool from pathos.pools import _ProcessPool as Pool Loading Loading @@ -53,7 +54,7 @@ import binary_c_python_api # that is stored into a python object. rather its just written to stdout class Population(): class Population: """ Population Object. Contains all the necessary functions to set up, run and process a population of systems Loading @@ -68,9 +69,7 @@ class Population(): self.cleaned_up_defaults = self.cleanup_defaults() # Different sections of options self.bse_options = ( {} ) # bse_options is just empty. self.bse_options = {} # bse_options is just empty. # Setting stuff will check against the defaults to see if the input is correct. self.grid_options = grid_options_defaults_dict.copy() self.custom_options = {} Loading Loading @@ -136,7 +135,9 @@ class Population(): else: print( "!! Key doesnt match previously known parameter: \ adding: {}={} to custom_options".format(key, kwargs[key]) adding: {}={} to custom_options".format( key, kwargs[key] ) ) self.custom_options[key] = kwargs[key] Loading Loading @@ -680,7 +681,6 @@ class Population(): if self.grid_options["parse_function"]: self.grid_options["parse_function"](self, out) def evolve_population(self): """ Function to evolve populations. This is the main function. Handles the setting up, evolving Loading Loading @@ -1252,10 +1252,7 @@ class Population(): ################################################### def write_binary_c_calls_to_file( self, output_dir=None, output_filename=None, include_defaults=False self, output_dir=None, output_filename=None, include_defaults=False ): """ Function that loops over the gridcode and writes the generated parameters to a file. Loading Loading @@ -1389,4 +1386,5 @@ class Population(): # Function to join the result dictionaries # """ ################################################################################################ binarycpython/utils/plot_functions.py +2 −3 Original line number Diff line number Diff line Loading @@ -21,9 +21,7 @@ import numpy as np # import matplotlib.pyplot as plt from binarycpython.utils.functions import ( output_lines, ) from binarycpython.utils.functions import output_lines from binarycpython.utils.run_system_wrapper import run_system from binarycpython.utils.custom_logging_functions import binary_c_log_code Loading Loading @@ -67,6 +65,7 @@ def dummy(): """Placeholder""" pass def parse_function_hr_diagram(output): """ Parsing function for the HR plotting routine Loading docs/source/conf.py +4 −4 Original line number Diff line number Diff line Loading @@ -40,10 +40,10 @@ author = "David Hendriks, Robert Izzard, Jeff Andrews" extensions = [ "sphinx.ext.autodoc", "sphinx.ext.doctest", 'sphinx.ext.todo', 'sphinx.ext.coverage', 'sphinx.ext.viewcode', 'sphinx.ext.napoleon', "sphinx.ext.todo", "sphinx.ext.coverage", "sphinx.ext.viewcode", "sphinx.ext.napoleon", "hawkmoth", "m2r", ] Loading Loading
binarycpython/utils/custom_logging_functions.py +2 −4 Original line number Diff line number Diff line Loading @@ -213,9 +213,7 @@ def return_compilation_dict(verbose=0): libs = defaults[ "libs" ] # = ($ENV{BINARY_GRID2_LIBS} // $defaults{libs}).' '.($ENV{BINARY_GRID2_EXTRALIBS}//''); ccflags = defaults[ "ccflags" ] # = $ENV{BINARY_GRID2_CCFLAGS} ccflags = defaults["ccflags"] # = $ENV{BINARY_GRID2_CCFLAGS} # // ($defaults{ccflags}) . ($ENV{BINARY_GRID2_EXTRACCFLAGS} // ''); # you must define _SEARCH_H to prevent it being loaded twice Loading
binarycpython/utils/distribution_functions.py +44 −28 Original line number Diff line number Diff line Loading @@ -9,9 +9,7 @@ generate probability distributions for sampling populations import math import numpy as np from binarycpython.utils.useful_funcs import ( calc_period_from_sep, ) from binarycpython.utils.useful_funcs import calc_period_from_sep ### # File containing probability distributions Loading @@ -27,6 +25,8 @@ from binarycpython.utils.useful_funcs import ( LOG_LN_CONVERTER = 1.0 / math.log(10.0) distribution_constants = {} # To store the constants in def prepare_dict(global_dict, list_of_sub_keys): """ Function that makes sure that the global dict is prepared to have a value set there Loading @@ -44,7 +44,6 @@ def prepare_dict(global_dict, list_of_sub_keys): internal_dict_value = internal_dict_value[k] def flat(): """ Dummy distribution function that returns 1 Loading Loading @@ -517,6 +516,7 @@ def sana12(M1, M2, a, P, amin, amax, x0, x1, p): return res def Izzard2012_period_distribution(P, M1, log10Pmin=1): """ period distribution which interpolates between Loading Loading @@ -546,21 +546,27 @@ def Izzard2012_period_distribution(P, M1, log10Pmin=1): # Calculate the normalisations # need to normalize the distribution for this mass # (and perhaps secondary mass) prepare_dict(distribution_constants, ['Izzard2012', M1]) if not distribution_constants['Izzard2012'][M1].get(log10Pmin): distribution_constants['Izzard2012'][M1][log10Pmin] = 1 # To prevent this loop from going recursive prepare_dict(distribution_constants, ["Izzard2012", M1]) if not distribution_constants["Izzard2012"][M1].get(log10Pmin): distribution_constants["Izzard2012"][M1][ log10Pmin ] = 1 # To prevent this loop from going recursive N = 200.0 # Resolution for normalisation. I hope 1000 is enough dlP = (10.0 - log10Pmin) / N C = 0 # normalisation const. for lP in np.arange(log10Pmin, 10, dlP): C += dlP * Izzard2012_period_distribution(10 ** lP, M1, log10Pmin) distribution_constants["Izzard2012"][M1][log10Pmin] = 1.0 / C print( "Normalization constant for Izzard2012 M={} (log10Pmin={}) is\ {}\n".format( M1, log10Pmin, distribution_constants["Izzard2012"][M1][log10Pmin] ) ) distribution_constants['Izzard2012'][M1][log10Pmin] = 1.0/C; print("Normalization constant for Izzard2012 M={} (log10Pmin={}) is\ {}\n".format(M1, log10Pmin, distribution_constants['Izzard2012'][M1][log10Pmin])) lP = math.log10(P); # log period lP = math.log10(P) # log period # # fits mu = interpolate_in_mass_izzard2012(M1, -17.8, 5.03) Loading @@ -570,16 +576,24 @@ def Izzard2012_period_distribution(P, M1, log10Pmin=1): g = 1.0 / (1.0 + 1e-30 ** (lP - nu)) lPmu = lP - mu print("M={} ({}) P={} : mu={} sigma={} K={} nu={} norm=%g\n".format( Mwas, M1, P, mu, sigma, K, nu)) print( "M={} ({}) P={} : mu={} sigma={} K={} nu={} norm=%g\n".format( Mwas, M1, P, mu, sigma, K, nu ) ) # print "FUNC $distdata{Izzard2012}{$M}{$log10Pmin} * (exp(- (x-$mu)**2/(2.0*$sigma*$sigma) ) + $K/MAX(0.1,$lP)) * $g;\n"; if ((lP < log10Pmin) or (lP > 10.0)): if (lP < log10Pmin) or (lP > 10.0): return 0 else: return distribution_constants['Izzard2012'][M1][log10Pmin] * (math.exp(- lPmu * lPmu / (2.0 * sigma * sigma)) + K/max(0.1, lP)) * g; return ( distribution_constants["Izzard2012"][M1][log10Pmin] * (math.exp(-lPmu * lPmu / (2.0 * sigma * sigma)) + K / max(0.1, lP)) * g ) def interpolate_in_mass_izzard2012(M, high, low): """ Loading @@ -592,7 +606,9 @@ def interpolate_in_mass_izzard2012(M, high, low): log_interpolation = False if log_interpolation: return (high-low)/(math.log10(16.3)-math.log10(1.15)) * (math.log10(M)-math.log10(1.15)) + low return (high - low) / (math.log10(16.3) - math.log10(1.15)) * ( math.log10(M) - math.log10(1.15) ) + low else: return (high - low) / (16.3 - 1.15) * (M - 1.15) + low Loading
binarycpython/utils/grid.py +46 −48 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ import argparse import importlib.util from pathos.helpers import mp as pathos_multiprocess # from pathos.multiprocessing import ProcessingPool as Pool from pathos.pools import _ProcessPool as Pool Loading Loading @@ -53,7 +54,7 @@ import binary_c_python_api # that is stored into a python object. rather its just written to stdout class Population(): class Population: """ Population Object. Contains all the necessary functions to set up, run and process a population of systems Loading @@ -68,9 +69,7 @@ class Population(): self.cleaned_up_defaults = self.cleanup_defaults() # Different sections of options self.bse_options = ( {} ) # bse_options is just empty. self.bse_options = {} # bse_options is just empty. # Setting stuff will check against the defaults to see if the input is correct. self.grid_options = grid_options_defaults_dict.copy() self.custom_options = {} Loading Loading @@ -136,7 +135,9 @@ class Population(): else: print( "!! Key doesnt match previously known parameter: \ adding: {}={} to custom_options".format(key, kwargs[key]) adding: {}={} to custom_options".format( key, kwargs[key] ) ) self.custom_options[key] = kwargs[key] Loading Loading @@ -680,7 +681,6 @@ class Population(): if self.grid_options["parse_function"]: self.grid_options["parse_function"](self, out) def evolve_population(self): """ Function to evolve populations. This is the main function. Handles the setting up, evolving Loading Loading @@ -1252,10 +1252,7 @@ class Population(): ################################################### def write_binary_c_calls_to_file( self, output_dir=None, output_filename=None, include_defaults=False self, output_dir=None, output_filename=None, include_defaults=False ): """ Function that loops over the gridcode and writes the generated parameters to a file. Loading Loading @@ -1389,4 +1386,5 @@ class Population(): # Function to join the result dictionaries # """ ################################################################################################
binarycpython/utils/plot_functions.py +2 −3 Original line number Diff line number Diff line Loading @@ -21,9 +21,7 @@ import numpy as np # import matplotlib.pyplot as plt from binarycpython.utils.functions import ( output_lines, ) from binarycpython.utils.functions import output_lines from binarycpython.utils.run_system_wrapper import run_system from binarycpython.utils.custom_logging_functions import binary_c_log_code Loading Loading @@ -67,6 +65,7 @@ def dummy(): """Placeholder""" pass def parse_function_hr_diagram(output): """ Parsing function for the HR plotting routine Loading
docs/source/conf.py +4 −4 Original line number Diff line number Diff line Loading @@ -40,10 +40,10 @@ author = "David Hendriks, Robert Izzard, Jeff Andrews" extensions = [ "sphinx.ext.autodoc", "sphinx.ext.doctest", 'sphinx.ext.todo', 'sphinx.ext.coverage', 'sphinx.ext.viewcode', 'sphinx.ext.napoleon', "sphinx.ext.todo", "sphinx.ext.coverage", "sphinx.ext.viewcode", "sphinx.ext.napoleon", "hawkmoth", "m2r", ] Loading