本文整理匯總了Python中obspy.core.stream.Stream.write方法的典型用法代碼示例。如果您正苦於以下問題:Python Stream.write方法的具體用法?Python Stream.write怎麽用?Python Stream.write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類obspy.core.stream.Stream
的用法示例。
在下文中一共展示了Stream.write方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: saveData
# 需要導入模塊: from obspy.core.stream import Stream [as 別名]
# 或者: from obspy.core.stream.Stream import write [as 別名]
def saveData(self, filename = None):
stream = Stream()
for i in range(0,self.ntraces):
curr_trace = self.data[:,i]
curr_trace = np.require(curr_trace, dtype='float32')
temp = Trace(data=curr_trace)
# Attributes in trace.stats will overwrite everything in
# trace.stats.segy.trace_header
temp.stats.delta = 0.01
# Add trace to stream
stream.append(temp)
print "Stream object before writing..."
print stream
stream.write(filename, format="SEGY", data_encoding=1,
byteorder=sys.byteorder)
示例2: range
# 需要導入模塊: from obspy.core.stream import Stream [as 別名]
# 或者: from obspy.core.stream.Stream import write [as 別名]
month=path[-2:]
lifile=glob.glob('*')
for days in [x+1 for x in range(31)]:
day=('%02d' % days)
for hours in [x for x in range(24)]:
hour=('%02d' % hours)
wav_files=[wav for wav in lifile if year in wav[0:4] \
and month in wav[5:7] \
and day in wav[8:10] \
and hour in wav[11:13]]
if not wav_files:
continue
else:
output_name='%s-%s-%s-%s00_%s.%s' % (year,month,day,hour,suffix,wav_format)
stream_wav=Stream()
for i in range(len(wav_files)):
stream_wav+=read(wav_files[i])
stream_wav.write(output_name,format=("%s" % wav_format))
stream_wav.clear()
shutil.move(output_name,("%s%s/%s/" % (final_base,year,month)))
print "Processing...%s...Please wait" % output_name
sys.exit()
# cat_wav=(' '.join(wav_files))
# cat_command('cat %s > %s-%s-%s-%s
# os.system(cat_command)
# print wav_files
# IPython.embed()
# 2008-07-21-1500_VANARC.MSEED
示例3: GetIIData
# 需要導入模塊: from obspy.core.stream import Stream [as 別名]
# 或者: from obspy.core.stream.Stream import write [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))
示例4: read
# 需要導入模塊: from obspy.core.stream import Stream [as 別名]
# 或者: from obspy.core.stream.Stream import write [as 別名]
#=============================================================
# Imports
import glob
from obspy.core import read
from obspy.core.stream import Stream
from obspy.core.trace import Trace
# Read multiple mSEED files
# st = read("/Users/Proxima/Documents/classes/Fall2015/hacking-measurement/save-seistool/examples/CHILE_M8.3/BDM.BK.LHN.00.D.2015.259.225431.gz")
st = Stream()
i = 0
# glob.glob returns a list of files in the directory
for file in glob.glob("../examples/CHILE_M8.3/*.gz"):
i += 1
if (i>5):
break
else:
st += read(file)
st.write("5_trace.mseed",format="mSEED")
# for stream in st:
# # stream.write("5_trace.mseed",format="mSEED")
# multiplestream += stream
# multiplestream = Stream(traces=[Trace(s) for s in st])
# multiplestream.write("5_trace_test.mseed",format="MSEED")
print("5 streams written into file 5_trace.mseed")
示例5: Collecting
# 需要導入模塊: from obspy.core.stream import Stream [as 別名]
# 或者: from obspy.core.stream.Stream import write [as 別名]
#.........這裏部分代碼省略.........
timeNow = datetime.time(datetime.now())
time = timeNow.minute + (timeNow.second + timeNow.microsecond/1000000.0)/60.0
hour = timeNow.hour
plotClear = False
if (hour != lastHour):
## Everytime the hour changes the following code saves hour long SAC Files
lastHour = hour
currentTime = str(datetime.utcnow())
now2 = currentTime.split(' ',1 )
now3 = now2[1].split(':',1)
now3 = int(now3[0])-1
if (now3 == -1):
now3 = 23
stats['endtime'] = UTCDateTime()
stats['ntps'] = len(hourSeismicData)
st = Stream([Trace(data=hourSeismicData, header=stats)])
sacdateAndTime = str(stats['starttime']).split('T')
sacdate = sacdateAndTime[0].split('-')
sactime = sacdateAndTime[1].split(':')
sacyear = sacdate[0][2:]
sacmonth = sacdate[1]
sacday = sacdate[2]
sachour = sactime[0]
sacminute = sactime[1]
fileNaame = str(sacyear+sacmonth+sacday+sachour+sacminute+stats['station']+".sac")
st.write(sacyear+sacmonth+sacday+sachour+sacminute+stats['station']+".sac", format='SAC')
stats = initializeHeader(stationId, stationName,stationAddress, longitude, latitude , elevation)
hourSeismicData = np.array([])
##Uploads SAC file right after creating it
contentType = "application/octet-stream" #image/png
c = pycurl.Curl()
c.setopt(c.URL, 'https://nzseis.phy.auckland.ac.nz/pyjamaseis/upload/')
c.setopt(c.HTTPHEADER, ['Authorization:'+'Basic %s' % base64.b64encode("kofi:pyjamaseis")])
c.setopt(c.HTTPPOST, [("payload",(c.FORM_FILE, fileNaame, c.FORM_CONTENTTYPE, contentType)), ("mode","sac")])
try:
c.perform()
c.close()
except pycurl.error, error:
errno, errstr = error
print 'An error occurred: ', errstr
totalHoursConst = totalHoursConst-1
if(totalHoursConst == -1):
plotClear = True
totalHoursConst = 23
hasHourChanged = True
if ((count % skipConst == 0) or hasHourChanged):
if ((tempSeismicData.size >= 18) or hasHourChanged):
##After every 18 values are read from the TC1 seismometer, the array containing these values along with the tempMillisecond array which contains the exact time the value was read put on the queue for the plotting process to read
queue.put([tempSeismicData, tempMillisecond, hasHourChanged, plotClear, mode])
mode = "None"
示例6: GetIIData
# 需要導入模塊: from obspy.core.stream import Stream [as 別名]
# 或者: from obspy.core.stream.Stream import write [as 別名]
#.........這裏部分代碼省略.........
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')
print self.stFinal
elif self.LOCWILD:
for self.location in self.locations:
print
print "For station: " + self.station
trace = self.st.select(location = self.location)
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()