mailr23566 - in /branches/disp_speed: lib/dispersion/ target_functions/ test_suite/unit_tests/_lib/_dispersion/


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

Header


Content

Posted by tlinnet on May 28, 2014 - 19:17:
Author: tlinnet
Date: Wed May 28 19:17:19 2014
New Revision: 23566

URL: http://svn.gna.org/viewcvs/relax?rev=23566&view=rev
Log:
Converting back to having back_calc as a function argument to model DPL94:

This is to clean up the API.
There can be bo no partial measures/implementations in the relax trunk.

The problem is, that many numerical models can't be optimised further, since 
they
evolve the spin-magnetisation in a matrix.  That spin evolvement can't be put 
into
a larger numpy array.

This is related to: task #7793: (https://gna.org/task/?7793) Speed-up of 
dispersion models.

Modified:
    branches/disp_speed/lib/dispersion/dpl94.py
    branches/disp_speed/target_functions/relax_disp.py
    branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_dpl94.py

Modified: branches/disp_speed/lib/dispersion/dpl94.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/disp_speed/lib/dispersion/dpl94.py?rev=23566&r1=23565&r2=23566&view=diff
==============================================================================
--- branches/disp_speed/lib/dispersion/dpl94.py (original)
+++ branches/disp_speed/lib/dispersion/dpl94.py Wed May 28 19:17:19 2014
@@ -66,7 +66,7 @@
 from numpy import abs, array, cos, isfinite, min, sin, sum
 
 
-def r1rho_DPL94(r1rho_prime=None, phi_ex=None, kex=None, theta=None, R1=0.0, 
spin_lock_fields2=None, num_points=None):
+def r1rho_DPL94(r1rho_prime=None, phi_ex=None, kex=None, theta=None, R1=0.0, 
spin_lock_fields2=None, back_calc=None, num_points=None):
     """Calculate the R1rho values for the DPL94 model.
 
     See the module docstring for details.
@@ -84,7 +84,9 @@
     @type R1:                   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
-    @keyword num_points:        The number of points on the dispersion 
curve, equal to the length of the spin_lock_fields.
+    @keyword back_calc:         The array for holding the back calculated 
R1rho values.  Each element corresponds to the combination of theta and spin 
lock field.
+    @type back_calc:            numpy rank-1 float array
+    @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
     """
 
@@ -101,7 +103,8 @@
     # Catch zeros (to avoid pointless mathematical operations).
     # This will result in no exchange, returning flat lines.
     if min(numer) == 0.0:
-        return R1_R2
+        back_calc[:] = R1_R2
+        return
 
     # Denominator.
     denom = kex2 + spin_lock_fields2
@@ -109,9 +112,8 @@
     # Catch math domain error of dividing with 0.
     # This is when denom =0.
     if min(abs(denom)) == 0:
-        R1rho = array([1e100]*num_points)
-
-        return R1rho
+        back_calc[:] = array([1e100]*num_points)
+        return
 
     # R1rho calculation.
     R1rho = R1_R2 + numer / denom
@@ -121,4 +123,4 @@
     if not isfinite(sum(R1rho)):
         R1rho = array([1e100]*num_points)
 
-    return R1rho
+    back_calc[:] = R1rho

Modified: branches/disp_speed/target_functions/relax_disp.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/disp_speed/target_functions/relax_disp.py?rev=23566&r1=23565&r2=23566&view=diff
==============================================================================
--- branches/disp_speed/target_functions/relax_disp.py  (original)
+++ branches/disp_speed/target_functions/relax_disp.py  Wed May 28 19:17:19 
2014
@@ -965,7 +965,7 @@
                 # Loop over the offsets.
                 for oi in range(self.num_offsets[0][si][mi]):
                     # Back calculate the R2eff values.
-                    self.back_calc[0][si][mi][oi] = 
r1rho_DPL94(r1rho_prime=R20[r20_index], phi_ex=phi_ex_scaled, kex=kex, 
theta=self.tilt_angles[0][si][mi][oi], R1=self.r1[si, mi], 
spin_lock_fields2=self.spin_lock_omega1_squared[0][mi][oi], 
num_points=self.num_disp_points[0][si][mi][oi])
+                    r1rho_DPL94(r1rho_prime=R20[r20_index], 
phi_ex=phi_ex_scaled, kex=kex, theta=self.tilt_angles[0][si][mi][oi], 
R1=self.r1[si, mi], 
spin_lock_fields2=self.spin_lock_omega1_squared[0][mi][oi], 
back_calc=self.back_calc[0][si][mi][oi], 
num_points=self.num_disp_points[0][si][mi][oi])
 
                     # For all missing data points, set the back-calculated 
value to the measured values so that it has no effect on the chi-squared 
value.
                     for di in range(self.num_disp_points[0][si][mi][oi]):

Modified: 
branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_dpl94.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_dpl94.py?rev=23566&r1=23565&r2=23566&view=diff
==============================================================================
--- branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_dpl94.py  
  (original)
+++ branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_dpl94.py  
  Wed May 28 19:17:19 2014
@@ -56,6 +56,7 @@
 
         # Required data structures.
         self.num_points = 11
+        self.R1rho = zeros(self.num_points, float64)
 
 
     def calc_r1rho(self):
@@ -65,7 +66,7 @@
         phi_ex_scaled, spin_lock_omega1_squared = 
self.param_conversion(pA=self.pA, dw=self.dw, sfrq=self.sfrq, 
spin_lock_nu1=self.spin_lock_nu1)
 
         # Calculate the R1rho values.
-        R1rho = r1rho_DPL94(r1rho_prime=self.r1rho_prime, 
phi_ex=phi_ex_scaled, kex=self.kex, theta=self.theta, R1=self.r1, 
spin_lock_fields2=spin_lock_omega1_squared, num_points=self.num_points)
+        r1rho_DPL94(r1rho_prime=self.r1rho_prime, phi_ex=phi_ex_scaled, 
kex=self.kex, theta=self.theta, R1=self.r1, 
spin_lock_fields2=spin_lock_omega1_squared, back_calc=self.R1rho, 
num_points=self.num_points)
 
         # Compare to function value.
         r1rho_no_rex = self.r1 * cos(self.theta)**2 + self.r1rho_prime * 
sin(self.theta)**2
@@ -73,10 +74,10 @@
         # Check all R1rho values.
         if self.kex > 1.e5:
             for i in range(self.num_points):
-                self.assertAlmostEqual(R1rho[i], r1rho_no_rex[i], 2)
+                self.assertAlmostEqual(self.R1rho[i], r1rho_no_rex[i], 2)
         else:
             for i in range(self.num_points):
-                self.assertAlmostEqual(R1rho[i], r1rho_no_rex[i])
+                self.assertAlmostEqual(self.R1rho[i], r1rho_no_rex[i])
 
 
     def param_conversion(self, pA=None, dw=None, sfrq=None, 
spin_lock_nu1=None):




Related Messages


Powered by MHonArc, Updated Wed May 28 19:20:03 2014