xinwucwp / faultSeg

Using synthetic datasets to train an end-to-end CNN for 3D fault segmentation (We are working on an improved version!)
223 stars 136 forks source link

seismic data format #2

Closed xuewengeophysics closed 2 years ago

xuewengeophysics commented 5 years ago

Hi, Dr Wu. Thank you so much for this awesome research. Which program can be used to transform .segy to .dat that can be tested in faultSeg. I used some programs in dhale/ipf and dhale/idh/segy, but the transformed data could not be used. Thanks

xinwucwp commented 5 years ago

Hi Wen,

Thanks for your interests. The idh/segy should work. However, your need to output LITTLE_ENDIAN as follows: def writeImageL(name,image): fileName = seismicDir+name+".dat" aos = ArrayOutputStream(fileName,ByteOrder.LITTLE_ENDIAN) aos.writeFloats(image) aos.close() return image

Or you can use fwrite in MATLAB to output a binary file with LITTLE_ENDIAN

Good luck, Xinming

On Feb 13, 2019, at 5:42 PM, Xue Wen notifications@github.com wrote:

Hi, Dr Wu. Thank you so much for this awesome research. Which program can be used to transform .segy to .dat that can be tested in faultSeg. I used some programs in dhale/ipf and dhale/idh/segy, but the transformed data could not be used. Thanks

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/xinwucwp/faultSeg/issues/2, or mute the thread https://github.com/notifications/unsubscribe-auth/AGlyOxQclsEWmVsipZr1i8-RUWNTkrcPks5vNKLMgaJpZM4a6gZr.

cqq-103100 commented 5 years ago

Dear Wen: I have tried diffirent version of the Tensorflow to run this work ,but it does not match. Could you please tell me the version of python and tensorflow in your work? Thank you! Yours sincecely, Chen Qingqing

augustoicaro commented 5 years ago

Hello dear @cqq-103100,

My clone is working well with tensorflow-gpu==1.12.0 and python==3.5.6.

Best,

augustoicaro commented 5 years ago

To who want to convert your segy to .dat the easy way is using segyio python package as in following snippet:

import segyio
file_path ='../SFD-CNN-TL/gsb.sgy'

data = segyio.tools.cube(file_path)
fileName = "gsb.dat"
data.astype('int16').tofile(fileName)

Or just use data as .dat loaded file, as in follow snippet:

import segyio
file_path ='../SFD-CNN-TL/gsb.sgy'
data = segyio.tools.cube(file_path)
...
gx,m1,m2,m3 = data,data.shape[0],data.shape[1],data.shape[2]

Best,

augustoicaro commented 3 years ago

There is a way to solve the problem for those who had problems with segyio cube function and got a sorting error. The problem is caused due to wrong bytes identification for inline and crossline when opening your Segy data, so you need to provide the correct location manually. For this, you need to rewrite de cube function in your code like this:

def cube(f, inline=5, crossline=21):
    """Read a full cube from a file
    Takes an open segy file (created with segyio.open) or a file name.
    If the file is a prestack file, the cube returned has the dimensions
    ``(fast, slow, offset, sample)``. If it is post-stack (only the one
    offset), the dimensions are normalised to ``(fast, slow, sample)``
    Parameters
    ----------
    f : str or segyio.SegyFile
    inline: inline byte position
    crossline: crossline byte position
    Returns
    -------
    cube : numpy.ndarray
    """
    if not isinstance(f, segyio.SegyFile):
        with segyio.open(f, iline = inline, xline = crossline) as fl:
            return cube(fl)
    ilsort = f.sorting == segyio.TraceSortingFormat.INLINE_SORTING
    fast = f.ilines if ilsort else f.xlines
    slow = f.xlines if ilsort else f.ilines
    fast, slow, offs = len(fast), len(slow), len(f.offsets)
    smps = len(f.samples)
    dims = (fast, slow, smps) if offs == 1 else (fast, slow, offs, smps)
    return f.trace.raw[:].reshape(dims)

Just change the default value to your data's most common position, and when it is different, just send the correct positions as an argument.

The original function can be found on https://github.com/equinor/segyio/blob/master/python/segyio/tools.py#L209

humbertogeologia commented 3 years ago

Hi everyone, i managed to finish the workflow and i assume the result is the fp.dat file .... how to i convert that to sgy to read it in petrel for instance?

thanks in advance

augustoicaro commented 3 years ago

To who want to convert your segy to .dat the easy way is using segyio python package as in following snippet:

import segyio
file_path ='../SFD-CNN-TL/gsb.sgy'

data = segyio.tools.cube(file_path)
fileName = "gsb.dat"
data.astype('int16').tofile(fileName)

Or just use data as .dat loaded file, as in follow snippet:

import segyio
file_path ='../SFD-CNN-TL/gsb.sgy'
data = segyio.tools.cube(file_path)
...
gx,m1,m2,m3 = data,data.shape[0],data.shape[1],data.shape[2]

Best,

@humbertogeologia just use the snippet that I provided above. If have problems with cube function try the solution provided in https://github.com/xinwucwp/faultSeg/issues/2#issuecomment-780212016.

Best,

humbertogeologia commented 3 years ago

@augustoicaro many thanks Augustus for the shift reply. That code worked pretty good from sgy to dat.

My question was to the reverse process, convert from Dat to Segy...is there a way to do it? I am trying to visualise results in petrel or opendtect later. Thanks again

augustoicaro commented 3 years ago

@humbertogeologia, sorry for my wrong answer. Yes it possible, I did a function for this exact purpose. The strategy is to change the segy data and keep all segy metadata.

import shutil
import segyio
import numpy as np

def export_volume(base_segy_path, new_path, new_volume, inline=189, crossline=193):
    """Replace .sgy data with fault probability volume saving in a new file
    Takes an open segy file or a file name, a path for the new segy fult volume, the fault_volume.
    ----------
    seismic_path : str or segyio.SegyFile
    fault_path: str
    fault_volume: fault volume result of faultSeg3D network
    inline: inline byte position
    crossline: crossline byte position
    """
    shutil.copyfile(base_segy_path, new_path)
    with segyio.open(new_path,"r+", iline = inline, xline = crossline) as fl:
        fl.trace.raw[:] = new_volume.reshape((new_volume.shape[0]*new_volume.shape[1],new_volume.shape[2]))

fp = np.fromfile("fp.dat",dtype=np.single)
export_volume("./base.sgy'", "./fp.sgy", fp.reshape(IL,XL,Z)) #Change to your cube values

Another option is to use segyio.tools.from_array function that creates a segY from an array. That you need to reshape your array to (inline, crossline, samples) and use the code below:

import segyio.tools as st
import numpy as np

fp = np.fromfile("fp.dat",dtype=np.single)
print(fp.shape) #  check shape (inline, croosline, samples)
st.from_array("fp.sgy", fp)

To open this new .sgy file in OpendTect you need to read the following bytes:

Property Byte
In-line range 189
Cross-line range 193
X-coordinate range 193
Y-coordinate range 189

Best,

BADR127s commented 9 months ago

How to convert dat data to sgy data?