Esempio n. 1
0
 def detect(self, alg, trace_list=None, allow_multiprocessing=True, **kwargs):
     """
     """
     trace_list = self.traces if trace_list is None else trace_list[:]
     n_traces = len(trace_list)
     if allow_multiprocessing and n_traces > 1:
         processes = min(mp.cpu_count(), n_traces)
         p = mp.Pool(processes=processes)
         processed_traces = p.map(_detect, itertools.izip(itertools.repeat(alg),
                                            collections.chunkify(trace_list, n_traces / processes),
                                            itertools.repeat(kwargs)))
         processed_traces = collections.flatten_list(processed_traces)
         # Update existing traces w. new events and cf from  processed events
         for trace, processed_trace in zip(trace_list, processed_traces):
             new_events = [event for event in processed_trace.events if event not in trace.events]
             for event in new_events:
                 trace.add_event_from_copy(event)
             trace.cf = processed_trace.cf[:]
         # Cleanup
         del processed_traces
         del trace_list
         p.close()
         p.join()
         gc.collect(2)
     else:
         _detect((alg, trace_list, kwargs))
Esempio n. 2
0
    def run(self, FILEIN, csv=None, cf=False, **kwargs):
        """Event/picking detection on a given set of seismic signals.

        Reads a list of command-line input arguments, performs event analysis
        over a given list of seismic data inputs and generates a summary of
        results.
        Analysis can be performed in two ways: supervised or unsupervised mode.
        In supervised mode the function graphs each of the candidate events
        found and asks the user whether to accept them or not, whereas in
        unsupervised mode the function just computes results without receiving
        any feedback from users.

        Args:
            FILEIN: A list of binary or text file objects containing seismic
                data.
            csv: Determines whether to save a summary of results to a CSV
                file or not. Default value is None, meaning no CSV summary
                will be saved.
            cf: Determines whether to save generated characteristic function
                to a file (binary or text format) or not. Default value is
                False.
        """
        # Extract method name from kwargs
        method = kwargs.get('method', 'ampa')
        takanami = kwargs.get('takanami', False)
        # Create a list of records from input files
        factory = rc.RecordFactory(notif=clt.print_msg, **kwargs)
        factory.on_notify = clt.print_msg
        records = []
        for f in FILEIN:
            records.append(factory.create_record(f, method=method))
        records = collections.flatten_list(records)
        # Configure method
        self.on_notify('Configuring %s method... ' % method.upper())
        if method == 'stalta':
            alg = stalta.StaLta(**kwargs)
        else:
            alg = ampa.Ampa(**kwargs)
        self.on_notify("Done\n")
        # Run analysis
        self._do_analysis(records, alg, **kwargs)

        # Show results
        draw_results(records, method=method)

        # Generate reports
        if csv:
            self.on_notify("Generating CSV report in %s... " % csv.name)
            rc.generate_csv(records, csv)
            self.on_notify("Done\n")

        # Save cf
        if cf:
            for record in records:
                # Create a new directory to store CFs
                cf_path = os.path.abspath(self._cf_dir)
                if not os.path.exists(cf_path):
                    os.makedirs(cf_path)
                # Generate cf filenames
                bname, rname = os.path.splitext(os.path.basename(os.path.abspath(record.filename)))
                fname = os.path.join(cf_path, "%s.cf%s" % (bname, rname))
                self.on_notify("Saving CF for input file %s in %s... " %
                               (record.filename, fname))
                record.save_cf(fname, fmt=kwargs.get('cff', 'binary'),
                               dtype=kwargs.get('cfd', 'float64'),
                               byteorder=kwargs.get('cfb', 'native'))
                self.on_notify("Done\n")
Esempio n. 3
0
    def run(self, FILEIN, csv=None, cf=False, **kwargs):
        """Event/picking detection on a given set of seismic signals.

        Reads a list of command-line input arguments, performs event analysis
        over a given list of seismic data inputs and generates a summary of
        results.
        Analysis can be performed in two ways: supervised or unsupervised mode.
        In supervised mode the function graphs each of the candidate events
        found and asks the user whether to accept them or not, whereas in
        unsupervised mode the function just computes results without receiving
        any feedback from users.

        Args:
            FILEIN: A list of binary or text file objects containing seismic
                data.
            csv: Determines whether to save a summary of results to a CSV
                file or not. Default value is None, meaning no CSV summary
                will be saved.
            cf: Determines whether to save generated characteristic function
                to a file (binary or text format) or not. Default value is
                False.
        """
        # Extract method name from kwargs
        method = kwargs.get('method', 'ampa')
        takanami = kwargs.get('takanami', False)
        # Create a list of records from input files
        factory = rc.RecordFactory(notif=clt.print_msg, **kwargs)
        factory.on_notify = clt.print_msg
        records = []
        for f in FILEIN:
            records.append(factory.create_record(f, method=method))
        records = collections.flatten_list(records)
        # Configure method
        self.on_notify('Configuring %s method... ' % method.upper())
        if method == 'stalta':
            alg = stalta.StaLta(**kwargs)
        else:
            alg = ampa.Ampa(**kwargs)
        self.on_notify("Done\n")
        # Run analysis
        self._do_analysis(records, alg, **kwargs)

        # Show results
        draw_results(records, method=method)

        # Generate reports
        if csv:
            self.on_notify("Generating CSV report in %s... " % csv.name)
            rc.generate_csv(records, csv)
            self.on_notify("Done\n")

        # Save cf
        if cf:
            for record in records:
                # Create a new directory to store CFs
                cf_path = os.path.abspath(self._cf_dir)
                if not os.path.exists(cf_path):
                    os.makedirs(cf_path)
                # Generate cf filenames
                bname, rname = os.path.splitext(
                    os.path.basename(os.path.abspath(record.filename)))
                fname = os.path.join(cf_path, "%s.cf%s" % (bname, rname))
                self.on_notify("Saving CF for input file %s in %s... " %
                               (record.filename, fname))
                record.save_cf(fname,
                               fmt=kwargs.get('cff', 'binary'),
                               dtype=kwargs.get('cfd', 'float64'),
                               byteorder=kwargs.get('cfb', 'native'))
                self.on_notify("Done\n")