Commits

Takeshi Nakazato authored dc438581138
CAS-13160 tweak antenna selection to include autocorr

casa5/gcwrap/python/scripts/tests/test_sdatmcor.py

Modified
1 1 import glob
2 2 import os
3 3 import numpy as np
4 4 import shutil
5 5 import sys
6 6 import unittest
7 7
8 8 from casatasks.private.casa_transition import is_CASA6
9 9 if is_CASA6:
10 10 from casatasks import sdatmcor
11 11 import casatasks.private.task_sdatmcor as sdatmcor_impl
12 + import casatasks.private.sdutil as sdutil
12 13 # default isn't used in casatasks
13 14
14 15 def default(atask):
15 16 pass
16 17 # for testhelper import
17 18 sys.path.append(
18 19 os.path.dirname(
19 20 os.path.abspath(
20 21 os.path.dirname(__file__))))
21 22 from casatasks.private.sdutil import tbmanager
30 31
31 32 else:
32 33 from tasks import sdatmcor
33 34 import task_sdatmcor as sdatmcor_impl
34 35
35 36 from tasks import gencal, applycal
36 37 from __main__ import default
37 38 from sdutil import tbmanager
38 39 from taskinit import cbtool as calibrater
39 40 from taskinit import mstool
41 + import sdutil
40 42
41 43 # Define the root for the data files
42 44 datapath = os.environ.get('CASAPATH').split()[0] + ''
43 45
44 46 def ctsys_resolve(apath):
45 47 dataPath = os.path.join(os.environ['CASAPATH'].split()[0], 'data')
46 48 subdir_hints = ['', 'casa-data-req']
47 49 for subdir in subdir_hints:
48 50 path = os.path.join(dataPath, subdir, apath)
49 51 if os.path.exists(path):
446 448 def test_sdatmcor_intent_selection(self):
447 449 '''test intent selection: test if selection of ON_SOURCE data (i.e. excluding OFF_SOURCE data) still works'''
448 450 sdatmcor(infile=self.infile, outfile=self.outfile, intent='OBSERVE_TARGET#ON_SOURCE*', datacolumn='data')
449 451 self.check_result({19: True, 23: True}, on_source_only=True)
450 452
451 453 def test_sdatmcor_spw_process_less_than_20_select_all(self):
452 454 '''test data selection: specify invalid spw to process'''
453 455 sdatmcor(infile=self.infile, spw='<20', outputspw='', outfile=self.outfile, datacolumn='data')
454 456 self.check_result({19: True, 23: False})
455 457
458 + def test_sdatmcor_antenna_selection(self):
459 + """Test antenna selection"""
460 + sdatmcor(infile=self.infile, antenna='PM02', outfile=self.outfile)
461 + self.check_result({19: True, 23: True})
462 +
463 + def test_sdatmcor_msselect(self):
464 + """Test msselect"""
465 + sdatmcor(infile=self.infile, msselect='ANTNNA1 == 1', outfile=self.outfile)
466 + self.check_result({19: True, 23: True})
467 +
456 468 def test_sdatmcor_gainfactor_float(self):
457 469 """test gainfactor: float input"""
458 470 gainfactor = 10.0
459 471 apply_gainfactor(self.infile, 19, gainfactor)
460 472 apply_gainfactor(self.infile, 23, gainfactor)
461 473 sdatmcor(infile=self.infile, outfile=self.outfile, datacolumn='data', gainfactor=gainfactor)
462 474 self.check_result({19: True, 23: True})
463 475
464 476 def test_sdatmcor_gainfactor_dict(self):
465 477 """test gainfactor: dict input"""
501 513 expected,
502 514 msg='failed: input {} result {} expected {}'.format(
503 515 spw, actual, expected
504 516 )
505 517 )
506 518 else:
507 519 # error cases
508 520 with self.assertRaises(expected):
509 521 actual = sdatmcor_impl.parse_spw(self.infile, spw)
510 522
523 + def test_tweak_antenna_selection(self):
524 + """Test tweak of antenna selection"""
525 + # common test cases
526 + test_cases0 = [
527 + ('', ''),
528 + ('PM02', 'PM02&&&'),
529 + ('PM02&', 'PM02&&&'),
530 + ('PM02&&', 'PM02&&'),
531 + ('PM02&&&', 'PM02&&&'),
532 + ('0', '0&&&'),
533 + ('0&', '0&&&'),
534 + ('0&&', '0&&'),
535 + ('0&&&', '0&&&'),
536 + ('0&1', '0&&&;1&&&'),
537 + ('0&&1', '0&&&;1&&&'),
538 + ('0;1', '0&&&;1&&&'),
539 + ]
540 + # specific to convert_antenna_spec_autocorr
541 + test_cases1 = [
542 + ('0&;1&&', '0&&&;1&&'),
543 + ('0&&&;1', '0&&&;1&&&')
544 + ]
545 + for antenna, expected in test_cases0 + test_cases1:
546 + actual = sdutil.convert_antenna_spec_autocorr(antenna)
547 + self.assertEqual(actual, expected)
548 + # specific to get_antenna_selection_include_autocorr
549 + test_cases2 = [
550 + ('0&;1&&', '0&;1&&'),
551 + ('0&&&;1', '0&&&;1'),
552 + ]
553 + for antenna, expected in test_cases0 + test_cases2:
554 + actual = sdutil.get_antenna_selection_include_autocorr(self.infile, antenna)
555 + self.assertEqual(actual, expected)
556 +
511 557
512 558 def suite():
513 559 return [test_sdatmcor]
514 560
515 561
516 562 if is_CASA6:
517 563 if __name__ == '__main__':
518 564 unittest.main()
519 565 """
520 566 History

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

Add shortcut