示例#1
0
 def test_io(self):
     """Test the IO operations on parameters"""
     from eqcorrscan.utils import parameters
     from obspy import UTCDateTime
     import os
     par = parameters.EQcorrscanParameters(['bob'], 2, 8, 3, 20, 0,
                                           UTCDateTime()-86400,
                                           UTCDateTime(), '.',
                                           'seishub', 4, False, '.',
                                           '.jpg', False, 8.0, 'MAD', 6.0)
     # Write out
     par.write('test_par')
     par_in = parameters.read_parameters('test_par')
     self.assertEqual(par.template_names, par_in.template_names)
     self.assertEqual(par.lowcut, par_in.lowcut)
     self.assertEqual(par.highcut, par_in.highcut)
     self.assertEqual(par.filt_order, par_in.filt_order)
     self.assertEqual(par.samp_rate, par_in.samp_rate)
     self.assertEqual(par.debug, par_in.debug)
     self.assertEqual(par.startdate, par_in.startdate)
     self.assertEqual(par.enddate, par_in.enddate)
     self.assertEqual(par.archive, par_in.archive)
     self.assertEqual(par.arc_type, par_in.arc_type)
     self.assertEqual(par.cores, par_in.cores)
     self.assertEqual(par.plotvar, par_in.plotvar)
     self.assertEqual(par.plotdir, par_in.plotdir)
     self.assertEqual(par.plot_format, par_in.plot_format)
     self.assertEqual(par.tempdir, par_in.tempdir)
     self.assertEqual(par.threshold, par_in.threshold)
     self.assertEqual(par.threshold_type, par_in.threshold_type)
     self.assertEqual(par.trigger_interval, par_in.trigger_interval)
     os.remove('test_par')
示例#2
0
 def test_io(self):
     """Test the IO operations on parameters"""
     from eqcorrscan.utils import parameters
     from obspy import UTCDateTime
     import os
     par = parameters.EQcorrscanParameters(['bob'], 2, 8, 3, 20, 0,
                                           UTCDateTime() - 86400,
                                           UTCDateTime(), '.', 'seishub', 4,
                                           False, '.', '.jpg', False, 8.0,
                                           'MAD', 6.0)
     # Write out
     par.write('test_par')
     par_in = parameters.read_parameters('test_par')
     self.assertEqual(par.template_names, par_in.template_names)
     self.assertEqual(par.lowcut, par_in.lowcut)
     self.assertEqual(par.highcut, par_in.highcut)
     self.assertEqual(par.filt_order, par_in.filt_order)
     self.assertEqual(par.samp_rate, par_in.samp_rate)
     self.assertEqual(par.debug, par_in.debug)
     self.assertEqual(par.startdate, par_in.startdate)
     self.assertEqual(par.enddate, par_in.enddate)
     self.assertEqual(par.archive, par_in.archive)
     self.assertEqual(par.arc_type, par_in.arc_type)
     self.assertEqual(par.cores, par_in.cores)
     self.assertEqual(par.plotvar, par_in.plotvar)
     self.assertEqual(par.plotdir, par_in.plotdir)
     self.assertEqual(par.plot_format, par_in.plot_format)
     self.assertEqual(par.tempdir, par_in.tempdir)
     self.assertEqual(par.threshold, par_in.threshold)
     self.assertEqual(par.threshold_type, par_in.threshold_type)
     self.assertEqual(par.trigger_interval, par_in.trigger_interval)
     os.remove('test_par')
示例#3
0
 def read_par(self, master):
     """
     Function to open a file-browser and to select a parameter file.
     """
     from eqcorrscan.utils import parameters
     from tkFileDialog import askopenfilename
     parameter_filename = askopenfilename()
     try:
         par = parameters.read_parameters(parameter_filename)
         # Start a new instance
         master.destroy()
         run(par=par)
     except IOError:
         print 'No such file'
         return
     except TypeError:
         print 'Invalid parameter file'
         return
示例#4
0
 def read_par(self, master):
     """
     Function to open a file-browser and to select a parameter file.
     """
     from eqcorrscan.utils import parameters
     from tkFileDialog import askopenfilename
     parameter_filename = askopenfilename()
     try:
         par = parameters.read_parameters(parameter_filename)
         # Start a new instance
         master.destroy()
         run(par=par)
     except IOError:
         print 'No such file'
         return
     except TypeError:
         print 'Invalid parameter file'
         return
示例#5
0
def run():
    """Internal run function so that this can be called from interactive \
    python session for debugging."""
    from eqcorrscan.utils import pre_processing
    from eqcorrscan.utils.archive_read import read_data
    from eqcorrscan.core import match_filter
    from obspy import UTCDateTime
    from eqcorrscan.utils.parameters import read_parameters
    import warnings
    import os
    import datetime as dt
    from obspy import read
    import copy

    # Read parameter files
    par = read_parameters('../parameters/VSP_parameters.txt')
    # Log the input parameters
    log_name = ('EQcorrscan_detection_log_' +
                dt.datetime.now().strftime('%Y.%j.%H:%M:%S') + '.log')
    f = open(os.path.join('..', 'detections', log_name), 'w')
    for parameter in par.__dict__.keys():
        f.write(parameter + ': ' + str(par.__dict__.get(parameter)) + '\n')
    f.write('\n###################################\n')
    f.write('template, detect-time, cccsum, threshold, number of channels\n')

    days = (par.enddate.date - par.startdate.date).days
    dates = [par.startdate + (i * 86400)
             for i in range(days)]

    # Read in templates
    templates = [read(os.path.join('..', 'templates', template))
                 for template in par.template_names]
    # We don't need the full file path in the match-filter routine, just the
    # final 'name'
    template_names_short = [t_name.split(os.sep)[-1]
                            for t_name in par.template_names]
    warnings.warn('Unable to check whether filters are correct in templates')
    # Check that the sampling rate is correct...
    for st in templates:
        for tr in st:
            if not tr.stats.sampling_rate == par.samp_rate:
                msg = 'Template sampling rate is not correct: ' + tr.__str__()
                raise IOError(msg)
    # Work out which stations and channels we will be using
    stachans = [(tr.stats.station, tr.stats.channel)
                for st in templates
                for tr in st]
    stachans = list(set(stachans))
    # Loop through days
    for date in dates:
        # Read in the data
        st = read_data(par.archive, par.arc_type, date.date, stachans)
        # Process the data
        st.merge(fill_value='interpolate')
        st = pre_processing.dayproc(st, lowcut=par.lowcut, highcut=par.highcut,
                                    filt_order=par.filt_order,
                                    samp_rate=par.samp_rate, debug=par.debug,
                                    starttime=UTCDateTime(date.date))
        # Will remove templates if they are deemed useless
        # (eg no matching channels)
        template_names_short_copy = copy.deepcopy(template_names_short)
        templates_copy = copy.deepcopy(templates)
        # Now conduct matched-filter
        detections = match_filter(template_names=template_names_short_copy,
                                  template_list=templates_copy,
                                  st=st, threshold=par.threshold,
                                  threshold_type=par.threshold_type,
                                  trig_int=par.trigger_interval,
                                  plotvar=par.plotvar,
                                  plotdir=par.plotdir,
                                  cores=par.cores,
                                  tempdir=par.tempdir,
                                  debug=par.debug,
                                  plot_format=par.plot_format)
        # Log the output
        for detection in detections:
            f.write(', '.join([detection.template_name,
                               str(detection.detect_time),
                               str(detection.detect_val),
                               str(detection.threshold),
                               str(detection.no_chans)+'\n']))
    f.close()