3. Reading SEG-Y files

3.1. ReadSegy

ReadSegy.m can be used to read files :

    >> [Data,SegyTraceHeaders,SegyHeader]=ReadSegy('data.segy');
    >> wiggle(Data,[],SegyHeader.time,[SegyTraceHeaders.cdp],'VA')
    >> imagesc([SegyTraceHeaders.cdp],[SegyHeader.time],Data)

This will read data.segy using the revision and data sample format specified in the binary header, and plot the data.

Data is a 2D variable containing the seismic data. [Nsamples*Ntraces];

SegyTraceHeadersis a structure of size [1,Ntraces] structure containing all the header values from the traces. Type SegyTraceHeaders to see a list of header information. SegyTraceHeaders(9), list all header names and values of trace number 9.

To access an array of trace header values simply us square brackets as :


SegyHeader is a structure containing all the header values. Typing '>> SegyHeader' will list the names and values of all header values.

A number of arguments can be given to ReadSegy, controlling which part of the data set to read, and the format.

3.1.1. Read specific trace numbers

To read traces 100, 201 and 320 use e.g.

>> [Data,SegyTraceHeaders,SegyHeader]=ReadSegy(filename,'traces',[100 201 320]);

Use for example ReadSegyTraceHeadervalue.m and 'find' to find a list of trace ids (this is equivalent to using the 'minmax' option)

>> cdp=ReadSegyTraceHeaderValue(filename,'key','cdp');
>> traces = find(cdp>100 & cdp<200)
>> [Data,SegyTraceHeaders,SegyHeader]=ReadSegy(filename,'traces',[100 201 320]);

3.1.2. Read only every 5th trace

      >> [Data,SegyTraceHeaders,SegyHeader]=

3.1.3. To read time slice 0.5 < t < 5

      >> [Data,SegyTraceHeaders,SegyHeader]=ReadSegy(filename,'trange',.5,3);

3.1.4. Read only every 5th trace

      >> [Data,SegyTraceHeaders,SegyHeader]=

3.1.5. Read data in a CDP header range : 5000cdp5800

cdp can be changed to any other valid header name

>> [Data,SegyTraceHeaders,SegyHeader]=

3.1.6. Read only header values

In some cases it can be desirable only to read the header files (file header and traceheaders). This will return an empty Data variable.

>> [Data,SegyTraceHeaders,SegyHeader]=

3.1.7. SEG-Y format revision

SEG-Y format revision number can be '0' (1975) or '1' (2002). By default the SEG-Y format revision number is read in the binary header, but this can be overruled using :

>> [Data,SegyTraceHeaders,SegyHeader]=

3.1.8. A specific Data Sample Format

One can overrule the Data Sample Format listed in the binary header, using the dsf argument. See Section 2.3.3, “Data Sample Format / Revision” for a list of valid and supported values.

>>  [Data,SegyTraceHeaders,SegyHeader]=
>>  [Data,SegyTraceHeaders,SegyHeader]=

If dsf is set to 5 and revision to 0, a warning message will occur, since data sample format 5 is only defined in revision 1. The revision is then automatically set to 1.

3.1.9. Force the use of a specific SegyHeader

>> [Data,SegyTraceHeaders,SegyHeader]=

3.2. ReadSegyFast

ReadSegyFast.m is a faster implementation of ReadSegy.m since no trace header values are read. Thus this function will just return the seismic data and the -header. e.g. :

>> [Data,SegyHeader]=ReadSegy('data.segy');
>> imagesc(Data)

This will read data.segy using the revision and data sample format specified in the binary header, and plot the data.

3.2.1. ReadSegyFast options

As for ReadSegy.m the -revision a number of option can be used. ReadSegyFast.m uses the same convention as ReadSegy.m >.

The data sample format can be chosen using the 'revision' and 'dsf' tags. Also a 'SegyHeader' can be specified.

ReadSegyFast.m is currently optimized only for reading the whole -file, but the options 'jump' and 'trange' can be used (but will currently not result in faster read times).

Since the trace header values are not read, the 'minmax' option is not supported.

3.3. ReadSegyHeader

ReadSegyHeader.m reads the Binary Segy Header only. It can be called with the same options as ReadSegy.m

3.3.1. Force using little endian :

>> SegyHeader=ReadSegyHeader(filename,'endian','l');

3.4. ReadSegyTraceHeaderValue

ReadSegyTraceHeaderValue.m(Section 8.18, “ReadSegyTraceHeaderValue”) reads one trace header value into an array. This approach is much faster than to read the whole file

3.4.1. using keyword

To read a trace header value by its trace header key (see Section 2.4, “Segy Trace Header name definition” for a list of defined keys) use


3.4.2. using location+type

To read a trace header by its position in the trace header using a specific data sample format, use:


Take a look at Section 8.30, “TraceHeaderDef”, or check the manual at Section 2.4, “Segy Trace Header name definition” to find the position of all trace header values.

3.5. ReadSegyConstantTraceLength

Assuming a constant trace length (which is much more common than not) allows much faster reading of parts of large file. For example to read trace number 2030, the whole segy data cube must be sequentially read, assuming variable trace length. Assuming constant trace length the trace can be directly (and fast) located in the data cube.

To read trace 2000 use


To read traces 1-2000 and 2020-2040 use


3.5.1. using keywords

Several keywords can be used to efficiently read parts of larger files.

To read only the part of a file with SourceX between 1000-2000 and SourceY between 4000-5000 use :


3.6. ReadSu

ReadSu.m works similar to ReadSegy.m and the same input parameters can be used. A SuHeader can optionally be returned, that simple is a mostly empty file header.

>> [Data,SuTraceHeaders,SuHeader]=ReadSu(filename);