From d2c8e1a360a9713d40e0808fc0ac341cb4e644ae Mon Sep 17 00:00:00 2001 From: Niels Bassler Date: Wed, 19 Apr 2023 21:26:10 +0200 Subject: [PATCH] suggestion for MC-summary table, output in markdown format. --- pymchelper/input_output.py | 1 - pymchelper/run.py | 4 ++++ pymchelper/writers/common.py | 5 ++++- pymchelper/writers/mcsum.py | 42 ++++++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 pymchelper/writers/mcsum.py diff --git a/pymchelper/input_output.py b/pymchelper/input_output.py index da8d41c17..a9b17abde 100644 --- a/pymchelper/input_output.py +++ b/pymchelper/input_output.py @@ -92,7 +92,6 @@ def fromfilelist(input_file_list, error=ErrorEstimate.stderr, nan: bool = True): # loop over all files with n running from 2 for n, filename in enumerate(input_file_list[1:], start=2): current_estimator = fromfile(filename) # x - print("filename", filename, n) result.total_number_of_primaries += current_estimator.number_of_primaries result.total_run_time += current_estimator.run_time result.total_run_time_sim += current_estimator.run_time_sim diff --git a/pymchelper/run.py b/pymchelper/run.py index 3fbb527b7..0dadacd02 100644 --- a/pymchelper/run.py +++ b/pymchelper/run.py @@ -81,6 +81,10 @@ def main(args=None): parser_inspect = subparsers.add_parser(Converters.inspect.name, help='prints metadata') add_default_options(parser_inspect) + + parser_mcsum = subparsers.add_parser(Converters.mcsum.name, help='MC summary table after Sechopoulos et al (2018)') + add_default_options(parser_mcsum) + parser_inspect.add_argument('-d', '--details', help='print detailed information about data attribute', action="store_true") diff --git a/pymchelper/writers/common.py b/pymchelper/writers/common.py index c9d4bdd12..f0f07b01c 100644 --- a/pymchelper/writers/common.py +++ b/pymchelper/writers/common.py @@ -9,6 +9,7 @@ from pymchelper.writers.trip98ddd import TRiP98DDDWriter from pymchelper.writers.hdf import HdfWriter from pymchelper.writers.json import JsonWriter +from pymchelper.writers.mcsum import MCSumWriter class Converters(IntEnum): @@ -25,6 +26,7 @@ class Converters(IntEnum): inspect = 8 hdf = 9 json = 10 + mcsum = 11 @classmethod def _converter_mapping(cls, item): @@ -38,7 +40,8 @@ def _converter_mapping(cls, item): cls.sparse: SparseWriter, cls.inspect: Inspector, cls.hdf: HdfWriter, - cls.json: JsonWriter + cls.json: JsonWriter, + cls.mcsum: MCSumWriter }.get(item) @classmethod diff --git a/pymchelper/writers/mcsum.py b/pymchelper/writers/mcsum.py new file mode 100644 index 000000000..5e33ad2f4 --- /dev/null +++ b/pymchelper/writers/mcsum.py @@ -0,0 +1,42 @@ +import logging +import time +import urllib.parse + +logger = logging.getLogger(__name__) + + +class MCSumWriter: + def __init__(self, filename, options): + logger.debug("Initialising Inspector writer") + self.options = options + + def write(self, estimator): + """Print all keys and values from estimator structure + + they include also a metadata read from binary output file + """ + + s = estimator.total_run_time + if s < 60: + ts = time.strftime('%S seconds', time.gmtime(s)) + elif s < 3600: + ts = time.strftime('%M minutes', time.gmtime(s)) + else: + ts = time.strftime('%H hours %M minutes', time.gmtime(s)) + + print('Item name | Description | References') + print('|---|---|---|') + print(f'| Code Version | {estimator.mc_code_version} | |') + print('| Validation | |') + print(f'| Timing | {estimator.file_counter} jobs, {ts} total runtime |') + print('| Geometry | |') + print('| Source | |') + print('| Physics | |') + print('| Scoring | |') + print(f'|\\# histories | {estimator.total_number_of_primaries} | |') + + url = urllib.parse.quote("https://doi.org/10.1002/mp.12702", safe="") + url = "https://doi.org/10.1002/mp.12702" + print('Table caption: Summary of Monte Carlo simulations parameters in AAPM TG268 format.') + print(f'[See Sechopoulos et al. (2018), {url}.]') + return 0