Author: bugman Date: Mon Feb 24 14:58:10 2014 New Revision: 22286 URL: http://svn.gna.org/viewcvs/relax?rev=22286&view=rev Log: Merged revisions 22283-22285 via svnmerge from svn+ssh://bugman@xxxxxxxxxxx/svn/relax/trunk ........ r22283 | tlinnet | 2014-02-24 14:20:41 +0100 (Mon, 24 Feb 2014) | 7 lines Added unit test for looping over: exp, frq, offset, point, time. Regarding bug #21665, (https://gna.org/bugs/?21665) - Running a CPMG analysis with two fields at two delay times. This unit test will fail, since the last loop over the time points has a weak assumption just to loop over all time points, instead of checking for existence of such time point. This unit test follows recommendation in thread: http://thread.gmane.org/gmane.science.nmr.relax.devel/5070. ........ r22284 | tlinnet | 2014-02-24 14:20:43 +0100 (Mon, 24 Feb 2014) | 3 lines Expanded the loop_time function to optional take the spectrometer frequency as input for restricting looping. Regarding bug #21665, (https://gna.org/bugs/?21665) - Running a CPMG analysis with two fields at two delay times. ........ r22285 | tlinnet | 2014-02-24 14:20:45 +0100 (Mon, 24 Feb 2014) | 3 lines Replaced print commands to be compatible with Python 3.x Regarding bug #21665, (https://gna.org/bugs/?21665) - Running a CPMG analysis with two fields at two delay times. ........ Modified: branches/double_rotor/ (props changed) branches/double_rotor/specific_analyses/relax_disp/disp_data.py branches/double_rotor/test_suite/unit_tests/_specific_analyses/_relax_disp/test_disp_data.py Propchange: branches/double_rotor/ ------------------------------------------------------------------------------ --- svnmerge-integrated (original) +++ svnmerge-integrated Mon Feb 24 14:58:10 2014 @@ -1,1 +1,1 @@ -/trunk:1-22281 +/trunk:1-22285 Modified: branches/double_rotor/specific_analyses/relax_disp/disp_data.py URL: http://svn.gna.org/viewcvs/relax/branches/double_rotor/specific_analyses/relax_disp/disp_data.py?rev=22286&r1=22285&r2=22286&view=diff ============================================================================== --- branches/double_rotor/specific_analyses/relax_disp/disp_data.py (original) +++ branches/double_rotor/specific_analyses/relax_disp/disp_data.py Mon Feb 24 14:58:10 2014 @@ -873,7 +873,7 @@ # Then the dispersion points. for point, di in loop_point(exp_type=exp_type, frq=frq, offset=offset, return_indices=True): # Finally the relaxation times. - for time, ti in loop_time(return_indices=True): + for time, ti in loop_time(frq=frq, return_indices=True): # Yield the data. if return_indices: yield exp_type, frq, offset, point, time, ei, mi, oi, di, ti @@ -1281,9 +1281,13 @@ yield id -def loop_time(return_indices=False): +def loop_time(exp_type=None, frq=None, return_indices=False): """Generator method for looping over the relaxation times. + @keyword exp_type: The experiment type. + @type exp_type: str + @keyword frq: The spectrometer frequency in Hz. + @type frq: float @keyword return_indices: A flag which if True will cause the relaxation time index to be returned as well. @type return_indices: bool @return: The relaxation time. @@ -1296,6 +1300,28 @@ # Loop over the time points. if hasattr(cdp, 'relax_time_list'): for time in cdp.relax_time_list: + # Find a matching experiment ID. + found = False + for id in cdp.exp_type.keys(): + # Skip non-matching experiments. + if exp_type != None and cdp.exp_type[id] != exp_type: + continue + + # Skip non-matching spectrometer frequencies. + if frq != None and hasattr(cdp, 'spectrometer_frq') and cdp.spectrometer_frq[id] != frq: + continue + + if time != cdp.relax_times[id]: + continue + + # Found. + found = True + break + + # No data. + if not found: + continue + # Increment the index. ti += 1 Modified: branches/double_rotor/test_suite/unit_tests/_specific_analyses/_relax_disp/test_disp_data.py URL: http://svn.gna.org/viewcvs/relax/branches/double_rotor/test_suite/unit_tests/_specific_analyses/_relax_disp/test_disp_data.py?rev=22286&r1=22285&r2=22286&view=diff ============================================================================== --- branches/double_rotor/test_suite/unit_tests/_specific_analyses/_relax_disp/test_disp_data.py (original) +++ branches/double_rotor/test_suite/unit_tests/_specific_analyses/_relax_disp/test_disp_data.py Mon Feb 24 14:58:10 2014 @@ -66,7 +66,7 @@ print("Checking the number of iterations of the loop.") count = 0 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): - print exp_type, frq, ei, mi + print(exp_type, frq, ei, mi) count += 1 self.assertEqual(count, 2) @@ -112,7 +112,7 @@ print("Checking the number of iterations of the loop.") count = 0 for exp_type, frq, offset, ei, mi, oi in loop_exp_frq_offset(return_indices=True): - print exp_type, frq, offset, ei, mi, oi + print(exp_type, frq, offset, ei, mi, oi) count += 1 self.assertEqual(count, 2) @@ -162,7 +162,7 @@ print("Checking the number of iterations of the loop.") count = 0 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): - print exp_type, frq, offset, point, ei, mi, oi, di + print(exp_type, frq, offset, point, ei, mi, oi, di) count += 1 self.assertEqual(count, 34) @@ -186,6 +186,69 @@ # Check the dispersion point info. self.assertAlmostEqual(point, data[frq_index][3][disp_index],2) self.assertEqual(di, indices[frq_index][3][disp_index]) + + # Increment the data index. + if disp_index == 16: + frq_index += 1 + disp_index = 0 + else: + disp_index += 1 + + + def test_loop_exp_frq_offset_point_time(self): + """Unit test of the loop_exp_frq_offset_point_time() function. + + This uses the data of the saved state attached to U{bug #21665<https://gna.org/bugs/?21665>}. + """ + + # Load the state. + statefile = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2' + state.load_state(statefile, force=True) + + # Original data (exp_type, frq, offset, point). + data = [ + ['SQ CPMG', 499862140.0, 0, [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 450.0, 500.0, 550.0, 600.0, 650.0, 700.0, 800.0, 900.0, 1000.0],0.04], + ['SQ CPMG', 599890858.69999993, 0, [33.3333, 66.666, 100.0, 133.333, 166.666, 200.0, 233.333, 266.666, 300.0, 333.333, 366.666, 400.0, 466.666, 533.333, 666.666, 866.666, 1000.0],0.06] + ] + + # Original indices (ei, mi, oi). + indices = [ + [0, 0, 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], 0], + [0, 1, 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], 1] + ] + + # Check the number of iterations. + print("Checking the number of iterations of the loop.") + count = 0 + for exp_type, frq, offset, point, time, ei, mi, oi, di, ti in loop_exp_frq_offset_point_time(return_indices=True): + print(exp_type, frq, offset, point, time, ei, mi, oi, di, ti) + count += 1 + self.assertEqual(count, 34) + + # Check the values. + print("Checking the values returned by the loop.") + frq_index = 0 + disp_index = 0 + for exp_type, frq, offset, point, time, ei, mi, oi, di, ti in loop_exp_frq_offset_point_time(return_indices=True): + # Check the experiment info. + self.assertEqual(exp_type, data[frq_index][0]) + self.assertEqual(ei, indices[frq_index][0]) + + # Check the frequency info. + self.assertEqual(frq, data[frq_index][1]) + self.assertEqual(mi, indices[frq_index][1]) + + # Check the offset info. + self.assertEqual(offset, data[frq_index][2]) + self.assertEqual(oi, indices[frq_index][2]) + + # Check the dispersion point info. + self.assertAlmostEqual(point, data[frq_index][3][disp_index],2) + self.assertEqual(di, indices[frq_index][3][disp_index]) + + # Check the time point info. + self.assertEqual(time, data[frq_index][4]) + self.assertEqual(ti, indices[frq_index][4]) # Increment the data index. if disp_index == 16: