equinor / segyio

Fast Python library for SEGY files.
Other
476 stars 214 forks source link

loading volume as a cube #466

Closed Ruaa93 closed 4 years ago

Ruaa93 commented 4 years ago

Hi, I'm trying to load my volume as a cube using (fault = segyio.tools.cube(filename)) and I'm getting the below error, please assist. Also I would like to read and view the time slices one by one to run some operations, how this can be done?

ValueError Traceback (most recent call last)

in ----> 1 fault = segyio.tools.cube(filename) ~\anaconda3\lib\site-packages\segyio\tools.py in cube(f) 228 229 if not isinstance(f, segyio.SegyFile): --> 230 with segyio.open(f) as fl: 231 return cube(fl) 232 ~\anaconda3\lib\site-packages\segyio\open.py in open(filename, mode, iline, xline, strict, ignore_geometry, endian) 185 return f 186 --> 187 return infer_geometry(f, metrics, iline, xline, strict) ~\anaconda3\lib\site-packages\segyio\open.py in infer_geometry(f, metrics, iline, xline, strict) 17 18 f.xfd.indices(metrics, ilines, xlines, offsets) ---> 19 f.interpret(ilines, xlines, offsets, f._sorting) 20 21 except: ~\anaconda3\lib\site-packages\segyio\segy.py in interpret(self, ilines, xlines, offsets, sorting) 924 error = "Inlines inconsistent" 925 solution = "expect all inlines to be unique" --> 926 raise ValueError("{}, {}".format(error, solution)) 927 928 if np.unique(xlines).size != xlines.size: ValueError: Inlines inconsistent, expect all inlines to be unique
jokva commented 4 years ago

Hi,

It's pretty much right there in the message - for it to be a cube, all inlines must be unique and regular, which they're not for your file. Open the file with ignore_geometry = True to make segyio not try to understand the survey as a cube, and instead just a bunch of traces. From there you can inspect header words and figure out what's going on.

https://segyio.readthedocs.io/en/latest/segyio.html#segyio.open

Ruaa93 commented 4 years ago

hi @jokva

thank you for your reply. how about for the other question, if i have 10 time slices in my segy when i run the below it displays the first time slide. how can i plot the 10 time slices(loop)? fig = plt.figure(figsize=(10,6)) ax = fig.add_subplot(121) sim = ax.imshow(fault[:,:,0]); fig.colorbar(sim, ax=ax) ax.set_xticks([]) ax.set_yticks([]) ax.invert_xaxis()

jokva commented 4 years ago

How do you obtain the value fault? There's not enough information in your snippet. You're on to something though, you need to loop over the individual time slices, and run pretty much what you have there for each iteration of the loop.

Ruaa93 commented 4 years ago

the below shows what i run, i'm a bit confused in how to run thru each time slice, can you please explain?

import segyio import numpy as np import matplotlib.pyplot as plt from scipy import ndimage as ndi from shutil import copyfile from skimage import exposure

filename = './3D_Seismic_fault.sgy' fault = segyio.tools.cube(filename)

with segyio.open(filename2, "r") as f: print(f.samples) output: [1400. 1404. 1408. 1412. 1416. 1420. 1424. 1428. 1432. 1436. 1440. 1444.

                      1. 1492.
                      1. 1540.
                      1. 1588.
    1. 1600.]

len(f.depth_slice) output: 51

fig = plt.figure(figsize=(10,6)) ax = fig.add_subplot(121) sim = ax.imshow(fault[:,:,0]); fig.colorbar(sim, ax=ax) ax.set_xticks([]) ax.set_yticks([]) ax.invert_xaxis()

Ruaa93 commented 4 years ago

@jokva, what does the error means?? fig = plt.figure(figsize=(30,20)) for n in f.samples: ax = fig.add_subplot() sim[n] = ax.imshow(fault[:,:,n], cmap='gray_r'); fig.colorbar(sim[n], ax=ax) ax.set_xticks([]) ax.set_yticks([]) ax.invert_xaxis()


IndexError Traceback (most recent call last)

in 2 for n in f.samples: 3 ax = fig.add_subplot() ----> 4 sim[n] = ax.imshow(fault[:,:,n], cmap='gray_r'); 5 fig.colorbar(sim[n], ax=ax) 6 ax.set_xticks([]) IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
jokva commented 4 years ago

Your time slices are the last dimension, so you could grab them like this:

for t in range(len(fault.shape[-1])):
    ax.imshow(fault([:, :, t]))

Remember, the array you obtain with cube has lost all connection with the samples in the original files, and are now just zero-indexed.