Author: tlinnet Date: Thu May 29 11:29:25 2014 New Revision: 23581 URL: http://svn.gna.org/viewcvs/relax?rev=23581&view=rev Log: Converting back to having back_calc as a function argument to model M61: 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/m61.py branches/disp_speed/target_functions/relax_disp.py branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_m61.py Modified: branches/disp_speed/lib/dispersion/m61.py URL: http://svn.gna.org/viewcvs/relax/branches/disp_speed/lib/dispersion/m61.py?rev=23581&r1=23580&r2=23581&view=diff ============================================================================== --- branches/disp_speed/lib/dispersion/m61.py (original) +++ branches/disp_speed/lib/dispersion/m61.py Thu May 29 11:29:25 2014 @@ -67,7 +67,7 @@ from numpy import abs, array, isfinite, min, sum -def r1rho_M61(r1rho_prime=None, phi_ex=None, kex=None, spin_lock_fields2=None, num_points=None): +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. See the module docstring for details. @@ -81,7 +81,9 @@ @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 - @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 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 """ @@ -94,7 +96,8 @@ # Catch zeros (to avoid pointless mathematical operations). # This will result in no exchange, returning flat lines. if numer == 0.0: - return array([r1rho_prime]*num_points) + back_calc[:] = array([r1rho_prime]*num_points) + return # Denominator. denom = kex2 + spin_lock_fields2 @@ -102,7 +105,8 @@ # Catch math domain error of dividing with 0. # This is when denom=0. if min(abs(denom)) == 0: - return array([1e100]*num_points) + back_calc[:] = array([1e100]*num_points) + return # R1rho calculation. R1rho = r1rho_prime + numer / denom @@ -110,6 +114,6 @@ # 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)): - return array([1e100]*num_points) + 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=23581&r1=23580&r2=23581&view=diff ============================================================================== --- branches/disp_speed/target_functions/relax_disp.py (original) +++ branches/disp_speed/target_functions/relax_disp.py Thu May 29 11:29:25 2014 @@ -1163,7 +1163,7 @@ phi_ex_scaled = phi_ex[si] * self.frqs[0][si][mi]**2 # Back calculate the R2eff values. - self.back_calc[0][si][mi][0] = r1rho_M61(r1rho_prime=R20[r20_index], phi_ex=phi_ex_scaled, kex=kex, spin_lock_fields2=self.spin_lock_omega1_squared[0][mi][0], num_points=self.num_disp_points[0][si][mi][0]) + r1rho_M61(r1rho_prime=R20[r20_index], phi_ex=phi_ex_scaled, kex=kex, spin_lock_fields2=self.spin_lock_omega1_squared[0][mi][0], back_calc=self.back_calc[0][si][mi][0], num_points=self.num_disp_points[0][si][mi][0]) # 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][0]): Modified: branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_m61.py URL: http://svn.gna.org/viewcvs/relax/branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_m61.py?rev=23581&r1=23580&r2=23581&view=diff ============================================================================== --- branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_m61.py (original) +++ branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_m61.py Thu May 29 11:29:25 2014 @@ -53,6 +53,7 @@ # Required data structures. self.num_points = 11 + self.R1rho = zeros(self.num_points, float64) def calc_r1rho(self): @@ -62,16 +63,16 @@ 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_M61(r1rho_prime=self.r1rho_prime, phi_ex=phi_ex_scaled, kex=self.kex, spin_lock_fields2=spin_lock_omega1_squared, num_points=self.num_points) + r1rho_M61(r1rho_prime=self.r1rho_prime, phi_ex=phi_ex_scaled, kex=self.kex, spin_lock_fields2=spin_lock_omega1_squared, back_calc=self.R1rho, num_points=self.num_points) # Check all R1rho values. if self.kex > 1.e5: for i in range(self.num_points): - self.assertAlmostEqual(R1rho[i], self.r1rho_prime, 2) + self.assertAlmostEqual(self.R1rho[i], self.r1rho_prime, 2) else: for i in range(self.num_points): - self.assertAlmostEqual(R1rho[i], self.r1rho_prime) + self.assertAlmostEqual(self.R1rho[i], self.r1rho_prime) def param_conversion(self, pA=None, dw=None, sfrq=None, spin_lock_nu1=None):