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()


9 logs found. 
0 logs skipped. 
Log loaded:
1 of 9
2 of 9
3 of 9
4 of 9
5 of 9
6 of 9
7 of 9
8 of 9
9 of 9

In [2]:
my_logs.log_types()


Number of Trajectory logs: 0
Number of Dynalogs: 9

In [5]:
print( my_logs[indx])


<pylinac.log_analyzer.MachineLog object at 0x7fab22b934e0>

In [40]:
my_logs[indx].axis_data.gantry.actual[indx]


Out[40]:
20.0

In [38]:
my_logs[indx].fluence.actual.calc_map(resolution=2)


Out[38]:
array([[ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],
       ..., 
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.]])

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]:
numpy.ndarray

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]:
<matplotlib.image.AxesImage at 0x7fab230a1dd8>

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]:
array([-19.9, -19.7, -19.5, -19.3, -19.1, -18.9, -18.7, -18.5, -18.3,
       -18.1, -17.9, -17.7, -17.5, -17.3, -17.1, -16.9, -16.7, -16.5,
       -16.3, -16.1, -15.9, -15.7, -15.5, -15.3, -15.1, -14.9, -14.7,
       -14.5, -14.3, -14.1, -13.9, -13.7, -13.5, -13.3, -13.1, -12.9,
       -12.7, -12.5, -12.3, -12.1, -11.9, -11.7, -11.5, -11.3, -11.1,
       -10.9, -10.7, -10.5, -10.3, -10.1,  -9.9,  -9.7,  -9.5,  -9.3,
        -9.1,  -8.9,  -8.7,  -8.5,  -8.3,  -8.1,  -7.9,  -7.7,  -7.5,
        -7.3,  -7.1,  -6.9,  -6.7,  -6.5,  -6.3,  -6.1,  -5.9,  -5.7,
        -5.5,  -5.3,  -5.1,  -4.9,  -4.7,  -4.5,  -4.3,  -4.1,  -3.9,
        -3.7,  -3.5,  -3.3,  -3.1,  -2.9,  -2.7,  -2.5,  -2.3,  -2.1,
        -1.9,  -1.7,  -1.5,  -1.3,  -1.1,  -0.9,  -0.7,  -0.5,  -0.3,
        -0.1,   0.1,   0.3,   0.5,   0.7,   0.9,   1.1,   1.3,   1.5,
         1.7,   1.9,   2.1,   2.3,   2.5,   2.7,   2.9,   3.1,   3.3,
         3.5,   3.7,   3.9,   4.1,   4.3,   4.5,   4.7,   4.9,   5.1,
         5.3,   5.5,   5.7,   5.9,   6.1,   6.3,   6.5,   6.7,   6.9,
         7.1,   7.3,   7.5,   7.7,   7.9,   8.1,   8.3,   8.5,   8.7,
         8.9,   9.1,   9.3,   9.5,   9.7,   9.9,  10.1,  10.3,  10.5,
        10.7,  10.9,  11.1,  11.3,  11.5,  11.7,  11.9,  12.1,  12.3,
        12.5,  12.7,  12.9,  13.1,  13.3,  13.5,  13.7,  13.9,  14.1,
        14.3,  14.5,  14.7,  14.9,  15.1,  15.3,  15.5,  15.7,  15.9,
        16.1,  16.3,  16.5,  16.7,  16.9,  17.1,  17.3,  17.5,  17.7,
        17.9,  18.1,  18.3,  18.5,  18.7,  18.9,  19.1,  19.3,  19.5,
        19.7,  19.9])

In [51]:
my_flip.shape


Out[51]:
(60, 200)

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]:
<matplotlib.image.AxesImage at 0x7fab2358db70>

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]:
<matplotlib.image.AxesImage at 0x7fab2345b5c0>

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]:
array([[ 0.003663  ,  0.01465201,  0.02564103,  0.01465201,  0.003663  ],
       [ 0.01465201,  0.05860806,  0.0952381 ,  0.05860806,  0.01465201],
       [ 0.02564103,  0.0952381 ,  0.15018315,  0.0952381 ,  0.02564103],
       [ 0.01465201,  0.05860806,  0.0952381 ,  0.05860806,  0.01465201],
       [ 0.003663  ,  0.01465201,  0.02564103,  0.01465201,  0.003663  ]])

In [78]:
blurry2 = ndi.convolve(my_new_interp_flip, norm_kern2, mode='constant',cval=0.0)

In [79]:
plt.imshow(blurry2)


Out[79]:
<matplotlib.image.AxesImage at 0x7fab235ff160>

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]:
array([[ 0.03688345,  0.03916419,  0.03995536,  0.03916419,  0.03688345],
       [ 0.03916419,  0.04158597,  0.04242606,  0.04158597,  0.03916419],
       [ 0.03995536,  0.04242606,  0.04328312,  0.04242606,  0.03995536],
       [ 0.03916419,  0.04158597,  0.04242606,  0.04158597,  0.03916419],
       [ 0.03688345,  0.03916419,  0.03995536,  0.03916419,  0.03688345]])

In [87]:
np.cumsum(gauss2D((5,5), 5))


Out[87]:
array([ 0.03688345,  0.07604764,  0.116003  ,  0.15516719,  0.19205063,
        0.23121482,  0.27280079,  0.31522686,  0.35681282,  0.39597702,
        0.43593238,  0.47835844,  0.52164156,  0.56406762,  0.60402298,
        0.64318718,  0.68477314,  0.72719921,  0.76878518,  0.80794937,
        0.84483281,  0.883997  ,  0.92395236,  0.96311655,  1.        ])

In [ ]: