1   
  2   
  3   
  4   
  5   
  6   
  7   
  8   
  9   
 10   
 11   
 12   
 13   
 14   
 15   
 16   
 17   
 18   
 19   
 20   
 21   
 22   
 23  from data_store import Relax_data_store; ds = Relax_data_store() 
 24  from pipe_control import pipes 
 25  from pipe_control.reset import reset 
 26  from lib.errors import RelaxError, RelaxNoPipeError, RelaxNoTensorError 
 27  from test_suite.unit_tests.base_classes import UnitTestCase 
 28   
 29   
 31      """Base class for the tests of the diffusion tensor modules. 
 32       
 33      This includes both the 'prompt.diffusion_tensor' and 'pipe_control.diffusion_tensor' modules.  The base class also contains many shared unit tests. 
 34      """ 
 35   
 37          """Set up for all the diffusion tensor unit tests.""" 
 38   
 39           
 40          ds.add(pipe_name='orig', pipe_type='mf') 
 41   
 42           
 43          ds.add(pipe_name='test', pipe_type='mf') 
 44   
 45           
 46          pipes.switch('orig') 
  47   
 48   
 50          """Test the copying of an ellipsoid diffusion tensor (pulling the data from another pipe). 
 51   
 52          The functions tested are both pipe_control.diffusion_tensor.copy() and 
 53          prompt.diffusion_tensor.copy(). 
 54          """ 
 55   
 56           
 57          self.diffusion_tensor_fns.init(params=(13.9, 1.8, 0.7, 10.6, -23.3, 0.34), time_scale=1e-9, d_scale=1e7, angle_units='rad', param_types=0, fixed=True) 
 58   
 59           
 60          pipes.switch('test') 
 61   
 62           
 63          dp = pipes.get_pipe('test') 
 64   
 65           
 66          self.diffusion_tensor_fns.copy(pipe_from='orig') 
 67   
 68           
 69          self.assertEqual(dp.diff_tensor.type, 'ellipsoid') 
 70          self.assertAlmostEqual(dp.diff_tensor.tm * 1e9, 13.9, 14) 
 71          self.assertEqual(dp.diff_tensor.Da, 1.8e7) 
 72          self.assertEqual(dp.diff_tensor.Dr, 0.7) 
 73          self.assertEqual(dp.diff_tensor.alpha, 1.1752220392306203) 
 74          self.assertEqual(dp.diff_tensor.beta, 1.8327412287183442) 
 75          self.assertEqual(dp.diff_tensor.gamma, 0.34) 
 76          self.assertEqual(dp.diff_tensor.fixed, 1) 
  77   
 78   
 80          """Test the copying of a spherical diffusion tensor (pulling the data from another pipe). 
 81   
 82          The functions tested are both pipe_control.diffusion_tensor.copy() and 
 83          prompt.diffusion_tensor.copy(). 
 84          """ 
 85   
 86           
 87          self.diffusion_tensor_fns.init(params=1e-9) 
 88   
 89           
 90          pipes.switch('test') 
 91   
 92           
 93          dp = pipes.get_pipe('test') 
 94   
 95           
 96          self.diffusion_tensor_fns.copy(pipe_from='orig') 
 97   
 98           
 99          self.assertEqual(dp.diff_tensor.type, 'sphere') 
100          self.assertEqual(dp.diff_tensor.tm, 1e-9) 
101          self.assertEqual(dp.diff_tensor.fixed, 1) 
 102   
103   
105          """Test the copying of a spheroidal diffusion tensor (pulling the data from another pipe). 
106   
107          The functions tested are both pipe_control.diffusion_tensor.copy() and 
108          prompt.diffusion_tensor.copy(). 
109          """ 
110   
111           
112          self.diffusion_tensor_fns.init(params=(8.6, 1.3, 600, -20), time_scale=1e-9, d_scale=1e7, angle_units='deg', param_types=2, spheroid_type='prolate', fixed=False) 
113   
114           
115          pipes.switch('test') 
116   
117           
118          dp = pipes.get_pipe('test') 
119   
120           
121          self.diffusion_tensor_fns.copy(pipe_from='orig', pipe_to='test') 
122   
123           
124          self.assertEqual(dp.diff_tensor.type, 'spheroid') 
125          self.assertEqual(dp.diff_tensor.spheroid_type, 'prolate') 
126          self.assertAlmostEqual(dp.diff_tensor.tm * 1e9, 8.6, 14) 
127          self.assertEqual(dp.diff_tensor.Da, 5.2854122621564493e6) 
128          self.assertEqual(dp.diff_tensor.theta, 5.2359877559829879) 
129          self.assertEqual(dp.diff_tensor.phi, 2.7925268031909276) 
130          self.assertEqual(dp.diff_tensor.fixed, 0) 
 131   
132   
134          """Test the copying of an ellipsoid diffusion tensor (pushing the data from another pipe). 
135   
136          The functions tested are both pipe_control.diffusion_tensor.copy() and 
137          prompt.diffusion_tensor.copy(). 
138          """ 
139   
140           
141          self.diffusion_tensor_fns.init(params=(13.9, 1.8, 0.7, 10.6, -23.3, 0.34), time_scale=1e-9, d_scale=1e7, angle_units='rad', param_types=0, fixed=True) 
142   
143           
144          self.diffusion_tensor_fns.copy(pipe_to='test') 
145   
146           
147          dp = pipes.get_pipe('test') 
148   
149           
150          self.assertEqual(dp.diff_tensor.type, 'ellipsoid') 
151          self.assertAlmostEqual(dp.diff_tensor.tm * 1e9, 13.9, 14) 
152          self.assertEqual(dp.diff_tensor.Da, 1.8e7) 
153          self.assertEqual(dp.diff_tensor.Dr, 0.7) 
154          self.assertEqual(dp.diff_tensor.alpha, 1.1752220392306203) 
155          self.assertEqual(dp.diff_tensor.beta, 1.8327412287183442) 
156          self.assertEqual(dp.diff_tensor.gamma, 0.34) 
157          self.assertEqual(dp.diff_tensor.fixed, 1) 
 158   
159   
161          """Test the copying of a spherical diffusion tensor (pushing the data from another pipe). 
162   
163          The functions tested are both pipe_control.diffusion_tensor.copy() and 
164          prompt.diffusion_tensor.copy(). 
165          """ 
166   
167           
168          self.diffusion_tensor_fns.init(params=1e-9) 
169   
170           
171          self.diffusion_tensor_fns.copy(pipe_to='test') 
172   
173           
174          dp = pipes.get_pipe('test') 
175   
176           
177          self.assertEqual(dp.diff_tensor.type, 'sphere') 
178          self.assertEqual(dp.diff_tensor.tm, 1e-9) 
179          self.assertEqual(dp.diff_tensor.fixed, 1) 
 180   
181   
183          """Test the copying of a spheroidal diffusion tensor (pushing the data from another pipe). 
184   
185          The functions tested are both pipe_control.diffusion_tensor.copy() and 
186          prompt.diffusion_tensor.copy(). 
187          """ 
188   
189           
190          self.diffusion_tensor_fns.init(params=(8.6, 1.3, 600, -20), time_scale=1e-9, d_scale=1e7, angle_units='deg', param_types=2, spheroid_type='prolate', fixed=False) 
191   
192           
193          self.diffusion_tensor_fns.copy(pipe_from='orig', pipe_to='test') 
194   
195           
196          dp = pipes.get_pipe('test') 
197   
198           
199          self.assertEqual(dp.diff_tensor.type, 'spheroid') 
200          self.assertEqual(dp.diff_tensor.spheroid_type, 'prolate') 
201          self.assertAlmostEqual(dp.diff_tensor.tm * 1e9, 8.6, 14) 
202          self.assertEqual(dp.diff_tensor.Da, 5.2854122621564493e6) 
203          self.assertEqual(dp.diff_tensor.theta, 5.2359877559829879) 
204          self.assertEqual(dp.diff_tensor.phi, 2.7925268031909276) 
205          self.assertEqual(dp.diff_tensor.fixed, 0) 
 206   
207   
209          """Test the deletion of the diffusion tensor data structure. 
210   
211          The functions tested are both pipe_control.diffusion_tensor.delete() and 
212          prompt.diffusion_tensor.delete(). 
213          """ 
214   
215           
216          self.diffusion_tensor_fns.init(params=(8.6, 1.3, 600, -20), time_scale=1e-9, d_scale=1e7, angle_units='deg', param_types=2, spheroid_type='prolate', fixed=False) 
217   
218           
219          self.diffusion_tensor_fns.delete() 
220   
221           
222          dp = pipes.get_pipe('test') 
223   
224           
225          self.failIf(hasattr(dp, 'diff_tensor')) 
 226   
227   
229          """Failure of deletion of the diffusion tensor data structure when there is no data. 
230   
231          The functions tested are both pipe_control.diffusion_tensor.delete() and 
232          prompt.diffusion_tensor.delete(). 
233          """ 
234   
235           
236          self.assertRaises(RelaxNoTensorError, self.diffusion_tensor_fns.delete) 
 237   
238   
240          """Failure of deletion of the diffusion tensor data structure when there is no data pipe. 
241   
242          The functions tested are both pipe_control.diffusion_tensor.delete() and 
243          prompt.diffusion_tensor.delete(). 
244          """ 
245   
246           
247          reset() 
248   
249           
250          self.assertRaises(RelaxNoPipeError, self.diffusion_tensor_fns.delete) 
 251   
252   
254          """Display an ellipsoidal diffusion tensor. 
255   
256          The functions tested are both pipe_control.diffusion_tensor.display() and 
257          prompt.diffusion_tensor.display(). 
258          """ 
259   
260           
261          self.diffusion_tensor_fns.init(params=(13.9, 1.8, 0.7, 10.6, -23.3, 0.34), time_scale=1e-9, d_scale=1e7, angle_units='rad', param_types=0, fixed=True) 
262   
263           
264          self.diffusion_tensor_fns.display() 
 265   
266   
268          """Failure of the display of the diffusion tensor data structure when there is no data. 
269   
270          The functions tested are both pipe_control.diffusion_tensor.display() and 
271          prompt.diffusion_tensor.display(). 
272          """ 
273   
274           
275          self.assertRaises(RelaxNoTensorError, self.diffusion_tensor_fns.display) 
 276   
277   
279          """Failure of the display of the diffusion tensor data structure when there is no data pipe. 
280   
281          The functions tested are both pipe_control.diffusion_tensor.display() and 
282          prompt.diffusion_tensor.display(). 
283          """ 
284   
285           
286          reset() 
287   
288           
289          self.assertRaises(RelaxNoPipeError, self.diffusion_tensor_fns.display) 
 290   
291   
293          """Display a spherical diffusion tensor. 
294   
295          The functions tested are both pipe_control.diffusion_tensor.display() and 
296          prompt.diffusion_tensor.display(). 
297          """ 
298   
299           
300          self.diffusion_tensor_fns.init(params=1e-9) 
301   
302           
303          self.diffusion_tensor_fns.display() 
 304   
305   
307          """Display a spheroidal diffusion tensor. 
308   
309          The functions tested are both pipe_control.diffusion_tensor.display() and 
310          prompt.diffusion_tensor.display(). 
311          """ 
312   
313           
314          self.diffusion_tensor_fns.init(params=(8.6, 1.3, 600, -20), time_scale=1e-9, d_scale=1e7, angle_units='deg', param_types=2, spheroid_type='prolate', fixed=False) 
315   
316           
317          self.diffusion_tensor_fns.display() 
 318   
319   
320   
322          """Test the failure of setting up a diffusion tensor when angle_units is incorrect. 
323   
324          The functions tested are both pipe_control.diffusion_tensor.init() and 
325          prompt.diffusion_tensor.init(). 
326          """ 
327   
328           
329          self.assertRaises(RelaxError, self.diffusion_tensor_fns.init, params=1e-9, angle_units='aaa') 
 330   
331   
333          """Test the setting up of a ellipsoid diffusion tensor. 
334   
335          The functions tested are both pipe_control.diffusion_tensor.init() and 
336          prompt.diffusion_tensor.init(). 
337          """ 
338   
339           
340          dp = pipes.get_pipe('orig') 
341   
342           
343          self.diffusion_tensor_fns.init(params=(13.9, 1.8, 0.7, 10.6, -23.3, 0.34), time_scale=1e-9, d_scale=1e7, angle_units='rad', param_types=0, fixed=True) 
344   
345           
346          self.assertEqual(dp.diff_tensor.type, 'ellipsoid') 
347          self.assertAlmostEqual(dp.diff_tensor.tm * 1e9, 13.9, 14) 
348          self.assertEqual(dp.diff_tensor.Da, 1.8e7) 
349          self.assertEqual(dp.diff_tensor.Dr, 0.7) 
350          self.assertEqual(dp.diff_tensor.alpha, 1.1752220392306203) 
351          self.assertEqual(dp.diff_tensor.beta, 1.8327412287183442) 
352          self.assertEqual(dp.diff_tensor.gamma, 0.34) 
353          self.assertEqual(dp.diff_tensor.fixed, 1) 
 354   
355   
357          """Test the setting up of a spherical diffusion tensor. 
358   
359          The functions tested are both pipe_control.diffusion_tensor.init() and 
360          prompt.diffusion_tensor.init(). 
361          """ 
362   
363           
364          dp = pipes.get_pipe('orig') 
365   
366           
367          self.diffusion_tensor_fns.init(params=1e-9) 
368   
369           
370          self.assertEqual(dp.diff_tensor.type, 'sphere') 
371          self.assertEqual(dp.diff_tensor.tm, 1e-9) 
372          self.assertEqual(dp.diff_tensor.fixed, 1) 
 373   
374   
376          """Test the setting up of a spheroidal diffusion tensor. 
377   
378          The functions tested are both pipe_control.diffusion_tensor.init() and 
379          prompt.diffusion_tensor.init(). 
380          """ 
381   
382           
383          dp = pipes.get_pipe('orig') 
384   
385           
386          self.diffusion_tensor_fns.init(params=(8.6, 1.3, 600, -20), time_scale=1e-9, d_scale=1e7, angle_units='deg', param_types=2, spheroid_type='prolate', fixed=False) 
387   
388           
389          self.assertEqual(dp.diff_tensor.type, 'spheroid') 
390          self.assertEqual(dp.diff_tensor.spheroid_type, 'prolate') 
391          self.assertAlmostEqual(dp.diff_tensor.tm * 1e9, 8.6, 14) 
392          self.assertEqual(dp.diff_tensor.Da, 5.2854122621564493e6) 
393          self.assertEqual(dp.diff_tensor.theta, 5.2359877559829879) 
394          self.assertEqual(dp.diff_tensor.phi, 2.7925268031909276) 
395          self.assertEqual(dp.diff_tensor.fixed, 0) 
  396