middle of refactor
This commit is contained in:
parent
431f3a4e44
commit
eadfa46e57
@ -1,10 +1,9 @@
|
||||
from baker import *
|
||||
from baker.tools import smblog
|
||||
import numpy as np
|
||||
import sys
|
||||
|
||||
import numpy as np
|
||||
|
||||
import itertools
|
||||
from tools import smberror
|
||||
from interp.tools import log, smberror
|
||||
|
||||
def get_phis(X, R):
|
||||
"""
|
||||
@ -32,7 +31,7 @@ def get_phis(X, R):
|
||||
phi = np.linalg.solve(A,b)
|
||||
except np.linalg.LinAlgError as e:
|
||||
msg = "calculation of phis yielded a linearly dependant system (%s)" % e
|
||||
smblog.error(msg)
|
||||
log.error(msg)
|
||||
raise smberror(msg)
|
||||
phi = np.dot(np.linalg.pinv(A), b)
|
||||
|
||||
@ -70,7 +69,7 @@ def get_phis_3D(X, R):
|
||||
try:
|
||||
phi = np.linalg.solve(A,b)
|
||||
except np.linalg.LinAlgError as e:
|
||||
smblog.error("calculation of phis yielded a linearly dependant system: %s" % e)
|
||||
log.error("calculation of phis yielded a linearly dependant system: %s" % e)
|
||||
phi = np.dot(np.linalg.pinv(A), b)
|
||||
|
||||
return phi
|
||||
@ -131,7 +130,7 @@ def get_error_quadratic(phi, R, S):
|
||||
try:
|
||||
(a, b, c) = np.linalg.solve(A,b)
|
||||
except np.linalg.LinAlgError as e:
|
||||
smblog.error("linear calculation went bad, resorting to np.linalg.pinv: %s" % e)
|
||||
log.error("linear calculation went bad, resorting to np.linalg.pinv: %s" % e)
|
||||
(a, b, c) = np.dot(np.linalg.pinv(A), b)
|
||||
|
||||
error_term = a * phi[0] * phi[1]\
|
||||
@ -172,7 +171,7 @@ def get_error_cubic(phi, R, S):
|
||||
try:
|
||||
(a, b, c, d, e, f, g) = np.linalg.solve(A,b)
|
||||
except np.linalg.LinAlgError as e:
|
||||
smblog.error("linear calculation went bad, resorting to np.linalg.pinv: %s" % e)
|
||||
log.error("linear calculation went bad, resorting to np.linalg.pinv: %s" % e)
|
||||
(a, b, c, d, e, f, g) = np.dot(np.linalg.pinv(A), b)
|
||||
|
||||
error_term = a * phi[0] * phi[1] * phi[1]\
|
||||
@ -186,12 +185,12 @@ def get_error_cubic(phi, R, S):
|
||||
return error_term
|
||||
|
||||
def get_error_sauron(phi, R, S, order = 2):
|
||||
smblog.debug("len(phi): %d"% len(phi))
|
||||
log.debug("len(phi): %d"% len(phi))
|
||||
B = [] # baker eq 9
|
||||
w = [] # baker eq 11
|
||||
|
||||
p = pattern(order, len(phi), offset = -1)
|
||||
smblog.debug("pattern: %s" % p)
|
||||
log.debug("pattern: %s" % p)
|
||||
|
||||
for (s,q) in zip(S.points, S.q):
|
||||
cur_phi, cur_qlin = qlinear(s, R)
|
||||
@ -205,8 +204,8 @@ def get_error_sauron(phi, R, S, order = 2):
|
||||
B.append(l)
|
||||
w.append(q - cur_qlin)
|
||||
|
||||
smblog.debug("B: %s" % B)
|
||||
smblog.debug("w: %s" % w)
|
||||
log.debug("B: %s" % B)
|
||||
log.debug("w: %s" % w)
|
||||
|
||||
|
||||
B = np.array(B)
|
||||
@ -219,10 +218,10 @@ def get_error_sauron(phi, R, S, order = 2):
|
||||
try:
|
||||
abc = np.linalg.solve(A,b)
|
||||
except np.linalg.LinAlgError as e:
|
||||
smblog.error("linear calculation went bad, resorting to np.linalg.pinv: %s" % e)
|
||||
log.error("linear calculation went bad, resorting to np.linalg.pinv: %s" % e)
|
||||
abc = np.dot(np.linalg.pinv(A), b)
|
||||
|
||||
smblog.debug(len(abc) == len(p))
|
||||
log.debug(len(abc) == len(p))
|
||||
|
||||
error_term = 0.0
|
||||
for (a, i) in zip(abc, p):
|
||||
@ -231,7 +230,7 @@ def get_error_sauron(phi, R, S, order = 2):
|
||||
cur_sum *= phi[j]
|
||||
error_term += cur_sum
|
||||
|
||||
smblog.debug("error_term smb: %s" % error_term)
|
||||
log.debug("error_term smb: %s" % error_term)
|
||||
return error_term, abc
|
||||
|
||||
def run_baker(X, R, S, order=2):
|
||||
@ -244,7 +243,7 @@ def run_baker(X, R, S, order=2):
|
||||
R = Simplex
|
||||
S = extra points
|
||||
"""
|
||||
smblog.debug("order = %d" % order)
|
||||
log.debug("order = %d" % order)
|
||||
|
||||
answer = {
|
||||
'qlin': None,
|
||||
@ -328,7 +327,7 @@ def run_baker_3D(X, R, S):
|
||||
try:
|
||||
(a, b, c, d, e, f) = np.linalg.solve(A,b)
|
||||
except np.linalg.LinAlgError as e:
|
||||
smblog.error("linear calculation went bad, resorting to np.linalg.pinv: %s", e)
|
||||
log.error("linear calculation went bad, resorting to np.linalg.pinv: %s", e)
|
||||
(a, b, c, d, e, f) = np.dot(np.linalg.pinv(A), b)
|
||||
|
||||
error_term = a * phi[0] * phi[1]\
|
||||
@ -374,7 +373,7 @@ def _samples_ur(items, k, offset = 0):
|
||||
yield tuple([x + offset for sel in selections for x in sel])
|
||||
|
||||
def pattern(power, phicount, offset = 0):
|
||||
smblog.debug("(power = %s, phicount = %s)" % (power, phicount))
|
||||
log.debug("(power = %s, phicount = %s)" % (power, phicount))
|
||||
r = []
|
||||
for i in _samples_ur(range(1, phicount + 1), power, offset):
|
||||
if not len(set(i)) == 1:
|
||||
|
@ -6,8 +6,8 @@ import inspect
|
||||
import numpy as np
|
||||
import scipy.spatial
|
||||
|
||||
from baker import run_baker
|
||||
from baker.tools import exact_func, smberror, smblog
|
||||
from interp.baker import run_baker
|
||||
from interp.tools import exact_func, smberror, log
|
||||
from simplex import face, contains
|
||||
from smcqdelaunay import *
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
from baker import get_phis, get_phis_3D
|
||||
from baker.tools import smblog
|
||||
from interp.baker import get_phis, get_phis_3D
|
||||
from interp.tools import log
|
||||
|
||||
TOL = 1e-8
|
||||
|
||||
|
@ -1,36 +1,36 @@
|
||||
import os
|
||||
|
||||
import logging
|
||||
import logging.handlers
|
||||
|
||||
import inspect
|
||||
import numpy as np
|
||||
|
||||
|
||||
class smbLog(object):
|
||||
interpolator = "%s ==> %s"
|
||||
def __init__(self, level = logging.DEBUG):
|
||||
logging.basicConfig(
|
||||
level = level,
|
||||
format = '%(asctime)s %(levelname)s %(message)s',
|
||||
filename = os.path.join(os.sep, 'tmp', 'baker.lol'),
|
||||
)
|
||||
self.log = logging.getLogger()
|
||||
def debug(self, message = None):
|
||||
msg = smbLog.interpolator % (inspect.stack()[1][3], message)
|
||||
self.log.debug(msg)
|
||||
def get_logger(filename, level = logging.DEBUG, logger_name = 'pymoab', size = 2048, backupCount = 10):
|
||||
"""
|
||||
This is a simple wrapper around a few sane
|
||||
defaults using Python's logging functionality.
|
||||
|
||||
def info(self, message = None):
|
||||
msg = smbLog.interpolator % (inspect.stack()[1][3], message)
|
||||
self.log.info(msg)
|
||||
An explaination of the optional parameters:
|
||||
filename : the filename
|
||||
level : one of either debug, info, warn, or error
|
||||
logger_name : if one needs multiple logfiles, one must name them.
|
||||
size : the size in bytes of the logfile before roll (defaults to 2MB)
|
||||
backupCount : number of rolled logs to keep around (defaults to 10)
|
||||
"""
|
||||
|
||||
def warn(self, message = None):
|
||||
msg = smbLog.interpolator % (inspect.stack()[1][3], message)
|
||||
self.log.warn(msg)
|
||||
logger = logging.getLogger(logger_name)
|
||||
logger.setLevel(level)
|
||||
my_format = logging.Formatter('%(asctime)s %(levelname)s (%(process)d) %(filename)s %(funcName)s:%(lineno)d %(message)s')
|
||||
handler = logging.handlers.RotatingFileHandler(
|
||||
filename, maxBytes = size * 1024, backupCount = backupCount)
|
||||
handler.setFormatter(my_format)
|
||||
logger.addHandler(handler)
|
||||
|
||||
def error(self, message = None):
|
||||
msg = smbLog.interpolator % (inspect.stack()[1][3], message)
|
||||
self.log.error(msg)
|
||||
return logger
|
||||
|
||||
|
||||
smblog = smbLog(logging.DEBUG)
|
||||
log = get_logger(filename = '/tmp/interp.log')
|
||||
|
||||
class smberror(Exception):
|
||||
"""
|
||||
|
@ -1,8 +1,9 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import unittest
|
||||
from interplosion import baker
|
||||
from interplosion import grid
|
||||
|
||||
from interp import baker
|
||||
from interp import grid
|
||||
|
||||
import numpy as np
|
||||
import scipy.spatial
|
||||
@ -28,8 +29,8 @@ class TestSequenceFunctions(unittest.TestCase):
|
||||
def testImports(self):
|
||||
import numpy
|
||||
import scipy
|
||||
import grid
|
||||
import baker
|
||||
import interp.grid
|
||||
import interp.baker
|
||||
|
||||
def testGetPhis(self):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user