From 458d9e867172e8b343bacec6ebf089b2f858c829 Mon Sep 17 00:00:00 2001 From: David Hendriks <davidhendriks93@gmail.com> Date: Tue, 5 Jan 2021 12:21:44 +0000 Subject: [PATCH] fixing tests and docs --- .../utils/custom_logging_functions.py | 42 ++++++++--------- binarycpython/utils/plot_functions.py | 47 ++++++++++--------- binarycpython/utils/run_system_wrapper.py | 13 ++--- 3 files changed, 51 insertions(+), 51 deletions(-) diff --git a/binarycpython/utils/custom_logging_functions.py b/binarycpython/utils/custom_logging_functions.py index 4f21aa95f..8fb3b0fdc 100644 --- a/binarycpython/utils/custom_logging_functions.py +++ b/binarycpython/utils/custom_logging_functions.py @@ -85,30 +85,29 @@ def binary_c_log_code(code: str, verbose: int=0) -> str: Function to construct the code to construct the custom logging function Example: - Code to log and terminate evolution when the primary star becomes a NS + Code to log and terminate evolution when the primary star becomes a NS:: - :: - if(stardata->star[0].stellar_type>=NS) - { - if (stardata->model.time < stardata->model.max_evolution_time) + if(stardata->star[0].stellar_type>=NS) { - Printf("EXAMPLE_LOG_CO %30.12e %g %g %g %g %d %d\\n", - // - stardata->model.time, // 1 - - stardata->star[0].mass, //2 - stardata->previous_stardata->star[0].mass, //3 - - stardata->star[0].radius, //4 - stardata->previous_stardata->star[0].radius, //5 - - stardata->star[0].stellar_type, //6 - stardata->previous_stardata->star[0].stellar_type //7 - ); + if (stardata->model.time < stardata->model.max_evolution_time) + { + Printf("EXAMPLE_LOG_CO %30.12e %g %g %g %g %d %d\\n", + // + stardata->model.time, // 1 + + stardata->star[0].mass, //2 + stardata->previous_stardata->star[0].mass, //3 + + stardata->star[0].radius, //4 + stardata->previous_stardata->star[0].radius, //5 + + stardata->star[0].stellar_type, //6 + stardata->previous_stardata->star[0].stellar_type //7 + ); + }; + /* Kill the simulation to save time */ + stardata->model.max_evolution_time = stardata->model.time - stardata->model.dtm; }; - /* Kill the simulation to save time */ - stardata->model.max_evolution_time = stardata->model.time - stardata->model.dtm; - }; Args: code: Exact c-statement to output information in binary_c. Can be wrapped in logical statements. @@ -116,7 +115,6 @@ def binary_c_log_code(code: str, verbose: int=0) -> str: Returns: string containing the custom logging code. This includes all the includes and other definitions. This code will be used as the shared library - """ verbose_print("Creating the code for the shared library for the custom logging", verbose, 0) diff --git a/binarycpython/utils/plot_functions.py b/binarycpython/utils/plot_functions.py index 63c812a03..f68aa62e7 100644 --- a/binarycpython/utils/plot_functions.py +++ b/binarycpython/utils/plot_functions.py @@ -102,21 +102,21 @@ def plot_HR_diagram( log temperature on x axis (reversed) requires: - time - stellar_type_1 - stellar_type_2 - radius_1 - radius_2 - luminosity_1 - luminosity_2 + - time + - stellar_type_1 + - stellar_type_2 + - radius_1 + - radius_2 + - luminosity_1 + - luminosity_2 Plots: - luminosity_1 vs teff_1 - luminosity_2 vs teff_2 + - luminosity_1 vs teff_1 + - luminosity_2 vs teff_2 Tasks: - TODO: add HD limit - TODO: add lines of constant radius + - TODO: add HD limit + - TODO: add lines of constant radius Args: df: pandas dataframe with the required columns @@ -296,7 +296,7 @@ def plot_masses(df, show_stellar_types: bool=False, show_plot: bool=True): - Pms mass 1 - pms mass 2 - pms total mass - (maybe?) core and env masses + - (maybe?) core and env masses Args: df: pandas dataframe with the required columns @@ -500,30 +500,31 @@ def plot_system(plot_type, **kwargs): - a preset custom logging for a specific plotting routine is loaded, depending on the choice of plot_type - This is used for the run_system call - The output of this run_system is loaded into a dataframe by - parsing it with a corresponding parsing function + parsing it with a corresponding parsing function - The dataframe is passed to the plotting routine - plot is shown or returned. There are several pre-set plots to choose from: - mass_evolution - orbit_evolution - hr_diagram + - mass_evolution + - orbit_evolution + - hr_diagram Tasks: - TODO: Complex Function! - TODO: make sure this way of passing args works correctly. - TODO: make the plotting specific keywords available via the inspect stuff + - TODO: Complex Function! + - TODO: make sure this way of passing args works correctly. + - TODO: make the plotting specific keywords available via the inspect stuff All keywords are considered kwargs, except for plot_type Args: - plot_type: string input should be one of the following types: - ['mass_evolution', 'orbit_evolution', 'hr_diagram']. - Input will be matched against this, - and then go through a dictionary to pick the correct plotting function. + 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 (makes so that you can customize it) + show_stellar_types: whether to plot the stellar type evolution on a second pane. This is not included in all the plotting routines. + Other input: other kwargs that are passed to run_system (inspect the docstring of run_system for more info) diff --git a/binarycpython/utils/run_system_wrapper.py b/binarycpython/utils/run_system_wrapper.py index f43d1eee9..0f45f4895 100644 --- a/binarycpython/utils/run_system_wrapper.py +++ b/binarycpython/utils/run_system_wrapper.py @@ -20,18 +20,19 @@ def run_system(**kwargs): Function that runs a system. Mostly as a useful utility function that handles all the setup of argument lists etc. - examples: - * run_system(M_1=10): will run a system with ZAMS mass 1 = 10 - * run_system(M_1=10, log_filename="~/example_log.txt"): Will run a system + Examples: + - run_system(M_1=10): will run a system with ZAMS mass 1 = 10 + - run_system(M_1=10, log_filename="~/example_log.txt"): Will run a system and write the logfile too - * run_system(M_1=10, parse_function=fancy_parsing_function) + - run_system(M_1=10, parse_function=fancy_parsing_function) Tasks: - TODO: Expand functionality. - TODO: Notify user when an unknown keyword is passed. + - TODO: Expand functionality. + - TODO: Notify user when an unknown keyword is passed. All~ the arguments known to binary_c can be passed to this function as kwargs. Several extra arguments can be passed through the kwargs: + Kwargs: custom_logging_code (string): Should contain a string containing the c-code for the shared library. If this is provided binary_c will use that custom logging code to output its data -- GitLab