示例#1
0
def decipher(ciphertext, keyword):

    # generate original and reordered alphabets.
    original, shuffled = reorder(keyword)

    # initialise a deciphertext.
    deciphertext = ''

    for char in ciphertext:
        if char in shuffled:
            deciphertext += original[shuffled.index(char)]
        else:
            deciphertext += char

    return deciphertext
示例#2
0
def cipher(message, keyword, groupify=False):

    # generate the orignal and re-ordered alphabets.
    original, shuffled = reorder(keyword)

    # initialise a ciphertext.
    ciphertext = ''

    for char in message:
        if char in original:
            anchor = original.index(char)
            ciphertext += shuffled[anchor]
        else:
            # copy it as it is in the ciphertext.
            ciphertext += char

    if not groupify:
        return ciphertext

    else:
        # omit punctuations and make groups of four.
        count = 0
        new_ciphertext = ''

        while ciphertext <> '':

            if count < 5:
                if ciphertext[0] in original:
                    new_ciphertext += ciphertext[0]
                    ciphertext = ciphertext[1::]
                    count += 1
                else:
                    ciphertext = ciphertext[1::]
            else:
                new_ciphertext += ' '
                count = 0

        return new_ciphertext
示例#3
0
def sort_readings(readings):
    almost_sorted = readings.sort("time")
    indices = reorder(almost_sorted.as_matrix(), 10, 9)
    return almost_sorted.iloc[indices]
示例#4
0
    def read(self):
        self.num_times = 1
        self.times = [0.0]

        filename = self.config['filename']
        # check if we are reading a ground or air conc
        if filename.find('Gconc') != -1:
            dim = 2
            cell_type = vtk.VTK_QUAD
        else:
            dim = 3
            cell_type = vtk.VTK_HEXAHEDRON

        print 'reading data...'
        data = np.genfromtxt(filename, delimiter=',')
        data = reorder.reorder(data, 0, dim)
        print 'done'

        num_pts = data.shape[0]

        var = vtk.vtkFloatArray()
        varname = os.path.basename(filename).split('_')[0]
        var.SetName(varname)
        var.SetNumberOfValues(num_pts)

        print 'creating points...'
        pts = vtk.vtkPoints()
        pts.SetNumberOfPoints(num_pts)
        if dim == 2:
            for i in xrange(0, num_pts):
                pts.SetPoint(i, data[i, 0], data[i, 1], 0.0)
                var.SetValue(i, data[i, 2])
        else:
            for i in xrange(0, num_pts):
                pts.SetPoint(i, data[i, 0], data[i, 1], data[i, 2])
                var.SetValue(i, data[i, 3])
        print 'done'

        print 'creating cells...'
        cell_array = vtk.vtkCellArray()
        coord_x, indices = np.unique(data[:, 0], return_index=True)
        indices_x = np.append(indices, num_pts)
        if dim == 2:
            for i in xrange(0, coord_x.shape[0] - 1):
                for j in xrange(0, indices_x[i + 1] - indices_x[i] - 1):
                    quad = vtk.vtkQuad()
                    quad.GetPointIds().SetId(0, indices_x[i] + j)
                    quad.GetPointIds().SetId(1, indices_x[i + 1] + j)
                    quad.GetPointIds().SetId(2, indices_x[i + 1] + j + 1)
                    quad.GetPointIds().SetId(3, indices_x[i] + j + 1)
                    cell_array.InsertNextCell(quad)

        else:
            for i in xrange(0, coord_x.shape[0] - 1):
                plane_b = data[indices_x[i]:indices_x[i + 1]]
                coord_y_b, indices_y_b = np.unique(plane_b[:, 1],
                                                   return_index=True)
                indices_y_b = np.append(indices_y_b, plane_b.shape[0])

                plane_f = data[indices_x[i + 1]:indices_x[i + 2]]
                coord_y_f, indices_y_f = np.unique(plane_f[:, 1],
                                                   return_index=True)
                indices_y_f = np.append(indices_y_f, plane_f.shape[0])

                for j in xrange(0, coord_y_b.shape[0] - 1):
                    for k in xrange(
                            0, indices_y_b[j + 2] - indices_y_b[j + 1] - 1):
                        hexa = vtk.vtkHexahedron()
                        p = []
                        p.append(indices_x[i] + indices_y_b[j] + k)
                        p.append(indices_x[i] + indices_y_b[j + 1] + k)
                        p.append(indices_x[i] + indices_y_b[j + 1] + k + 1)
                        p.append(indices_x[i] + indices_y_b[j] + k + 1)
                        p.append(indices_x[i + 1] + indices_y_f[j] + k)
                        p.append(indices_x[i + 1] + indices_y_f[j + 1] + k)
                        p.append(indices_x[i + 1] + indices_y_f[j + 1] + k + 1)
                        p.append(indices_x[i + 1] + indices_y_f[j] + k + 1)
                        hexa = vtk.vtkHexahedron()
                        for l in range(0, 8):
                            hexa.GetPointIds().SetId(l, p[l])
                        cell_array.InsertNextCell(hexa)
        print 'done'

        self.grid.append(vtk.vtkUnstructuredGrid())
        self.grid[0].SetPoints(pts)
        self.grid[0].SetCells(cell_type, cell_array)
        self.grid[0].GetPointData().SetScalars(var)
示例#5
0
def reorder(cmdline):
    survey = model.survey.Survey.load(cmdline['project'])

    import reorder

    return reorder.reorder(survey)
示例#6
0
    def read(self):
        self.num_times = 1
        self.times = [0.0]

        filename = self.config['filename']
        # check if we are reading a ground or air conc
        if filename.find('Gconc') != -1:
            dim = 2
            cell_type = vtk.VTK_QUAD
        else:
            dim = 3
            cell_type = vtk.VTK_HEXAHEDRON

        print 'reading data...'
        data = np.genfromtxt(filename, delimiter=',')
        data = reorder.reorder(data, 0, dim)
        print 'done'

        num_pts = data.shape[0]

        var = vtk.vtkFloatArray()
        varname = os.path.basename(filename).split('_')[0]
        var.SetName(varname)
        var.SetNumberOfValues(num_pts)

        print 'creating points...'
        pts = vtk.vtkPoints()
        pts.SetNumberOfPoints(num_pts)
        if dim == 2:
            for i in xrange(0, num_pts):
                pts.SetPoint(i, data[i,0], data[i,1], 0.0)
                var.SetValue(i, data[i,2])
        else:
            for i in xrange(0, num_pts):
                pts.SetPoint(i, data[i,0], data[i,1], data[i,2])
                var.SetValue(i, data[i,3])
        print 'done'

        print 'creating cells...'
        cell_array = vtk.vtkCellArray()
        coord_x, indices = np.unique(data[:,0], return_index=True)
        indices_x = np.append(indices, num_pts)
        if dim == 2:
            for i in xrange(0, coord_x.shape[0]-1):
                for j in xrange(0, indices_x[i+1]-indices_x[i]-1):
                    quad = vtk.vtkQuad()
                    quad.GetPointIds().SetId(0, indices_x[i]  +j)
                    quad.GetPointIds().SetId(1, indices_x[i+1]+j)
                    quad.GetPointIds().SetId(2, indices_x[i+1]+j+1)
                    quad.GetPointIds().SetId(3, indices_x[i]  +j+1)
                    cell_array.InsertNextCell(quad)

        else:
            for i in xrange(0, coord_x.shape[0]-1):
                plane_b = data[indices_x[i]:indices_x[i+1]]
                coord_y_b, indices_y_b = np.unique(plane_b[:,1], return_index=True)
                indices_y_b = np.append(indices_y_b, plane_b.shape[0])

                plane_f = data[indices_x[i+1]:indices_x[i+2]]
                coord_y_f, indices_y_f = np.unique(plane_f[:,1], return_index=True)
                indices_y_f = np.append(indices_y_f, plane_f.shape[0])

                for j in xrange(0, coord_y_b.shape[0]-1):
                    for k in xrange(0, indices_y_b[j+2]-indices_y_b[j+1]-1):
                        hexa = vtk.vtkHexahedron()
                        p = []
                        p.append(indices_x[i]  +indices_y_b[j]  +k  )
                        p.append(indices_x[i]  +indices_y_b[j+1]+k  )
                        p.append(indices_x[i]  +indices_y_b[j+1]+k+1)
                        p.append(indices_x[i]  +indices_y_b[j]  +k+1)
                        p.append(indices_x[i+1]+indices_y_f[j]  +k  )
                        p.append(indices_x[i+1]+indices_y_f[j+1]+k  )
                        p.append(indices_x[i+1]+indices_y_f[j+1]+k+1)
                        p.append(indices_x[i+1]+indices_y_f[j]  +k+1)
                        hexa = vtk.vtkHexahedron()
                        for l in range(0,8):
                            hexa.GetPointIds().SetId(l, p[l])
                        cell_array.InsertNextCell(hexa)
        print 'done'

        self.grid.append(vtk.vtkUnstructuredGrid())
        self.grid[0].SetPoints(pts)
        self.grid[0].SetCells(cell_type, cell_array)
        self.grid[0].GetPointData().SetScalars(var)
示例#7
0
def reorder(cmdline):
    survey = model.survey.Survey.load(cmdline['project'])

    import reorder

    return reorder.reorder(survey)