# Working with SEGY file format for storing geophysical data

Posted 3 years ago
5103 Views
|
2 Replies
|
10 Total Likes
|

## Preamble

Several days ago I found this question in the Community. I think it interesting theme for discussion. Because I want to show how you can using the package GeologyIO. Something of this article will repeat comments on the previous question, but I want save this post to be a stand-alone tutorial for the package and SEGY in Wolfram Language.

## Installation

PacletInstall[URLDownload[
"https://wolfr.am/EXwLqEET",
FileNameJoin[{CreateDirectory[], "GeologyIO-0.2.1.paclet"}]
]]

(* Out[..] := Paclet[GeologyIO, 0.2.1, <>] *)


Now let try read the .segy-file. For demonstration in the repository exist the file "/GeologyIO/Resources/MarmousiModel.segy"

If you was installed the package, you may execute following in any notebook:

Get["GeologyIO"]
pathMarmousi =  FileNameJoin[{\$GeologyIODirectory, "Examples", "Marmousi.segy"}];
segyMarmousi = SEGYImport[pathMarmousi]


This output contains all data from .segy-file. equivalents of the last line of code:

Now we have the variable segyMarmousi. This is a object with type SEGYData. For this type in the package defined special operations. For example you can get same of elements:

segyMarmousi["TextHeader"]

(* Out[..] := <about marmousi 3200 characters> *)


Similarly, you can get other elements:

4. Traces
segyMarmousi["BinaryHeader"]
(* Out[..] := {"JobID" -> 0, "LineNumber" -> 0, ..} *)

(* Out[..] := {"tracl", ..} -> {{0, 1, ..}, ..} *)

segyMarmousi["Traces"]
(* Out[..] := {{0.0, 1.0, ..}, ..} *)


## Optimization

To convert IBM 32 Float numbers, the compiled function is used. By default, it is compiled into bytecode, but if you have a C-compiler, you can use it. On average, this gives a 2-fold gain in the speed of data import:

SEGYImport[pathMarmousi, "CompilationTarget" -> "C"]


This is a very interesting thing that I realized specifically for working with large files (more RAM available). You can not store such a file in the repository.Therefore, the demonstration will be conducted on the same Marmousi model. The function SEGYImport has an additional option for calling:

(* by default loading has value "Memory" *)



Unloaded elements contain only references to sections of the indexed file, which allows not storing large amounts of data entirely in memory. You can get the data with a special loader:

SEGYLoad


## Exporting SEGY Data

This was much more difficult than import, but in this package, data export to SEGY is also available. Only exported data must fully correspond to the internal structure of SEGYData. For example you can create the copy of the MarmousiModel:

SEGYExport[StringReplace[pathMarmousi, ".segy" -> "Copy.segy"], marmousiData]

(* Out[..] := <path to copy> *)
`

2 Replies
Sort By:
Posted 3 years ago
 - Congratulations! This post is now a Staff Pick as distinguished by a badge on your profile! Thank you, keep it coming!