In [45]:
import numpy as np
indx = 8
In [1]:
from pylinac.log_analyzer import MachineLogs as mlgs
my_logs = mlgs()
my_logs.load_dir_UI()
In [2]:
my_logs.log_types()
In [5]:
print( my_logs[indx])
In [40]:
my_logs[indx].axis_data.gantry.actual[indx]
Out[40]:
In [38]:
my_logs[indx].fluence.actual.calc_map(resolution=2)
Out[38]:
In [9]:
%matplotlib inline
In [41]:
my_logs[indx].fluence.actual.plot_map()
In [43]:
my_flip = my_logs[indx].fluence.actual.calc_map(resolution=2)
type(my_flip)
Out[43]:
In [46]:
my_flip = np.flipud(my_flip)
In [47]:
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(6, 3.2))
ax = fig.add_subplot(111)
ax.set_title('FLipd')
plt.imshow(my_flip)
Out[47]:
In [48]:
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]
In [52]:
flu_x = np.linspace(-19.9, 19.9, 200)
In [53]:
flu_x
Out[53]:
In [51]:
my_flip.shape
Out[51]:
In [54]:
from scipy import interpolate as interpl
my_interp_flip = interpl.RectBivariateSpline(flu_y, flu_x, my_flip)
In [56]:
new_y = np.linspace(-9.4, 9.4, 95)
In [57]:
new_x = np.linspace(-12.4, 12.4, 125)
In [58]:
my_new_interp_flip = my_interp_flip(new_y, new_x)
In [59]:
fig = plt.figure(figsize=(6, 3.2))
ax1 = fig.add_subplot(111)
ax1.set_title('MyDynalogFlu')
plt.imshow(my_new_interp_flip)
Out[59]:
In [73]:
kernel = np.array([[0.5, 0.7, 1, 0.7, 0.5],
[0.5, 0.7, 1.5, 0.7, 0.5],
[0.8, 0.8, 3.0, 0.8, 0.8],
[0.5, 0.7, 1.5, 0.7, 0.5],
[0.5, 0.7, 1, 0.7, 0.5]])
In [74]:
from scipy import ndimage as ndi
blurry = ndi.convolve(my_new_interp_flip, kernel, mode='constant',cval=0.0)
In [75]:
plt.imshow(blurry)
Out[75]:
In [76]:
normaliser = 1.0/273.0
kernel2 = np.array([[1., 4., 7., 4., 1.],
[4., 16., 26., 16., 4.],
[7., 26., 41., 26., 7.],
[4., 16., 26., 16., 4.],
[1., 4., 7., 4., 1.]])
norm_kern2 = normaliser * kernel2
In [77]:
norm_kern2
Out[77]:
In [78]:
blurry2 = ndi.convolve(my_new_interp_flip, norm_kern2, mode='constant',cval=0.0)
In [79]:
plt.imshow(blurry2)
Out[79]:
In [81]:
import numpy as np
def gauss2D(shape=(3,3),sigma=0.5):
"""
2D gaussian mask - should give the same result as MATLAB's
fspecial('gaussian',[shape],[sigma])
"""
m,n = [(ss-1.)/2. for ss in shape]
y,x = np.ogrid[-m:m+1,-n:n+1]
h = np.exp( -(x*x + y*y) / (2.*sigma*sigma) )
h[ h < np.finfo(h.dtype).eps*h.max() ] = 0
sumh = h.sum()
if sumh != 0:
h /= sumh
return h
In [ ]:
In [86]:
gauss2D((5,5), 5)
Out[86]:
In [87]:
np.cumsum(gauss2D((5,5), 5))
Out[87]:
In [ ]: