mailr23910 - /branches/disp_spin_speed/lib/dispersion/m61.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by tlinnet on June 13, 2014 - 10:33:
Author: tlinnet
Date: Fri Jun 13 10:33:43 2014
New Revision: 23910

URL: http://svn.gna.org/viewcvs/relax?rev=23910&view=rev
Log:
Methods to replace math domain errors in model M61, has been replaced with 
numpy masks.

Documentation is also fixed.

Task #7807 (https://gna.org/task/index.php?7807): Speed-up of dispersion 
models for Clustered analysis.

Modified:
    branches/disp_spin_speed/lib/dispersion/m61.py

Modified: branches/disp_spin_speed/lib/dispersion/m61.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/disp_spin_speed/lib/dispersion/m61.py?rev=23910&r1=23909&r2=23910&view=diff
==============================================================================
--- branches/disp_spin_speed/lib/dispersion/m61.py      (original)
+++ branches/disp_spin_speed/lib/dispersion/m61.py      Fri Jun 13 10:33:43 
2014
@@ -64,8 +64,8 @@
 """
 
 # Python module imports.
-from numpy import abs, array, isfinite, min, sum
-
+from numpy import abs, any, array, isfinite, min, sum
+from numpy.ma import fix_invalid, masked_where
 
 def r1rho_M61(r1rho_prime=None, phi_ex=None, kex=None, 
spin_lock_fields2=None, back_calc=None, num_points=None):
     """Calculate the R2eff values for the M61 model.
@@ -74,18 +74,22 @@
 
 
     @keyword r1rho_prime:       The R1rho_prime parameter value (R1rho with 
no exchange).
-    @type r1rho_prime:          float
+    @type r1rho_prime:          numpy float array of rank 
[NE][NS][[NM][NO][ND]
     @keyword phi_ex:            The phi_ex parameter value (pA * pB * 
delta_omega^2).
-    @type phi_ex:               float
+    @type phi_ex:               numpy float array of rank 
[NE][NS][[NM][NO][ND]
     @keyword kex:               The kex parameter value (the exchange rate 
in rad/s).
     @type kex:                  float
     @keyword spin_lock_fields2: The R1rho spin-lock field strengths squared 
(in rad^2.s^-2).
-    @type spin_lock_fields2:    numpy rank-1 float array
+    @type spin_lock_fields2:    numpy float array of rank 
[NE][NS][[NM][NO][ND]
     @keyword back_calc:         The array for holding the back calculated 
R1rho values.  Each element corresponds to the combination of spin lock field.
-    @type back_calc:            numpy rank-1 float array
+    @type back_calc:            numpy float array of rank 
[NE][NS][[NM][NO][ND]
     @keyword num_points:        The number of points on the dispersion 
curve, equal to the length of the spin_lock_fields and back_calc arguments.
-    @type num_points:           int
+    @type num_points:           numpy int array of rank [NE][NS][[NM][NO][ND]
     """
+
+    # Flag to tell if values should be replaced if numer is zero.
+    t_numer_zero = False
+    t_denom_zero = False
 
     # Repetitive calculations (to speed up calculations).
     kex2 = kex**2
@@ -95,25 +99,34 @@
 
     # Catch zeros (to avoid pointless mathematical operations).
     # This will result in no exchange, returning flat lines.
-    if numer == 0.0:
-        back_calc[:] = array([r1rho_prime]*num_points)
-        return
+    if min(numer) == 0.0:
+        t_numer_zero = True
+        mask_numer_zero = masked_where(numer == 0.0, numer)
 
     # Denominator.
     denom = kex2 + spin_lock_fields2
 
     # Catch math domain error of dividing with 0.
     # This is when denom=0.
-    if min(abs(denom)) == 0:
-        back_calc[:] = array([1e100]*num_points)
-        return
+    mask_denom_zero = denom == 0.0
+    if any(mask_denom_zero):
+        t_denom_zero = True
+        denom[mask_denom_zero] = 1.0
 
     # R1rho calculation.
-    R1rho = r1rho_prime + numer / denom
+    back_calc[:] = r1rho_prime + numer / denom
+
+    # Replace data in array.
+    # If numer is zero.
+    if t_numer_zero:
+        back_calc[mask_numer_zero.mask] = r1rho_prime[mask_numer_zero.mask]
+
+    # If denom is zero.
+    if t_denom_zero:
+        back_calc[mask_denom_zero] = 1e100
 
     # Catch errors, taking a sum over array is the fastest way to check for
     # +/- inf (infinity) and nan (not a number).
-    if not isfinite(sum(R1rho)):
-        R1rho = array([1e100]*num_points)
-
-    back_calc[:] = R1rho
+    if not isfinite(sum(back_calc)):
+        # Replaces nan, inf, etc. with fill value.
+        fix_invalid(back_calc, copy=False, fill_value=1e100)




Related Messages


Powered by MHonArc, Updated Fri Jun 13 10:40:02 2014