File: make-ps-file.py

package info (click to toggle)
segyio 1.8.3-1.2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,724 kB
  • sloc: cpp: 17,823; ansic: 4,637; python: 4,326; makefile: 38; sh: 23
file content (60 lines) | stat: -rw-r--r-- 2,564 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import sys
import numpy as np
import segyio


def main():
    if len(sys.argv) < 9:
        sys.exit(" ".join(["Usage: {} [file] [samples]",
                           "[first iline] [last iline]",
                           "[first xline] [last xline]",
                           "[first offset] [last offset]"]
                         ).format(sys.argv[0]))

    spec = segyio.spec()
    filename = sys.argv[1]

    # to create a file from nothing, we need to tell segyio about the structure of
    # the file, i.e. its inline numbers, crossline numbers, etc. You can also add
    # more structural information, This is the absolute minimal specification for a
    # N-by-M volume with K offsets volume
    spec.sorting = 2
    spec.format = 1
    spec.samples = range(int(sys.argv[2]))
    spec.ilines = range(*map(int, sys.argv[3:5]))
    spec.xlines = range(*map(int, sys.argv[5:7]))
    spec.offsets = range(*map(int, sys.argv[7:9]))
    if len(spec.offsets) == 0: spec.offsets = [1]

    with segyio.create(filename, spec) as f:
        # one inline consists of 50 traces
        # which in turn consists of 2000 samples
        start = 0.0
        step = 0.00001
        # fill a trace with predictable values: left-of-comma is the inline
        # number. Immediately right of comma is the crossline number
        # the rightmost digits is the index of the sample in that trace meaning
        # looking up an inline's i's jth crosslines' k should be roughly equal
        # to (offset*100) + i.j0k.
        trace = np.arange(start = start,
                          stop  = start + step * len(spec.samples),
                          step  = step,
                          dtype = np.single)

        nx, no = len(spec.xlines), len(spec.offsets)
        # one inline is N traces concatenated. We fill in the xline number
        line = np.concatenate([trace + (xl / 100.0) for xl in spec.xlines])
        line = line.reshape( (nx, len(spec.samples)) )

        for ilindex, ilno in enumerate(spec.ilines):
            iline = line + ilno
            for tr, xlno in enumerate(spec.xlines):
                for offset_index, offset in enumerate(spec.offsets):
                    ix = (ilindex * nx * no) + (tr * no) + offset_index
                    f.trace[ix] = iline[tr] + (offset * 100)
                    f.header[ix] = { segyio.TraceField.INLINE_3D: ilno,
                                     segyio.TraceField.CROSSLINE_3D: xlno,
                                     segyio.TraceField.offset: offset }

if __name__ == '__main__':
    main()