Author: tlinnet Date: Wed May 21 13:03:07 2014 New Revision: 23303 URL: http://svn.gna.org/viewcvs/relax?rev=23303&view=rev Log: Align math-domain catching for model TSMFK01 with trunk implementation. task #7793: (https://gna.org/task/?7793) Speed-up of dispersion models. This is to implement catching of math domain errors, before they occur. The catching of errors have to be more careful. Modified: branches/disp_speed/lib/dispersion/tsmfk01.py Modified: branches/disp_speed/lib/dispersion/tsmfk01.py URL: http://svn.gna.org/viewcvs/relax/branches/disp_speed/lib/dispersion/tsmfk01.py?rev=23303&r1=23302&r2=23303&view=diff ============================================================================== --- branches/disp_speed/lib/dispersion/tsmfk01.py (original) +++ branches/disp_speed/lib/dispersion/tsmfk01.py Wed May 21 13:03:07 2014 @@ -67,7 +67,7 @@ """ # Python module imports. -from numpy import abs, array, min, sin, isfinite, sum +from numpy import array, min, sin, isfinite, sum def r2eff_TSMFK01(r20a=None, dw=None, k_AB=None, tcp=None, num_points=None): @@ -91,15 +91,18 @@ # Denominator. denom = dw * tcp - # Catch math domain error of dividing with 0. - # This is when sin(0). - if min(abs(denom)) == 0: - R2eff = array([1e100]*num_points) - - return R2eff - # The numerator. numer = sin(denom) + + # Catch zeros (to avoid pointless mathematical operations). + # This will result in no exchange, returning flat lines. + if min(numer) == 0.0: + return r20a + k_AB + + # Catch math domain error of dividing with 0. + # This is when sin(denom) = 0. + if min(denom) == 0.0: + return array([1e100]*num_points) # Calculate R2eff. R2eff = r20a + k_AB - k_AB * numer / denom