<commit_before>#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
Tiny tool to calculate the surface entrance dose of a certain x-ray measurement
Gives the same results as the 'Diagnostische Referenzwerte' Excel calculator on
the BAG-page, in the right side-bar of http://is.gd/E2qIPA.
The calculation is based on 'Merkblatt R-06-04' from BAG
"""

import numpy as np
import matplotlib.pylab as plt
from mpl_toolkits.mplot3d import Axes3D

plt.ion()

# Parameters

# The K-value is based on the machine. The BAG-calculator (see below) list 0.1
K = 0.1
FocusDistance = 1.4
# RSF as found by Arouna2000, cited by BAG2012. *This* RSF gives the same SED
# values as the XLS-calculator from BAG (http://is.gd/oTpniQ) which I copied to
# /afs/psi.ch/project/EssentialMed/PresentationsAndInfo/BAG/R-0 DRWCalc 5.0.xls
RSF = 1.35
# RSF as found in BAG2012. "Der über verschiedene Anlagen gemittelte
# Korrekturfaktor betrug 1.15"
#RSF = 1.15

Range_kV = range(30, 130)
Range_mAs = range(0, 60)

# Using *bloody* list comprehension in Python as specified by
# http://stackoverflow.com/a/2397150/323100 Why do I always forget this?
Dose = np.asarray([[K *
                  (float(kV) / 100) ** 2
                  * mAs *
                  (1 / FocusDistance) ** 2
                  * RSF
                  for kV in Range_kV] for mAs in Range_mAs])

# Give out fixed data
print '---'
print 'The characteristic constant of the x-ray setup is', K, 'mGy/mA, the'
print 'focus-surface-distance is', FocusDistance, 'm, the "Rückstreufaktor"'
print 'RSF was set to', str(RSF) + '.'
print
print 'If we calculate the surface entrance dose'
print 'SED = K*(U/100)^2*Q*(1/FOD)^2*RSF'

# Give out plot and varying data
# Surfaceplot based on http://stackoverflow.com/a/3812324/323100, since we only
# have matplotlib 0.99.1.1 installed here at PSI. Check the installed version
# with "python -c 'import matplotlib; print matplotlib.__version__'" in your
# terminal.
fig = plt.figure()
ax = Axes3D(fig)
X, Y = np.meshgrid(Range_kV, Range_mAs)
    ax.plot_surface(X, Y, Dose, cmap='jet', cstride=1, rstride=1, linewidth=0)

showCase = 1
if showCase == 1:
    # Multiple Values, including Zhentians Breast scan
    showkV = (46., 70., 120., 125., 40.)
    showmAs = (50., 2, 50., 2., 25.)
    what = ('Wrist 1', 'Wrist 2', 'LWS ap', 'Thorax', 'Zhentian')
elif showCase == 2:<commit_msg>Fix whitespace errors<commit_after># -*- coding: utf-8 -*-

'''
Tiny tool to calculate the surface entrance dose of a certain x-ray measurement
Gives the same results as the 'Diagnostische Referenzwerte' Excel calculator on
the BAG-page, in the right side-bar of http://is.gd/E2qIPA.
The calculation is based on 'Merkblatt R-06-04' from BAG
'''

import numpy as np
import matplotlib.pylab as plt
from mpl_toolkits.mplot3d import Axes3D

plt.ion()

# Parameters

# The K-value is based on the machine. The BAG-calculator (see below) list 0.1
K = 0.1
FocusDistance = 1.4
# RSF as found by Arouna2000, cited by BAG2012. *This* RSF gives the same SED
# values as the XLS-calculator from BAG (http://is.gd/oTpniQ) which I copied to
# /afs/psi.ch/project/EssentialMed/PresentationsAndInfo/BAG/R-0 DRWCalc 5.0.xls
RSF = 1.35
# RSF as found in BAG2012. "Der über verschiedene Anlagen gemittelte
# Korrekturfaktor betrug 1.15"
#RSF = 1.15

Range_kV = range(30, 130)
Range_mAs = range(0, 60)

# Using *bloody* list comprehension in Python as specified by
# http://stackoverflow.com/a/2397150/323100 Why do I always forget this?
Dose = np.asarray([[K *
                  (float(kV) / 100) ** 2
                  * mAs *
                  (1 / FocusDistance) ** 2
                  * RSF
                  for kV in Range_kV] for mAs in Range_mAs])

# Give out fixed data
print '---'
print 'The characteristic constant of the x-ray setup is', K, 'mGy/mA, the'
print 'focus-surface-distance is', FocusDistance, 'm, the "Rückstreufaktor"'
print 'RSF was set to', str(RSF) + '.'
print
print 'If we calculate the surface entrance dose'
print 'SED = K*(U/100)^2*Q*(1/FOD)^2*RSF'

# Give out plot and varying data
# Surfaceplot based on http://stackoverflow.com/a/3812324/323100, since we only
# have matplotlib 0.99.1.1 installed here at PSI. Check the installed version
# with "python -c 'import matplotlib; print matplotlib.__version__'" in your
# terminal.
fig = plt.figure()
ax = Axes3D(fig)
X, Y = np.meshgrid(Range_kV, Range_mAs)
ax.plot_surface(X, Y, Dose, cmap='jet', cstride=1, rstride=1, linewidth=0)

showCase = 1
if showCase == 1:
    # Multiple Values, including Zhentians Breast scan
    showkV = (46., 70., 120., 125., 40.)
    showmAs = (50., 2, 50., 2., 25.)
    what = ('Wrist 1', 'Wrist 2', 'LWS ap', 'Thorax', 'Zhentian')
elif showCase == 2:
{'fraction_non_alphanumeric': 0.1227137388345385, 'fraction_numerical': 0.05019140791152701, 'mean_word_length': 3.326586936522539, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4854640', 'n_tokens_mistral': 1860, 'n_tokens_neox': 1690, 'n_words': 573}