polishing, and using numpy's deg2rad/rad2deg

This commit is contained in:
Claudio Zambaldi 2012-07-19 16:05:05 +00:00
parent 7d4ff278cb
commit 9078d70af0
1 changed files with 5 additions and 11 deletions

View File

@ -1,22 +1,16 @@
# some utility functions
# damask utility functions
import math
try:
import numpy
except:
numpy=None
# Matlab like trigonometric functions that take and return angles in degrees.
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))
exec('def %sd(deg): return (numpy.%s(numpy.deg2rad(deg)))'%(f,f))
exec('def a%sd(val): return (numpy.rad2deg(numpy.arc%s(val)))'%(f,f))
else:
exec('def %sd(deg): return (math.%s(deg/180.*math.pi))'%(f,f))
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