Commits
22 22 | from casatools import image, quanta, table |
23 23 | |
24 24 | DATACOLUMN = 'DATA' |
25 25 | OVERWRITE = True |
26 26 | |
27 27 | IMAGE_STACK_MAX_HEIGHT = 5 |
28 28 | MS_STACK_MAX_HEIGHT = 3 |
29 29 | |
30 30 | qa = quanta() |
31 31 | do_not_erase_temporary_files = False |
32 + | dump_tasks = False |
32 33 | |
33 34 | |
34 35 | class AbstractFolder: |
35 36 | """Abstract class has Image/MeasurementSet file path. |
36 37 | |
37 38 | This class and child classes are wrapper of CasaImage/MeasurementSet file. |
38 39 | The wrapped path could be decided to erase by which child classes are implemented. |
39 40 | """ |
40 41 | |
41 42 | has_file = False |
595 596 | self.kimage = '' |
596 597 | self.scale = -1.0 |
597 598 | elif self.kernel != 'none': |
598 599 | raise ValueError(f'Unsupported maskmode, {self.kernel}', 'SEVERE') |
599 600 | |
600 601 | def __call__(self) -> Union[List[Any], Dict[str, str]]: |
601 602 | """Convert the class into arguments of imsmooth(). |
602 603 | |
603 604 | __log_origin is for callabletask.log_origin_setter |
604 605 | """ |
605 - | return dict(self.FIXED_PARAM, imagename=self.infile, kernel=self.kernel, major=self.major, |
606 - | minor=self.minor, pa=self.pa, kimage=self.kimage, scale=self.scale, |
607 - | outfile=self.outfile, __log_origin='imbaseline') |
606 + | retval = dict(self.FIXED_PARAM, imagename=self.infile, kernel=self.kernel, major=self.major, |
607 + | minor=self.minor, pa=self.pa, kimage=self.kimage, scale=self.scale, |
608 + | outfile=self.outfile, __log_origin='imbaseline') |
609 + | if dump_tasks: |
610 + | print(_dump_tasks('imsmooth', retval)) |
611 + | return retval |
608 612 | |
609 613 | |
610 614 | class _SdsmoothParams(AbstractValidatable): |
611 615 | """Parameter manipulation class for execution of casatasks.sdsmooth.""" |
612 616 | |
613 617 | FIXED_PARAM = dict( |
614 618 | spw='', |
615 619 | field='', |
616 620 | antenna='', |
617 621 | timerange='', |
638 642 | if self.kernel == 'none': |
639 643 | self.kwidth = 5 |
640 644 | elif not (self.kernel == 'gaussian' or self.kernel == 'boxcar'): |
641 645 | raise ValueError(f'Unsupported maskmode, {self.kernel}', 'SEVERE') |
642 646 | |
643 647 | def __call__(self) -> Dict[str, Any]: |
644 648 | """Convert the class into arguments of sdsmooth(). |
645 649 | |
646 650 | __log_origin is for sdutil.callabletask_decorator. |
647 651 | """ |
648 - | return dict(self.FIXED_PARAM, infile=self.infile, datacolumn=self.datacolumn, |
649 - | kernel=self.kernel, kwidth=self.kwidth, outfile=self.outfile, |
650 - | __log_origin='imbaseline') |
652 + | retval = dict(self.FIXED_PARAM, infile=self.infile, datacolumn=self.datacolumn, |
653 + | kernel=self.kernel, kwidth=self.kwidth, outfile=self.outfile, |
654 + | __log_origin='imbaseline') |
655 + | if dump_tasks: |
656 + | print(_dump_tasks('sdsmooth', retval)) |
657 + | return retval |
651 658 | |
652 659 | |
653 660 | class _SdbaselineParams(AbstractValidatable): |
654 661 | """Parameter manipulation class for execution of casatasks.sdbaseline.""" |
655 662 | |
656 663 | FIXED_PARAM = dict( |
657 664 | antenna='', |
658 665 | field='', |
659 666 | timerange='', |
660 667 | scan='', |
737 744 | raise ValueError(f'Unsupported blfunc, {self.blfunc}', 'SEVERE') |
738 745 | |
739 746 | if self.blfunc == 'variable' and not os.path.exists(self.blparam): |
740 747 | raise ValueError(f'input file {self.blparam} does not exists', 'SEVERE') |
741 748 | |
742 749 | def __call__(self) -> Dict[str, Any]: |
743 750 | """Convert the class into arguments of sdbaseline(). |
744 751 | |
745 752 | __log_origin is for sdutil.callabletask_decorator. |
746 753 | """ |
747 - | return dict(self.FIXED_PARAM, infile=self.infile, datacolumn=self.datacolumn, |
748 - | maskmode=self.maskmode, thresh=self.thresh, avg_limit=self.avg_limit, |
749 - | minwidth=self.minwidth, edge=self.edge, bloutput=self.bloutput, |
750 - | blfunc=self.blfunc, order=self.order, npiece=self.npiece, |
751 - | applyfft=self.applyfft, fftthresh=self.fftthresh, addwn=self.addwn, |
752 - | rejwn=self.rejwn, clipthresh=self.clipthresh, clipniter=self.clipniter, |
753 - | blparam=self.blparam, outfile=self.outfile, spw=self.spw, |
754 - | __log_origin='imbaseline') |
754 + | retval = dict(self.FIXED_PARAM, infile=self.infile, datacolumn=self.datacolumn, |
755 + | maskmode=self.maskmode, thresh=self.thresh, avg_limit=self.avg_limit, |
756 + | minwidth=self.minwidth, edge=self.edge, bloutput=self.bloutput, |
757 + | blfunc=self.blfunc, order=self.order, npiece=self.npiece, |
758 + | applyfft=self.applyfft, fftthresh=self.fftthresh, addwn=self.addwn, |
759 + | rejwn=self.rejwn, clipthresh=self.clipthresh, clipniter=self.clipniter, |
760 + | blparam=self.blparam, outfile=self.outfile, spw=self.spw, |
761 + | __log_origin='imbaseline') |
762 + | if dump_tasks: |
763 + | print(_dump_tasks('sdbaseline', retval)) |
764 + | |
765 + | return retval |
755 766 | |
756 767 | |
757 768 | class _Image2MSParams(AbstractValidatable): |
758 769 | """Parameter manipulation class for executing image2ms().""" |
759 770 | |
760 771 | def __init__(self, infile: str=None, outfile: str=None, datacolumn: str='DATA', |
761 772 | input_image_shape: _ImageShape=None) -> None: |
762 773 | self.infile = infile |
763 774 | self.outfile = outfile |
764 775 | self.datacolumn = datacolumn |
1098 1109 | if input_image_shape.axis_pol > 0: |
1099 1110 | image_array = np.expand_dims(image_array, input_image_shape.axis_pol) |
1100 1111 | return image_array |
1101 1112 | |
1102 1113 | |
1103 1114 | def __output_image(outfile: str=None, image_array: np.array=None) -> None: |
1104 1115 | with tool_manager(outfile, image) as ia: |
1105 1116 | ia.putchunk(pixels=image_array, locking=True) |
1106 1117 | |
1107 1118 | |
1119 + | def _dump_tasks(taskname: str, vals: dict): |
1120 + | cmd = f'{taskname}(' |
1121 + | arr = [] |
1122 + | for key, val in vals.items(): |
1123 + | if key != '__log_origin': |
1124 + | quote = '' if type(val) in (bool, int, float) else '\'' |
1125 + | arr.append(f'{key}={quote}{val}{quote}') |
1126 + | cmd += ', '.join(arr) |
1127 + | cmd += ')' |
1128 + | return cmd |
1129 + | |
1130 + | |
1108 1131 | class _EmptyMSBaseInformation: |
1109 1132 | """The Parameters class for creating an empty MeasurementSet. |
1110 1133 | |
1111 1134 | This class contains dictionaries to create an empty MS using table.create(), and it has no method. |
1112 1135 | Dictionaries have two types; desc(desctiption) and dminfo(data management infomation), |
1113 1136 | these are used as arguments of table.create(), and for a table creating, it needs a desc dict and a dminfo dict. |
1114 1137 | so there are dicts of twice of table amount in a MeasurementSet. |
1115 1138 | """ |
1116 1139 | |
1117 1140 | ms_desc = { |