def test_download_various_methods(self):
     """
     Will download data from server and store in various databases,
     then create templates using the various methods.
     """
     client = Client('GEONET')
     # get the events
     catalog = Catalog()
     data_stream = client._download(
         'http://quakeml.geonet.org.nz/quakeml/1.2/2016p008194')
     data_stream.seek(0, 0)
     catalog += read_events(data_stream, format="quakeml")
     data_stream.close()
     # Select 3 channels to use and download
     sta_chans = [(pick.waveform_id.station_code,
                   pick.waveform_id.channel_code)
                  for pick in catalog[0].picks[0:3]]
     t1 = UTCDateTime(catalog[0].origins[0].time.date)
     t2 = t1 + 86400
     bulk = [('NZ', sta_chan[0], '*', sta_chan[1], t1, t2)
             for sta_chan in sta_chans]
     continuous_st = client.get_waveforms_bulk(bulk)
     continuous_st.merge(fill_value=0)
     # Test multi_template_gen
     templates = multi_template_gen(catalog, continuous_st, length=3)
     self.assertEqual(len(templates), 1)
     # Test without an event
     templates = multi_template_gen(Catalog(), continuous_st, length=3)
     self.assertEqual(len(templates), 0)
     # Test from contbase method
     sfile = eventtosfile(catalog[0],
                          'TEST',
                          'L',
                          '.',
                          'None',
                          overwrite=True)
     os.makedirs(catalog[0].origins[0].time.date.strftime('Y%Y'))
     os.makedirs(catalog[0].origins[0].time.date.strftime('Y%Y' + os.sep +
                                                          'R%j.01'))
     for tr in continuous_st:
         tr.write(catalog[0].origins[0].time.date.strftime('Y%Y' + os.sep +
                                                           'R%j.01') +
                  os.sep + tr.stats.station + '.' + tr.stats.network + '.' +
                  tr.stats.location + '.' + tr.stats.channel +
                  tr.stats.starttime.strftime('%Y.%j'),
                  format='MSEED')
     template = from_contbase(sfile,
                              contbase_list=[('.', 'Yyyyy/Rjjj.01', 'NZ')],
                              lowcut=1.0,
                              highcut=5.0,
                              samp_rate=20,
                              filt_order=4,
                              length=3,
                              prepick=0.5,
                              swin='all')
     self.assertTrue(isinstance(template, Stream))
     shutil.rmtree(continuous_st[0].stats.starttime.strftime('Y%Y'))
Beispiel #2
0
templates = []
delays = []
stations = []
print 'Template generation parameters are:'
print 'sfilebase: ' + templatedef.sfilebase
print 'samp_rate: ' + str(templatedef.samp_rate) + ' Hz'
print 'lowcut: ' + str(templatedef.lowcut) + ' Hz'
print 'highcut: ' + str(templatedef.highcut) + ' Hz'
print 'length: ' + str(templatedef.length) + ' s'
print 'swin: ' + templatedef.swin + '\n'
for sfile in templatedef.sfiles:
    print 'Working on: ' + sfile + '\r'
    if not os.path.isfile(templatedef.saveloc + '/' + sfile + '_template.ms'):
        template=template_gen.from_contbase(templatedef.sfilebase+'/'+sfile,\
                                            tempdef=templatedef,\
                                            matchdef=matchdef)

        print 'saving template as: '+templatedef.saveloc+'/'+\
                str(template[0].stats.starttime)+'.ms'
        template.write(templatedef.saveloc+'/'+\
                   sfile+'_template.ms',format="MSEED")
    else:
        template = obsread(templatedef.saveloc + '/' + sfile + '_template.ms')
    templates += [template]
    # Will read in seisan s-file and generate a template from this,
    # returned name will be the template name, used for parsing to the later
    # functions

# for tfile in templatedef.tfiles:
# # Loop through pre-existing template files
Beispiel #3
0
templates = []
delays = []
stations = []
print 'Template generation parameters are:'
print 'sfilebase: ' + templatedef.sfilebase
print 'samp_rate: ' + str(templatedef.samp_rate) + ' Hz'
print 'lowcut: ' + str(templatedef.lowcut) + ' Hz'
print 'highcut: ' + str(templatedef.highcut) + ' Hz'
print 'length: ' + str(templatedef.length) + ' s'
print 'swin: ' + templatedef.swin + '\n'
for sfile in templatedef.sfiles:
    print 'Working on: ' + sfile + '\r'
    if not os.path.isfile(templatedef.saveloc + '/' + sfile + '_template.ms'):
        print sfile
        template=template_gen.from_contbase(sfile, tempdef=templatedef, \
                    matchdef=matchdef)

        print 'saving template as: '+templatedef.saveloc+'/'+\
                str(template[0].stats.starttime)+'.ms'
        template.write(templatedef.saveloc+'/'+\
                   sfile+'_template.ms',format="MSEED")
    else:
        template = obsread(templatedef.saveloc + '/' + sfile + '_template.ms')
    templates += [template]
    # Will read in seisan s-file and generate a template from this,
    # returned name will be the template name, used for parsing to the later
    # functions

# for tfile in templatedef.tfiles:
# # Loop through pre-existing template files
# sys.stdout.write("\rReading in pre-existing template: "+tfile+"\r")
Beispiel #4
0
templates=[]
delays=[]
stations=[]
print 'Template generation parameters are:'
print 'sfilebase: '+templatedef.sfilebase
print 'samp_rate: '+str(templatedef.samp_rate)+' Hz'
print 'lowcut: '+str(templatedef.lowcut)+' Hz'
print 'highcut: '+str(templatedef.highcut)+' Hz'
print 'length: '+str(templatedef.length)+' s'
print 'swin: '+templatedef.swin+'\n'
for sfile in templatedef.sfiles:
    print 'Working on: '+sfile+'\r'
    if not os.path.isfile(templatedef.saveloc+'/'+sfile+'_template.ms'):
        print sfile
        template=template_gen.from_contbase(sfile, tempdef=templatedef, \
                    matchdef=matchdef)

        print 'saving template as: '+templatedef.saveloc+'/'+\
                str(template[0].stats.starttime)+'.ms'
        template.write(templatedef.saveloc+'/'+\
                   sfile+'_template.ms',format="MSEED")
    else:
        template=obsread(templatedef.saveloc+'/'+sfile+'_template.ms')
    templates+=[template]
    # Will read in seisan s-file and generate a template from this,
    # returned name will be the template name, used for parsing to the later
    # functions

# for tfile in templatedef.tfiles:
    # # Loop through pre-existing template files
    # sys.stdout.write("\rReading in pre-existing template: "+tfile+"\r")
Beispiel #5
0
templates=[]
delays=[]
stations=[]
print 'Template generation parameters are:'
print 'sfilebase: '+templatedef.sfilebase
print 'samp_rate: '+str(templatedef.samp_rate)+' Hz'
print 'lowcut: '+str(templatedef.lowcut)+' Hz'
print 'highcut: '+str(templatedef.highcut)+' Hz'
print 'length: '+str(templatedef.length)+' s'
print 'swin: '+templatedef.swin+'\n'
for sfile in templatedef.sfiles:
    print 'Working on: '+sfile+'\r'
    if not os.path.isfile(templatedef.saveloc+'/'+sfile+'_template.ms'):
        template=template_gen.from_contbase(templatedef.sfilebase+'/'+sfile,\
                                            tempdef=templatedef,\
                                            matchdef=matchdef)

        print 'saving template as: '+templatedef.saveloc+'/'+\
                str(template[0].stats.starttime)+'.ms'
        template.write(templatedef.saveloc+'/'+\
                   sfile+'_template.ms',format="MSEED")
    else:
        template=obsread(templatedef.saveloc+'/'+sfile+'_template.ms')
    templates+=[template]
    # Will read in seisan s-file and generate a template from this,
    # returned name will be the template name, used for parsing to the later
    # functions

# for tfile in templatedef.tfiles:
    # # Loop through pre-existing template files