Skip to content

Commit

Permalink
#14 more logging
Browse files Browse the repository at this point in the history
  • Loading branch information
carsten-forty2 committed Jan 7, 2018
1 parent 049ddf7 commit 9ee5a5a
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 77 deletions.
45 changes: 41 additions & 4 deletions python/pygimli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import locale
import sys


def checkAndFixLocaleDecimal_point(verbose=False):
"""
"""
Expand Down Expand Up @@ -59,19 +60,55 @@ def checkAndFixLocaleDecimal_point(verbose=False):
from .core import *
from .testing import test

import logging

logger = logging.getLogger('pyGIMLi')

def setDebug(d):
if d:
core._pygimli_.setDebug(True)
logger.setLevel(logging.DEBUG)
logging.getLogger('Core').setLevel(logging.DEBUG)
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
datefmt='%m/%d/%Y %H:%M:%S',
#filename='pygimli.log'
)
logger.debug("Set debug mode: on")
else:
core._pygimli_.setDebug(False)
logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
datefmt='%m/%d/%Y %H:%M:%S',
#filename='pygimli.log'
)
logger.debug("Set debug mode: off")
logging.getLogger('Core').setLevel(logging.INFO)
logger.setLevel(logging.INFO)

if '--debug' in sys.argv:
print("set debug mode")
core._pygimli_.setDebug(True)
setDebug(True)
else:
setDebug(False)


def deprecated(msg, hint):
logger.warn(msg + ", is deprecated, use:" + hint + " instead.")

def renameKWarg(old, new, kwargs):
if old in kwargs:
logger.warn("Keyword argument name changed from '" + old + \
"' to '" + new + "'")
kwargs[new] = kwargs.pop(old)

def warnNonEmptyArgs(kwargs):
if len(kwargs) > 0:
print("Warning! unrecognized keyword arguments", kwargs)
logger.warn("unrecognized keyword arguments", kwargs)

__version__ = get_versions()['version']
del get_versions

def version():
"""Shortcut to show and return current version."""
print(__version__, "core:", pg.versionStr())
logger.info('Version: ' + __version__ + " core:" + pg.versionStr())
return __version__
21 changes: 14 additions & 7 deletions python/pygimli/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,16 @@ def RVector_str(self, valsOnly=False):
" [" + str(self[0]) + ",...," + str(self[self.size() - 1]) + "]"
)


def RVector3_str(self):
return("RVector3: (" + str(self.x()) + ", " +
str(self.y()) + ", " + str(self.z()) + ")")


def R3Vector_str(self):
return "R3Vector: n=" + str(self.size())


def RMatrix_str(self):
s = "RMatrix: " + str(self.rows()) + " x " + str(self.cols())

Expand All @@ -114,6 +117,7 @@ def RMatrix_str(self):
s += self[v].__str__(True) + '\n'
return s


def CMatrix_str(self):
s = "CMatrix: " + str(self.rows()) + " x " + str(self.cols())

Expand All @@ -123,21 +127,26 @@ def CMatrix_str(self):
s += self[v].__str__(True) + '\n'
return s


def Line_str(self):
return "Line: " + str(self.p0()) + " " + str(self.p1())


def Mesh_str(self):
return ("Mesh: Nodes: " + str(self.nodeCount()) + " Cells: " +
str(self.cellCount()) + " Boundaries: " +
str(self.boundaryCount()))


def Data_str(self):
return (
"Data: Sensors: " +
str(self.sensorCount()) + " data: " + str(self.size())
)


def ElementMatrix_str(self):

s = ''
for i in range(self.size()):
s += str(self.idx(i)) + "\t: "
Expand All @@ -157,6 +166,7 @@ def MeshEntity_str(self):
s += '\t' + str(n.id()) + " " + str(n.pos()) + "\n"
return s


_pygimli_.RVector.__str__ = RVector_str
_pygimli_.CVector.__str__ = RVector_str
_pygimli_.BVector.__str__ = RVector_str
Expand All @@ -175,8 +185,6 @@ def MeshEntity_str(self):
# _pygimli_.stdVectorIndex.size = _pygimli_.stdVectorIndex.__len__
# _pygimli_.stdVectorIndex.__str__ = RVector_str



############################
# compatibility stuff
############################
Expand All @@ -188,8 +196,12 @@ def nonzero_test(self):
"Use binary operators '&' or '|' instead. " +
"If you looking for the nonzero test, use len(v) > 0")

def np_round__(self, r):
return np.round(self.array(), r)

_pygimli_.RVector.__nonzero__ = nonzero_test
_pygimli_.RVector.__bool__ = nonzero_test
_pygimli_.RVector.__round__ = np_round__
_pygimli_.R3Vector.__nonzero__ = nonzero_test
_pygimli_.R3Vector.__bool__ = nonzero_test
_pygimli_.BVector.__nonzero__ = nonzero_test
Expand Down Expand Up @@ -982,11 +994,6 @@ def __init__(self, mesh=None, dataContainer=None, verbose=False):
# some backward compatibility
############################


def deprecated(msg, hint):
print("Warning! " + msg + ", is deprecated, use:" + hint + " instead.")


def __MeshGetCellMarker__(self):
deprecated(msg='Mesh::cellMarker()', hint='Mesh::cellMarkers()')
return self.cellMarkers()
Expand Down
9 changes: 5 additions & 4 deletions python/pygimli/mplviewer/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@

from pygimli.mplviewer import saveFigure, updateAxes


cdict = {'red': ((0.0, 0.0, 0.0), (0.5, 1.0, 1.0), (1.0, 1.0, 1.0)),
'green': ((0.0, 0.0, 0.0), (0.5, 1.0, 1.0), (1.0, 0.0, 0.0)),
'blue': ((0.0, 1.0, 1.0), (0.5, 1.0, 1.0), (1.0, 0.0, 0.0))}

blueRedCMap = mpl.colors.LinearSegmentedColormap('my_colormap', cdict, 256)


def autolevel(z, nLevs, logscale=None, zmin=None, zmax=None):
"""Create N levels for the data array z based on matplotlib ticker.
Examples
--------
>>> import numpy as np
>>> from pygimli.mplviewer import autolevel
>>> x = np.linspace(1,10,100)
>>> x = np.linspace(1, 10, 100)
>>> autolevel(x, 3)
array([ 0. , 2.5, 5. , 7.5, 10. ])
>>> autolevel(x, 3, logscale=True)
Expand All @@ -40,11 +40,12 @@ def autolevel(z, nLevs, logscale=None, zmin=None, zmax=None):
locator = ticker.MaxNLocator(nLevs + 1)

if zmin is None:
zmin = min(z)
zmin = min(round(z, 4))

if zmax is None:
zmax = max(z)
zmax = max(round(z, 4))

print("autolevel", zmin, zmax)
return locator.tick_values(zmin, zmax)


Expand Down
2 changes: 2 additions & 0 deletions python/pygimli/mplviewer/meshview.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def __init__(self, mesh, data=None, ax=None):
fontsize=mpl.rcParams['font.size'] - 2,
weight='bold', xytext=(50, 20), arrowprops=arrowprops,
textcoords='offset points', bbox=bbox, va='center')

self.text = self.ax.annotate(None, xy=(0, 0), **kwargs)

def connect(self):
Expand Down Expand Up @@ -740,6 +741,7 @@ def drawMPLTri(ax, mesh, data=None, cMin=None, cMax=None,
if len(levels) == 0:
levels = autolevel(data, nLevs, zmin=cMin, zmax=cMax)

print("drawMPLTri:", nLevs, levels)
if interpolate and len(data) == mesh.cellCount():
z = pg.meshtools.cellDataToNodeData(mesh, data)

Expand Down
Loading

0 comments on commit 9ee5a5a

Please sign in to comment.