equinor / segyio

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

from_arrray issue #456

Closed pythonmobile closed 4 years ago

pythonmobile commented 4 years ago

I am using from_array3d to write a numpy array to a segy file. When I open the binary headers for it, I see this:

{JobID: 0, LineNumber: 0, ReelNumber: 0, Traces: -11028, AuxTraces: -11028, Interval: 4000, IntervalOriginal: 4000, Samples: 84, SamplesOriginal: 84, Format: 1, EnsembleFold: 0, SortingCode: 2, VerticalSum: 0, SweepFrequencyStart: 0, SweepFrequencyEnd: 0, SweepLength: 0, Sweep: 0, SweepChannel: 0, SweepTaperStart: 0, SweepTaperEnd: 0, Taper: 0, CorrelatedTraces: 0, BinaryGainRecovery: 0, AmplitudeRecovery: 0, MeasurementSystem: 0, ImpulseSignalPolarity: 0, VibratoryPolarity: 0, SEGYRevision: 0, TraceFlag: 0, ExtendedHeaders: 0}

Note: Traces < 0 AuxTraces, etc. How can I generate a valid Segy file from a numpy array?

When I use from_array3d, I also get this warning:

.pyenv/versions/3.8.2/lib/python3.8/site-packages/segyio/utils.py:18: RuntimeWarning: Implicit conversion to contiguous array warnings.warn(msg, RuntimeWarning)

Any idea why this is happening? I am writing a little-endian float 3d ndarray to a sgy.

I would also want to write the long/lat/coordinate units for the trace headers output. How can I do that?

Thanks.

jokva commented 4 years ago

How many traces are you writing?

The warning simply means your source data is non-contiugous, and segyio is converting it for you on the fly.

pythonmobile commented 4 years ago

I am writing 4904172 traces, each of length 84. This is the numpy array shape: (1996, 2457, 84)

jokva commented 4 years ago

Ok, so SEG-Y pre-rev2 had a maximum trace count of 2^15-1, due to the trace count word being signed 2-byte. Your almost five million overflows that quite significantly. segyio never trusted this number (a lot of files are bigger), instead assuming all traces are of equal length and computing the number of traces. This assumption is wrong (well, ambiguous is rev0, explicitly wrong in rev1).

What that means is that in practice this is a display bug. SEG-Y rev2 introduces a new, 4-byte header word for trace count to handle files with large amount of traces, but it is not really exposed by segyio.

pythonmobile commented 4 years ago

If I understand the problem - is there a plan to use SEG-Y rev2 for from_array3d anytime soon? Thanks.

jokva commented 4 years ago

It's a display bug, your file is still ok (for segyio to work with). Other programs might struggle more with it.

pythonmobile commented 4 years ago

Thanks. I will give it a try again. Please fix the display bug if you have not already - whenever you get time. It is not urgent.