Commits

Kazuhiko Shimada authored c0385634707
CAS-13520: formatted source code

casatasks/tests/tasks/test_imbaseline.py

Modified
31 31 _SdbaselineMethods,
32 32 _SdbaselineParams,
33 33 _SdsmoothMethods,
34 34 _SdsmoothParams,
35 35 _UnerasableFolder, imbaseline)
36 36 from casatools import ctsys, image, table
37 37
38 38 _tb = table()
39 39
40 40 # https://open-bitbucket.nrao.edu/projects/CASA/repos/casatestdata/browse/unittest
41 -DATAPATH = ctsys.resolve('unittest/imbaseline/')
41 +DATAPATH = ctsys.resolve("unittest/imbaseline/")
42 42
43 -DATACOLUMN = 'DATA'
44 -UNEXISTS = 'unexists'
45 -DUMMY_FOLDERS = ('dummy1', 'dummy2', 'dummy3')
43 +DATACOLUMN = "DATA"
44 +UNEXISTS = "unexists"
45 +DUMMY_FOLDERS = ("dummy1", "dummy2", "dummy3")
46 46
47 -casalog.origin('imbaseline')
47 +casalog.origin("imbaseline")
48 48
49 49
50 50 class test_base(unittest.TestCase):
51 51 """Base class of ibmaseline testing."""
52 52
53 53 @staticmethod
54 54 def exception_case(exception_type, exception_pattern):
55 55 """Decorate tests intended to throw a specific exception.
56 56
57 57 exception_type: type of exception
58 58 exception_pattern: regex for inspecting exception message using re.search
59 59 """
60 +
60 61 def wrapper(func):
61 62 @functools.wraps(func)
62 63 def _wrapper(self):
63 - self.assertTrue(len(exception_pattern) > 0,
64 - msg='Internal Error')
64 + self.assertTrue(len(exception_pattern) > 0, msg="Internal Error")
65 65 with self.assertRaises(exception_type) as ctx:
66 66 func(self)
67 - self.fail(msg='The task must throw an exception')
67 + self.fail(msg="The task must throw an exception")
68 68 the_exception = ctx.exception
69 69 message = str(the_exception)
70 70 self.assertIsNotNone(
71 - re.search(
72 - exception_pattern,
73 - message),
74 - msg=f'Expected: \'{exception_pattern}\', got: \'{message}\'')
71 + re.search(exception_pattern, message),
72 + msg=f"Expected: '{exception_pattern}', got: '{message}'",
73 + )
74 +
75 75 return _wrapper
76 +
76 77 return wrapper
77 78
78 79 @classmethod
79 80 def setUpClass(cls):
80 81 cls.workdir = Workdir.create()
81 82 cls.workdir.chdir()
82 83
83 84 @classmethod
84 85 def tearDownClass(cls):
85 - os.chdir('..')
86 + os.chdir("..")
86 87 cls.workdir.clean()
87 88
88 89 def tearDown(self):
89 90 _eraseable_folder_register.clear()
90 91 self.assertTrue(len(_tb.showcache()) == 0)
91 92 # make sure directory is clean as per verification test requirement
92 93 cwd = os.getcwd()
93 94 for filename in os.listdir(cwd):
94 95 file_path = os.path.join(cwd, filename)
95 96 try:
96 97 if os.path.isfile(file_path) or os.path.islink(file_path):
97 98 os.unlink(file_path)
98 99 elif os.path.isdir(file_path):
99 100 shutil.rmtree(file_path)
100 101 except Exception as e:
101 - print('Failed to delete %s. Reason: %s' % (file_path, e))
102 + print("Failed to delete %s. Reason: %s" % (file_path, e))
102 103
103 104 def _create_dummy_folders(self):
104 105 def _setup_folder(folder):
105 106 if os.path.exists(folder):
106 107 shutil.rmtree(folder)
107 108 os.mkdir(folder)
108 109
109 110 [_setup_folder(folder) for folder in DUMMY_FOLDERS]
110 111
111 112 def _copy_test_files(self, filename):
126 127
127 128 def _create_image(self, datapath, val=1, shape=[0, 0, 0, 0]):
128 129 _ia = image()
129 130 ary = _ia.makearray(v=val, shape=shape)
130 131 _ia.fromarray(outfile=datapath, pixels=ary, overwrite=True)
131 132 _ia.done()
132 133
133 134 def _check_ms_tables(self, path):
134 135 self.assertTrue(os.path.exists(path))
135 136 for table_name in (
136 - '',
137 - 'ANTENNA',
138 - 'DATA_DESCRIPTION',
139 - 'FEED',
140 - 'FIELD',
141 - 'FLAG_CMD',
142 - 'HISTORY',
143 - 'OBSERVATION',
144 - 'POINTING',
145 - 'POLARIZATION',
146 - 'PROCESSOR',
147 - 'SOURCE',
148 - 'SPECTRAL_WINDOW',
149 - 'STATE'):
137 + "",
138 + "ANTENNA",
139 + "DATA_DESCRIPTION",
140 + "FEED",
141 + "FIELD",
142 + "FLAG_CMD",
143 + "HISTORY",
144 + "OBSERVATION",
145 + "POINTING",
146 + "POLARIZATION",
147 + "PROCESSOR",
148 + "SOURCE",
149 + "SPECTRAL_WINDOW",
150 + "STATE",
151 + ):
150 152 table_path = os.path.join(path, table_name)
151 - self.assertTrue(os.path.exists(
152 - os.path.join(table_path, 'table.dat')))
153 + self.assertTrue(os.path.exists(os.path.join(table_path, "table.dat")))
153 154
154 155
155 156 class TestFileStack(test_base):
156 157 """Test classes of inherit AbstractFileStack / _(Un)EraseableFolder.
157 158
158 159 01. successful case: Create Stack with exist file
159 160 02. failure case: Create Stack with unexist file, an exception raises
160 161 03. successful case: push() exist file into stack
161 162 04. failure case: push() unexist file into stack, an exception raises
162 163 05. successful case: pop() exist stuff into stack
178 179 def setUp(self):
179 180 self._create_dummy_folders()
180 181 if os.path.exists(UNEXISTS):
181 182 shutil.rmtree(UNEXISTS)
182 183
183 184 def test_filestack_01(self):
184 185 """01. successful case: Create Stack with exist file."""
185 186 stack = _CasaImageStack(_UnerasableFolder(DUMMY_FOLDERS[0]))
186 187 self.assertTrue(stack.height() == 1)
187 188
188 - @test_base.exception_case(ValueError, f'file {UNEXISTS} is not found')
189 + @test_base.exception_case(ValueError, f"file {UNEXISTS} is not found")
189 190 def test_filestack_02(self):
190 191 """02. failure case: Create Stack with unexist file, an exception raises."""
191 192 _CasaImageStack(_UnerasableFolder(UNEXISTS))
192 193
193 194 def test_filestack_03(self):
194 195 """03. successful case: push() exist file into stack."""
195 196 stack = _CasaImageStack()
196 197 stack.push(_UnerasableFolder(DUMMY_FOLDERS[0]))
197 198 self.assertTrue(stack.height() == 1)
198 199
199 - @test_base.exception_case(ValueError, f'file {UNEXISTS} is not found')
200 + @test_base.exception_case(ValueError, f"file {UNEXISTS} is not found")
200 201 def test_filestack_04(self):
201 202 """04. failure case: push() unexist file into stack, an exception raises."""
202 203 stack = _CasaImageStack()
203 204 stack.push(_UnerasableFolder(UNEXISTS))
204 205
205 206 def test_filestack_05(self):
206 207 """05. successful case: pop() exist stuff into stack."""
207 208 stack = _CasaImageStack()
208 209 stack.push(_UnerasableFolder(DUMMY_FOLDERS[0]))
209 210 obj = _UnerasableFolder(DUMMY_FOLDERS[1])
210 211 stack.push(obj)
211 212 tmp = stack.pop()
212 213 self.assertEqual(obj, tmp)
213 214 self.assertTrue(stack.height() == 1)
214 215
215 - @test_base.exception_case(RuntimeError, 'the stack cannot pop')
216 + @test_base.exception_case(RuntimeError, "the stack cannot pop")
216 217 def test_filestack_06(self):
217 218 """06. failure case: pop() unexist stuff into stack, an exception raises."""
218 219 stack = _CasaImageStack()
219 220 stack.pop()
220 221
221 222 def test_filestack_07(self):
222 223 """07. successful case: peak() exist stuff into stack."""
223 224 stack = _CasaImageStack()
224 225 obj1 = _UnerasableFolder(DUMMY_FOLDERS[0])
225 226 stack.push(obj1)
226 227 obj2 = _UnerasableFolder(DUMMY_FOLDERS[1])
227 228 stack.push(obj2)
228 229 obj3 = _UnerasableFolder(DUMMY_FOLDERS[2])
229 230 stack.push(obj3)
230 231 self.assertEqual(stack.peak(), obj3)
231 232 self.assertEqual(stack.subpeak(), obj2)
232 233 self.assertEqual(stack.bottom(), obj1)
233 234
234 - @test_base.exception_case(RuntimeError, 'the stack is empty')
235 + @test_base.exception_case(RuntimeError, "the stack is empty")
235 236 def test_filestack_08(self):
236 237 """08. failure case: peak() unexist stuff into stack, an exception raises."""
237 238 stack = _CasaImageStack()
238 239 stack.peak()
239 240
240 241 def test_filestack_09(self):
241 242 """09. successful case: subpeak() exist stuff into stack."""
242 243 stack = _CasaImageStack()
243 244 obj1 = _UnerasableFolder(DUMMY_FOLDERS[0])
244 245 stack.push(obj1)
245 246 obj2 = _UnerasableFolder(DUMMY_FOLDERS[1])
246 247 stack.push(obj2)
247 248 self.assertEqual(stack.subpeak(), obj1)
248 249 self.assertEqual(stack.bottom(), obj1)
249 250 obj3 = _UnerasableFolder(DUMMY_FOLDERS[2])
250 251 stack.push(obj3)
251 252 self.assertEqual(stack.subpeak(), obj2)
252 253 self.assertEqual(stack.bottom(), obj1)
253 254
254 - @test_base.exception_case(RuntimeError, 'the stack has only one stuff')
255 + @test_base.exception_case(RuntimeError, "the stack has only one stuff")
255 256 def test_filestack_10(self):
256 257 """10. failure case: subpeak() unexist stuff into stack, an exception raises."""
257 258 stack = _CasaImageStack(_UnerasableFolder(DUMMY_FOLDERS[0]))
258 259 stack.subpeak()
259 260
260 261 def test_filestack_11(self):
261 262 """11. successful case: bottom() exist stuff into stack."""
262 263 stack = _CasaImageStack()
263 264 obj1 = _UnerasableFolder(DUMMY_FOLDERS[0])
264 265 stack.push(obj1)
269 270 self.assertEqual(stack.peak(), obj2)
270 271 obj3 = _UnerasableFolder(DUMMY_FOLDERS[2])
271 272 stack.push(obj3)
272 273 self.assertEqual(stack.bottom(), obj1)
273 274 self.assertEqual(stack.peak(), obj3)
274 275 self.assertEqual(stack.subpeak(), obj2)
275 276 stack.pop()
276 277 self.assertEqual(stack.peak(), obj2)
277 278 self.assertEqual(stack.bottom(), obj1)
278 279
279 - @test_base.exception_case(RuntimeError,
280 - 'the stack has not have enough stuff')
280 + @test_base.exception_case(RuntimeError, "the stack has not have enough stuff")
281 281 def test_filestack_12(self):
282 282 """12. failure case: bottom() unexist stuff into stack, an exception raises."""
283 283 stack = _CasaImageStack()
284 284 stack.bottom()
285 285
286 286 def test_filestack_13(self):
287 287 """13. successful case: do clear() of _EraseableFolder contains a file."""
288 288 file = _EraseableFolder(DUMMY_FOLDERS[0])
289 289 stack = _CasaImageStack(file)
290 290 stack.clear(False)
318 318 self.assertEqual(stack.height(), 1)
319 319 stack.push(_UnerasableFolder(DUMMY_FOLDERS[1]))
320 320 self.assertEqual(stack.height(), 2)
321 321 stack.push(_UnerasableFolder(DUMMY_FOLDERS[2]))
322 322 self.assertEqual(stack.height(), 3)
323 323 stack.pop()
324 324 self.assertEqual(stack.height(), 2)
325 325 stack.pop()
326 326 self.assertEqual(stack.height(), 1)
327 327
328 - @test_base.exception_case(RuntimeError, 'the stack cannot pop')
328 + @test_base.exception_case(RuntimeError, "the stack cannot pop")
329 329 def test_filestack_18(self):
330 330 """18. failure case: pop() when height is 1, an exception raises."""
331 331 stack = _CasaImageStack()
332 332 stack.push(_UnerasableFolder(DUMMY_FOLDERS[0]))
333 333 stack.pop()
334 334
335 335
336 336 class TestImageShape(test_base):
337 337 """Test _ImageShape.
338 338
342 342 """
343 343
344 344 def setUp(self):
345 345 pass
346 346
347 347 def tearDown(self):
348 348 pass
349 349
350 350 def test_imageshape_01(self):
351 351 """01. successful case: axis_sp = axis_pol = 2or3, axis_sp != axis_pol."""
352 - shape = _ImageShape(im_shape=np.array(
353 - [100, 100, 1, 100]), axis_dir=np.array([0, 1]), axis_sp=3, axis_pol=2)
352 + shape = _ImageShape(
353 + im_shape=np.array([100, 100, 1, 100]),
354 + axis_dir=np.array([0, 1]),
355 + axis_sp=3,
356 + axis_pol=2,
357 + )
354 358 shape.validate()
355 - shape = _ImageShape(im_shape=np.array(
356 - [100, 100, 100, 1]), axis_dir=np.array([0, 1]), axis_sp=2, axis_pol=3)
359 + shape = _ImageShape(
360 + im_shape=np.array([100, 100, 100, 1]),
361 + axis_dir=np.array([0, 1]),
362 + axis_sp=2,
363 + axis_pol=3,
364 + )
357 365 shape.validate()
358 366 # any exceptions are not thrown, its OK
359 367
360 - @test_base.exception_case(ValueError,
361 - 'nchan \\d is too few to perform baseline subtraction')
368 + @test_base.exception_case(
369 + ValueError, "nchan \\d is too few to perform baseline subtraction"
370 + )
362 371 def test_imageshape_02(self):
363 372 """02. failure case: invalid im_nchan, an exception raises."""
364 - shape = _ImageShape(im_shape=np.array(
365 - [100, 100, 1, 1]), axis_dir=np.array([0, 1]), axis_sp=3, axis_pol=2)
373 + shape = _ImageShape(
374 + im_shape=np.array([100, 100, 1, 1]),
375 + axis_dir=np.array([0, 1]),
376 + axis_sp=3,
377 + axis_pol=2,
378 + )
366 379 shape.validate()
367 380
368 - @test_base.exception_case(ValueError,
369 - 'invalid value: dir_shape \\[\\d+\\]')
381 + @test_base.exception_case(ValueError, "invalid value: dir_shape \\[\\d+\\]")
370 382 def test_imageshape_03(self):
371 383 """03. failure case: invalid dir_shape, an exception raises."""
372 - shape = _ImageShape(np.array([100, 100, 1, 100]), axis_dir=np.array(
373 - [0]), axis_sp=3, axis_pol=2)
384 + shape = _ImageShape(
385 + np.array([100, 100, 1, 100]), axis_dir=np.array([0]), axis_sp=3, axis_pol=2
386 + )
374 387 shape.validate()
375 388
376 389
377 390 class TestImsmooth(test_base):
378 391 """Test imsmooth execution.
379 392
380 393 Tests of imsmooth rely on ones of test_imsmooth basically, so we have minimal tests in imbaseline.
381 394
382 395 01. successful case: call imsmooth with some parameters
383 396 02. failure case: invalid dirkernel, an exception raises
384 397 03. set values for _ImsmoothParams and do validate(), and compare properties of it to the correct values
385 398 """
386 399
387 - tiny = 'tiny.im'
400 + tiny = "tiny.im"
388 401
389 402 def setUp(self):
390 403 self._copy_test_files(self.tiny)
391 404
392 405 def test_imsmooth_01(self):
393 406 """01. successful case: call imsmooth with some parameters."""
394 - major = '2.5arcsec'
395 - minor = '2arcsec'
396 - pa = '0deg'
397 - dirkernel = 'gaussian'
398 - kimage = ''
407 + major = "2.5arcsec"
408 + minor = "2arcsec"
409 + pa = "0deg"
410 + dirkernel = "gaussian"
411 + kimage = ""
399 412 scale = -1
400 413
401 414 stack = _CasaImageStack(top=_UnerasableFolder(self.tiny))
402 415
403 - _ImsmoothMethods.execute(
404 - dirkernel, major, minor, pa, kimage, scale, stack)
416 + _ImsmoothMethods.execute(dirkernel, major, minor, pa, kimage, scale, stack)
405 417 self.assertTrue(os.path.exists(stack.peak().path))
406 418
407 - @test_base.exception_case(ValueError,
408 - 'Unsupported direction smoothing kernel, foobar')
419 + @test_base.exception_case(
420 + ValueError, "Unsupported direction smoothing kernel, foobar"
421 + )
409 422 def test_imsmooth_02(self):
410 423 """02. failure case: invalid dirkernel, an exception raises."""
411 - major = '2.5arcsec'
412 - minor = '2arcsec'
413 - pa = '0deg'
414 - dirkernel = 'foobar'
415 - kimage = ''
424 + major = "2.5arcsec"
425 + minor = "2arcsec"
426 + pa = "0deg"
427 + dirkernel = "foobar"
428 + kimage = ""
416 429 scale = -1
417 430
418 431 stack = _CasaImageStack(top=_UnerasableFolder(self.tiny))
419 432
420 - _ImsmoothMethods.execute(
421 - dirkernel, major, minor, pa, kimage, scale, stack)
433 + _ImsmoothMethods.execute(dirkernel, major, minor, pa, kimage, scale, stack)
422 434
423 435 def test_imsmooth_03(self):
424 436 """03. set values for _ImsmoothParams and do validate(), and compare properties of it to the correct values."""
425 437 targetres = stretch = False
426 - mask = region = box = chans = stokes = ''
438 + mask = region = box = chans = stokes = ""
427 439 beam = {}
428 - infile = 'infile'
429 - outfile = 'outfile'
430 - kernel = ('none', 'image', 'gaussian', 'boxcar')
431 - major = '2.5arcsec'
432 - minor = '2arcsec'
433 - pa = '0deg'
440 + infile = "infile"
441 + outfile = "outfile"
442 + kernel = ("none", "image", "gaussian", "boxcar")
443 + major = "2.5arcsec"
444 + minor = "2arcsec"
445 + pa = "0deg"
434 446 kimage = self.tiny
435 447 scale = -2.0
436 - logorigin = 'imbaseline'
448 + logorigin = "imbaseline"
437 449
438 450 def compare_params(
439 - _kernel,
440 - _major=major,
441 - _minor=minor,
442 - _pa=pa,
443 - _kimage=kimage,
444 - _scale=scale):
451 + _kernel, _major=major, _minor=minor, _pa=pa, _kimage=kimage, _scale=scale
452 + ):
445 453 valid_param = dict(
446 454 targetres=targetres,
447 455 mask=mask,
448 456 beam=beam,
449 457 region=region,
450 458 box=box,
451 459 chans=chans,
452 460 stokes=stokes,
453 461 stretch=stretch,
454 462 overwrite=True,
455 463 imagename=infile,
456 464 outfile=outfile,
457 465 kernel=_kernel,
458 466 major=_major,
459 467 minor=_minor,
460 468 pa=_pa,
461 469 kimage=_kimage,
462 470 scale=_scale,
463 - __log_origin=logorigin)
471 + __log_origin=logorigin,
472 + )
464 473 param = _ImsmoothParams(
465 - infile, outfile, _kernel, _major, _minor, _pa, _kimage, _scale)
474 + infile, outfile, _kernel, _major, _minor, _pa, _kimage, _scale
475 + )
466 476 param.validate()
467 477 self.assertEqual(param(), valid_param)
468 478
469 479 # none
470 480 compare_params(kernel[0])
471 481
472 482 # image
473 - compare_params(kernel[1], _major='', _minor='', _pa='')
483 + compare_params(kernel[1], _major="", _minor="", _pa="")
474 484
475 485 # gaussian
476 - compare_params(kernel[2], _kimage='', _scale=-1.0)
486 + compare_params(kernel[2], _kimage="", _scale=-1.0)
477 487
478 488 # boxcar
479 - compare_params(kernel[3], _kimage='', _scale=-1.0)
489 + compare_params(kernel[3], _kimage="", _scale=-1.0)
480 490
481 491
482 492 class TestImage2MS(test_base):
483 493 """Test image2ms.
484 494
485 495 01. successful case: create MeasurementSet from a image
486 496 02. failure case: execute image2ms with invalid datacolumn parameter, an exception raises
487 497 03. failure case: execute image2ms with invalid image data, an exception raises
488 498 04. failure case: execute image2ms with empty stack, an exception raises
489 499 05. set values for _Image2MSParams and do validate(), and compare properties of it to the correct values
490 500 """
491 501
492 - expected = 'expected.im'
502 + expected = "expected.im"
493 503 datacolumn = DATACOLUMN
494 504
495 505 def setUp(self):
496 506 self._create_dummy_folders()
497 507 self._copy_test_files(self.expected)
498 508 self.image_shape = _get_image_shape(self.expected)
499 509
500 510 def test_image2ms_01(self):
501 511 """01. successful case: create MeasurementSet from a image."""
502 512 image_stack = _CasaImageStack(top=_UnerasableFolder(self.expected))
503 513 ms_stack = _MeasurementSetStack()
504 514 _Image2MSMethods.execute(
505 - self.datacolumn, self.image_shape, image_stack, ms_stack)
515 + self.datacolumn, self.image_shape, image_stack, ms_stack
516 + )
506 517 self.assertEqual(ms_stack.height(), 1)
507 518 self._check_ms_tables(ms_stack.peak().path)
508 519
509 - @test_base.exception_case(RuntimeError, 'column INVALID does not exist')
520 + @test_base.exception_case(RuntimeError, "column INVALID does not exist")
510 521 def test_image2ms_02(self):
511 522 """02. failure case: execute image2ms with invalid datacolumn parameter, an exception raises."""
512 523 image_stack = _CasaImageStack(top=_UnerasableFolder(self.expected))
513 524 ms_stack = _MeasurementSetStack()
514 - _Image2MSMethods.execute(
515 - 'INVALID', self.image_shape, image_stack, ms_stack)
525 + _Image2MSMethods.execute("INVALID", self.image_shape, image_stack, ms_stack)
516 526
517 - @test_base.exception_case(RuntimeError, 'Unable to open image dummy1.')
527 + @test_base.exception_case(RuntimeError, "Unable to open image dummy1.")
518 528 def test_image2ms_03(self):
519 529 """03. failure case: execute image2ms with invalid image data, an exception raises."""
520 530 image_stack = _CasaImageStack(top=_UnerasableFolder(DUMMY_FOLDERS[0]))
521 531 ms_stack = _MeasurementSetStack()
522 532 _Image2MSMethods.execute(
523 - self.datacolumn, self.image_shape, image_stack, ms_stack)
533 + self.datacolumn, self.image_shape, image_stack, ms_stack
534 + )
524 535
525 - @test_base.exception_case(RuntimeError, 'the stack is empty')
536 + @test_base.exception_case(RuntimeError, "the stack is empty")
526 537 def test_image2ms_04(self):
527 538 """04. failure case: execute image2ms with empty stack, an exception raises."""
528 539 image_stack = _CasaImageStack()
529 540 ms_stack = _MeasurementSetStack()
530 541 _Image2MSMethods.execute(
531 - self.datacolumn, self.image_shape, image_stack, ms_stack)
542 + self.datacolumn, self.image_shape, image_stack, ms_stack
543 + )
532 544
533 545 def test_image2ms_05(self):
534 546 """05. set values for _Image2MSParams and do validate(), and compare properties of it to the correct values."""
535 - outfile = 'output_4_5.ms'
547 + outfile = "output_4_5.ms"
536 548 params = _Image2MSParams(
537 - self.expected, outfile, self.datacolumn, self.image_shape)
549 + self.expected, outfile, self.datacolumn, self.image_shape
550 + )
538 551 params.validate()
539 552 self.assertEqual(params.infile, self.expected)
540 553 self.assertEqual(params.outfile, outfile)
541 - for attr in ('im_shape', 'axis_dir', 'dir_shape'):
542 - self.assertTrue(np.all(getattr(params, attr) == getattr(self.image_shape, attr)))
543 - for attr in ('axis_sp', 'axis_pol', 'im_nrow', 'im_nchan', 'im_npol'):
544 - self.assertEqual(getattr(params, attr),
545 - getattr(self.image_shape, attr))
554 + for attr in ("im_shape", "axis_dir", "dir_shape"):
555 + self.assertTrue(
556 + np.all(getattr(params, attr) == getattr(self.image_shape, attr))
557 + )
558 + for attr in ("axis_sp", "axis_pol", "im_nrow", "im_nchan", "im_npol"):
559 + self.assertEqual(getattr(params, attr), getattr(self.image_shape, attr))
546 560
547 561
548 562 class TestSdsmooth(test_base):
549 563 """Test sdsmooth execution.
550 564
551 565 Tests of sdsmooth rely on ones of test_sdsmooth basically, so we have minimal tests in imbaseline.
552 566
553 567 01. successful case: call sdsmooth with some parameters
554 568 02. failure case: call sdsmooth with invalid ms stack, an exception raises
555 569 03. failure case: call sdsmooth with invalid image stack, an exception raises
556 570 04. set values for _SdsmoothParams and do validate(), and compare properties of it to the correct values
557 571 """
558 572
559 - input_image = 'expected.im'
560 - input_ms = 'expected.ms'
573 + input_image = "expected.im"
574 + input_ms = "expected.ms"
561 575 datacolumn = DATACOLUMN
562 - spkenel = 'gaussian'
576 + spkenel = "gaussian"
563 577 kwidth = 5
564 578
565 579 def setUp(self):
566 580 self._copy_test_files(self.input_image)
567 581 self._copy_test_files(self.input_ms)
568 582 self.image_shape = _get_image_shape(self.input_image)
569 583
570 584 def test_sdsmooth_01(self):
571 585 """01. successful case: call sdsmooth with some parameters."""
572 586 image_stack = _CasaImageStack(top=_UnerasableFolder(self.input_image))
573 587 ms_stack = _MeasurementSetStack()
574 588 ms_stack.push(_EraseableFolder(self.input_ms))
575 589 _SdsmoothMethods.execute(
576 590 self.datacolumn,
577 591 self.spkenel,
578 592 self.kwidth,
579 593 image_stack,
580 594 ms_stack,
581 - self.image_shape)
595 + self.image_shape,
596 + )
582 597 self.assertEqual(image_stack.height(), 2)
583 598 self.assertEqual(ms_stack.height(), 2)
584 - self.assertTrue(os.path.exists(os.path.join(
585 - image_stack.peak().path, 'table.dat')))
599 + self.assertTrue(
600 + os.path.exists(os.path.join(image_stack.peak().path, "table.dat"))
601 + )
586 602 self._check_ms_tables(ms_stack.peak().path)
587 603
588 - @test_base.exception_case(RuntimeError, 'the stack is empty')
604 + @test_base.exception_case(RuntimeError, "the stack is empty")
589 605 def test_sdsmooth_02(self):
590 606 """02. failure case: call sdsmooth with invalid ms stack, an exception raises."""
591 607 image_stack = _CasaImageStack(top=_UnerasableFolder(self.input_image))
592 608 ms_stack = _MeasurementSetStack()
593 609 _SdsmoothMethods.execute(
594 610 self.datacolumn,
595 611 self.spkenel,
596 612 self.kwidth,
597 613 image_stack,
598 614 ms_stack,
599 - self.image_shape)
615 + self.image_shape,
616 + )
600 617
601 - @test_base.exception_case(RuntimeError,
602 - 'the stack has not have enough stuff')
618 + @test_base.exception_case(RuntimeError, "the stack has not have enough stuff")
603 619 def test_sdsmooth_03(self):
604 620 """03. failure case: call sdsmooth with invalid image stack, an exception raises."""
605 621 image_stack = _CasaImageStack()
606 622 ms_stack = _MeasurementSetStack()
607 623 ms_stack.push(_EraseableFolder(self.input_ms))
608 624 _SdsmoothMethods.execute(
609 625 self.datacolumn,
610 626 self.spkenel,
611 627 self.kwidth,
612 628 image_stack,
613 629 ms_stack,
614 - self.image_shape)
630 + self.image_shape,
631 + )
615 632
616 633 def test_sdsmooth_04(self):
617 634 """04. set values for _SdsmoothParams and do validate(), and compare properties of it to the correct values."""
618 - spw = field = antenna = timerange = scan = pol = intent = ''
635 + spw = field = antenna = timerange = scan = pol = intent = ""
619 636 reindex = overwrite = True
620 - infile = 'infile'
621 - outfile = 'outfile'
637 + infile = "infile"
638 + outfile = "outfile"
622 639 datacolumn = DATACOLUMN
623 - kernel = ('none', 'gaussian', 'boxcar')
640 + kernel = ("none", "gaussian", "boxcar")
624 641 kwidth = 5
625 - logorigin = 'imbaseline'
642 + logorigin = "imbaseline"
626 643
627 644 def compare_params(_kernel):
628 645 valid_params = dict(
629 646 spw=spw,
630 647 field=field,
631 648 antenna=antenna,
632 649 timerange=timerange,
633 650 scan=scan,
634 651 pol=pol,
635 652 intent=intent,
636 653 reindex=reindex,
637 654 overwrite=overwrite,
638 655 infile=infile,
639 656 datacolumn=datacolumn,
640 657 kernel=_kernel,
641 658 kwidth=kwidth,
642 659 outfile=outfile,
643 - __log_origin=logorigin)
660 + __log_origin=logorigin,
661 + )
644 662 params = _SdsmoothParams(
645 663 infile=infile,
646 664 outfile=outfile,
647 665 datacolumn=datacolumn,
648 666 spkernel=_kernel,
649 - kwidth=kwidth)
667 + kwidth=kwidth,
668 + )
650 669 params.validate()
651 670 self.assertEqual(params(), valid_params)
652 671
653 672 [compare_params(_kernel) for _kernel in kernel]
654 673
655 674
656 675 class TestSdbaseline(test_base):
657 676 """Test sdbaseline execution.
658 677
659 678 Tests of sdbaseline rely on ones of test_sdbaseline basically, so we have minimal tests in imbaseline.
660 679
661 680 01. successful case: call sdbaseline with some parameters
662 681 02. failure case: call sdbaseline with invalid ms stack, an exception raises
663 682 03. failure case: call sdbaseline with invalid image stack, an exception raise
664 683 04. set values for _SdbaselineParams and do validate(), and compare properties of it to the correct values
665 684 """
666 685
667 - input_image = 'expected.im'
668 - input_ms = 'expected.ms'
669 - bloutput = 'test.csv'
670 - maskmode = 'auto'
671 - blparam = 'analytic_variable_blparam.txt'
672 - chans = ''
686 + input_image = "expected.im"
687 + input_ms = "expected.ms"
688 + bloutput = "test.csv"
689 + maskmode = "auto"
690 + blparam = "analytic_variable_blparam.txt"
691 + chans = ""
673 692 thresh = 5.0
674 693 avg_limit = 4
675 694 minwidth = 4
676 695 edge = [0, 0]
677 - blfunc = 'cspline'
696 + blfunc = "cspline"
678 697 order = 5
679 698 npiece = 1
680 699 applyfft = True
681 700 fftthresh = 3.0
682 701 addwn = [0]
683 702 rejwn = []
684 703 clipniter = 10
685 704 clipthresh = 2.0
686 705 datacolumn = DATACOLUMN
687 706
710 729 self.npiece,
711 730 self.applyfft,
712 731 self.fftthresh,
713 732 self.addwn,
714 733 self.rejwn,
715 734 self.blparam,
716 735 self.clipniter,
717 736 self.clipthresh,
718 737 image_stack,
719 738 ms_stack,
720 - self.image_shape)
739 + self.image_shape,
740 + )
721 741 self.assertTrue(os.path.exists(ms_stack.peak().path))
722 742 self.assertTrue(os.path.exists(self.bloutput))
723 743 self.assertTrue(os.path.exists(image_stack.peak().path))
724 744
725 - @test_base.exception_case(RuntimeError, 'the stack is empty')
745 + @test_base.exception_case(RuntimeError, "the stack is empty")
726 746 def test_sdbaseline_02(self):
727 747 """02. failure case: call sdbaseline with invalid ms stack, an exception raises."""
728 748 image_stack = _CasaImageStack(top=_UnerasableFolder(self.input_image))
729 749 ms_stack = _MeasurementSetStack()
730 750 _SdbaselineMethods.execute(
731 751 self.datacolumn,
732 752 self.bloutput,
733 753 self.maskmode,
734 754 self.chans,
735 755 self.thresh,
741 761 self.npiece,
742 762 self.applyfft,
743 763 self.fftthresh,
744 764 self.addwn,
745 765 self.rejwn,
746 766 self.blparam,
747 767 self.clipniter,
748 768 self.clipthresh,
749 769 image_stack,
750 770 ms_stack,
751 - self.image_shape)
771 + self.image_shape,
772 + )
752 773
753 - @test_base.exception_case(RuntimeError,
754 - 'the stack has not have enough stuff')
774 + @test_base.exception_case(RuntimeError, "the stack has not have enough stuff")
755 775 def test_sdbaseline_03(self):
756 776 """03. failure case: call sdbaseline with invalid image stack, an exception raise."""
757 777 image_stack = _CasaImageStack()
758 778 ms_stack = _MeasurementSetStack()
759 779 ms_stack.push(_EraseableFolder(self.input_ms))
760 780 _SdbaselineMethods.execute(
761 781 self.datacolumn,
762 782 self.bloutput,
763 783 self.maskmode,
764 784 self.chans,
771 791 self.npiece,
772 792 self.applyfft,
773 793 self.fftthresh,
774 794 self.addwn,
775 795 self.rejwn,
776 796 self.blparam,
777 797 self.clipniter,
778 798 self.clipthresh,
779 799 image_stack,
780 800 ms_stack,
781 - self.image_shape)
801 + self.image_shape,
802 + )
782 803
783 804 def test_sdbaseline_04(self):
784 805 """04. set values for _SdbaselineParams and do validate(), and compare properties of it to the correct values."""
785 - antenna = field = timerange = scan = pol = intent = bltable = ''
806 + antenna = field = timerange = scan = pol = intent = bltable = ""
786 807 reindex = dosubtract = overwrite = True
787 808 updateweight = showprogress = verbose = False
788 - blmode = 'fit'
789 - blformat = 'csv'
790 - sigmavalue = 'stddev'
809 + blmode = "fit"
810 + blformat = "csv"
811 + sigmavalue = "stddev"
791 812 minnrow = 1000
792 - fftmethod = 'fft'
793 -
794 - infile = 'infile'
795 - outfile = 'outfile'
796 - datacolumn = 'DATA'
797 - bloutput = 'bloutput'
798 - maskmode = ('list', 'auto')
799 - chans = ''
800 - spw = '0'
813 + fftmethod = "fft"
814 +
815 + infile = "infile"
816 + outfile = "outfile"
817 + datacolumn = "DATA"
818 + bloutput = "bloutput"
819 + maskmode = ("list", "auto")
820 + chans = ""
821 + spw = "0"
801 822 thresh = 6.0
802 823 avg_limit = 5
803 824 minwidth = 5
804 825 edge = [1, 1]
805 - blfunc = ('poly', 'chebyshev', 'cspline', 'sinusoid', 'variable')
826 + blfunc = ("poly", "chebyshev", "cspline", "sinusoid", "variable")
806 827 order = 6
807 828 npiece = 2
808 829 applyfft = False
809 830 fftthresh = 4.0
810 831 addwn = [1]
811 832 rejwn = [1]
812 833 blparam = self.blparam
813 834 clipniter = 11
814 835 clipthresh = 3.0
815 - logorigin = 'imbaseline'
836 + logorigin = "imbaseline"
816 837
817 838 def compare_params(_maskmode, _blfunc):
818 839 valid_param = dict(
819 840 antenna=antenna,
820 841 field=field,
821 842 spw=spw,
822 843 timerange=timerange,
823 844 scan=scan,
824 845 pol=pol,
825 846 intent=intent,
847 868 order=order,
848 869 npiece=npiece,
849 870 applyfft=applyfft,
850 871 fftthresh=fftthresh,
851 872 addwn=addwn,
852 873 rejwn=rejwn,
853 874 clipthresh=clipthresh,
854 875 clipniter=clipniter,
855 876 blparam=blparam,
856 877 outfile=outfile,
857 - __log_origin=logorigin)
878 + __log_origin=logorigin,
879 + )
858 880 params = _SdbaselineParams(
859 881 infile=infile,
860 882 outfile=outfile,
861 883 datacolumn=datacolumn,
862 884 bloutput=bloutput,
863 885 maskmode=_maskmode,
864 886 chans=chans,
865 887 thresh=thresh,
866 888 avg_limit=avg_limit,
867 889 minwidth=minwidth,
868 890 edge=edge,
869 891 blfunc=_blfunc,
870 892 order=order,
871 893 npiece=npiece,
872 894 applyfft=applyfft,
873 895 fftthresh=fftthresh,
874 896 addwn=addwn,
875 897 rejwn=rejwn,
876 898 blparam=blparam,
877 899 clipniter=clipniter,
878 - clipthresh=clipthresh)
900 + clipthresh=clipthresh,
901 + )
879 902 params.validate()
880 903 self.assertEqual(params(), valid_param)
881 904
882 - [compare_params(_maskmode, _blfunc)
883 - for _maskmode in maskmode for _blfunc in blfunc]
905 + [
906 + compare_params(_maskmode, _blfunc)
907 + for _maskmode in maskmode
908 + for _blfunc in blfunc
909 + ]
884 910
885 911
886 912 class TestImageSubtraction(test_base):
887 913 """Test image subtractions.
888 914
889 915 01. successful test: subtracted output = input_image - (smoothed_image - smoothed_and_subtracted_image)
890 916 02. successful test: subtracted output = subtracted_image
891 917 03. failure case: subtract three images have unmatched shape, an exception raises
892 918 04. successful test: subtract two images have unmatched shape (any exceptions do not raise)
893 919 05. output data check: three images subtraction test
894 920 06. output data check: two images subtraction test
895 921 """
896 922
897 - existing_image = 'expected.im'
898 - existing_imsmoothed_image = 'expected.imsmooth.im'
899 - existing_baselined_image = 'expected.bl.im'
900 - input_image = ('input_image.im', 1.5, [64, 64, 4, 128])
901 - smoothed_image = ('smoothed_image.im', 2.0, [64, 64, 4, 128])
923 + existing_image = "expected.im"
924 + existing_imsmoothed_image = "expected.imsmooth.im"
925 + existing_baselined_image = "expected.bl.im"
926 + input_image = ("input_image.im", 1.5, [64, 64, 4, 128])
927 + smoothed_image = ("smoothed_image.im", 2.0, [64, 64, 4, 128])
902 928 smoothed_and_subtracted_image = (
903 - 'smoothed_and_subtracted_image.im', 2.5, [64, 64, 4, 128])
904 - testdata_err = ('testdata_err.im', 1, [65, 64, 4, 128])
929 + "smoothed_and_subtracted_image.im",
930 + 2.5,
931 + [64, 64, 4, 128],
932 + )
933 + testdata_err = ("testdata_err.im", 1, [65, 64, 4, 128])
905 934
906 935 def setUp(self):
907 936 self._copy_test_files(self.existing_image)
908 937 self._copy_test_files(self.existing_imsmoothed_image)
909 938 self._copy_test_files(self.existing_baselined_image)
910 939 self._create_image(
911 - self.input_image[0], self.input_image[1], self.input_image[2])
940 + self.input_image[0], self.input_image[1], self.input_image[2]
941 + )
912 942 self._create_image(
913 - self.smoothed_image[0],
914 - self.smoothed_image[1],
915 - self.smoothed_image[2])
943 + self.smoothed_image[0], self.smoothed_image[1], self.smoothed_image[2]
944 + )
916 945 self._create_image(
917 946 self.smoothed_and_subtracted_image[0],
918 947 self.smoothed_and_subtracted_image[1],
919 - self.smoothed_and_subtracted_image[2])
948 + self.smoothed_and_subtracted_image[2],
949 + )
920 950 self._create_image(
921 - self.testdata_err[0], self.testdata_err[1], self.testdata_err[2])
951 + self.testdata_err[0], self.testdata_err[1], self.testdata_err[2]
952 + )
922 953
923 954 def test_image_subtraction_01(self):
924 955 """01. successful test: subtracted output = input_image - (smoothed_image - smoothed_and_subtracted_image)."""
925 - image_stack = _CasaImageStack(
926 - top=_UnerasableFolder(self.existing_image))
956 + image_stack = _CasaImageStack(top=_UnerasableFolder(self.existing_image))
927 957 image_stack.push(_EraseableFolder(self.existing_imsmoothed_image))
928 958 image_stack.push(_EraseableFolder(self.existing_baselined_image))
929 - output = 'output_7_1.im'
959 + output = "output_7_1.im"
930 960 _ImageSubtractionMethods.execute(output, image_stack)
931 961 self.assertTrue(os.path.exists(output))
932 962
933 963 def test_image_subtraction_02(self):
934 964 """02. successful test: subtracted output = subtracted_image."""
935 - image_stack = _CasaImageStack(
936 - top=_UnerasableFolder(self.existing_image))
965 + image_stack = _CasaImageStack(top=_UnerasableFolder(self.existing_image))
937 966 image_stack.push(_EraseableFolder(self.existing_baselined_image))
938 - output = 'output_7_2.im'
967 + output = "output_7_2.im"
939 968 _ImageSubtractionMethods.execute(output, image_stack)
940 969 self.assertTrue(os.path.exists(output))
941 970
942 - @test_base.exception_case(ValueError,
943 - 'operands could not be broadcast together with shapes')
971 + @test_base.exception_case(
972 + ValueError, "operands could not be broadcast together with shapes"
973 + )
944 974 def test_image_subtraction_03(self):
945 975 """03. failure case: subtract three images have unmatched shape, an exception raises."""
946 - image_stack = _CasaImageStack(
947 - top=_UnerasableFolder(self.input_image[0]))
976 + image_stack = _CasaImageStack(top=_UnerasableFolder(self.input_image[0]))
948 977 image_stack.push(_EraseableFolder(self.smoothed_image[0]))
949 978 image_stack.push(_EraseableFolder(self.testdata_err[0]))
950 - output = 'output_7_3.im'
979 + output = "output_7_3.im"
951 980 _ImageSubtractionMethods.execute(output, image_stack)
952 981
953 982 def test_image_subtraction_04(self):
954 983 """04. successful test: subtract two images have unmatched shape (any exceptions do not raise)."""
955 - image_stack = _CasaImageStack(
956 - top=_UnerasableFolder(self.input_image[0]))
984 + image_stack = _CasaImageStack(top=_UnerasableFolder(self.input_image[0]))
957 985 image_stack.push(_EraseableFolder(self.testdata_err[0]))
958 - output = 'output_7_4.im'
986 + output = "output_7_4.im"
959 987 _ImageSubtractionMethods.execute(output, image_stack)
960 988 self.assertTrue(os.path.exists(output))
961 989 self.assertFalse(os.path.exists(self.testdata_err[0]))
962 990
963 991 def test_image_subtraction_05(self):
964 992 """05. output data check: three images subtraction test."""
965 993 # output = input_image - (smoothed_image - smoothed_and_subtracted_image)
966 - image_stack = _CasaImageStack(
967 - top=_UnerasableFolder(self.input_image[0]))
994 + image_stack = _CasaImageStack(top=_UnerasableFolder(self.input_image[0]))
968 995 image_stack.push(_EraseableFolder(self.smoothed_image[0]))
969 - image_stack.push(_EraseableFolder(
970 - self.smoothed_and_subtracted_image[0]))
971 - output = 'output_7_5.im'
996 + image_stack.push(_EraseableFolder(self.smoothed_and_subtracted_image[0]))
997 + output = "output_7_5.im"
972 998 _ImageSubtractionMethods.execute(output, image_stack)
973 999 with tool_manager(output, image) as ia:
974 1000 arr = ia.getchunk()
975 - self.assertTrue(np.array_equal(
976 - arr, np.full((64, 64, 4, 128), 2.0)))
1001 + self.assertTrue(np.array_equal(arr, np.full((64, 64, 4, 128), 2.0)))
977 1002
978 1003 def test_image_subtraction_06(self):
979 1004 """06. output data check: two images subtraction test."""
980 1005 # output = smoothed_image
981 - image_stack = _CasaImageStack(
982 - top=_UnerasableFolder(self.input_image[0]))
1006 + image_stack = _CasaImageStack(top=_UnerasableFolder(self.input_image[0]))
983 1007 image_stack.push(_EraseableFolder(self.smoothed_image[0]))
984 - output = 'output_7_6.im'
1008 + output = "output_7_6.im"
985 1009 _ImageSubtractionMethods.execute(output, image_stack)
986 1010 with tool_manager(output, image) as ia:
987 1011 arr = ia.getchunk()
988 - self.assertTrue(np.array_equal(
989 - arr, np.full((64, 64, 4, 128), 2.0)))
1012 + self.assertTrue(np.array_equal(arr, np.full((64, 64, 4, 128), 2.0)))
990 1013
991 1014
992 1015 class TestMS2Image(test_base):
993 1016 """Test MS2Image.
994 1017
995 1018 01. successful case: convert a MeasurementSet to image and compare it to the correct chunk
996 1019 02. failure case: attempt to convert a MeasurementSet without base image, an exception raises
997 1020 03. failure case: attempt to convert a MeasurementSet unexisted, an exception raises
998 1021 """
999 1022
1000 - input_image = 'expected.im'
1001 - original_image = 'expected_orig.im'
1002 - input_ms = 'expected.ms'
1003 - baselined_ms = 'expected.bl.ms'
1023 + input_image = "expected.im"
1024 + original_image = "expected_orig.im"
1025 + input_ms = "expected.ms"
1026 + baselined_ms = "expected.bl.ms"
1004 1027
1005 1028 def setUp(self):
1006 1029 self._copy_test_files(self.input_image)
1007 1030 self._copy_test_files(self.input_ms)
1008 1031 self._copy_test_files(self.baselined_ms)
1009 1032 if os.path.exists(self.input_image):
1010 1033 os.rename(self.input_image, self.original_image)
1011 1034 else:
1012 - raise RuntimeError('some errors occured in copying files')
1035 + raise RuntimeError("some errors occured in copying files")
1013 1036 if not os.path.exists(self.original_image):
1014 - raise RuntimeError('some errors occured in copying files')
1037 + raise RuntimeError("some errors occured in copying files")
1015 1038 self.image_shape = _get_image_shape(self.original_image)
1016 1039
1017 1040 def test_ms2image_01(self):
1018 1041 """01. successful case: convert a MeasurementSet to image and compare it to the correct chunk."""
1019 - _MS2ImageMethods.convert(base_image=self.original_image,
1020 - input_ms=self.input_ms,
1021 - input_image_shape=self.image_shape,
1022 - datacolumn=DATACOLUMN)
1042 + _MS2ImageMethods.convert(
1043 + base_image=self.original_image,
1044 + input_ms=self.input_ms,
1045 + input_image_shape=self.image_shape,
1046 + datacolumn=DATACOLUMN,
1047 + )
1023 1048 self.assertTrue(os.path.exists(self.input_image))
1024 1049 with tool_manager(self.input_image, image) as ia:
1025 1050 arr1 = ia.getchunk()
1026 1051 with tool_manager(self.original_image, image) as ia:
1027 1052 arr2 = ia.getchunk()
1028 1053 self.assertTrue(np.array_equal(arr1, arr2))
1029 1054
1030 - @test_base.exception_case(TypeError, 'stat: path should be string, ')
1055 + @test_base.exception_case(TypeError, "stat: path should be string, ")
1031 1056 def test_ms2image_02(self):
1032 1057 """02. failure case: attempt to convert a MeasurementSet without base image, an exception raises."""
1033 - _MS2ImageMethods.convert(base_image=None,
1034 - input_ms=self.input_ms,
1035 - input_image_shape=self.image_shape,
1036 - datacolumn=DATACOLUMN)
1037 -
1038 - @test_base.exception_case(TypeError, 'stat: path should be string, ')
1058 + _MS2ImageMethods.convert(
1059 + base_image=None,
1060 + input_ms=self.input_ms,
1061 + input_image_shape=self.image_shape,
1062 + datacolumn=DATACOLUMN,
1063 + )
1064 +
1065 + @test_base.exception_case(TypeError, "stat: path should be string, ")
1039 1066 def test_ms2image_03(self):
1040 1067 """03. failure case: attempt to convert a MeasurementSet unexisted, an exception raises."""
1041 - _MS2ImageMethods.convert(base_image=self.original_image,
1042 - input_ms=self.baselined_ms,
1043 - input_image_shape=self.image_shape,
1044 - datacolumn=DATACOLUMN)
1045 - converted = 'expected.bl.im'
1068 + _MS2ImageMethods.convert(
1069 + base_image=self.original_image,
1070 + input_ms=self.baselined_ms,
1071 + input_image_shape=self.image_shape,
1072 + datacolumn=DATACOLUMN,
1073 + )
1074 + converted = "expected.bl.im"
1046 1075 self.assertTrue(os.path.exists(converted))
1047 1076 with tool_manager(self.original_image, image) as ia:
1048 1077 arr1 = ia.getchunk()
1049 1078 with tool_manager(converted, image) as ia:
1050 1079 arr2 = ia.getchunk()
1051 1080 self.assertFalse(np.array_equal(arr1, arr2))
1052 1081
1053 - _MS2ImageMethods.convert(base_image=self.original_image,
1054 - input_ms=None,
1055 - input_image_shape=self.image_shape,
1056 - datacolumn=DATACOLUMN)
1082 + _MS2ImageMethods.convert(
1083 + base_image=self.original_image,
1084 + input_ms=None,
1085 + input_image_shape=self.image_shape,
1086 + datacolumn=DATACOLUMN,
1087 + )
1057 1088
1058 1089
1059 1090 class TestModuleMethodsOfImbaseline(test_base):
1060 1091 """Test global methods.
1061 1092
1062 1093 The white tests of global methods of imbaseline module must be implemented in this class.
1063 1094
1064 1095 01. _get_image_shape: successful case: get an image shape and check properties of it
1065 1096 02. _get_image_shape: failure case: attempt to read an image unexisted, an exception raises
1066 1097 03. _get_image_shape: failure case: attempt to read an image has invalid shape, an exception raises
1067 1098 """
1068 1099
1069 - input_image = 'expected.im'
1070 - g192_im = 'g192_a2.image'
1100 + input_image = "expected.im"
1101 + g192_im = "g192_a2.image"
1071 1102
1072 1103 def setUp(self):
1073 1104 self._copy_test_files(self.input_image)
1074 1105 self._copy_test_files(self.g192_im)
1075 1106
1076 1107 def test_module_methods_01(self):
1077 1108 """01. _get_image_shape: successful case: get an image shape and check properties of it."""
1078 1109 shape = _get_image_shape(self.input_image)
1079 1110 self.assertTrue(np.array_equal(shape.im_shape, [20, 20, 100]))
1080 1111 self.assertTrue(np.array_equal(shape.axis_dir, [0, 1]))
1088 1119 shape = _get_image_shape(self.g192_im)
1089 1120 self.assertTrue(np.array_equal(shape.im_shape, [512, 512, 1, 40]))
1090 1121 self.assertTrue(np.array_equal(shape.axis_dir, [0, 1]))
1091 1122 self.assertEqual(shape.axis_sp, 3)
1092 1123 self.assertEqual(shape.axis_pol, 2)
1093 1124 self.assertTrue(np.array_equal(shape.dir_shape, [512, 512]))
1094 1125 self.assertEqual(shape.im_nrow, 262144)
1095 1126 self.assertEqual(shape.im_nchan, 40)
1096 1127 self.assertEqual(shape.im_npol, 1)
1097 1128
1098 - @test_base.exception_case(ValueError, 'path \'notexists\' is not found')
1129 + @test_base.exception_case(ValueError, "path 'notexists' is not found")
1099 1130 def test_module_methods_02(self):
1100 1131 """02. _get_image_shape: failure case: attempt to read an image unexisted, an exception raises."""
1101 - _get_image_shape('notexists')
1132 + _get_image_shape("notexists")
1102 1133
1103 - @test_base.exception_case(ValueError,
1104 - 'image \'testdata_01.im\' is invalid')
1134 + @test_base.exception_case(ValueError, "image 'testdata_01.im' is invalid")
1105 1135 def test_module_methods_03(self):
1106 1136 """03. _get_image_shape: failure case: attempt to read an image has invalid shape, an exception raises."""
1107 - testimage = 'testdata_01.im'
1137 + testimage = "testdata_01.im"
1108 1138 self._create_image(testimage, 1.0, [64, 64])
1109 1139 _get_image_shape(testimage)
1110 1140
1111 1141
1112 1142 class TestImbaseline(test_base):
1113 1143 """imbaseline tests.
1114 1144
1115 1145 01. failure case: attempt to read imagefile set None, an exception raises
1116 1146 02. successful case: execute imbaseline with output_cont set False, cont file does not generate
1117 1147 03. successful case: execute imbaseline with bloutput set output path, bloutput generates
1118 1148 """
1119 1149
1120 - input_image = 'ref_multipix.signalband'
1121 - blparam = 'analytic_variable_blparam_spw1.txt'
1150 + input_image = "ref_multipix.signalband"
1151 + blparam = "analytic_variable_blparam_spw1.txt"
1122 1152 f_1_count = 1
1123 1153
1124 1154 def setUp(self):
1125 1155 self._copy_test_files(self.input_image)
1126 1156 self._copy_test_files(self.blparam)
1127 1157
1128 - @test_base.exception_case(ValueError, 'Error: file is not found.')
1158 + @test_base.exception_case(ValueError, "Error: file is not found.")
1129 1159 def test_imbaseline_01(self):
1130 1160 """01. failure case: attempt to read imagefile set None, an exception raises."""
1131 - imagefile = ''
1132 - linefile = 'output_imbaseline_01'
1133 - dirkernel = 'gaussian'
1134 - spkernel = 'gaussian'
1135 - major = '20arcsec'
1136 - minor = '10arcsec'
1137 - pa = '0deg'
1138 - blfunc = 'sinusoid'
1161 + imagefile = ""
1162 + linefile = "output_imbaseline_01"
1163 + dirkernel = "gaussian"
1164 + spkernel = "gaussian"
1165 + major = "20arcsec"
1166 + minor = "10arcsec"
1167 + pa = "0deg"
1168 + blfunc = "sinusoid"
1139 1169 output_cont = True
1140 1170
1141 - imbaseline(imagename=imagefile,
1142 - linefile=linefile,
1143 - dirkernel=dirkernel,
1144 - spkernel=spkernel,
1145 - major=major,
1146 - minor=minor,
1147 - pa=pa,
1148 - blfunc=blfunc,
1149 - output_cont=output_cont)
1171 + imbaseline(
1172 + imagename=imagefile,
1173 + linefile=linefile,
1174 + dirkernel=dirkernel,
1175 + spkernel=spkernel,
1176 + major=major,
1177 + minor=minor,
1178 + pa=pa,
1179 + blfunc=blfunc,
1180 + output_cont=output_cont,
1181 + )
1150 1182
1151 1183 def test_imbaseline_02(self):
1152 1184 """03. successful case: execute imbaseline with output_cont set False, cont file does not generate."""
1153 1185 imagefile = self.input_image
1154 - linefile = 'output_imbaseline_02'
1155 - dirkernel = 'gaussian'
1156 - spkernel = 'gaussian'
1157 - major = '20arcsec'
1158 - minor = '10arcsec'
1159 - pa = '0deg'
1160 - blfunc = 'sinusoid'
1186 + linefile = "output_imbaseline_02"
1187 + dirkernel = "gaussian"
1188 + spkernel = "gaussian"
1189 + major = "20arcsec"
1190 + minor = "10arcsec"
1191 + pa = "0deg"
1192 + blfunc = "sinusoid"
1161 1193 output_cont = False
1162 1194
1163 - imbaseline(imagename=imagefile,
1164 - linefile=linefile,
1165 - dirkernel=dirkernel,
1166 - spkernel=spkernel,
1167 - major=major,
1168 - minor=minor,
1169 - pa=pa,
1170 - blfunc=blfunc,
1171 - output_cont=output_cont)
1172 - self.assertFalse(os.path.exists(linefile + '.cont'))
1195 + imbaseline(
1196 + imagename=imagefile,
1197 + linefile=linefile,
1198 + dirkernel=dirkernel,
1199 + spkernel=spkernel,
1200 + major=major,
1201 + minor=minor,
1202 + pa=pa,
1203 + blfunc=blfunc,
1204 + output_cont=output_cont,
1205 + )
1206 + self.assertFalse(os.path.exists(linefile + ".cont"))
1173 1207
1174 1208 def test_imbaseline_03(self):
1175 1209 """04. successful case: execute imbaseline with bloutput set output path, bloutput generates."""
1176 1210 imagefile = self.input_image
1177 - linefile = 'output_imbaseline_03'
1178 - dirkernel = 'gaussian'
1179 - spkernel = 'gaussian'
1180 - major = '20arcsec'
1181 - minor = '10arcsec'
1182 - pa = '0deg'
1183 - blfunc = 'sinusoid'
1211 + linefile = "output_imbaseline_03"
1212 + dirkernel = "gaussian"
1213 + spkernel = "gaussian"
1214 + major = "20arcsec"
1215 + minor = "10arcsec"
1216 + pa = "0deg"
1217 + blfunc = "sinusoid"
1184 1218 output_cont = True
1185 - bloutput = self.input_image + 'bloutput'
1186 -
1187 - imbaseline(imagename=imagefile,
1188 - linefile=linefile,
1189 - dirkernel=dirkernel,
1190 - spkernel=spkernel,
1191 - major=major,
1192 - minor=minor,
1193 - pa=pa,
1194 - blfunc=blfunc,
1195 - output_cont=output_cont,
1196 - bloutput=bloutput)
1219 + bloutput = self.input_image + "bloutput"
1220 +
1221 + imbaseline(
1222 + imagename=imagefile,
1223 + linefile=linefile,
1224 + dirkernel=dirkernel,
1225 + spkernel=spkernel,
1226 + major=major,
1227 + minor=minor,
1228 + pa=pa,
1229 + blfunc=blfunc,
1230 + output_cont=output_cont,
1231 + bloutput=bloutput,
1232 + )
1197 1233 self.assertTrue(os.path.exists(bloutput))
1198 1234
1199 1235
1200 1236 class TestImbaselineExecution(test_base):
1201 1237 """Imbaseline execution testing.
1202 1238
1203 1239 This test class generate tests dynamically and register them with the class
1204 1240 while module initialisation.
1205 1241 """
1206 1242
1207 - input_image = 'ref_multipix.signalband'
1208 - blparam = 'analytic_variable_blparam_spw1.txt'
1209 - test_name_prefix = 'test_imbaseline_execution'
1210 - linefile = 'output_f_1'
1243 + input_image = "ref_multipix.signalband"
1244 + blparam = "analytic_variable_blparam_spw1.txt"
1245 + test_name_prefix = "test_imbaseline_execution"
1246 + linefile = "output_f_1"
1211 1247 output_cont = True
1212 - bloutput = input_image + '.bloutput'
1213 - chans = ''
1248 + bloutput = input_image + ".bloutput"
1249 + chans = ""
1214 1250 thresh = 5.0
1215 1251 avg_limit = 5
1216 1252 minwidth = 5
1217 1253 edge = [0, 0]
1218 1254 order = 5
1219 1255 npiece = 3
1220 1256 applyfft = True
1221 1257 fftthresh = 3.0
1222 1258 addwn = [0]
1223 1259 rejwn = []
1224 1260 clipniter = 0
1225 1261 clipthresh = 3.0
1226 - major = '20arcsec'
1227 - minor = '10arcsec'
1228 - pa = '0deg'
1262 + major = "20arcsec"
1263 + minor = "10arcsec"
1264 + pa = "0deg"
1229 1265 kimage = os.path.join(DATAPATH, "bessel.im")
1230 1266 scale = -1.0
1231 1267 kwidth = 5
1232 1268 filenames_existence_check = (linefile, bloutput)
1233 1269
1234 1270 test_no = 1
1235 1271
1236 1272 def setUp(self):
1237 1273 self._copy_test_files(self.input_image)
1238 1274 self._copy_test_files(self.blparam)
1239 1275
1240 1276 @staticmethod
1241 1277 def generate_tests():
1242 - maskmode = ('auto', 'list')
1243 - blfunc = ('poly', 'chebyshev', 'cspline', 'sinusoid', 'variable')
1244 - dirkernel = ('none', 'gaussian', 'boxcar', 'image')
1245 - spkernel = ('none', 'gaussian', 'boxcar')
1278 + maskmode = ("auto", "list")
1279 + blfunc = ("poly", "chebyshev", "cspline", "sinusoid", "variable")
1280 + dirkernel = ("none", "gaussian", "boxcar", "image")
1281 + spkernel = ("none", "gaussian", "boxcar")
1246 1282
1247 1283 def __register_a_test_with_the_class(
1248 - _class, maskmode, blfunc, dirkernel, spkernel):
1249 - test_name = f'{_class.test_name_prefix}_{maskmode}_{blfunc}_{dirkernel}_{spkernel}'
1284 + _class, maskmode, blfunc, dirkernel, spkernel
1285 + ):
1286 + test_name = (
1287 + f"{_class.test_name_prefix}_{maskmode}_{blfunc}_{dirkernel}_{spkernel}"
1288 + )
1250 1289 setattr(
1251 1290 _class,
1252 1291 test_name,
1253 1292 _class._generate_a_test(
1254 - maskmode,
1255 - blfunc,
1256 - dirkernel,
1257 - spkernel,
1258 - test_name))
1259 -
1260 - [__register_a_test_with_the_class(__class__, _maskmode, _blfunc, _dirkernel, _spkernel)
1261 - for _maskmode in maskmode
1262 - for _blfunc in blfunc
1263 - for _dirkernel in dirkernel
1264 - for _spkernel in spkernel]
1293 + maskmode, blfunc, dirkernel, spkernel, test_name
1294 + ),
1295 + )
1296 +
1297 + [
1298 + __register_a_test_with_the_class(
1299 + __class__, _maskmode, _blfunc, _dirkernel, _spkernel
1300 + )
1301 + for _maskmode in maskmode
1302 + for _blfunc in blfunc
1303 + for _dirkernel in dirkernel
1304 + for _spkernel in spkernel
1305 + ]
1265 1306
1266 1307 @staticmethod
1267 1308 def _generate_a_test(maskmode, blfunc, dirkernel, spkernel, test_name):
1268 1309 def test_method(self):
1269 1310 """TestImbaselineExecution method No."""
1270 1311 params = dict(
1271 1312 imagename=self.input_image,
1272 1313 linefile=self.linefile,
1273 1314 output_cont=self.output_cont,
1274 1315 bloutput=self.bloutput,
1288 1329 blparam=self.blparam,
1289 1330 clipniter=self.clipniter,
1290 1331 clipthresh=self.clipthresh,
1291 1332 dirkernel=dirkernel,
1292 1333 major=self.major,
1293 1334 minor=self.minor,
1294 1335 pa=self.pa,
1295 1336 kimage=self.kimage,
1296 1337 scale=self.scale,
1297 1338 spkernel=spkernel,
1298 - kwidth=self.kwidth)
1339 + kwidth=self.kwidth,
1340 + )
1299 1341 casalog.post(
1300 - f'{test_name} [maskmode={maskmode}, blfunc={blfunc}, '
1301 - f'dirkernel={dirkernel}, spkernel={spkernel}]', 'INFO')
1342 + f"{test_name} [maskmode={maskmode}, blfunc={blfunc}, "
1343 + f"dirkernel={dirkernel}, spkernel={spkernel}]",
1344 + "INFO",
1345 + )
1302 1346 imbaseline(**params)
1303 1347 for file in self.filenames_existence_check:
1304 1348 self.assertTrue(os.path.exists(file))
1305 - test_method.__doc__ += (f'{TestImbaselineExecution.test_no:03} [maskmode={maskmode}, '
1306 - f'blfunc={blfunc}, dirkernel={dirkernel}, spkernel={spkernel}]')
1349 +
1350 + test_method.__doc__ += (
1351 + f"{TestImbaselineExecution.test_no:03} [maskmode={maskmode}, "
1352 + f"blfunc={blfunc}, dirkernel={dirkernel}, spkernel={spkernel}]"
1353 + )
1307 1354 TestImbaselineExecution.test_no += 1
1308 1355 return test_method
1309 1356
1310 1357
1311 1358 # generate test methods of TestImbaselineExecution dynamically
1312 1359 TestImbaselineExecution.generate_tests()
1313 1360
1314 1361
1315 1362 class TestImbaselineOutputs(test_base):
1316 1363 """Imbaseline output testing.
1317 1364
1318 1365 This test class generate tests dynamically and register them with the class
1319 1366 while module initialisation.
1320 1367 """
1321 1368
1322 - input_image = 'ref_multipix.signalband'
1323 - blparam = 'analytic_variable_blparam_spw1.txt'
1369 + input_image = "ref_multipix.signalband"
1370 + blparam = "analytic_variable_blparam_spw1.txt"
1324 1371 TEST_IMAGE_SHAPE = [128, 128, 1, 10]
1325 1372 TEST_IMAGE_VALUE = 2.0
1326 1373 expected_output_chunk = np.full(TEST_IMAGE_SHAPE, 0.0)
1327 1374 expected_cont_chunk = np.full(TEST_IMAGE_SHAPE, TEST_IMAGE_VALUE)
1328 1375
1329 - test_name_prefix = 'test_imbaseline_outputs'
1330 - linefile = 'output.im'
1376 + test_name_prefix = "test_imbaseline_outputs"
1377 + linefile = "output.im"
1331 1378 output_cont = True
1332 - bloutput = linefile + '.bloutput'
1333 - test_image = 'input_image.im'
1334 - major = '20arcsec'
1335 - minor = '10arcsec'
1336 - pa = '0deg'
1379 + bloutput = linefile + ".bloutput"
1380 + test_image = "input_image.im"
1381 + major = "20arcsec"
1382 + minor = "10arcsec"
1383 + pa = "0deg"
1337 1384
1338 1385 test_no = 1
1339 1386
1340 1387 def setUp(self):
1341 1388 self._copy_test_files(self.input_image)
1342 1389 self._copy_test_files(self.blparam)
1343 1390
1344 1391 @staticmethod
1345 1392 def generate_tests():
1346 - blfunc = ('poly', 'chebyshev', 'cspline', 'sinusoid')
1347 - dirkernel = ('none', 'gaussian', 'boxcar')
1348 - spkernel = ('none', 'gaussian', 'boxcar')
1393 + blfunc = ("poly", "chebyshev", "cspline", "sinusoid")
1394 + dirkernel = ("none", "gaussian", "boxcar")
1395 + spkernel = ("none", "gaussian", "boxcar")
1349 1396
1350 - def __register_a_test_with_the_class(
1351 - _class, blfunc, dirkernel, spkernel):
1352 - test_name = f'{_class.test_name_prefix}_{blfunc}_{dirkernel}_{spkernel}'
1397 + def __register_a_test_with_the_class(_class, blfunc, dirkernel, spkernel):
1398 + test_name = f"{_class.test_name_prefix}_{blfunc}_{dirkernel}_{spkernel}"
1353 1399 setattr(
1354 1400 _class,
1355 1401 test_name,
1356 - _class._generate_a_test(
1357 - blfunc,
1358 - dirkernel,
1359 - spkernel,
1360 - test_name))
1402 + _class._generate_a_test(blfunc, dirkernel, spkernel, test_name),
1403 + )
1361 1404
1362 - [__register_a_test_with_the_class(__class__, _blfunc, _dirkernel, _spkernel)
1363 - for _blfunc in blfunc
1364 - for _dirkernel in dirkernel
1365 - for _spkernel in spkernel]
1405 + [
1406 + __register_a_test_with_the_class(__class__, _blfunc, _dirkernel, _spkernel)
1407 + for _blfunc in blfunc
1408 + for _dirkernel in dirkernel
1409 + for _spkernel in spkernel
1410 + ]
1366 1411
1367 1412 @staticmethod
1368 1413 def _generate_a_test(blfunc, dirkernel, spkernel, test_name):
1369 1414 def test_method(self):
1370 1415 """TestImbaselineOutputs test."""
1371 1416 self._create_image(
1372 - self.test_image, self.TEST_IMAGE_VALUE, self.TEST_IMAGE_SHAPE)
1417 + self.test_image, self.TEST_IMAGE_VALUE, self.TEST_IMAGE_SHAPE
1418 + )
1373 1419 params = dict(
1374 1420 imagename=self.test_image,
1375 1421 linefile=self.linefile,
1376 1422 output_cont=self.output_cont,
1377 1423 bloutput=self.bloutput,
1378 1424 blfunc=blfunc,
1379 1425 dirkernel=dirkernel,
1380 1426 spkernel=spkernel,
1381 1427 major=self.major,
1382 1428 minor=self.minor,
1383 - pa=self.pa)
1429 + pa=self.pa,
1430 + )
1384 1431 casalog.post(
1385 - f'{test_name} [maskmode=auto, blfunc={blfunc}, '
1386 - f'dirkernel={dirkernel}, spkernel={spkernel}]', 'INFO')
1432 + f"{test_name} [maskmode=auto, blfunc={blfunc}, "
1433 + f"dirkernel={dirkernel}, spkernel={spkernel}]",
1434 + "INFO",
1435 + )
1387 1436 imbaseline(**params)
1388 1437 if os.path.exists(self.linefile):
1389 1438 with tool_manager(self.linefile, image) as ia:
1390 1439 chunk = ia.getchunk()
1391 1440 self._summary(False, test_name, chunk)
1392 - self.assertTrue(np.allclose(
1393 - chunk, self.expected_output_chunk, atol=2.0))
1394 - if os.path.exists(self.test_image + '.cont'):
1395 - with tool_manager(self.test_image + '.cont', image) as ia:
1441 + self.assertTrue(
1442 + np.allclose(chunk, self.expected_output_chunk, atol=2.0)
1443 + )
1444 + if os.path.exists(self.test_image + ".cont"):
1445 + with tool_manager(self.test_image + ".cont", image) as ia:
1396 1446 chunk = ia.getchunk()
1397 1447 self._summary(True, test_name, chunk)
1398 - self.assertTrue(np.allclose(
1399 - chunk, self.expected_cont_chunk, atol=2.0))
1400 -
1401 - test_method.__doc__ += (f' No.{TestImbaselineOutputs.test_no:03} [blfunc={blfunc}, '
1402 - f'dirkernel={dirkernel}, spkernel={spkernel}]')
1448 + self.assertTrue(
1449 + np.allclose(chunk, self.expected_cont_chunk, atol=2.0)
1450 + )
1451 +
1452 + test_method.__doc__ += (
1453 + f" No.{TestImbaselineOutputs.test_no:03} [blfunc={blfunc}, "
1454 + f"dirkernel={dirkernel}, spkernel={spkernel}]"
1455 + )
1403 1456 TestImbaselineOutputs.test_no += 1
1404 1457 return test_method
1405 1458
1406 1459 def _summary(self, is_cont, test_name, chunk): # temporary method
1407 - m = re.match(
1408 - r'test_imbaseline_outputs_([^_]+)_([^_]+)_([^_]+)', test_name)
1409 - prefix = 'cont' if is_cont else ' out'
1460 + m = re.match(r"test_imbaseline_outputs_([^_]+)_([^_]+)_([^_]+)", test_name)
1461 + prefix = "cont" if is_cont else " out"
1410 1462 print(
1411 - f'{prefix} blfunc:{m[1]} dirkernel:{m[2]} spkernel:{m[3]}, {np.max(chunk)}, '
1412 - f'{np.min(chunk)}, {np.average(chunk)}, {np.median(chunk)}')
1463 + f"{prefix} blfunc:{m[1]} dirkernel:{m[2]} spkernel:{m[3]}, {np.max(chunk)}, "
1464 + f"{np.min(chunk)}, {np.average(chunk)}, {np.median(chunk)}"
1465 + )
1413 1466
1414 1467
1415 1468 # generate test methods of TestImbaselineOutputs dynamically
1416 1469 TestImbaselineOutputs.generate_tests()
1417 1470
1418 1471
1419 -class Workdir():
1472 +class Workdir:
1420 1473 """Workdir manipulation class."""
1421 1474
1422 1475 def __init__(self, path: str):
1423 1476 """Initialize function."""
1424 1477 self.path = path
1425 1478
1426 1479 def clean(self, dry_run: bool = False):
1427 1480 if os.path.exists(self.path) and dry_run is False:
1428 1481 try:
1429 1482 shutil.rmtree(self.path)
1430 1483 except Exception:
1431 - casalog.post(
1432 - 'Some errors occured when clearing work dir', 'SEVERE')
1484 + casalog.post("Some errors occured when clearing work dir", "SEVERE")
1433 1485 raise RuntimeError
1434 1486
1435 1487 def chdir(self):
1436 1488 if os.path.exists(self.path):
1437 1489 os.chdir(self.path)
1438 1490 else:
1439 - casalog.post(
1440 - 'Some errors occured when chdir to work dir', 'SEVERE')
1491 + casalog.post("Some errors occured when chdir to work dir", "SEVERE")
1441 1492 raise RuntimeError
1442 1493
1443 1494 @classmethod
1444 - def create(cls, parent_path: str = None) -> 'Workdir':
1495 + def create(cls, parent_path: str = None) -> "Workdir":
1445 1496 def is_valid_parent_path(path):
1446 - return \
1447 - os.path.exists(path) and \
1448 - os.path.isdir(path) and \
1449 - os.access(path, os.W_OK)
1497 + return (
1498 + os.path.exists(path)
1499 + and os.path.isdir(path)
1500 + and os.access(path, os.W_OK)
1501 + )
1450 1502
1451 1503 if not parent_path:
1452 1504 parent_path = os.getcwd()
1453 1505
1454 1506 if is_valid_parent_path(parent_path):
1455 1507 path = parent_path
1456 1508 while True:
1457 1509 path = os.path.join(parent_path, str(uuid.uuid4()))
1458 1510 if not os.path.exists(path):
1459 1511 os.mkdir(path)
1460 - casalog.post(f'created working directory: {path}', 'WARN')
1512 + casalog.post(f"created working directory: {path}", "WARN")
1461 1513 break
1462 1514 if path == parent_path:
1463 - raise RuntimeError(
1464 - 'Some errors occured when creating work dir')
1515 + raise RuntimeError("Some errors occured when creating work dir")
1465 1516 return Workdir(path)
1466 1517
1467 - raise RuntimeError('Some errors occured when creating work dir')
1518 + raise RuntimeError("Some errors occured when creating work dir")
1468 1519
1469 1520
1470 1521 def suite():
1471 1522 """Unittest suite definition."""
1472 1523 return [
1473 1524 TestImsmooth,
1474 1525 TestFileStack,
1475 1526 TestImageShape,
1476 1527 TestImbaseline,
1477 1528 TestImage2MS,
1478 1529 TestSdbaseline,
1479 1530 TestSdsmooth,
1480 1531 TestMS2Image,
1481 1532 TestImageSubtraction,
1482 1533 TestModuleMethodsOfImbaseline,
1483 1534 TestImbaselineExecution,
1484 - TestImbaselineOutputs]
1535 + TestImbaselineOutputs,
1536 + ]
1485 1537
1486 1538
1487 -if __name__ == '__main__':
1539 +if __name__ == "__main__":
1488 1540 unittest.main()

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut