Skip to content

Commit

Permalink
suggestion for MC-summary table, output in markdown format.
Browse files Browse the repository at this point in the history
  • Loading branch information
nbassler authored and grzanka committed Apr 20, 2023
1 parent 549b1d0 commit d2c8e1a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
1 change: 0 additions & 1 deletion pymchelper/input_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions pymchelper/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 4 additions & 1 deletion pymchelper/writers/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -25,6 +26,7 @@ class Converters(IntEnum):
inspect = 8
hdf = 9
json = 10
mcsum = 11

@classmethod
def _converter_mapping(cls, item):
Expand All @@ -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
Expand Down
42 changes: 42 additions & 0 deletions pymchelper/writers/mcsum.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d2c8e1a

Please sign in to comment.