Commit 4d85802e authored by David Hendriks's avatar David Hendriks
Browse files

Working on event based logging documentation functionality

parent 92e03c21
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ binarycpython/tests/test_c_bindings.py
binarycpython/tests/test_custom_logging.py
binarycpython/tests/test_dicts.py
binarycpython/tests/test_ensemble.py
binarycpython/tests/test_event_logging.py
binarycpython/tests/test_functions.py
binarycpython/tests/test_grid.py
binarycpython/tests/test_notebooks.py
@@ -44,6 +45,7 @@ binarycpython/utils/__init__.py
binarycpython/utils/custom_logging_functions.py
binarycpython/utils/dicts.py
binarycpython/utils/ensemble.py
binarycpython/utils/event_logging.py
binarycpython/utils/functions.py
binarycpython/utils/moe_di_stefano_2017_data.py
binarycpython/utils/plot_functions.py
+92 −22
Original line number Diff line number Diff line
@@ -14,7 +14,9 @@ dimensionless_unit = u.m / u.m
# event based logging header dictionary
event_based_logging_event_dict = {
    "SN_BINARY": {
        "description": "",
        "name": "SN_BINARY",
        "longname": "binary star system SN event",
        "description": "SN_BINARY events are events that capture a supernova occuring in a binary system. The log contains information about the pre-supernova state of the system, the post-supernova state of the system, and the natal velocity kick.",
        "parameter_list": [
            "uuid",
            "event_type",
@@ -62,7 +64,9 @@ event_based_logging_event_dict = {
        ],
    },
    "SN_SINGLE": {
        "description": "",
        "name": "SN_SINGLE",
        "longname": "single star system SN event",
        "description": "SN_SINGLE events are events that capture a supernova occuring in a single system. The log contains information about the pre-supernova state of the system, the post-supernova state of the system, and the natal velocity kick.",
        "parameter_list": [
            "uuid",
            "event_type",
@@ -97,7 +101,9 @@ event_based_logging_event_dict = {
        ],
    },
    "RLOF": {
        "description": "",
        "name": "RLOF",
        "longname": "RLOF event",
        "description": "RLOF events are events that capture RLOF episode in a binary system. The log contains information about the pre-RLOF state of the system, the post-RLOF state of the system, and some cumulative properties recorded during the RLOF.",
        "parameter_list": [
            "uuid",
            "event_type",
@@ -153,6 +159,12 @@ event_based_logging_event_dict = {
    },
}

event_based_logging_parameter_list_dict = {
    event_key: event_dict["parameter_list"]
    for event_key, event_dict in event_based_logging_event_dict.items()
}


########################
# event based logging parameter description dictionary
#   this dictionary contains descriptions and units for the parameters that are contained in the event based logging output
@@ -620,9 +632,13 @@ def event_based_logging_parse_description(description_dict):

def event_based_logging_build_event_description_table(event_dict):
    """
    Function to create an table with information about the event and the parameters that are included in the output.
    Function to create a table containing the description of the parameters in the event log
    """

    #
    indent = "   "

    # Get parameter list and parse descriptions
    parameter_list = event_dict["parameter_list"]
    parameter_list_with_descriptions = [
        [
@@ -635,35 +651,89 @@ def event_based_logging_build_event_description_table(event_dict):
        ]
        for parameter in parameter_list
    ]
    # rst_table = tabulate(parameter_list_with_descriptions, tablefmt='rst')

    description_table_text = ""
    description_table_text += "The Section Title\n-----------------"
    # Construct parameter list
    rst_event_table = """
.. list-table:: {}
{}:widths: 25, 75
{}:header-rows: 1

""".format(
        event_dict["name"] + " event output log contents", indent, indent
    )

    #
    rst_event_table += indent + "* - Parameter\n"
    rst_event_table += indent + "  - Description\n"

    for parameter_el in parameter_list_with_descriptions:
        rst_event_table += indent + "* - {}\n".format(parameter_el[0])
        rst_event_table += indent + "  - {}\n".format(parameter_el[1])

    return rst_event_table

    rst_table_header = """
.. list-table:: Title
\t:widths: 25 50
\t:header-rows: 1

def event_based_logging_build_event_description_section(event_dict):
    """
    Function to create the section for the event log
    """

    indent = "\t"
    # Set up event section rst
    rst_event_section = ""

    rst_table = rst_table_header
    rst_table += indent + "* - Parameter\n"
    rst_table += indent + "  - Description\n"
    # Construct section name

    for parameter_el in parameter_list_with_descriptions:
        rst_table += indent + "* - {}\n".format(parameter_el[0])
        rst_table += indent + "  - {}\n".format(parameter_el[1])
    longname = event_dict["longname"]
    longname = longname[0].capitalize() + longname[1:]

    rst_event_section_name = "{} ({}) section\n".format(longname, event_dict["name"])
    rst_event_section += rst_event_section_name
    rst_event_section += "-" * len(rst_event_section_name.strip()) + "\n"
    rst_event_section += "\n"

    print(rst_table)
    # Construct description of event
    rst_event_section += event_dict["description"] + "\n\n"

    # Construct the table of the section
    rst_event_table = event_based_logging_build_event_description_table(event_dict)
    rst_event_section += rst_event_table

    return rst_event_section


def event_based_logging_build_event_descriptions_rst(event_based_logging_event_dict):
    """
    Main function to build the event descriptions rst string
    """

    rst_string = """Event based logging\n===================

We can configure binary_c to output information about certain events. See Notebook ....

In the following subsections we describe the content of each of these event output logs.\n\n
"""

    # construct event sections
    for _, event_dict in event_based_logging_event_dict.items():
        rst_event_section = event_based_logging_build_event_description_section(
            event_dict
        )
        rst_event_section += "\n"

        rst_string += rst_event_section

    return rst_string


if __name__ == "__main__":

    event_based_logging_build_event_description_table(
        event_based_logging_event_dict["SN_BINARY"]
    rst_string = event_based_logging_build_event_descriptions_rst(
        event_based_logging_event_dict
    )
    print(rst_string)
    # event_based_logging_build_event_description_section(
    #     event_based_logging_event_dict["SN_BINARY"]
    # )

    # for key in event_based_logging_headers_dict:
    #     for parameter in event_based_logging_headers_dict[key]:
+5 −5
Original line number Diff line number Diff line
@@ -28,8 +28,8 @@ from colorama import init as colorama_init
from binarycpython.utils.dicts import AutoVivificationDict
from binarycpython.utils.ensemble import new_grid_ensemble_results
from binarycpython.utils.event_logging import (
    combine_individual_event_files,
    split_event_types_to_files,
    event_based_logging_combine_individual_event_files,
    event_based_logging_split_event_types_to_files,
)
from binarycpython.utils.functions import (
    check_if_in_shell,
@@ -593,8 +593,8 @@ class Population(
        if self.grid_options["handle_events_logging_output"]:

            # Combine and split event types
            if self.grid_options["combine_individual_event_files"]:
                combine_individual_event_files(
            if self.grid_options["event_based_logging_combine_individual_event_files"]:
                event_based_logging_combine_individual_event_files(
                    data_dir=self.custom_options["data_dir"],
                    basename="events",
                    combined_name="total_events.dat",
@@ -606,7 +606,7 @@ class Population(

            # Split combined events file to files for each specific type of event
            if self.grid_options["split_events_file_to_each_type"]:
                split_event_types_to_files(
                event_based_logging_split_event_types_to_files(
                    input_file=os.path.join(
                        self.custom_options["data_dir"],
                        "total_events.dat",
+5 −5
Original line number Diff line number Diff line
@@ -24,8 +24,8 @@ import sys

from binarycpython.utils.custom_logging_functions import temp_dir
from binarycpython.utils.event_logging import (
    event_based_logging_headers_dict,
    event_logging_output_parser,
    event_based_logging_event_dict,
    event_based_logging_output_parser,
)
from binarycpython.utils.functions import command_string_from_list, now

@@ -315,13 +315,13 @@ class grid_options_defaults:
            ########################################
            "handle_events_logging_output": False,
            "combine_events_logging_output": False,
            "combine_individual_event_files": False,
            "event_based_logging_combine_individual_event_files": False,
            "remove_individual_events_files_after_combining": False,
            "split_events_file_to_each_type": False,
            "remove_original_combined_events_file_after_splitting": True,
            "event_logging_output_separator": "\t",
            "event_logging_parse_function": event_logging_output_parser,  # Function to parse event logging output with.
            "event_based_logging_headers_dict": event_based_logging_headers_dict,
            "event_based_logging_output_parser": event_based_logging_output_parser,  # Function to parse event logging output with.
            "event_based_logging_event_dict": event_based_logging_event_dict,
        }

    def get_grid_options_descriptions(self):
Loading