Created
December 6, 2019 00:00
-
-
Save jrkerns/12ab58f5fc328a6f2cb8fdcbfabb95c3 to your computer and use it in GitHub Desktop.
loading a .PRS Sun Nuclear file and analyzing the symmetry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from pylinac.core.profile import SingleProfile | |
from pylinac.flatsym import SYMMETRY_EQUATIONS | |
prs_file = '9E GA0.prs' | |
data_slice = slice(5, 259) # this cuts off the empty columns before and after in the data | |
detector_row = 106 | |
bias_row = 107 | |
calibration_row = 108 | |
data_row = 110 | |
with open(prs_file) as f: | |
raw_data = f.read().splitlines() | |
detectors = raw_data[detector_row].split('\t')[data_slice] | |
bias = raw_data[bias_row].split('\t')[data_slice] | |
calibration = raw_data[calibration_row].split('\t')[data_slice] | |
data = raw_data[data_row].split('\t')[data_slice] | |
timetic = float(raw_data[bias_row].split('\t')[2]) | |
df = pd.DataFrame({'Bias': bias, 'Calibration': calibration, 'Data': data}) | |
df = df.astype(float) # convert from string to floats | |
df['Detector'] = detectors # these are strings, so add this column after float conversion | |
df["Integrated Dose"] = df['Calibration'] * (df['Data'] - df['Bias'] * timetic) | |
x_values = df['Integrated Dose'].iloc[:64] # the first 65 values are the X detectors | |
x_prof = SingleProfile(x_values.values) # convert to a pylinac Profile | |
x_prof_interp_values = x_prof._values_interp # I'm cheating here using a private attr, | |
# but this is the interpolated values using the default interpolation of 'linear' and factor of 100 | |
x_prof_interp = SingleProfile(x_prof_interp_values) # this another shortcut. | |
# I made a new profile using the interpolated values of the original profile. | |
# this is an extra annoying step, but convenient nonetheless. | |
x_sym, _, _, _ = SYMMETRY_EQUATIONS['varian'](x_prof_interp) # calc the symmetry | |
print(f'{x_sym:2.2f}%') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment