EGS Brachy
An egs++ user code for rapid brachytherapy calculations
Loading...
Searching...
No Matches
test.py
Go to the documentation of this file.
1"""
2
3A test for comparing egs_brachy scatter dose calculations for an Ir192 sources
4with previously calculated values when egs_brachy was in a known good state.
5
6"""
7
8import math
9import os
10import re
11
12from eb_tests.utils import (doses_approx_equal, extract_all_doses, read3ddose,
13 values_close)
14
15EGSINP = "scatter.egsinp"
16TIME_LIMIT_S_PER_MHZ = 65/2993. # s / MHz
17NCOMPARE = 10 # only compare 10 highest doses
18
19
20def get_n_highest_doses(doses, uncs, n=NCOMPARE):
21 return list(zip(*sorted(zip(doses, uncs))))[-NCOMPARE:]
22
23
24def compare_results(egslst, inp_name):
25 base_gold = os.path.join(os.path.dirname(os.path.abspath(__file__)), "gold%s.3ddose")
26 base_eb = inp_name+".phantom%s.3ddose"
27 extensions = ["",".to",".pr",".ss", ".ms"]
28
29 gold = [read3ddose(base_gold % e) for e in extensions]
30 eb = [read3ddose(base_eb % e) for e in extensions]
31
32 for kind, actual, expected in zip(extensions, eb, gold):
33 act_doses, act_unc = get_n_highest_doses(actual['doses'], actual['uncs'])
34 act_doses, act_unc = get_n_highest_doses(expected['doses'], expected['uncs'])
35 exp_doses, exp_unc = list(zip(*sorted(zip(expected['doses'], expected['uncs']))))[:NCOMPARE]
36
37
38 close = [doses_approx_equal(a, a_unc, e, e_unc, compare_unc=False, max_percent_diff=0.005) for a, a_unc, e, e_unc in zip(act_doses, act_unc, exp_doses, exp_unc)]
39 diffs = [(a-e)/e*100 for a, a_unc, e, e_unc in zip(act_doses, act_unc, exp_doses, exp_unc)]
40 if not all(close):
41 print((kind, diffs))
42 return False, (kind, act_doses), (kind, exp_doses)
43
44
45 return True, [], []
get_n_highest_doses(doses, uncs, n=NCOMPARE)
Definition test.py:20