Commits

Kazuhiko Shimada authored c09b615f1b7
CAS-13520: added some tests
No tags

casatasks/tests/tasks/test_imbaseline.py

Modified
1 -import math
2 1 import os
3 -import random
4 2 import re
5 3 import shutil
6 -import sys
7 4 import unittest
8 5
9 6 import numpy as np
10 7 from casatasks import casalog
11 8 from casatasks.private.sdutil import calibrater_manager, table_manager
12 9 from casatasks.private.task_imbaseline import *
13 -from casatools import (componentlist, ctsys, image, ms, quanta, regionmanager,
14 - table)
15 -from scipy import signal
10 +from casatools import ctsys, image, quanta, regionmanager, table
16 11
17 12 _ia = image()
18 13 _rg = regionmanager()
19 14 _tb = table()
20 15 _qa = quanta()
21 16 ctsys_resolve = ctsys.resolve
22 17
23 18
24 19 class test_base(unittest.TestCase):
25 20
425 420 execute_sdsmooth(self.datacolumn, self.spkenel, self.kwidth, image_stack, ms_stack, self.image_shape)
426 421
427 422 @test_base.exception_case(RuntimeError, 'the stack has not have enough stuff')
428 423 def test_5_3(self):
429 424 image_stack = CasaImageStack()
430 425 ms_stack = MeasurementSetStack()
431 426 ms_stack.push(EraseableFolder(self.expected_ms))
432 427 execute_sdsmooth(self.datacolumn, self.spkenel, self.kwidth, image_stack, ms_stack, self.image_shape)
433 428
434 429
435 - ####################################################################
436 - # ms2image test
437 - # 6-1. simple successful case
438 - # 6-2. simple failure case
439 - ####################################################################
430 +class sdbaseline_test(test_base):
431 + """sdbaseline test
440 432
433 + Tests of sdbaseline rely on test_sdbaselinebasically, so we have minimal tests in imbaseline.
434 +
435 + 6-1. simple successful case
436 + 6-2. invalid ms stack
437 + 6-3. invalid image stack
438 + """
439 +
440 + datapath = ctsys_resolve('unittest/imbaseline/')
441 + expected_im = "expected.im"
442 + expected_ms = "expected.ms"
443 + bloutput = "test.csv"
444 + maskmode = "auto"
445 + chans = ""
446 + thresh = 5.0
447 + avg_limit = 4
448 + minwidth = 4
449 + edge = [0, 0]
450 + blfunc = "cspline"
451 + order = 5
452 + npiece = 1
453 + applyfft = True
454 + fftthresh = 3.0
455 + addwn = [0]
456 + rejwn = []
457 + blparam = ''
458 + clipniter = 10
459 + clipthresh = 2.0
460 + datacolumn = DATACOLUMN
461 +
462 + def setUp(self):
463 + self._copy_test_files(self.datapath, self.expected_im)
464 + self._copy_test_files(self.datapath, self.expected_ms)
465 + self.image_shape = get_image_shape(os.path.join(self.datapath, self.expected_im))
466 +
467 + def test_6_1(self):
468 + image_stack = CasaImageStack(top=UnerasableFolder(self.expected_im))
469 + ms_stack = MeasurementSetStack()
470 + ms_stack.push(EraseableFolder(self.expected_ms))
471 + execute_sdbaseline(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)
474 + self.assertTrue(os.path.exists(ms_stack.peak().path))
475 + self.assertTrue(os.path.exists(self.bloutput))
476 + self.assertTrue(os.path.exists(image_stack.peak().path))
477 +
478 + @test_base.exception_case(RuntimeError, 'the stack is empty')
479 + def test_6_2(self):
480 + image_stack = CasaImageStack(top=UnerasableFolder(self.expected_im))
481 + ms_stack = MeasurementSetStack()
482 + execute_sdbaseline(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)
485 +
486 + @test_base.exception_case(RuntimeError, 'the stack has not have enough stuff')
487 + def test_6_3(self):
488 + image_stack = CasaImageStack()
489 + ms_stack = MeasurementSetStack()
490 + ms_stack.push(EraseableFolder(self.expected_ms))
491 + execute_sdbaseline(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)
494 +
495 +
496 +class image_subtraction_test(test_base):
497 + """Image subtraction test
498 + """
499 +
500 + datapath = ctsys_resolve('unittest/imbaseline/')
501 + expected_im = "expected.im"
502 + expected_imsmoothed = "expected.imsmooth.im"
503 + expected_bl = "expected.bl.im"
504 +
505 + def setUp(self):
506 + self._copy_test_files(self.datapath, self.expected_im)
507 + self._copy_test_files(self.datapath, self.expected_imsmoothed)
508 + self._copy_test_files(self.datapath, self.expected_bl)
509 +
510 + def test_7_1(self):
511 + image_stack = CasaImageStack(top=UnerasableFolder(self.expected_im))
512 + image_stack.push(EraseableFolder(self.expected_imsmoothed))
513 + image_stack.push(EraseableFolder(self.expected_bl))
514 + output = "output_7_1.im"
515 + execute_image_subtraction(output, image_stack)
516 + self.assertTrue(os.path.exists(output))
517 +
518 + def test_7_2(self):
519 + image_stack = CasaImageStack(top=UnerasableFolder(self.expected_im))
520 + image_stack.push(EraseableFolder(self.expected_bl))
521 + output = "output_7_2.im"
522 + execute_image_subtraction(output, image_stack)
523 + self.assertTrue(os.path.exists(output))
441 524
442 - ####################################################################
443 - # full test
444 - # 7-1. simple successful case
445 - # 7-2. simple failure case
446 - ####################################################################
447 525
448 526 class imbaseline_test(test_base):
527 + """Full test.
528 +
529 + x-1. simple successful case
530 + """
449 531
450 532 datapath = ctsys_resolve('unittest/imbaseline/')
451 533 expected = "expected.im"
452 534
453 535 def setUp(self):
454 536 self.ia = image()
455 537 self._copy_test_files(self.datapath, self.expected)
456 538
457 - def test_7_1(self):
539 + def test_x_1(self):
458 540 imagefile = self.expected
459 541 linefile = 'output_7_1'
460 542 dirkernel = 'gaussian'
461 543 spkernel = 'gaussian'
462 544 major = '20arcsec'
463 545 minor = '10arcsec'
464 546 pa = '0deg'
465 547 blfunc = 'sinusoid'
466 548 output_cont = True
467 549
471 553 spkernel=spkernel,
472 554 major=major,
473 555 minor=minor,
474 556 pa=pa,
475 557 blfunc=blfunc,
476 558 output_cont=output_cont)
477 559 self.assertTrue(os.path.exists(linefile))
478 560
479 561
480 562 def suite():
481 - return [imsmooth_test, AbstractFileStack_test, ImageShape_test, imbaseline_test, image2ms_test]
563 + 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