Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def addXcorrSides(self):
self.setHI('starttime', UTCDateTime('2000-01-01'))
for tr in self:
N = tr.stats.npts
tr.data = tr.data[N // 2:] + tr.data[N // 2 + N % 2 - 1::-1]
fh.seek(0)
# start with event file header
# line 1
data = _readline(fh)
number_of_channels = int(data[30:33])
# calculate number of lines with channels
number_of_lines = number_of_channels // 3 + (number_of_channels % 3 and 1)
if number_of_lines < 10:
number_of_lines = 10
# line 2
data = _readline(fh)
# line 3
for _i in xrange(0, number_of_lines):
data = _readline(fh)
# now parse each event file channel header + data
stream = Stream()
dlen = arch / 8
dtype = byteorder + 'i' + str(dlen)
stype = '=i' + str(dlen)
for _i in xrange(number_of_channels):
# get channel header
temp = _readline(fh, 1040)
# create Stats
header = Stats()
header['network'] = (temp[16] + temp[19]).strip()
header['station'] = temp[0:5].strip()
header['location'] = (temp[7] + temp[12]).strip()
header['channel'] = (temp[5:7] + temp[8]).strip()
header['sampling_rate'] = float(temp[36:43])
header['npts'] = int(temp[43:50])
# create start and end times
year = int(temp[9:12]) + 1900
def picks_no_origin(self):
""" create a events that has picks but no origin """
t0 = UTCDateTime("2016-01-01T10:12:15.222")
def wave_id(seed_str):
return ev.WaveformStreamID(seed_string=seed_str)
picks = [
ev.Pick(time=t0 + 2, waveform_id=wave_id("UU.TMU..HHZ")),
ev.Pick(time=t0 + 1.2, waveform_id=wave_id("UU.BOB.01.ELZ")),
ev.Pick(time=t0 + 3.2, waveform_id=wave_id("UU.TEX..EHZ")),
]
return picks_to_dataframe(ev.Event(picks=picks))
def test_hdf5_headonly(self):
stream = self.stream
with NamedTemporaryFile(suffix='.h5') as ft:
fname = ft.name
stream.write(fname, 'H5')
stream2 = read(fname, 'H5', headonly=True)
stream2[0].stats.header = -42
self.assertEqual(len(stream2[0]), 0)
stream2.write(fname, 'H5', mode='a', headonly=True)
stream2 = read(fname, 'H5')
self.assertEqual(stream2[0].stats.header, -42)
stream2[0].stats.header = 42
for tr in stream2:
del tr.stats._format
self.assertEqual(stream, stream2)
def test_trc_num(self):
stream = self.stream.copy()
set_index('waveforms/{trc_num:03d}')
with NamedTemporaryFile(suffix='.h5') as ft:
fname = ft.name
stream.write(fname, 'H5')
stream.write(fname, 'H5', mode='a', offset_trc_num=3)
stream2 = read(fname, 'H5')
for tr in stream2:
del tr.stats._format
set_index()
self.assertEqual(len(stream2), 6)
self.assertEqual(stream2[::2], stream)
self.assertEqual(stream2[1::2], stream)
def setUp(self):
self.stream = read().sort()
# add processing info
self.stream.decimate(2)
self.stream.differentiate()
self.stream[0].stats.onset = UTC()
self.stream[0].stats.header = 42
self.stream[0].stats.header2 = 'Test entry'
self.stream[0].stats.header3 = u'Test entry unicode'
stack = dict(group='all', count=5, type=['pw', 2])
self.stream[0].stats.stack = stack
for tr in self.stream:
if 'response' in tr.stats:
del tr.stats.response
def test_positive_gradient(self):
from OP_waveforms import stream_positive_derivative
from obspy.core import read
base_path = self.wo.opdict['base_path']
test_datadir = self.wo.opdict['test_datadir']
st = read(os.path.join(base_path, test_datadir, 'raw_data',
'YA.UV15.00.HHZ.MSEED'))
tr = st[0]
npts = len(tr.data)
dt = tr.stats.delta
x = np.arange(npts)*dt
# set up a polynomial function
y = (3+2*x+4*x*x+5*x*x*x)
dy_exp = (2+8*x+15*x*x)
tr.data = y
st = stream_positive_derivative(st)
np.testing.assert_almost_equal(tr.data[20:100], dy_exp[20:100], 2)
def sm_generator(scnls=None, amplitudes=None):
""" Function to create station magntiudes for testing."""
counter = 1
sms = []
scnls = scnls or []
params = {
"origin_id": ev.ResourceIdentifier(),
"station_magnitude_type": "M",
"method_id": "mag_calculator",
}
for scnl in scnls:
sm = ev.StationMagnitude(
mag=counter,
mag_errors=ev.QuantityError(uncertainty=counter * 0.1, confidence_level=95),
waveform_id=ev.WaveformStreamID(seed_string=scnl),
creation_info=ev.CreationInfo(
agency_id="dummy_agency", author="dummy", creation_time=UTCDateTime()
),
**params,
)
sms.append(sm)
counter += 1
def event_only_picks(self, picks):
return ev.Event(picks=picks)
def event(self):
origin = Origin(time=self.time, latitude=47, longitude=-111.7)
return Event(origins=[origin])