From 921e4e13102cead6d874dbe04510b4b5a6a30cc7 Mon Sep 17 00:00:00 2001 From: Niels Bassler Date: Wed, 19 Apr 2023 20:46:42 +0200 Subject: [PATCH] suggestion for addidn total times for all estimators --- pymchelper/estimator.py | 13 +++++++++++++ pymchelper/input_output.py | 4 ++++ pymchelper/readers/shieldhit/binary_spec.py | 2 ++ pymchelper/readers/shieldhit/reader_bdo2019.py | 3 +++ 4 files changed, 22 insertions(+) diff --git a/pymchelper/estimator.py b/pymchelper/estimator.py index 285c652dd..72e8c5784 100644 --- a/pymchelper/estimator.py +++ b/pymchelper/estimator.py @@ -62,6 +62,11 @@ def __init__(self): self.z = self.x self.number_of_primaries = 0 # number of histories simulated + self.run_time = 0 # runtime in seconds + self.run_time_sim = 0 # run time in seconds excluding initialization header + self.total_number_of_primaries = 0 # number of histories simulated + self.total_run_time = 0 # runtime in seconds + self.total_run_time_sim = 0 # run time in seconds excluding initialization header self.file_counter = 0 # number of files read self.file_corename = "" # common core for paths of contributing files self.file_format = "" # binary file format of the input files @@ -131,9 +136,17 @@ def average_with_nan(estimator_list, error_estimate=ErrorEstimate.stderr): # TODO add compatibility check if not estimator_list: return None + result = copy.deepcopy(estimator_list[0]) + + for n, estimator in enumerate(estimator_list, start=2): + result.total_number_of_primaries += estimator.number_of_primaries + result.total_run_time += estimator.run_time + result.total_run_time_sim += estimator.run_time_sim + for page_no, page in enumerate(result.pages): page.data_raw = np.nanmean([estimator.pages[page_no].data_raw for estimator in estimator_list], axis=0) + result.file_counter = len(estimator_list) if result.file_counter > 1 and error_estimate != ErrorEstimate.none: # s = stddev = sqrt(1/(n-1)sum(x-)**2) diff --git a/pymchelper/input_output.py b/pymchelper/input_output.py index 25609d751..da8d41c17 100644 --- a/pymchelper/input_output.py +++ b/pymchelper/input_output.py @@ -92,6 +92,10 @@ 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 # Running variance algorithm based on algorithm by B. P. Welford, # presented in Donald Knuth's Art of Computer Programming, Vol 2, page 232, 3rd edition. diff --git a/pymchelper/readers/shieldhit/binary_spec.py b/pymchelper/readers/shieldhit/binary_spec.py index 2a4250013..17b2b8a6e 100644 --- a/pymchelper/readers/shieldhit/binary_spec.py +++ b/pymchelper/readers/shieldhit/binary_spec.py @@ -208,6 +208,8 @@ class SHBDOTagID(IntEnum): SHBDOTagID.user: 'user', SHBDOTagID.host: 'host', SHBDOTagID.rt_nstat: 'number_of_primaries', + SHBDOTagID.rt_time: 'run_time', + SHBDOTagID.rt_timesim: 'run_time_sim', SHBDOTagID.number_of_pages: 'page_count', SHBDOTagID.geo_unit_ids: 'geo_unit_ids', SHBDOTagID.geo_units: 'geo_units', diff --git a/pymchelper/readers/shieldhit/reader_bdo2019.py b/pymchelper/readers/shieldhit/reader_bdo2019.py index 31350efe4..188034610 100644 --- a/pymchelper/readers/shieldhit/reader_bdo2019.py +++ b/pymchelper/readers/shieldhit/reader_bdo2019.py @@ -176,6 +176,9 @@ def read_data(self, estimator, nscale=1): page.error_raw /= np.float64(estimator.number_of_primaries) estimator.file_format = 'bdo2019' + estimator.total_number_of_primaries = estimator.number_of_primaries + estimator.total_run_time = estimator.run_time + estimator.total_run_time_sim = estimator.run_time_sim logger.debug("Done reading bdo file.") return True