1

I am trying to save data in SEG-Y format using Python's ObsPy. I am having trouble with the data types. I need higher precision than float32, because I have a very high sampling rate (10 MSamples/sec), so a time interval of only 0.1 microseconds. Likewise, my high_cut_frequency is 20MHz, which is beyond the capacity of float32 (20000000). When I write the header information, these values are overwritten with default values (1.0 or 0.0). This is with both the SEG-Y header and the generic ObsPy header. Is it possible to save in float64? Or, is there another trick to get the precision I need with SEG-Y? From what I gather, the data encoding only allows float32.

Below is the basic code, with comments on lines that generate error:

    import numpy as np
    from numpy import matrix
    import sys
    import getopt
    import time        
    from obspy import read, Trace, Stream, UTCDateTime
    from obspy.core.trace import Stats
    from obspy.core import AttribDict
    from obspy.segy.segy import SEGYTraceHeader, SEGYBinaryFileHeader
    from obspy.segy.core import readSEGY

    dataStream=Stream()
    averages = np.random.rand(10)
    data = np.require(averages, dtype='float32')

    trace = Trace(data=data)
    stats = Stats()

    trace.stats.starttime = UTCDateTime()

    if not hasattr(trace.stats, 'segy.trace_header'):
        trace.stats.segy = {}

    trace.stats.segy.trace_header =  SEGYTraceHeader()

    trace.stats.segy.trace_header.lag_time_B = 154
    trace.stats.segy.trace_header.scalar_to_be_applied_to_times = -4
    trace.stats.segy.trace_header.sample_interval_in_ms_for_this_trace = 10 #100 microseconds *10-4 = 0.01 us:  shows up as 1.0 when I read the file.
    trace.stats.segy.trace_header.high_cut_frequency = 20000000 #error: number to large with 20MHz
    trace.stats.segy.trace_header.number_of_samples_in_this_trace = len(trace)

    trace.stats.delta = 0.1*10**-6 # this will work for 1 us, but not 0.1 us!!

    dataStream.stats = AttribDict()
    dataStream.stats.binary_file_header = SEGYBinaryFileHeader()
    dataStream.stats.binary_file_header.number_of_data_traces_per_ensemble = 1
    dataStream.stats.binary_file_header.number_of_samples_per_data_trace = len(trace)

    dataStream.write('Test.sgy', format='SEGY', data_encoding=1, byteorder=sys.byteorder)
mtrw
  • 34,200
  • 7
  • 63
  • 71
user3403779
  • 157
  • 2
  • 10
  • I have read no relevant documentation, but couldn't you just modify the `np.require()` call? – Ignacio Vazquez-Abrams Mar 23 '14 at 21:44
  • I have tried this, but then I get an error with the data encoding when I try to save to SEG-Y format. `obspy.segy.core.SEGYCoreWritingError: The dtype of the data and the chosen data_encoding do not match. You need to manually convert the dtype if you want to use that data_encoding. Please refer to the obspy.segy manual for more details.` data_encoding=1 and data_encoding=5 are float32 (IBM and IEEE, respectively) but I have not found documentation beyond float32. – user3403779 Mar 23 '14 at 22:02

1 Answers1

1

In the SEG-Y standard, the sample interval must be specified as an integer in microseconds. If you are going below 1 microsecond, you will be outside the scope of the SEG-Y format.

What are you going to do with the data? There may be better options (DZT format for example).

Tim Nixon
  • 45
  • 8