本文整理汇总了Python中obspy.core.stream.Stream.split方法的典型用法代码示例。如果您正苦于以下问题:Python Stream.split方法的具体用法?Python Stream.split怎么用?Python Stream.split使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类obspy.core.stream.Stream
的用法示例。
在下文中一共展示了Stream.split方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GetIIData
# 需要导入模块: from obspy.core.stream import Stream [as 别名]
# 或者: from obspy.core.stream.Stream import split [as 别名]
#.........这里部分代码省略.........
self.CHANWILD = True
DupChannels.append(self.tr.stats.channel)
elif self.channel != '*':
self.CHANWILD = False
#except TimeoutError:
#print 'Get waveform timeout, exiting...'
#sys.exit(0)
except:
print 'Trouble getting data'
sys.exit(0)
# Takes duplicate stations out of list and
# makes station, location, and channel into an array
# for looping( probably easier way but it works)
self.stations = list(set(DupStations))
if self.station != '*':
self.stations.append(self.station)
self.locations = list(set(DupLocations))
if self.location != '*':
self.locations.append(self.location)
self.channels = list(set(DupChannels))
if self.channel != '*':
self.channels.append(self.channel)
print
print "Station(s) being pulled: " + str(self.stations)
print "Location(s) being pulled: " + str(self.locations)
print "Channel(s) being pulled: " + str(self.channels)
# Now call code to store streams in mseed files
self.storeMSEED()
def storeMSEED(self):
#Main program
#code for storing MSEED files
codepath = '/home/mkline/dev/getIIdataBackup/TEST_ARCHIVE/'
self.stFinal = Stream()
for self.channel in self.channels:
self.trace2 = self.st.select(channel = self.channel)
for self.location in self.locations:
self.trace1 = self.trace2.select(location = self.location)
for self.station in self.stations:
print
print "For station, location, and channel: " \
+ self.station +" "+ self.location +" "+ self.channel
trace = self.trace1.select(station = self.station)
trace.merge()
trace.sort()
trace.count()
for dayIndex in range(0,self.days):
print "Day properties: "
#startTime works better than trace[0].stats.starttime
trimStart = self.startTime + (dayIndex)*24*60*60
trimEnd = self.startTime + (dayIndex+1)*24*60*60
print "Start of day: " + str(trimStart)
print "End of day: " + str(trimEnd)
#Converting date into julian day to store in directory
timesplit = re.split('T', str(trimStart))
s = timesplit[0]
fmt = '%Y-%m-%d'
dt = datetime.datetime.strptime(s, fmt)
tt = dt.timetuple()
NewStartDay = str(tt.tm_yday).zfill(3)
self.stFinal = trace.copy()
self.stFinal.trim(starttime = trimStart, endtime = trimEnd)
# This if statement is used to make sure traces with no
# data dont get added to the directory structure
if not self.stFinal or str(self.stFinal[0].max()) == '--':
print "No trace for given day"
else:
#Added the directory structures in here since you won't want to
#add directory structures that you don't use
self.stFinal = self.stFinal.split()
if not os.path.exists(codepath + self.network + '_' + self.station + '/'):
os.mkdir(codepath + self.network + '_' + self.station + '/')
if not os.path.exists(codepath + self.network + '_' + self.station + '/' \
+ self.year + '/'):
os.mkdir(codepath + self.network + '_' + self.station + '/' \
+ self.year + '/')
stpath = codepath + self.network + '_' + self.station + '/' + self.year + \
'/' + self.year + '_' + NewStartDay + '/'
if not os.path.exists(stpath):
os.mkdir(stpath)
# Here we write the data using STEIM 2 and 512 record lengths
self.stFinal.write(stpath + self.stFinal[0].stats.location + '_' + \
self.stFinal[0].stats.channel + '.512.seed', format='MSEED', \
reclen = 512, encoding='STEIM2')
print self.stFinal
# convert optional boolean strings to boolean vars
def toBool(self, value):
"""
Converts 'string' to boolean. Raises exception for invalid formats
True values: 1, True, true, "1", "True", "true", "yes", "y", "t"
False values: 0, False, false, "0", "False", "false", "no", "n", "f"
"""
if str(value).lower() in ("true", "yes", "t", "y", "1"): return True
if str(value).lower() in ("false", "no", "f", "n", "0"): return False
raise Exception('Invalid value for boolean conversion: ' + str(value))
示例2: GetIIData
# 需要导入模块: from obspy.core.stream import Stream [as 别名]
# 或者: from obspy.core.stream.Stream import split [as 别名]
#.........这里部分代码省略.........
self.channels = list(set(DupChannels))
print self.stations
print self.locations
print self.channels
# Now call code to store streams in mseed files
self.storeMSEED()
#LAST THING TO DO!!!!
def storeMSEED(self):
#code for storing MSEED files
#Need to check if the directories exist and if not make them
#Main program
codepath = '/home/mkline/dev/getIIdata/TEST_ARCHIVE/'
self.days = int(round((self.st[-1].stats.endtime \
- self.st[0].stats.starttime)/(24*60*60)))
self.stFinal = Stream()
if self.STAWILD:
for self.station in self.stations:
print
print "For station: " + self.station
trace = self.st.select(station = self.station)
trace.merge()
trace.sort()
trace.count()
for dayIndex in range(0,self.days):
print "Day properties: "
#startTime works better than trace[0].stats.starttime
trimStart = self.startTime + (dayIndex)*24*60*60
trimEnd = self.startTime + (dayIndex+1)*24*60*60
print "Start of day: " + str(trimStart)
print "End of day: " + str(trimEnd)
#Converting date into julian day
timesplit = re.split('T', str(trimStart))
s = timesplit[0]
fmt = '%Y-%m-%d'
dt = datetime.datetime.strptime(s, fmt)
tt = dt.timetuple()
if tt.tm_yday < 10:
NewStartDay = '00' + str(tt.tm_yday)
elif tt.tm_yday < 100:
NewStartDay = '0' + str(tt.tm_yday)
else:
NewStartDay = str(tt.tm_yday)
self.stFinal = trace.copy()
self.stFinal.trim(starttime = trimStart, endtime = trimEnd)
self.stFinal = self.stFinal.split()
if not self.stFinal:
print "No trace for given day"
else:
#Added the directory structures in here since you won't want to
#add directory structures that you don't use
if not os.path.exists(codepath + self.network + '_' + self.station + '/'):
os.mkdir(codepath + self.network + '_' + self.station + '/')
if not os.path.exists(codepath + self.network + '_' + self.station + '/' \
+ self.year + '/'):
os.mkdir(codepath + self.network + '_' + self.station + '/' \
+ self.year + '/')
stpath = codepath + self.network + '_' + self.station + '/' + self.year + \
'/' + self.year + '_' + NewStartDay + '/'
if not os.path.exists(stpath):
os.mkdir(stpath)
# Here we write the data using STEIM 2 and 512 record lengths
self.stFinal.write(stpath + self.stFinal[0].stats.location + '_' + \
self.stFinal[0].stats.channel + '.512.seed', format='MSEED', \
reclen = 512, encoding='STEIM2')