Beispiel #1
0
def logging_test():
    "Test the PISM.logging module"
    grid = create_dummy_grid()

    import PISM.logging as L

    PISM.PIO(grid.com, "netcdf3", "log.nc", PISM.PISM_READWRITE_MOVE)
    c = L.CaptureLogger("log.nc")

    L.clear_loggers()

    L.add_logger(L.print_logger)
    L.add_logger(c)

    L.log("log message\n", L.kError)

    L.logError("error message\n")

    L.logWarning("warning message\n")

    L.logMessage("log message (again)\n")

    L.logDebug("debug message\n")

    L.logPrattle("prattle message\n")

    c.write()  # default arguments
    c.readOldLog()

    PISM.PIO(grid.com, "netcdf3", "other_log.nc", PISM.PISM_READWRITE_MOVE)
    c.write("other_log.nc", "other_log")  # non-default arguments
Beispiel #2
0
 def __call__(self, siplesolver, it, zeta, u, u_obs, r):
     """Callback from `siple`.  Gathers together the long list of arguments
     into a dictionary and passes it along in a standard form to the python listener."""
     data = Bunch(zeta=zeta.core(), u=u.core(), r=r.core(), u_obs=u_obs.core())
     try:
         self.listener(self.owner, it, data)
     except Exception as e:
         logError("\nWARNING: Exception occured during an inverse solver DesignUpdate listener callback:\n%s\n\n" % str(e))
Beispiel #3
0
 def __call__(self, siplesolver, it, zeta, u, u_obs, r):
     """Callback from `siple`.  Gathers together the long list of arguments
     into a dictionary and passes it along in a standard form to the python listener."""
     data = Bunch(zeta=zeta.core(), u=u.core(), r=r.core(), u_obs=u_obs.core())
     try:
         self.listener(self.owner, it, data)
     except Exception as e:
         logError("\nWARNING: Exception occured during an inverse solver DesignUpdate listener callback:\n%s\n\n" % str(e))
Beispiel #4
0
    def __call__(self, siplesolver, it, x, y, d, r, Td, TStarR):
        """Callback from `siple`.  Gathers together the long list of arguments
        into a dictionary and passes it along in a standard form to the python listener."""

        data = Bunch(x=x.core(), y=y.core(), r=r.core(), d=d.core(), Td=Td.core(), TSTarR=TStarR.core())
        try:
            self.listener(self.owner, it, data)
        except Exception:
            logError("\nERROR: Exception occured during an inverse solver listener callback:\n\n")
            traceback.print_exc(file=sys.stdout)
            raise
Beispiel #5
0
    def __call__(self, siplesolver, it, x, y, d, r, Td, TStarR):
        """Callback from `siple`.  Gathers together the long list of arguments
        into a dictionary and passes it along in a standard form to the python listener."""

        data = Bunch(x=x.core(), y=y.core(), r=r.core(), d=d.core(), Td=Td.core(), TSTarR=TStarR.core())
        try:
            self.listener(self.owner, it, data)
        except Exception:
            logError("\nERROR: Exception occured during an inverse solver listener callback:\n\n")
            traceback.print_exc(file=sys.stdout)
            raise
Beispiel #6
0
 def iteration(self, problem, eta, it, objVal, penaltyVal, d, diff_d, grad_d, u, diff_u, grad_u, grad):
     """Called during IP_SSATaucTaoTikhonovProblem iterations.  Gathers together the long list of arguments
     into a dictionary and passes it along in a standard form to the python listener."""
     data = Bunch(tikhonov_penalty=eta, JDesign=objVal, JState=penaltyVal,
                  zeta=d, zeta_step=diff_d, grad_JDesign=grad_d,
                  u=u, residual=diff_u, grad_JState=grad_u, grad_JTikhonov=grad)
     try:
         self.listener(self.owner, it, data)
     except Exception:
         logError("\nERROR: Exception occured during an inverse solver listener callback:\n\n")
         traceback.print_exc(file=sys.stdout)
         raise
Beispiel #7
0
 def iteration(self, problem, eta, it, objVal, penaltyVal, d, diff_d, grad_d, u, diff_u, grad_u, grad):
     """Called during IP_SSATaucTaoTikhonovProblem iterations.  Gathers together the long list of arguments
     into a dictionary and passes it along in a standard form to the python listener."""
     data = Bunch(tikhonov_penalty=eta, JDesign=objVal, JState=penaltyVal,
                  zeta=d, zeta_step=diff_d, grad_JDesign=grad_d,
                  u=u, residual=diff_u, grad_JState=grad_u, grad_JTikhonov=grad)
     try:
         self.listener(self.owner, it, data)
     except Exception:
         logError("\nERROR: Exception occured during an inverse solver listener callback:\n\n")
         traceback.print_exc(file=sys.stdout)
         raise
Beispiel #8
0
    def __call__(self, siplesolver, it, x, Fx, y, d, r, *args):
        """Callback from `siple`.  Gathers together the long list of arguments
        into a dictionary and passes it along in a standard form to the python listener."""
        data = Bunch(zeta=x.core(), u=Fx.core(), zeta_step=d.core(), residual=r.core(), target_misfit=self.owner.target_misfit)

        if self.owner.method == 'ign':
            data.update(T_zeta_step=args[0].core())
        else:
            data.update(TStar_residual=args[0].core())
        try:
            self.listener(self.owner, it, data)
        except Exception:
            logError("\nERROR: Exception occured during an inverse solver listener callback:\n\n")
            traceback.print_exc(file=sys.stdout)
            raise
Beispiel #9
0
    def __call__(self, siplesolver, it, x, Fx, y, d, r, *args):
        """Callback from `siple`.  Gathers together the long list of arguments
        into a dictionary and passes it along in a standard form to the python listener."""
        data = Bunch(zeta=x.core(), u=Fx.core(), zeta_step=d.core(), residual=r.core(), target_misfit=self.owner.target_misfit)

        if self.owner.method == 'ign':
            data.update(T_zeta_step=args[0].core())
        else:
            data.update(TStar_residual=args[0].core())
        try:
            self.listener(self.owner, it, data)
        except Exception:
            logError("\nERROR: Exception occured during an inverse solver listener callback:\n\n")
            traceback.print_exc(file=sys.stdout)
            raise
Beispiel #10
0
def logging_test():
    "Test the PISM.logging module"
    grid = create_dummy_grid()

    import PISM.logging as L

    log_filename = filename("log")
    try:
        PISM.File(grid.com, log_filename, PISM.PISM_NETCDF3,
                  PISM.PISM_READWRITE_MOVE)
        c = L.CaptureLogger(log_filename)

        L.clear_loggers()

        L.add_logger(L.print_logger)
        L.add_logger(c)

        L.log("log message\n", L.kError)

        L.logError("error message\n")

        L.logWarning("warning message\n")

        L.logMessage("log message (again)\n")

        L.logDebug("debug message\n")

        L.logPrattle("prattle message\n")

        c.write()  # default arguments
        c.readOldLog()
    finally:
        os.remove(log_filename)

    log_filename = filename("other_log")
    try:
        PISM.File(grid.com, log_filename, PISM.PISM_NETCDF3,
                  PISM.PISM_READWRITE_MOVE)
        c.write(log_filename, "other_log")  # non-default arguments
    finally:
        os.remove(log_filename)
Beispiel #11
0
def logging_test():
    "Test the PISM.logging module"
    grid = create_dummy_grid()
    pio = PISM.PIO(grid.com, "netcdf3")

    import PISM.logging as L

    pio.open("log.nc", PISM.PISM_READWRITE_MOVE)
    pio.close()
    c = L.CaptureLogger("log.nc")

    L.clear_loggers()

    L.add_logger(L.print_logger)
    L.add_logger(c)

    PISM.setVerbosityLevel(2)

    L.log("log message\n", L.kError)

    L.logError("error message\n")

    L.logWarning("warning message\n")

    L.logMessage("log message (again)\n")

    L.logDebug("debug message\n")

    L.logPrattle("prattle message\n")

    c.write()                   # default arguments
    c.readOldLog()

    pio.open("other_log.nc", PISM.PISM_READWRITE_MOVE)
    pio.close()
    c.write("other_log.nc", "other_log")  # non-default arguments