def get_data(self): self.data_path = os.path.join(self.data_dir, "F3Seis_IL190_490_Amplitude.segy") # [iline, xline, time] self.label_path = os.path.join(self.data_dir, "F3Seis_IL190_490_Label.segy") self.data_cube = np.transpose(segyio.cube(self.data_path), (0,2,1)) # 只是hw互换 [c,h,w] self.label_cube = np.transpose(segyio.cube(self.label_path), (0,2,1)) self.labels = np.unique(self.label_cube) self.num_class = self.labels.max() self.label_inv = labelInverse(self.num_class) # 得到从PIL图片到标签[0,1,2,3,4]的映射
def marmousi_model(): """Function returns the marmousi acoustic impedance model""" den_file = segyio.open(pjoin('data', 'MODEL_DENSITY_1.25m.segy')) rho = segyio.cube(den_file).squeeze().T rho = rho[:, ::5] v_file = segyio.open('./data/MODEL_P-WAVE_VELOCITY_1.25m.segy') vp = segyio.cube(v_file).squeeze().T vp = vp[:, ::5] AI = vp * rho return AI
def test_from_array3D(tmpdir, create): fresh = str(tmpdir / 'fresh.sgy') with segyio.open("test-data/small.sgy") as f: cube = segyio.cube(f) dt, delrt = 4000, 0 create(fresh, cube, dt=dt, delrt=delrt) with segyio.open(fresh) as g: assert int(g.format) == SegySampleFormat.IBM_FLOAT_4_BYTE assert int(g.sorting) == TraceSortingFormat.INLINE_SORTING assert len(g.samples) == len(f.samples) assert g.tracecount == f.tracecount assert np.array_equal(f.trace, g.trace) assert list(g.ilines) == list(range(1, 6)) assert list(g.xlines) == list(range(1, 6)) assert list(f.offsets) == list(range(1, 2)) assert list( f.samples) == list((np.arange(len(f.samples)) * dt / 1000) + delrt) xlines = np.tile(np.arange(1, 6), 5) ilines = np.repeat(np.arange(1, 6), 5) offsets = np.ones(25) assert list(g.attributes(TraceField.INLINE_3D)) == list(ilines) assert list(g.attributes(TraceField.CROSSLINE_3D)) == list(xlines) assert list(g.attributes(TraceField.offset)) == list(offsets) assert list(g.attributes(TraceField.TraceNumber)) == list( range(25)) assert list(g.attributes(TraceField.CDP_TRACE)) == list(range(25)) assert list(g.attributes( TraceField.TRACE_SAMPLE_INTERVAL)) == list(4000 * np.ones(25)) assert list(g.attributes(TraceField.TRACE_SAMPLE_COUNT)) == list( 50 * np.ones(25)) assert g.bin[BinField.SortingCode] == 2
def marmousi_seismic(): """Function returns the seismic data that comes with the marmousi model""" seismic = segyio.cube(pjoin('data', 'Kirchhoff_PoSDM.segy')) seismic = np.transpose(seismic, axes=[1, 0, 2]) return seismic
import numpy as np import segyio from PIL import Image import os from matplotlib import pyplot as plt from torchvision.transforms import ToPILImage import torch from torchvision import transforms data_dir = "/home/cym/Datasets/StData-12/F3_block/" data_path = os.path.join(data_dir, "F3Seis_IL190_490_Amplitude.segy") label_path = os.path.join(data_dir, "F3Seis_IL190_490_Label.segy") data_cube = np.transpose(segyio.cube(data_path), (0, 2, 1)) label_cube = np.transpose(segyio.cube(label_path), (0, 2, 1)) # min4 = label_cube.min(axis=(1,2)) # print(min4) # label_cube = label_cube - np.expand_dims(min4, axis=(1,2)) # print(label_cube.min(axis=(1,2))) # range4 = label_cube.max(axis=(1,2)) - label_cube.min(axis=(1,2)) # range4 = np.expand_dims(range4, axis=(1,2)) # label_cube = (label_cube / range4 * 255).astype(np.uint8) # out_path_tmp = "outs/img_data_{num}_img.png" # for i in range(data_cube.shape[0]): # out_path = out_path_tmp.format(num=i) # img = Image.fromarray(data_cube[i], mode="L") # img.save(out_path) # out_path_tmp = "outs/img_label_{num}_img.png" # for i in range(label_cube.shape[0]):
""" Created on Thu Jan 24 17:31:42 2019 @author: Henry.Campos (Actually is a merge and modification of software created by other people!) This program starts by opening a .segy seismic file and converting it into a numpy array. Then it calculates single-frequency freqs volumes from that numpy array and saves them as 'Piedras{freqs}Hz.npy """ import segyio with segyio.open( '../Desktop/PythonClass/data/d_recon_cwt_Piedras_pcfilt2-48.segy' ) as s: c = segyio.cube(s) import matplotlib.pyplot as plt plt.imshow(c[100].T, cmap='Greys') import numpy as np #fL = 0.1 # Cutoff frequency as a fraction of the sampling rate (in (0, 0.5)). #fH = 0.2 # Cutoff frequency as a fraction of the sampling rate (in (0, 0.5)). #b = 0.08 # Transition band, as a fraction of the sampling rate (in (0, 0.5)). #N = int(np.ceil((4 / b))) #if not N % 2: N += 1 # Make sure that N is odd. #n = np.arange(N) # Compute a low-pass filter with cutoff frequency fH. #hlpf = np.sinc(2 * fH * (n - (N - 1) / 2.))
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)