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 to ensure superposition mode calculations work when a source has zero
4weighting.
5
6Gold standard dose distribution was generated with egs_brachy and gold_standard.egsinp
7
8"""
9
10import math
11import os
12import re
13
14from eb_tests.utils import (compare_3ddose_files, doses_approx_equal,
15 extract_all_doses, read3ddose)
16
17EGSINP = "tg43mode_zeroweight.egsinp"
18TIME_LIMIT_S_PER_MHZ = 2000/2993. # s / MHz
19NCOMPARE = 10
20
21def get_n_highest_dose_pairs(dose1, dose2, n=NCOMPARE):
22 return list(sorted(zip(dose1, dose2)))[-n:]
23
24def compare_results(egslst, inp_name):
25
26 gold_standard = read3ddose(os.path.join(os.path.dirname(os.path.abspath(__file__)), "gold_standard.3ddose"))
27 run_doses = read3ddose(inp_name+".phantom.3ddose")
28 # only look at voxels overlapped by zero activity source
29 dose_pairs = list(zip(gold_standard['doses'], run_doses['doses']))[7:12]
30 dose_diff = [abs(a-b)/a for a, b in dose_pairs]
31 doses_close = max(dose_diff) < 0.01
32
33 # make sure energy deposition and tlen doses roughly equal
34 run_doses_edep = read3ddose(inp_name+".phantom.edep.3ddose")
35 dose_pairs_edep = get_n_highest_dose_pairs(run_doses['doses'], run_doses_edep['doses'],n=5)
36 dose_diff_edep = [abs(a-b)/a for a, b in dose_pairs_edep]
37 doses_close_edep = max(dose_diff_edep) < 0.10
38
39 actual = {
40 'edep': run_doses_edep['doses'],
41 'tlen': run_doses['doses']
42 }
43
44 expected = {
45 'edep': run_doses['doses'],
46 'tlen': gold_standard['doses']
47 }
48 return doses_close and doses_close_edep, actual, expected
49
get_n_highest_dose_pairs(dose1, dose2, n=NCOMPARE)
Definition test.py:21