Ejemplo n.º 1
0
    def calculateInversion(self):
        """
        Calculating inversion for all possible centroid depths in parallel
        """
        try:
            _multi_proc_list = []

            self.log.info('Calculating inversions for all possible ' + \
                          'centroid depths...\n')

            for depth in self.depth_list:
                _p = multiProcess(target=self.invertDepth, args=(depth,))
                _p.start()
                _multi_proc_list.append(_p)

            # waiting for all inversions to finish
            for _p in _multi_proc_list:
                _p.join()

            # prints all logs to log file
            for depth in self.depth_list:

                _log_path = os.path.join(self.dir.inversion, str(depth),
                                         "green_log")
                _log_file = open(_log_path,"r")
                _log_path2 = os.path.join(self.dir.inversion, str(depth),
                                         "invert_log")
                _log_file2 = open(_log_path2,"r")

                # writing each separated log of multiprocessing
                # to main log file
                _log_file.seek(0)
                _msg = "Calculating Green's functions and elementary" +\
                        " seismograms for depth (in km): " + str(depth) + "\n"
                _msg += _log_file.read()
                _log_file.close()
                self.log.info(_msg)

                _log_file2.seek(0)
                _msg = "Calculating inversion for depth (in km): " +\
                        str(depth) + "\n"
                _msg += _log_file2.read()
                _log_file2.close()
                self.log.info(_msg)

        except:
            self.log.info('Error occurred in inversion calculation...\n')
            raise
Ejemplo n.º 2
0
    def start(self):
        """
        Starting process (automatic or revised)
        """
        try:
            if self.origin and self.settings and self.db_scisola:

                # if already running
                if self.proc:
                    self.stop()

                self.seedlink = seedlink.Seedlink()
                self.seedlink.name = self.settings.seedlink_path
                self.seedlink.host = self.settings.seedlink_host
                self.seedlink.port = self.settings.seedlink_port
                self.seedlink.sc3_path = self.settings.sc3_path

                # now
                self.origin.timestamp = datetime.datetime.utcnow()
                # if station_list is empty then the process is automatic
                # else is revised
                self.origin.automatic = not bool(self.station_list)

                # automatic or revised procedure
                if self.origin.automatic:
                    self.proc = multiProcess(target=self.automatic)

                else:
                    self.proc = multiProcess(target=self.revised)

                if self.parent:
                    if self.origin.automatic:
                        self.parent.master_log.info("Starting automatic " + \
                        "procedure for event_id: " + \
                        str(self.origin.event_id) + \
                        "...\n")
                        self.parent.master_log.origin(self.origin)

                    else:
                        self.parent.master_log.info("Starting revised " + \
                                                    "procedure for " + \
                                                    "origin_id: " + \
                                                    str(self.origin.id) + \
                                                    "...\n")

                self.proc.start()
                self.proc.join(timeout=self.timeout)
                self.stop()

                if self.parent:
                    if self.origin.automatic:
                        self.parent.master_log.info("Automatic procedure" + \
                                                " finished successfully...\n")
                    else:
                        self.parent.master_log.info("Revised procedure" + \
                                                " finished successfully...\n")

        except:
            if self.parent:
                self.parent.master_log.exception()
            return -1