From e93828da3d4410c1b578bb2693ceffbda55cfc54 Mon Sep 17 00:00:00 2001 From: David Hendriks <davidhendriks93@gmail.com> Date: Sun, 10 Jan 2021 10:53:29 +0000 Subject: [PATCH] bugfixes and small modifications --- binarycpython/utils/functions.py | 10 ++++++---- binarycpython/utils/grid.py | 13 ++++--------- binarycpython/utils/plot_functions.py | 16 ++++++++++------ binarycpython/utils/useful_funcs.py | 10 +++++----- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/binarycpython/utils/functions.py b/binarycpython/utils/functions.py index 72cf8c7a9..2d4bb8fb2 100644 --- a/binarycpython/utils/functions.py +++ b/binarycpython/utils/functions.py @@ -70,7 +70,8 @@ def remove_file(file: str, verbosity: int = 0) -> None: except FileNotFoundError as inst: print("Error while deleting file {}: {}".format(file, inst)) - + else: + verbose_print("File/directory {} doesn't exist. Can't remove it.", verbosity, 1) def temp_dir() -> str: """ @@ -403,7 +404,7 @@ def parse_binary_c_version_info(version_info_string: str) -> dict: ######################################################## -def output_lines(output: str) -> str: +def output_lines(output: str) -> list: """ Function that outputs the lines that were recieved from the binary_c run, but now as an iterator. @@ -532,7 +533,7 @@ def get_arg_keys() -> list: list of all the parameters that binary_c accepts (and has default values for, since we call get_defaults()) """ - return get_defaults().keys() + return list(get_defaults().keys()) def filter_arg_dict(arg_dict: dict) -> dict: @@ -579,7 +580,7 @@ def create_arg_string( # Whether to filter the arguments if filter_values: - arg_dict = filter_values(arg_dict) + arg_dict = filter_arg_dict(arg_dict) # keys = sorted(arg_dict.keys()) if sort else arg_dict.keys() @@ -1161,6 +1162,7 @@ def merge_dicts(dict_1: dict, dict_2: dict) -> dict: type(dict_1[key]), type(dict_2[key]) ) ) + raise ValueError # return new_dict diff --git a/binarycpython/utils/grid.py b/binarycpython/utils/grid.py index f8d309251..04759ed7c 100644 --- a/binarycpython/utils/grid.py +++ b/binarycpython/utils/grid.py @@ -184,15 +184,6 @@ class Population: ) self.custom_options[key] = kwargs[key] - def _set_bse_option(self, key, arg): - """ - Setter for the BSE options. - - # TODO: Put a check here that compares it to the defaults and says something - """ - - self.bse_options[key] = arg - def parse_cmdline(self) -> None: """ Function to handle settings values via the command line. @@ -200,6 +191,7 @@ class Population: Tasks: - TODO: remove the need for --cmdline + - TODO: fix that the input is converted to the correct type (i.e. type of the default value) """ parser = argparse.ArgumentParser() @@ -234,6 +226,9 @@ class Population: parameter = split[0] value = split[1] + # TODO: convert to correct type here + + # Add to dict cmdline_dict[parameter] = value diff --git a/binarycpython/utils/plot_functions.py b/binarycpython/utils/plot_functions.py index 3312dea11..d6e558575 100644 --- a/binarycpython/utils/plot_functions.py +++ b/binarycpython/utils/plot_functions.py @@ -44,8 +44,8 @@ Printf("MASS_PLOTTING %30.12e %g %g %g %g\\n", stardata->model.time, // 1 // masses - stardata->star[0].pms_mass, // - stardata->star[1].pms_mass, // + stardata->common.zero_age.mass[0], // + stardata->common.zero_age.mass[1], // stardata->star[0].mass, stardata->star[1].mass @@ -80,8 +80,8 @@ Printf("HR_PLOTTING %30.12e %d %d %g %g %g %g %g %g\\n", stardata->star[1].radius, // 7 // masses - stardata->star[0].pms_mass, // 8 - stardata->star[1].pms_mass // 9 + stardata->common.zero_age.mass[0], // 8 + stardata->common.zero_age.mass[1] // 9 ); """ @@ -235,6 +235,8 @@ def plot_orbit(df, show_stellar_types: bool = False, show_plot: bool = True): - Separation - eccentricity + TODO: fix stellar_types plot + Args: df: pandas dataframe with the required columns show_stellar_types: whether to color code the tracks and show the stellar types @@ -301,6 +303,8 @@ def plot_masses(df, show_stellar_types: bool = False, show_plot: bool = True): - pms total mass - (maybe?) core and env masses + TODO: fix stellar_types plot + Args: df: pandas dataframe with the required columns show_stellar_types: whether to color code the tracks and show the stellar types @@ -522,7 +526,7 @@ def plot_system(plot_type, **kwargs): plot_type: string input should be one of ['mass_evolution', 'orbit_evolution', 'hr_diagram']. Input will be matched against this, and then go through a dictionary to pick the correct plotting function. - return_fig: boolean whether to return the fig object instead of plotting the plot + show_plot: boolean whether to show the plot. If False it returns the figure object (makes so that you can customize it) show_stellar_types: whether to plot the stellar type evolution on a second pane. @@ -536,7 +540,7 @@ def plot_system(plot_type, **kwargs): """ # set defaults and options - return_fig = False + show_plot = False show_stellar_types = False plot_types_dict = { diff --git a/binarycpython/utils/useful_funcs.py b/binarycpython/utils/useful_funcs.py index bff269388..134c5219f 100644 --- a/binarycpython/utils/useful_funcs.py +++ b/binarycpython/utils/useful_funcs.py @@ -34,7 +34,7 @@ def calc_period_from_sep( sep: Separation in solar radii Returns: - period in years + period in days """ return YEARDY * (sep / AURSUN) * math.sqrt(sep / (AURSUN * (M1 + M2))) @@ -46,8 +46,6 @@ def calc_sep_from_period( """ Calculate separation from period. - TODO: check whether this is still correct - Args: M1: Primary mass in solar mass M2: Secondary mass in solar mass @@ -68,7 +66,7 @@ def roche_lobe(q: Union[int, float]) -> Union[int, float]: # TODO: check whether the logs are correct Args: - q: mass ratio of the binary (secondary/primary) + q: mass ratio of the binary (secondary/primary). If you input: q = mass_accretor/mass_donor, you will get the rochelobe radius of the accretor. And vice versa for the donor. Returns: Roche lobe radius in units of the separation @@ -82,6 +80,8 @@ def ragb(m: Union[int, float], z: Union[int, float]) -> Union[int, float]: """ Function to calculate radius of a star in units of solar radii at first thermal pulse as a function of mass (Z=0.02 only, but also good for Z=0.0001) + TODO: ask rob about this function + Args: m: mass of star in units of solar mass z: metallicity of star @@ -93,7 +93,7 @@ def ragb(m: Union[int, float], z: Union[int, float]) -> Union[int, float]: return m * 40.0 + 20.0 -def zams_collission( +def zams_collision( m1: Union[int, float], m2: Union[int, float], sep: Union[int, float], -- GitLab