Commits

Kazuhiko Shimada authored 0b11c926258
CAS-13520: added tests
No tags

casatasks/tests/tasks/test_imbaseline.py

Modified
461 461
462 462 def setUp(self):
463 463 self._copy_test_files(self.datapath, self.expected_im)
464 464 self._copy_test_files(self.datapath, self.expected_ms)
465 465 self.image_shape = get_image_shape(os.path.join(self.datapath, self.expected_im))
466 466
467 467 def test_6_1(self):
468 468 image_stack = CasaImageStack(top=UnerasableFolder(self.expected_im))
469 469 ms_stack = MeasurementSetStack()
470 470 ms_stack.push(EraseableFolder(self.expected_ms))
471 - SdbaselineMethods.execute(self.datacolumn, self.bloutput, self.maskmode, self.chans, self.thresh, self.avg_limit, self.minwidth,
472 - self.edge, self.blfunc, self.order, self.npiece, self.applyfft, self.fftthresh, self.addwn, self.rejwn, self.blparam,
473 - self.clipniter, self.clipthresh, image_stack, ms_stack, self.image_shape)
471 + SdbaselineMethods.execute(self.datacolumn, self.bloutput, self.maskmode, self.chans, self.thresh, self.avg_limit,
472 + self.minwidth, self.edge, self.blfunc, self.order, self.npiece, self.applyfft,
473 + self.fftthresh, self.addwn, self.rejwn, self.blparam, self.clipniter, self.clipthresh,
474 + image_stack, ms_stack, self.image_shape)
474 475 self.assertTrue(os.path.exists(ms_stack.peak().path))
475 476 self.assertTrue(os.path.exists(self.bloutput))
476 477 self.assertTrue(os.path.exists(image_stack.peak().path))
477 478
478 479 @test_base.exception_case(RuntimeError, 'the stack is empty')
479 480 def test_6_2(self):
480 481 image_stack = CasaImageStack(top=UnerasableFolder(self.expected_im))
481 482 ms_stack = MeasurementSetStack()
482 - SdbaselineMethods.execute(self.datacolumn, self.bloutput, self.maskmode, self.chans, self.thresh, self.avg_limit, self.minwidth,
483 - self.edge, self.blfunc, self.order, self.npiece, self.applyfft, self.fftthresh, self.addwn, self.rejwn, self.blparam,
484 - self.clipniter, self.clipthresh, image_stack, ms_stack, self.image_shape)
483 + SdbaselineMethods.execute(self.datacolumn, self.bloutput, self.maskmode, self.chans, self.thresh, self.avg_limit,
484 + self.minwidth, self.edge, self.blfunc, self.order, self.npiece, self.applyfft,
485 + self.fftthresh, self.addwn, self.rejwn, self.blparam, self.clipniter, self.clipthresh,
486 + image_stack, ms_stack, self.image_shape)
485 487
486 488 @test_base.exception_case(RuntimeError, 'the stack has not have enough stuff')
487 489 def test_6_3(self):
488 490 image_stack = CasaImageStack()
489 491 ms_stack = MeasurementSetStack()
490 492 ms_stack.push(EraseableFolder(self.expected_ms))
491 - SdbaselineMethods.execute(self.datacolumn, self.bloutput, self.maskmode, self.chans, self.thresh, self.avg_limit, self.minwidth,
492 - self.edge, self.blfunc, self.order, self.npiece, self.applyfft, self.fftthresh, self.addwn, self.rejwn, self.blparam,
493 - self.clipniter, self.clipthresh, image_stack, ms_stack, self.image_shape)
493 + SdbaselineMethods.execute(self.datacolumn, self.bloutput, self.maskmode, self.chans, self.thresh, self.avg_limit,
494 + self.minwidth, self.edge, self.blfunc, self.order, self.npiece, self.applyfft,
495 + self.fftthresh, self.addwn, self.rejwn, self.blparam, self.clipniter, self.clipthresh,
496 + image_stack, ms_stack, self.image_shape)
494 497
495 498
496 499 class image_subtraction_test(test_base):
497 - """Image subtraction test
500 + """Image subtraction test.
501 +
502 + 7-1. successful test: input_image - (smoothed_image - smoothed_and_subtracted_image)
503 + 7-2. successful test: input_image - baseline_image
504 + 7-3. unmatch shape
505 + 7-4. unmatch shape(exception is not thrown)
506 + 7-5. three arrays subtraction test
507 + 7-5. two arrays subtraction test
498 508 """
499 509
500 510 datapath = ctsys_resolve('unittest/imbaseline/')
501 511 expected_im = "expected.im"
502 512 expected_imsmoothed = "expected.imsmooth.im"
503 513 expected_bl = "expected.bl.im"
514 + testdata_01 = ("testdata_01.im", 1.5, [64, 64, 4, 128])
515 + testdata_02 = ("testdata_02.im", 2.0, [64, 64, 4, 128])
516 + testdata_03 = ("testdata_03.im", 2.5, [64, 64, 4, 128])
517 + testdata_err = ("testdata_err.im", 1, [65, 64, 4, 128])
504 518
505 519 def setUp(self):
506 520 self._copy_test_files(self.datapath, self.expected_im)
507 521 self._copy_test_files(self.datapath, self.expected_imsmoothed)
508 522 self._copy_test_files(self.datapath, self.expected_bl)
523 + self.create_image(self.testdata_01[0], self.testdata_01[1], self.testdata_01[2])
524 + self.create_image(self.testdata_02[0], self.testdata_02[1], self.testdata_02[2])
525 + self.create_image(self.testdata_03[0], self.testdata_03[1], self.testdata_03[2])
526 + self.create_image(self.testdata_err[0], self.testdata_err[1], self.testdata_err[2])
527 +
528 + def create_image(self, datapath, val=1, shape=[0, 0, 0, 0]):
529 + _ia = image()
530 + ary = _ia.makearray(v=val, shape=shape)
531 + _ia.fromarray(outfile=datapath, pixels=ary, overwrite=True)
532 + _ia.done()
509 533
510 534 def test_7_1(self):
511 535 image_stack = CasaImageStack(top=UnerasableFolder(self.expected_im))
512 536 image_stack.push(EraseableFolder(self.expected_imsmoothed))
513 537 image_stack.push(EraseableFolder(self.expected_bl))
514 538 output = "output_7_1.im"
515 539 ImageSubtractionMethods.execute(output, image_stack)
516 540 self.assertTrue(os.path.exists(output))
517 541
518 542 def test_7_2(self):
519 543 image_stack = CasaImageStack(top=UnerasableFolder(self.expected_im))
520 544 image_stack.push(EraseableFolder(self.expected_bl))
521 545 output = "output_7_2.im"
522 546 ImageSubtractionMethods.execute(output, image_stack)
523 547 self.assertTrue(os.path.exists(output))
524 548
549 + @test_base.exception_case(ValueError, 'operands could not be broadcast together with shapes')
550 + def test_7_3(self):
551 + image_stack = CasaImageStack(top=UnerasableFolder(self.testdata_01[0]))
552 + image_stack.push(EraseableFolder(self.testdata_02[0]))
553 + image_stack.push(EraseableFolder(self.testdata_err[0]))
554 + output = "output_7_3.im"
555 + ImageSubtractionMethods.execute(output, image_stack)
556 +
557 + def test_7_4(self):
558 + image_stack = CasaImageStack(top=UnerasableFolder(self.testdata_01[0]))
559 + image_stack.push(EraseableFolder(self.testdata_err[0]))
560 + output = "output_7_4.im"
561 + ImageSubtractionMethods.execute(output, image_stack)
562 + self.assertTrue(os.path.exists(output))
563 + self.assertFalse(os.path.exists(self.testdata_err[0]))
564 +
565 + def test_7_5(self):
566 + image_stack = CasaImageStack(top=UnerasableFolder(self.testdata_01[0]))
567 + image_stack.push(EraseableFolder(self.testdata_02[0]))
568 + image_stack.push(EraseableFolder(self.testdata_03[0]))
569 + output = "output_7_5.im"
570 + ImageSubtractionMethods.execute(output, image_stack)
571 + with tool_manager(output, image) as ia:
572 + arr = ia.getchunk()
573 + self.assertTrue(np.array_equal(arr, np.full((64, 64, 4, 128), 2.0)))
574 +
575 + def test_7_6(self):
576 + image_stack = CasaImageStack(top=UnerasableFolder(self.testdata_01[0]))
577 + image_stack.push(EraseableFolder(self.testdata_02[0]))
578 + output = "output_7_6.im"
579 + ImageSubtractionMethods.execute(output, image_stack)
580 + with tool_manager(output, image) as ia:
581 + arr = ia.getchunk()
582 + self.assertTrue(np.array_equal(arr, np.full((64, 64, 4, 128), 2.0)))
583 +
525 584
526 585 class imbaseline_test(test_base):
527 586 """Full test.
528 587
529 588 x-1. simple successful case
530 589 """
531 590
532 591 datapath = ctsys_resolve('unittest/imbaseline/')
533 592 expected = "expected.im"
534 593
554 613 major=major,
555 614 minor=minor,
556 615 pa=pa,
557 616 blfunc=blfunc,
558 617 output_cont=output_cont)
559 618 self.assertTrue(os.path.exists(linefile))
560 619
561 620
562 621 def suite():
563 622 return [imsmooth_test, AbstractFileStack_test, ImageShape_test, imbaseline_test, image2ms_test, sdbaseline_test, image_subtraction_test]
564 -

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

Add shortcut