Package test_suite :: Package unit_tests :: Module diffusion_tensor_testing_base
[hide private]
[frames] | no frames]

Source Code for Module test_suite.unit_tests.diffusion_tensor_testing_base

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2007-2013 Edward d'Auvergne                                   # 
  4  #                                                                             # 
  5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  6  #                                                                             # 
  7  # This program is free software: you can redistribute it and/or modify        # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation, either version 3 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # This program is distributed in the hope that it will be useful,             # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 19  #                                                                             # 
 20  ############################################################################### 
 21   
 22  # relax module imports. 
 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   
30 -class Diffusion_tensor_base_class(UnitTestCase):
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
36 - def setUp(self):
37 """Set up for all the diffusion tensor unit tests.""" 38 39 # Add a data pipe to the data store. 40 ds.add(pipe_name='orig', pipe_type='mf') 41 42 # Add a second data pipe for copying tests. 43 ds.add(pipe_name='test', pipe_type='mf') 44 45 # Set the current data pipe to 'orig'. 46 pipes.switch('orig')
47 48
49 - def test_copy_pull_ellipsoid(self):
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 # Initialise the tensor. 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 # Change the current data pipe. 60 pipes.switch('test') 61 62 # Get the data pipe. 63 dp = pipes.get_pipe('test') 64 65 # Copy the tensor to the test pipe. 66 self.diffusion_tensor_fns.copy(pipe_from='orig') 67 68 # Test the diffusion tensor. 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
79 - def test_copy_pull_sphere(self):
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 # Initialise the tensor. 87 self.diffusion_tensor_fns.init(params=1e-9) 88 89 # Change the current data pipe. 90 pipes.switch('test') 91 92 # Get the data pipe. 93 dp = pipes.get_pipe('test') 94 95 # Copy the tensor to the test pipe. 96 self.diffusion_tensor_fns.copy(pipe_from='orig') 97 98 # Test the diffusion tensor 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
104 - def test_copy_pull_spheroid(self):
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 # Initialise the tensor. 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 # Change the current data pipe. 115 pipes.switch('test') 116 117 # Get the data pipe. 118 dp = pipes.get_pipe('test') 119 120 # Copy the tensor to the test pipe. 121 self.diffusion_tensor_fns.copy(pipe_from='orig', pipe_to='test') 122 123 # Test the diffusion tensor. 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
133 - def test_copy_push_ellipsoid(self):
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 # Initialise the tensor. 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 # Copy the tensor to the test pipe. 144 self.diffusion_tensor_fns.copy(pipe_to='test') 145 146 # Get the data pipe. 147 dp = pipes.get_pipe('test') 148 149 # Test the diffusion tensor. 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
160 - def test_copy_push_sphere(self):
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 # Initialise the tensor. 168 self.diffusion_tensor_fns.init(params=1e-9) 169 170 # Copy the tensor to the test pipe. 171 self.diffusion_tensor_fns.copy(pipe_to='test') 172 173 # Get the data pipe. 174 dp = pipes.get_pipe('test') 175 176 # Test the diffusion tensor 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
182 - def test_copy_push_spheroid(self):
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 # Initialise the tensor. 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 # Copy the tensor to the test pipe. 193 self.diffusion_tensor_fns.copy(pipe_from='orig', pipe_to='test') 194 195 # Get the data pipe. 196 dp = pipes.get_pipe('test') 197 198 # Test the diffusion tensor. 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
208 - def test_delete(self):
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 # Initialise the tensor. 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 # Delete the tensor data. 219 self.diffusion_tensor_fns.delete() 220 221 # Get the data pipe. 222 dp = pipes.get_pipe('test') 223 224 # Test that the diff_tensor object does not exist. 225 self.failIf(hasattr(dp, 'diff_tensor'))
226 227
228 - def test_delete_fail_no_data(self):
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 # Try to delete the tensor data. 236 self.assertRaises(RelaxNoTensorError, self.diffusion_tensor_fns.delete)
237 238
239 - def test_delete_fail_no_pipe(self):
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 # Reset relax. 247 reset() 248 249 # Try to delete the tensor data. 250 self.assertRaises(RelaxNoPipeError, self.diffusion_tensor_fns.delete)
251 252
253 - def test_display_ellipsoid(self):
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 # Initialise the tensor. 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 # Display the diffusion tensor. 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 # Try to display the tensor data. 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 # Reset relax. 286 reset() 287 288 # Try to display the tensor data. 289 self.assertRaises(RelaxNoPipeError, self.diffusion_tensor_fns.display)
290 291
292 - def test_display_sphere(self):
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 # Initialise the tensor. 300 self.diffusion_tensor_fns.init(params=1e-9) 301 302 # Display the diffusion tensor. 303 self.diffusion_tensor_fns.display()
304 305
306 - def test_display_spheroid(self):
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 # Initialise the tensor. 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 # Display the diffusion tensor. 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 # Initialise the tensor. 329 self.assertRaises(RelaxError, self.diffusion_tensor_fns.init, params=1e-9, angle_units='aaa')
330 331
332 - def test_init_ellipsoid(self):
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 # Get the data pipe. 340 dp = pipes.get_pipe('orig') 341 342 # Initialise the tensor. 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 # Test the diffusion tensor. 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
356 - def test_init_sphere(self):
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 # Get the data pipe. 364 dp = pipes.get_pipe('orig') 365 366 # Initialise the tensor. 367 self.diffusion_tensor_fns.init(params=1e-9) 368 369 # Test the diffusion tensor 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
375 - def test_init_spheroid(self):
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 # Get the data pipe. 383 dp = pipes.get_pipe('orig') 384 385 # Initialise the tensor. 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 # Test the diffusion tensor. 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