Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_dt_fallback(self):
with TestContext("dt_fallback") as context:
context.copy_file(self.filename)
with segyio.open("small.sgy", "r+") as f:
# Both zero
f.bin[BinField.Interval] = 0
f.header[0][TraceField.TRACE_SAMPLE_INTERVAL] = 0
f.flush()
fallback_dt = 4
np.testing.assert_almost_equal(segyio.dt(f, fallback_dt), fallback_dt)
# dt in bin header different from first trace
f.bin[BinField.Interval] = 6000
f.header[0][TraceField.TRACE_SAMPLE_INTERVAL] = 1000
f.flush()
fallback_dt = 4
np.testing.assert_almost_equal(segyio.dt(f, fallback_dt), fallback_dt)
def test_dt_fallback(self):
with TestContext("dt_fallback") as context:
context.copy_file(self.filename)
with segyio.open("small.sgy", "r+") as f:
# Both zero
f.bin[BinField.Interval] = 0
f.header[0][TraceField.TRACE_SAMPLE_INTERVAL] = 0
f.flush()
fallback_dt = 4
np.testing.assert_almost_equal(segyio.dt(f, fallback_dt), fallback_dt)
# dt in bin header different from first trace
f.bin[BinField.Interval] = 6000
f.header[0][TraceField.TRACE_SAMPLE_INTERVAL] = 1000
f.flush()
fallback_dt = 4
np.testing.assert_almost_equal(segyio.dt(f, fallback_dt), fallback_dt)
def test_dt_fallback(self):
f_name = self.filename.replace( ".sgy", "_dt_test.sgy")
shutil.copyfile(self.filename, f_name)
with segyio.open(f_name, "r+") as f:
# Both zero
f.bin[BinField.Interval] = 0
f.header[0][TraceField.TRACE_SAMPLE_INTERVAL] = 0
f.flush()
fallback_dt = 4
np.testing.assert_almost_equal(segyio.dt(f, fallback_dt), fallback_dt)
# dt in bin header different from first trace
f.bin[BinField.Interval] = 6000
f.header[0][TraceField.TRACE_SAMPLE_INTERVAL] = 1000
f.flush()
fallback_dt = 4
np.testing.assert_almost_equal(segyio.dt(f, fallback_dt), fallback_dt)
f.bin[0]
with self.assertRaises(IndexError):
f.bin[50000]
with self.assertRaises(IndexError):
f.bin[3214]
d = { BinField.Traces: 43,
BinField.SweepFrequencyStart: 11 }
# assign multiple fields at once by using a dict
f.bin = d
f.flush()
self.assertEqual(43, f.bin[BinField.Traces])
self.assertEqual(11, f.bin[BinField.SweepFrequencyStart])
# looking up multiple values at once returns a { TraceField: value } dict
self.assertEqual(d, f.bin[BinField.Traces, BinField.SweepFrequencyStart])
# copy a header
f.bin = f.bin
spec.sorting = int(src.sorting)
spec.format = int(src.format)
spec.samples = range(50)
spec.ilines = src.ilines[:5]
spec.xlines = src.xlines[:5]
with segyio.create(destfile, spec) as dst:
# Copy all textual headers, including possible extended
for i in range(1 + src.ext_headers):
dst.text[i] = src.text[i]
# copy the binary header, then insert the modifications needed for
# the new shape
dst.bin = src.bin
dst.bin = { segyio.BinField.Samples: 50,
segyio.BinField.Traces: 5 * 5
}
# Copy all headers in the new inlines. Since we know we're copying
# the five first we don't have to take special care to update
# headers
dst.header.iline = src.header.iline
# the copy traces (in line mode)
dst.iline = src.iline
num_inline = trace_inlines_unique.size
num_xline = trace_xlines_unique.size
num_zsamples = len(segy_file.samples)
min_inline = trace_inlines_unique.min()
min_xline = trace_xlines_unique.min()
min_zsample = segy_file.samples.min()
max_inline = trace_inlines_unique.max()
max_xline = trace_xlines_unique.max()
max_zsample = segy_file.samples.max()
inc_inline = int((max_inline - min_inline) / num_inline)
inc_xline = int((max_xline - min_xline) / num_xline)
inc_zsample = segy_file.bin[segyio.BinField.Interval] / 1000
shape = (trace_inlines_unique.size, trace_xlines_unique.size, num_zsamples)
ti_idx = trace_inlines - trace_inlines.min()
tx_idx = trace_xlines - trace_xlines.min()
idx = np.arange(ti_idx.size)
coords = np.dstack((ti_idx, tx_idx, idx))[0]
coords = da.from_array(coords, chunks=(25, 3))
with h5py.File(out_path, 'w') as f:
dset = f.create_dataset(out_name, shape=shape)
dset.attrs['dims'] = shape
dset.attrs['inc_inline'] = inc_inline
dset.attrs['inc_xline'] = inc_xline
spec = segyio.spec()
spec.sorting = int(src.sorting)
spec.format = int(src.format)
spec.samples = range(50)
spec.ilines = src.ilines[:5]
spec.xlines = src.xlines[:5]
with segyio.create(destfile, spec) as dst:
# Copy all textual headers, including possible extended
for i in range(1 + src.ext_headers):
dst.text[i] = src.text[i]
# copy the binary header, then insert the modifications needed for
# the new shape
dst.bin = src.bin
dst.bin = { segyio.BinField.Samples: 50,
segyio.BinField.Traces: 5 * 5
}
# Copy all headers in the new inlines. Since we know we're copying
# the five first we don't have to take special care to update
# headers
dst.header.iline = src.header.iline
# the copy traces (in line mode)
dst.iline = src.iline