# http://pyrocko.org - GPLv3 # # The Pyrocko Developers, 21st Century # ---|P------/S----------~Lg----------
""" Converts an IBM floating point number into IEEE format. :param: ibm - 32 bit unsigned integer: unpack('>L', f.read(4)) """ if ibm == 0: return 0.0 sign = ibm >> 31 & 0x01 exponent = ibm >> 24 & 0x7f mantissa = (ibm & 0x00ffffff) / float(pow(2, 24)) print('x', sign, exponent - 64, mantissa) return (1 - 2 * sign) * mantissa * float(pow(16, exponent - 64))
.astype(num.float) # for i in range(len(data)/4): # yyy = ibm2ieee(struct.unpack('>L', data[i*4:(i+1)*4])[0]) # print('y', sign[i], exponent[i] - 64, mantissa[i]) # print(xxx[i], yyy) # if xxx[i] != yyy: # sys.exit()
'''Read SEGY file.
filename -- Name of SEGY file. load_data -- If True, the data is read, otherwise only read headers. '''
raise SEGYError('incomplete textual file header')
raise SEGYError('incomplete binary file header')
nsamples_orig, format, ensemble_fold) = hvals[0:8]
struct.unpack(endianness+'3H', binary_file_header[100:100+3*2])
ntraces = 1
1: (unpack_ibm_f4, 4, "4-byte IBM floating-point"), 2: (endianness+'i4', 4, "4-byte, two's complement integer"), 3: (endianness+'i4', 2, "2-byte, two's complement integer"), 4: (None, 4, "4-byte fixed-point with gain (obolete)"), 5: (endianness+'f4', 4, "4-byte IEEE floating-point"), 6: (None, 0, "not currently used"), 7: (None, 0, "not currently used"), 8: ('i1', 1, "1-byte, two's complement integer")}
raise SEGYError('unsupported sample data format %i: %s' % ( format, formats[format][2]))
f.read(nbthx)
raise SEGYError('incomplete trace header')
struct.unpack(endianness+'4f', trace_header[72:72+4*4])
struct.unpack(endianness+'2f', trace_header[180:180+2*4]) struct.unpack(endianness+'1I', trace_header[20:24]) struct.unpack(endianness+'1I', trace_header[24:28]) struct.unpack(endianness+'1I', trace_header[0:4]) struct.unpack(endianness+'1I', trace_header[4:8]) struct.unpack(endianness+'1I', trace_header[8:12]) struct.unpack(endianness+'1I', trace_header[12:16])
# don't know if this is standard: distance to shot [m] as int
endianness+'12H', trace_header[94:94+12*2])
endianness+'1H', trace_header[214:216])[0]
elif tscalar < 0: tscalar = 1.0 / tscalar else: tscalar = float(tscalar)
struct.unpack(endianness+'5H', trace_header[156:156+2*5])
# maybe not standard? endianness+'2H', trace_header[168:168+4])
(year, 1, doy, hour, minute, second))) \ + msecs * 1.0e-3 + usecs * 1.0e-6
except Exception: raise SEGYError('invalid start date/time')
if (nsamples_this, deltat_us_this) \ != (nsamples, deltat_us):
raise SEGYError( 'trace of incorrect length or sampling ' 'rate (trace=%i)' % itrace+1)
raise SEGYError('incomplete trace data')
data = num.fromstring(datablock, dtype=dtype) else:
else: f.seek(nsamples_this*sample_size, 1) tmax = tmin + deltat_us_this/1000000.*(nsamples_this-1) data = None
str(dtype).startswith('<') or str(dtype).startswith('>')):
data = data.astype(str(dtype)[1:])
'', '%05i' % (line_number), '%02i' % (ensemble_num), '%03i' % (ortrace_num), tmin=tmin, tmax=tmax, deltat=deltat_us_this/1000000., ydata=data, meta=dict( orfield_num=orfield_num, distance=float(idist)))
except (OSError, SEGYError) as e: raise FileLoadError(e)
finally: |