equinor / segyio

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

Exporting inline and xline as TIFF images from SEG-Y #431

Closed KirillSimonov closed 4 years ago

KirillSimonov commented 4 years ago

Dear authors,

Thank you for your excellent library! I am now trying to do project and want to export xlines and inlines from SEG-Y as TIFF images (or other image format). I tried to do in Petrel, but could not do it (the only export I see is export again in SEG-Y). I want to do it using "segyio", but at now I continously fail.

Could you please tell if I am correct in my pursue (may be this is inadequate operation) and if yes, please tell if this can be realized using segyio and how? Thank you.


Sincerely, Kirill

jokva commented 4 years ago

Hi Kirill,

segyio does not have any native export functionality, which is a conscious decision as it's out-of-scope for the project. As such, there's no "one-button" export.

However, segyio is perfectly capable of delivering data to such an export. I'm not 100% sure if I got it right, but you want to plot and export an inline, right? Well, if so, you can pretty much read directly from segyio into matplotlib and have it work - something like matplotlib.pyplot.imshow(f.iline[il].T, cmap = 'seismic')

KirillSimonov commented 4 years ago

Dear @jokva , I want to extract data from SEG-Y in form of 2D images like one I attached ( to the left). I will try your method and report a result. 2019-12-24_17h32_06

jokva commented 4 years ago

https://notebooks.gesis.org/binder/jupyter/user/equinor-segyio-notebooks-j6ktebz6/notebooks/notebooks/basic/02_segy_quicklook.ipynb

You can refer to this example, and the others in https://mybinder.org/v2/gh/equinor/segyio-notebooks/master

KirillSimonov commented 4 years ago

Dear @jokva , Thank you! 1) I managed to do it but there is issue concerning the way I get image using matplotlib.pyplot.imshow option as xline/iline gets rotated (without a priori knowing it, one will not understand it). I will attach image for clear picture. Is there a way to get image in correct configuration/ 2020-01-09_17h33_41 2) Could please explain or follow me to certaind docs on difference in opening segyfile in different manner:

jokva commented 4 years ago

I will attach image for clear picture. Is there a way to get image in correct configuration/

Your seismic uses axes differently than your image, which is completely expected. Transpose your data, i.e. plt.imshow(seismic[:, 100, :].T, cmap = 'gray', resample = None)

with segyio.open(filename) as f:

This is just opening the file (in a context manager), and builds an index of the in/crosslines. The file is read-only.

seismic = segyio.tools.cube(filename)

This is just a short-hand for reading all the data into a numpy array, assuming it's a proper 3D cube.

segyfile = segyio.open(filename, 'r+')

This should be with segyio.open(filename, 'r+') as f, and is the same as the regular open, except now the file is in writable mode.

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

KirillSimonov commented 4 years ago

Thank you very much!

aazadkhorasa commented 2 years ago

I want to import data with SEGY format and extract, tiff(.tif)

da-wad commented 2 years ago

There are plenty of ways to do this, but here's one which should work fine:

import segyio
from PIL import Image
import numpy as np
from matplotlib import cm

with segyio.open('my_file.sgy') as segyfile:
    slice_segy = segyfile.iline[segyfile.ilines[len(segyfile.ilines)//2]]
    abs_max = np.max(np.abs(slice_segy))
    scale = 1.0/(2.0*abs_max)

im = Image.fromarray(np.uint8(cm.seismic((slice_segy.T.clip(-abs_max, abs_max) + abs_max) * scale)*255))
im.save('out_inline-sgy.tif')