Beispiel #1
0
            S = G
        else:
            beta = gn / gnp
            s = g + s * beta
            S = G + S * beta
        gnp = gn
        alpha = -gn / S.dot2()
        p = p + s * alpha
        R = R + S * alpha
    x = prec(adj=0)[p]
    return x


if __name__ == "__main__":
    # test matrix and data
    matrix = m8r.File([[1, 1, 1, 0], [1, 2, 0, 0], [1, 3, 1, 0], [1, 4, 0, 1],
                       [1, 5, 1, 1]])
    y = m8r.File([3, 3, 5, 7, 9])
    x0 = m8r.File([0, 0, 0, 0])
    # matrix multiplication operator
    matmult = m8r.matmult(mat=matrix)

    # Using sfconjgrad
    x = m8r.conjgrad(mod=x0, niter=6)[y, matmult]
    y1 = matmult[x]
    print x[:]
    print y1[:]

    # Using function above
    causint = m8r.causint

    matmult = m8r.matmult(mat=matrix)
Beispiel #2
0
def seisresult():
    form = InputForm(request.form)
    script = None
    div = None
    if request.method == 'POST' and form.validate() == False:
        NumSamp = np.load('static/QC.npz')['arr_2']
        InlineKeyNumber = np.load('static/QC.npz')['arr_0']
        XlineKeyNumber = np.load('static/QC.npz')['arr_1']
        upload_file = request.files['file']
        filename = secure_filename(upload_file.filename)
        upload_file.save(os.path.join(UPLOAD_FOLDER, filename))
        image_height = 156
        image_width = 156
        image_depth = 100
        num_channels = 1
        images = []
        # Reading the seismic using Pickle
        #with open(os.path.join(UPLOAD_FOLDER, filename), 'rb') as f:
        #test = pickle.load(f, encoding='bytes')
        #test=np.array(test)
        try:
            seis = segyio.open(os.path.join(UPLOAD_FOLDER, filename),
                               iline=int(InlineKeyNumber),
                               xline=int(XlineKeyNumber))
            seismic = segyio.cube(seis)
        except:
            seismic = np.load(os.path.join(UPLOAD_FOLDER, filename))
        #np.savez_compressed('static/seishape.npz',seismic.shape[0],seismic.shape[1],seismic.shape[2])
        seismic.tofile('static/seismic.asc', sep=" ")
        os.system(
            'echo in=static/seismic.asc n1=%d n2=%d n3=%d data_format=ascii_float | sfdd form=native | sfpatch w=100,156,156>static/seismicaf.rsf'
            % (seismic.shape[2], seismic.shape[1], seismic.shape[0]))
        e = m8r.File('static/seismicaf.rsf')
        c = e[:]

        test = c.reshape(-1, 156, 156, 100)
        #print('Size of seismic volume is: %s' % str(test.shape))

        m = -6.40475426972431e-05
        s = 0.006666915856214509
        test = (test - m) / s

        graph = app.graph
        ## NOW the complete graph with values has been restored
        y_pred = tf.nn.softmax(graph.get_tensor_by_name("Classifier/logits:0"))
        ## Let's feed the images to the input placeholders
        #using the model for prediction
        x_tensor = graph.get_tensor_by_name("Input/Placeholder:0")
        #keep_prob is not always necessary it depends on your model
        keep_prob = graph.get_tensor_by_name("Input/Placeholder_2:0")
        is_training = graph.get_tensor_by_name("Input/Placeholder_3:0")
        config = tf.compat.v1.ConfigProto()
        config.gpu_options.per_process_gpu_memory_fraction = 0.9

        sess = tf.compat.v1.Session(graph=graph, config=config)
        ### Creating the feed_dict that is required to be fed to calculate y_pred
        feed_dict_testing = {x_tensor: test, keep_prob: 0.7, is_training: True}

        prob_iter_tot = []
        pred_iter_tot = []
        prob_variance_tot = []
        for i in range(NumSamp):
            result = sess.run(y_pred, feed_dict=feed_dict_testing)
            prob_iter_tot.append(result)
            #pred_iter_tot.append(np.reshape(np.argmax(result,axis = -1),[result.shape[0],-1]))

        #pred_iter_tot = np.array(pred_iter_tot)
        #pred_iter_tot = np.reshape(pred_iter_tot,(NumSamp,result.shape[0],-1))
        #pred_iter_tot = np.transpose(pred_iter_tot,(1,0,2))
        prob_iter_tot = np.array(prob_iter_tot)
        prob_iter_tot = np.reshape(prob_iter_tot,
                                   (NumSamp, test.shape[0], 156, 156, 100, 2))
        #prob_iter_tot_transp = np.transpose(prob_iter_tot,(1,0,2,3,4,5))

        #for k in range(test.shape[0]):
        #prob_variance,pred = MAX_VOTE(pred_iter_tot[k,:,:], prob_iter_tot_transp[k,:,:,:,:,:],2)
        #prob_variance_tot.append(prob_variance)

        prob = np.nanmean(prob_iter_tot, axis=0)
        var = np.nanvar(prob_iter_tot, axis=0)
        #prob_variance_tot = np.array(prob_variance_tot)
        #prob_variance_tot = np.reshape(prob_variance_tot,(test.shape[0],156,156,100,2))

        test = np.reshape(test,
                          (c.shape[0], c.shape[1], c.shape[2], 156, 156, 100))
        result1 = np.reshape(
            prob[:, :, :, :,
                 1], (c.shape[0], c.shape[1], c.shape[2], 156, 156, 100))
        var1 = np.reshape(var[:, :, :, :, 1],
                          (c.shape[0], c.shape[1], c.shape[2], 156, 156, 100))
        #var2 = np.reshape(prob_variance_tot[:,:,:,:,1],(c.shape[0],c.shape[2],156,156,100))
        var1.tofile('static/var1.asc', sep=" ")
        #var2.tofile('static/var2.asc', sep=" ")
        result1.tofile('static/result1.asc', sep=" ")
        test.tofile('static/test.asc', sep=" ")

        os.system(
            'echo in=static/test.asc n1=100 n2=156 n3=156 n4=%d n5=%d n6=%d data_format=ascii_float | sfdd form=native | sfpatch inv=y weight=y n0=%d,%d,%d>static/test.rsf'
            % (c.shape[2], c.shape[1], c.shape[0], seismic.shape[2],
               seismic.shape[1], seismic.shape[0]))
        f = m8r.File('static/test.rsf')
        a = f[:]
        a = np.reshape(a,
                       (seismic.shape[0], seismic.shape[1], seismic.shape[2]))
        os.system(
            'echo in=static/result1.asc n1=100 n2=156 n3=156 n4=%d n5=%d n6=%d data_format=ascii_float | sfdd form=native | sfpatch inv=y weight=y n0=%d,%d,%d>static/result1.rsf'
            % (c.shape[2], c.shape[1], c.shape[0], seismic.shape[2],
               seismic.shape[1], seismic.shape[0]))
        g = m8r.File('static/result1.rsf')
        b = g[:]
        b = np.reshape(b,
                       (seismic.shape[0], seismic.shape[1], seismic.shape[2]))
        os.system(
            'echo in=static/var1.asc n1=100 n2=156 n3=156 n4=%d n5=%d n6=%d data_format=ascii_float | sfdd form=native | sfpatch inv=y weight=y n0=%d,%d,%d>static/var1.rsf'
            % (c.shape[2], c.shape[1], c.shape[0], seismic.shape[2],
               seismic.shape[1], seismic.shape[0]))
        h = m8r.File('static/var1.rsf')
        k = h[:]
        k = np.reshape(k,
                       (seismic.shape[0], seismic.shape[1], seismic.shape[2]))
        #os.system('echo in=static/var2.asc n1=100 n2=156 n3=156 n4=%d n5=%d n6=%d data_format=ascii_float | sfdd form=native | sfpatch inv=y weight=y n0=%d,%d,%d>static/var2.rsf' % (c.shape[2],c.shape[1],c.shape[0],seismic.shape[2],seismic.shape[1],seismic.shape[0]))
        #l = m8r.File('static/var2.rsf')
        #l1 = l[:]
        #l1 = np.reshape(l1,(seismic.shape[0],seismic.shape[1],seismic.shape[2]))

        np.savez_compressed('static/result.npz', b)
        np.savez_compressed('static/test.npz', seismic)
        np.savez_compressed('static/var.npz', k)
        #np.savez_compressed('static/var2.npz',l1)
        #form = InputForm(request.form)
        return render_template("channel_index6.html",
                               form=form,
                               script=script,
                               div=div)
    if request.method == "POST" and form.validate():
        # Determine the selected slice
        current_slice = form.Position.data
        # Determine the selected slice number
        current_slice_number = form.Number.data

        result = np.load('static/result.npz')['arr_0']
        test = np.load('static/test.npz')['arr_0']
        var = np.load('static/var.npz')['arr_0']
        #var2 = np.load('static/var2.npz')['arr_0']

        #rsfarray_1 = m8r.File(test)
        #rsfarray_2 = m8r.put(d1=0.004, o1=0).patch(inv=True, weight=True, n0=[100,312,312])[rsfarray_1]
        #test = rsfarray_2[:]

        #rsfarray_1 = m8r.File(result1)
        #rsfarray_2 = m8r.put(d1=0.004, o1=0).patch(inv=True, weight=True, n0=[100,312,312])[rsfarray_1]
        #result = rsfarray_2[:]

        #print(result.shape)
        #print(test.shape)
        # Create the plot
        plot = create_figure(result, var, test, current_slice,
                             current_slice_number)
        # Embed plot into HTML via Flask Render
        script, div = components(plot)
    return render_template("channel_index6.html",
                           form=form,
                           script=script,
                           div=div)
Beispiel #3
0
def save_numpy_array_as_rsf_file(numpy_array, target_file_name):
    out = m8r.File(numpy_array)
    out.sfin()
Beispiel #4
0
            s = g
            S = G
        else:
            beta = gn / gnp
            s = g + s * beta
            S = G + S * beta
        gnp = gn
        alpha = -gn / S.cdot2()
        x = x + s * alpha
        R = R + S * alpha
    return x


if __name__ == "__main__":
    # test matrix and data
    matrix = m8r.File([[1, 1, 1, 0], [1, 2, 0, 0], [1, 3, 1, 0], [1, 4, 0, 1],
                       [1, 5, 1, 1]])
    cmatrix = m8r.cmplx[matrix, matrix]
    cmatmult = m8r.cmatmult(mat=cmatrix)
    yr = m8r.File([3, 2, 5, 6, 9])
    yi = m8r.File([3, 4, 5, 8, 9])
    y = m8r.cmplx[yr, yi]
    x0 = m8r.File([0, 0, 0, 0])
    x1 = m8r.cmplx[x0, x0]

    # Using sfcconjgrad
    x = m8r.cconjgrad(mod=x1, niter=6)[y, cmatmult]
    y1 = cmatmult[x]
    print x[:]
    print y1[:]

    # Using function above