__init__ of damask package not crashing in python 2.5 if core module not available

added some Matlab-like utility functions (damask.sind, cosd, tand, acosd, ...)  that take and return degree instead of radians
This commit is contained in:
Claudio Zambaldi 2012-07-18 13:46:33 +00:00
parent ddf3fcc877
commit b2a7f85101
2 changed files with 29 additions and 2 deletions

View File

@ -9,7 +9,12 @@ from .result import Result # one class with subclasses
from .geometry import Geometry # one class with subclasses
from .solver import Solver # one class with subclasses
from .test import Test
from util import *
try:
from . import core
except Exception, e:
sys.stderr.write('\nWARNING: Core module (Fortran code) not available, try to run setup_processing.py\nError Message when importing core.so: %s\n\n'%e)
except ImportError:
sys.stderr.write('\nWARNING: Core module (Fortran code) not available, try to run setup_processing.py\nError Message when importing core.so: \n\n')
core = None # from http://www.python.org/dev/peps/pep-0008/

22
lib/damask/util.py Normal file
View File

@ -0,0 +1,22 @@
# some utility functions
import math
try:
import numpy
except:
numpy=None
for f in ['cos', 'sin', 'tan']:
exec('def %sd(deg): return ((numpy or math).%s(deg/180.*math.pi))'%(f,f))
if numpy:
exec('def a%sd(val): return (numpy.arc%s(val)*180./math.pi)'%(f,f))
else:
exec('def a%sd(val): return (math.a%s(val)*180./math.pi)'%(f,f))
# Matlab like functions to allow for cosd(degree),...
# it is open how these compare to the numpy.cos, which can operate on arrays
# ->full array compatibility can be achieved through numpy.deg2rad|rad2deg