Author: tlinnet Date: Wed Jun 11 14:05:35 2014 New Revision: 23832 URL: http://svn.gna.org/viewcvs/relax?rev=23832&view=rev Log: Changed the catching when dw is zero, to use masked array. Implemented backwards compability with unit tests. Task #7807 (https://gna.org/task/index.php?7807): Speed-up of dispersion models for Clustered analysis. Modified: branches/disp_spin_speed/lib/dispersion/cr72.py Modified: branches/disp_spin_speed/lib/dispersion/cr72.py URL: http://svn.gna.org/viewcvs/relax/branches/disp_spin_speed/lib/dispersion/cr72.py?rev=23832&r1=23831&r2=23832&view=diff ============================================================================== --- branches/disp_spin_speed/lib/dispersion/cr72.py (original) +++ branches/disp_spin_speed/lib/dispersion/cr72.py Wed Jun 11 14:05:35 2014 @@ -92,8 +92,8 @@ """ # Python module imports. -from numpy import allclose, arccosh, array, cos, cosh, isfinite, isnan, min, max, ndarray, ones, sqrt, sum, zeros -from numpy.ma import masked_greater_equal +from numpy import allclose, arccosh, array, cos, cosh, isfinite, isnan, fabs, min, max, ndarray, ones, sqrt, sum, zeros +from numpy.ma import masked_greater_equal, masked_where # Repetitive calculations (to speed up calculations). eta_scale = 2.0**(-3.0/2.0) @@ -123,6 +123,7 @@ """ # Flag to tell if values should be replaced if max_etapos in cosh function is violated. + t_dw_zero = False t_max_etapos = False # Catch parameter values that will result in no exchange, returning flat R2eff = R20 lines (when kex = 0.0, k_AB = 0.0). @@ -131,10 +132,10 @@ back_calc[:] = r20a return - # Test if dw is zero. - if allclose(dw, zeros(dw.shape)): - back_calc[:] = r20a - return + # Test if dw is zero. Wait for replacement, since this is spin specific. + if min(fabs(dw)) == 0.0: + t_dw_zero = True + mask_dw_zero = masked_where(dw == 0.0, dw) # The B population. pB = 1.0 - pA @@ -188,8 +189,19 @@ R2eff = r20_kex - cpmg_frqs * arccosh( fact ) # Replace data in array. + if t_dw_zero: + if isinstance(r20a, float): + back_calc[:] = array([r20a]*num_points) + return + else: + R2eff[mask_dw_zero.mask] = r20a[mask_dw_zero.mask] + if t_max_etapos: - R2eff[mask_max_etapos.mask] = r20a[mask_max_etapos.mask] + if isinstance(r20a, float): + back_calc[:] = array([r20a]*num_points) + return + else: + R2eff[mask_max_etapos.mask] = r20a[mask_max_etapos.mask] # Catch errors, taking a sum over array is the fastest way to check for # +/- inf (infinity) and nan (not a number).