import numpy as np
import zlib
import matplotlib.pyplot as plt

class DataVis(object):
    

    def __init__(self, cells=500, planes=500, views=3):
        ''' Constructor.

        Args:
            cells: image cells.
            planes: image planes.
            views: number of views.
        '''
        self.cells = cells
        self.planes = planes
        self.views = views

    def vis(self, sample = 0, plane = 0):
        with open('dataset/event' + str(sample) + '.gz', 'rb') as image_file:
            pixels = np.fromstring(zlib.decompress(image_file.read()), dtype=np.uint8, sep='')
            pixels = pixels.reshape(self.views, self.planes, self.cells)

            pixels = np.transpose(pixels, (0, 2, 1))
            pixels = np.ma.array(pixels)
            pixels_ma = np.ma.masked_where(pixels<=0, pixels)
            plt.imshow(pixels_ma[plane]
            , cmap="jet"
            , interpolation="none"
            , origin='lower'
            , aspect=1.)
            plt.clim(0,255)
            plt.colorbar()
            plt.show()

if __name__ == "__main__":
    dv = DataVis()
    for sample in range(1,20):
        for plane in range(3):
            dv.vis(sample, plane)