In [1]:
from scipy import interpolate as interpl
import numpy as np
import os
from pylinac import log_analyzer as lga
class Dyn_to_Dose:
def __init__(self,my_dir):
"""class to import a folder full of dynalog files for a treatment"""
self.my_logs = lga.MachineLogs();
self.flip_fluences = list()
self.interp_fluences = list()
#TODO more rigorous checking of my_dir
if not os.path.exists(my_dir):
self.my_logs.load_dir_UI()
else:
self.my_logs.load_dir(my_dir)
def do_calcs(self, res_mm=1.0):
if len(self.my_logs) == 0:
print("No valid log files loaded ...")
return
for log in self.my_logs:
log.fluence.actual.calc_map(resolution=res_mm)
def do_flip(self):
for log in self.my_logs:
tmp = log.fluence.actual.calc_map(resolution=1.0)
self.flip_fluences.append(np.flipud(tmp))
def make_interp(self,y_dim, x_dim):
"""y_dim must be 1D array containing co-ords in cms
for fluence and x_dim 1D array likewise. x is parallel to leaf motion
"""
flu_y = [-19.5, -18.5, -17.5, -16.5, -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.75,
-9.25, -8.75, -8.25, -7.75, -7.25, -6.75, -6.25, -5.75, -5.25, -4.75, -4.25,
-3.75, -3.25, -2.75, -2.25, -1.75, -1.25, -0.75, -0.25, 0.25, 0.75, 1.25,
1.75, 2.25, 2.75, 3.25, 3.75, 4.25, 4.75, 5.25, 5.75, 6.25, 6.75, 7.25, 7.75,
8.25, 8.75, 9.25, 9.75, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5, 16.5, 17.5, 18.5,
19.5]
flu_x = np.linspace(-19.95, 19.95, 400) #TODO get rid of hardcoding dimensions of 1mm res
for flu in self.flip_fluences:
#first create interpolating object tmp
tmp = interpl.RectBivariateSpline(flu_y, flu_x, flu)
# now create new interpolated fluences and store
self.interp_fluences.append(tmp(y_dim, x_dim))
In [2]:
my_dyn2dose = Dyn_to_Dose('/home/mpre/tmp_dynalogs_la4/OBRIEN_Michael')
In [3]:
my_dyn2dose.do_calcs(1.0)
In [4]:
my_dyn2dose.do_flip()
In [5]:
pin_x = np.linspace(-12.7, 12.7, 128)
pin_y = np.linspace(-9.1, 9.1, 92)
my_dyn2dose.make_interp(pin_y, pin_x)
In [55]:
import matplotlib.pyplot as plt
%matplotlib inline
fig = plt.figure(figsize=(6, 3.2))
ax1 = fig.add_subplot(111)
plt.imshow(my_dyn2dose.interp_fluences[2])
Out[55]:
In [56]:
import PinDoseMap
In [57]:
my_dose_map = PinDoseMap.PinDoseMap('/home/mpre/Documents/10')
In [58]:
my_dyn2dose.make_interp(my_dose_map.y_pos, my_dose_map.x_pos)
In [59]:
my_dose_map.do_plot()
In [60]:
%matplotlib inline
fig = plt.figure(figsize=(6, 3.2))
ax1 = fig.add_subplot(111)
plt.imshow(my_dyn2dose.interp_fluences[2])
Out[60]:
In [61]:
my_flu_sample = my_dyn2dose.interp_fluences[2][25,31]
In [62]:
my_flu_sample
Out[62]:
In [63]:
my_dose_sample = my_dose_map.itrp_dose_array[25,31]
my_dose_sample
Out[63]:
In [64]:
my_norm = 0.81899999999999973 / 0.66608057743943438
In [66]:
my_norm
Out[66]:
In [95]:
new_flu = my_norm * my_dyn2dose.interp_fluences[2]
In [96]:
my_dyn2dose.my_logs[2]
Out[96]:
In [97]:
def print_attributes(obj):
for attr in obj.__dict__:
print (attr, getattr(obj, attr))
print_attributes(my_dyn2dose.my_logs[2])
In [98]:
print_attributes(my_dyn2dose.my_logs[2].axis_data.jaws)
In [99]:
print( my_dyn2dose.my_logs[2].axis_data.jaws.y2.actual)
In [100]:
print_attributes(my_dyn2dose.my_logs[2].fluence.actual._jaws.x2)
In [101]:
print_attributes(my_dyn2dose.my_logs[2].fluence.actual._jaws.x1)
In [101]:
In [102]:
print_attributes(my_dyn2dose.my_logs[2].fluence.actual._jaws.y1)
In [103]:
rows = np.linspace(-2.5, 3.5, 61)
In [104]:
rows
Out[104]:
In [105]:
cols = np.linspace(-7., 1., 81)
In [106]:
cols
Out[106]:
In [111]:
my_dyn2dose.make_interp(cols, rows)
In [114]:
plt.imshow(my_dyn2dose.interp_fluences[2])
Out[114]:
In [115]:
my_tmp = interpl.RectBivariateSpline(my_dose_map.y_pos, my_dose_map.x_pos, my_dose_map.raw_dose_array)
In [116]:
my_pin_zoom = my_tmp(rows, cols)
In [117]:
plt.imshow(my_pin_zoom)
Out[117]:
In [118]:
from scipy import ndimage as ndi
In [119]:
blur3 = ndi.filters.gaussian_filter(my_dyn2dose.interp_fluences[2], 3.0, mode='reflect')
plt.imshow(blur3)
Out[119]:
In [120]:
my_diff1 = blur3 - my_pin_zoom
In [121]:
plt.imshow(my_diff1)
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: