本文整理汇总了Python中obspy.core.Stats类的典型用法代码示例。如果您正苦于以下问题:Python Stats类的具体用法?Python Stats怎么用?Python Stats使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Stats类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_deepcopy
def test_deepcopy(self):
"""
Tests deepcopy method of Stats object.
"""
stats = Stats()
stats.network = 'BW'
stats['station'] = 'ROTZ'
stats['other1'] = {'test1': '1'}
stats['other2'] = AttribDict({'test2': '2'})
stats['other3'] = 'test3'
stats2 = copy.deepcopy(stats)
stats.network = 'CZ'
stats.station = 'RJOB'
self.assertEqual(stats2.__class__, Stats)
self.assertEqual(stats2.network, 'BW')
self.assertEqual(stats2.station, 'ROTZ')
self.assertEqual(stats2.other1.test1, '1')
self.assertEqual(stats2.other1.__class__, AttribDict)
self.assertEqual(len(stats2.other1), 1)
self.assertEqual(stats2.other2.test2, '2')
self.assertEqual(stats2.other2.__class__, AttribDict)
self.assertEqual(len(stats2.other2), 1)
self.assertEqual(stats2.other3, 'test3')
self.assertEqual(stats.network, 'CZ')
self.assertEqual(stats.station, 'RJOB')
示例2: create_trace
def create_trace(self, channel, stats, data):
"""Utility to create a new trace object.
Parameters
----------
channel : str
channel name.
stats : obspy.core.Stats
channel metadata to clone.
data : numpy.array
channel data.
Returns
-------
obspy.core.Trace
trace containing data and metadata.
"""
stats = Stats(stats)
if self.data_type is None:
stats.data_type = 'adjusted'
else:
stats.data_type = self.data_type
if self.data_type is None:
stats.location = 'A0'
else:
stats.location = self.location
trace = super(AdjustedAlgorithm, self).create_trace(channel, stats,
data)
return trace
示例3: test_casted_stats_nscl_writes_to_mseed
def test_casted_stats_nscl_writes_to_mseed(self):
"""
Ensure a Stream object that has had its nslc types cast to str can
still be written.
"""
st = Stream(traces=read()[0])
# Get a new stats object with just the basic items in it
stats_items = set(Stats())
new_stats = Stats()
new_stats.__dict__.update({x: st[0].stats[x] for x in stats_items})
with warnings.catch_warnings(record=True):
new_stats.network = 1
new_stats.station = 1.1
new_stats.channel = 'Non'
st[0].stats = new_stats
# try writing stream to bytes buffer
bio = io.BytesIO()
st.write(bio, 'mseed')
bio.seek(0)
# read bytes and compare
stt = read(bio)
# remove _mseed so streams can compare equal
stt[0].stats.pop('mseed')
del stt[0].stats._format # format gets added upon writing
self.assertEqual(st, stt)
示例4: _create_trace
def _create_trace(data, channel, starttime, delta=60.):
stats = Stats()
stats.channel = channel
stats.delta = delta
stats.starttime = starttime
stats.npts = len(data)
data = numpy.array(data, dtype=numpy.float64)
return Trace(data, stats)
示例5: test_update
def test_update(self):
"""
Tests update method of Stats object.
"""
x = Stats({"a": 5})
self.assertTrue("a" in dir(x))
x.update({"b": 5})
self.assertTrue("b" in dir(x))
y = {"a": 5}
y.update({"b": 5})
x = Stats(y)
self.assertTrue("b" in dir(x))
示例6: test_nestedStats
def test_nestedStats(self):
"""
Various setter and getter tests.
"""
# 1
stats = Stats()
stats.test = dict()
stats.test["test2"] = "muh"
self.assertEqual(stats.test.test2, "muh")
self.assertEqual(stats.test["test2"], "muh")
self.assertEqual(stats["test"].test2, "muh")
self.assertEqual(stats["test"]["test2"], "muh")
stats.test["test2"] = "maeh"
self.assertEqual(stats.test.test2, "maeh")
self.assertEqual(stats.test["test2"], "maeh")
self.assertEqual(stats["test"].test2, "maeh")
self.assertEqual(stats["test"]["test2"], "maeh")
# 2 - multiple initialization
stats = Stats({"muh": "meah"})
stats2 = Stats(Stats(Stats(stats)))
self.assertEqual(stats2.muh, "meah")
# 3 - check conversion to AttribDict
stats = Stats()
stats.sub1 = {"muh": "meah"}
stats.sub2 = AttribDict({"muh2": "meah2"})
stats2 = Stats(stats)
self.assertTrue(isinstance(stats.sub1, AttribDict))
self.assertTrue(isinstance(stats.sub2, AttribDict))
self.assertEqual(stats2.sub1.muh, "meah")
self.assertEqual(stats2.sub2.muh2, "meah2")
示例7: ascii
def ascii(path, filenames):
""" Reads SPECFEM3D-style ascii data
"""
from numpy import loadtxt
from obspy.core import Stream, Stats, Trace
stream = Stream()
for filename in filenames:
stats = Stats()
data = loadtxt(path +'/'+ filename)
stats.filename = filename
stats.starttime = data[0,0]
stats.sampling_rate = data[0,1] - data[0,0]
stats.npts = len(data[:,0])
try:
parts = filename.split('.')
stats.network = parts[0]
stats.station = parts[1]
stats.channel = temp[2]
except:
pass
stream.append(Trace(data=data[:,1], header=stats))
return stream
示例8: test_simpleStats
def test_simpleStats(self):
"""
Various setter and getter tests.
"""
stats = Stats()
stats.test = 1
self.assertEqual(stats.test, 1)
self.assertEqual(stats['test'], 1)
stats['test2'] = 2
self.assertEqual(stats.test2, 2)
self.assertEqual(stats['test2'], 2)
stats['test'] = 2
self.assertEqual(stats.test, 2)
self.assertEqual(stats['test'], 2)
stats.test2 = 1
self.assertEqual(stats.test2, 1)
self.assertEqual(stats['test2'], 1)
示例9: test_setCalib
def test_setCalib(self):
"""
Test to prevent setting a calibration factor of 0
"""
x = Stats()
# this should work
x.update({'calib': 1.23})
self.assertTrue(x.calib, 1.23)
# this raises UserWarning
with warnings.catch_warnings(record=True):
warnings.simplefilter('error', UserWarning)
# 1
self.assertRaises(UserWarning, x.__setitem__, 'calib', 0)
# 2
self.assertRaises(UserWarning, x.update, {'calib': 0})
# calib value should nevertheless be set to 0
self.assertTrue(x.calib, 0)
示例10: test_pickleStats
def test_pickleStats(self):
"""
Test pickling Stats objects. Test case for issue #10.
"""
stats = Stats()
stats.muh = 1
stats['maeh'] = 'hallo'
# ASCII
temp = pickle.dumps(stats, protocol=0)
stats2 = pickle.loads(temp)
self.assertEqual(stats, stats2)
# old binary
temp = pickle.dumps(stats, protocol=1)
stats2 = pickle.loads(temp)
self.assertEqual(stats, stats2)
# new binary
temp = pickle.dumps(stats, protocol=2)
stats2 = pickle.loads(temp)
self.assertEqual(stats, stats2)
示例11: get_obspy_trace
def get_obspy_trace(self):
"""
Return class contents as obspy.Trace object
"""
stat = Stats()
stat.network = self.net.split(b'\x00')[0].decode()
stat.station = self.sta.split(b'\x00')[0].decode()
location = self.loc.split(b'\x00')[0].decode()
if location == '--':
stat.location = ''
else:
stat.location = location
stat.channel = self.chan.split(b'\x00')[0].decode()
stat.starttime = UTCDateTime(self.start)
stat.sampling_rate = self.rate
stat.npts = len(self.data)
return Trace(data=self.data, header=stat)
示例12: create_empty_trace
def create_empty_trace(trace, channel):
"""
Utility to create an empty trace, similar to another trace.
Parameters
----------
trace: obspy.core.Trace
Trace that is source of most metadata, including array length.
channel: String
Channel name for created Trace.
Returns
-------
obspy.core.Trace
a Trace object, filled with numpy.nan.
"""
stats = Stats(trace.stats)
stats.channel = channel
count = len(trace.data)
numpy_data = numpy.full((count), numpy.nan)
return Trace(numpy_data, stats)
示例13: test_pickle_stats
def test_pickle_stats(self):
"""
Test pickling Stats objects. Test case for issue #10.
"""
stats = Stats()
stats.muh = 1
stats['maeh'] = 'hallo'
# ASCII
temp = pickle.dumps(stats, protocol=0)
stats2 = pickle.loads(temp)
self.assertEqual(stats, stats2)
# old binary
temp = pickle.dumps(stats, protocol=1)
stats2 = pickle.loads(temp)
self.assertEqual(stats, stats2)
# new binary
temp = pickle.dumps(stats, protocol=2)
stats2 = pickle.loads(temp)
self.assertEqual(stats, stats2)
# SOH channels sampling_rate & delta == 0. for #1989
stats.sampling_rate = 0
pickle.loads(pickle.dumps(stats, protocol=0))
pickle.loads(pickle.dumps(stats, protocol=1))
pickle.loads(pickle.dumps(stats, protocol=2))
示例14: read_specfem_seismogram
def read_specfem_seismogram(output_files, network, station, band):
st = Stream()
for component in 'ZNE':
channel = '%sX%s' % (band, component)
filename = os.path.join(output_files,
'%s.%s.%s.sem.ascii' % (network, station,
channel))
tmp = np.genfromtxt(filename)
stats = Stats()
stats.network = network
stats.station = station
stats.channel = channel
stats.delta = tmp[1, 0] - tmp[0, 0]
stats.npts = tmp.shape[0]
stats.starttime = tmp[0, 0]
tr = Trace(tmp[:, 1], stats)
st += tr
return st
示例15: readTSPAIR
def readTSPAIR(filename, headonly=False, **kwargs): # @UnusedVariable
"""
Reads a ASCII TSPAIR file and returns an ObsPy Stream object.
.. warning::
This function should NOT be called directly, it registers via the
ObsPy :func:`~obspy.core.stream.read` function, call this instead.
:type filename: str
:param filename: ASCII file to be read.
:type headonly: bool, optional
:param headonly: If set to True, read only the headers. This is most useful
for scanning available data in huge (temporary) data sets.
:rtype: :class:`~obspy.core.stream.Stream`
:return: A ObsPy Stream object.
.. rubric:: Example
>>> from obspy import read
>>> st = read('/path/to/tspair.ascii')
"""
fh = open(filename, "rt")
# read file and split text into channels
headers = {}
key = None
for line in fh:
if line.isspace():
# blank line
continue
elif line.startswith("TIMESERIES"):
# new header line
key = line
headers[key] = StringIO()
elif headonly:
# skip data for option headonly
continue
elif key:
# data entry - may be written in multiple columns
headers[key].write(line.strip().split()[-1] + " ")
fh.close()
# create ObsPy stream object
stream = Stream()
for header, data in headers.iteritems():
# create Stats
stats = Stats()
parts = header.replace(",", "").split()
temp = parts[1].split("_")
stats.network = temp[0]
stats.station = temp[1]
stats.location = temp[2]
stats.channel = temp[3]
stats.sampling_rate = parts[4]
# quality only used in MSEED
stats.mseed = AttribDict({"dataquality": temp[4]})
stats.ascii = AttribDict({"unit": parts[-1]})
stats.starttime = UTCDateTime(parts[6])
stats.npts = parts[2]
if headonly:
# skip data
stream.append(Trace(header=stats))
else:
data = _parse_data(data, parts[8])
stream.append(Trace(data=data, header=stats))
return stream