def setup_exception_handler(self, exc):
     chained_exc = util.chain_exc(
         exc, f"preparing to run {self.pod.full_name}.",
         util.PodRuntimeError)
     self.pod.deactivate(chained_exc)
     self.tear_down()
     raise exc  # include in production, or just for debugging?
示例#2
0
 def runtime_exception_handler(self, exc):
     """Handler which is called if an exception is raised during the POD's
     execution (including setup and clean up).
     """
     chained_exc = util.chain_exc(exc, f"running {self.pod.full_name}.",
         util.PodExecutionError)
     self.pod.deactivate(chained_exc)
     self.tear_down()
     raise exc # include in production, or just for debugging?
示例#3
0
 def load_ds(self, var):
     """Top-level method to load dataset and parse metadata; spun out so that
     child classes can modify it. Calls child class :meth:`read_dataset`.
     """
     try:
         ds = self.read_dataset(var)
     except Exception as exc:
         raise util.chain_exc(exc, (f"loading "
                                    f"dataset for {var.full_name}."),
                              util.DataPreprocessEvent)
     var.log.debug("Read %d mb for %s.", ds.nbytes / (1024 * 1024),
                   var.full_name)
     try:
         ds = self.parser.parse(var, ds)
     except Exception as exc:
         raise util.chain_exc(exc, (f"parsing file "
                                    f"metadata for {var.full_name}."),
                              util.DataPreprocessEvent)
     return ds
示例#4
0
 def write_ds(self, var, ds):
     """Top-level method to write out processed dataset; spun out so
     that child classes can modify it. Calls child class :meth:`write_dataset`.
     """
     path_str = util.abbreviate_path(var.dest_path, self.WK_DIR, '$WK_DIR')
     var.log.info("Writing %d mb to %s", ds.nbytes / (1024 * 1024),
                  path_str)
     try:
         ds = self.clean_output_attrs(var, ds)
         ds = self.log_history_attr(var, ds)
     except Exception as exc:
         raise util.chain_exc(exc, (f"cleaning attributes to "
                                    f"write data for {var.full_name}."),
                              util.DataPreprocessEvent)
     try:
         self.write_dataset(var, ds)
     except Exception as exc:
         raise util.chain_exc(exc, f"writing data for {var.full_name}.",
                              util.DataPreprocessEvent)
     del ds  # shouldn't be necessary
示例#5
0
 def process_ds(self, var, ds):
     """Top-level method to apply selected functions to dataset; spun out so
     that child classes can modify it.
     """
     for f in self.functions:
         try:
             var.log.debug("Calling %s on %s.", f.__class__.__name__,
                           var.full_name)
             ds = f.process(var, ds)
         except Exception as exc:
             raise util.chain_exc(exc,
                                  (f"Preprocessing on {var.full_name} "
                                   f"failed at {f.__class__.__name__}."),
                                  util.DataPreprocessEvent)
     return ds
 def process_ds(self, var, ds):
     """Top-level method to call the :meth:`~PreprocessorFunctionBase.process`
     of each included PreprocessorFunction on the Dataset *ds*. Spun out into
     its own method so that child classes can modify it.
     """
     for f in self.functions:
         try:
             var.log.debug("Calling %s on %s.", f.__class__.__name__,
                           var.full_name)
             ds = f.process(var, ds)
         except Exception as exc:
             raise util.chain_exc(exc,
                                  (f"Preprocessing on {var.full_name} "
                                   f"failed at {f.__class__.__name__}."),
                                  util.DataPreprocessEvent)
     return ds
示例#7
0
    def pre_run_setup(self):
        """Extra code only applicable in frepp cooperative mode. If this code is
        called, all the POD's model data has been generated. Write a placeholder
        directory to POD_OUT_DIR, so if frepp invokes the MDTF package again
        while we're running, only our results will be written to the overall
        output.
        """
        super(GfdlDiagnostic, self).pre_run_setup()

        config = core.ConfigManager()
        frepp_mode = config.get('frepp', False)
        if frepp_mode and not os.path.exists(self.POD_OUT_DIR):
            try:
                gfdl_util.make_remote_dir(self.POD_OUT_DIR, log=self.log)
                self._has_placeholder = True
            except Exception as exc:
                chained_exc = util.chain_exc(exc, (f"Making output directory at "
                    f"{self.POD_OUT_DIR}."), util.PodRuntimeError)
                self.deactivate(chained_exc)
 def runtime_exception_handler(self, exc):
     chained_exc = util.chain_exc(exc, f"running {self.pod.full_name}.",
                                  util.PodExecutionError)
     self.pod.deactivate(chained_exc)
     self.tear_down()
     raise exc  # include in production, or just for debugging?