##################### generated by xml-casa (v2) from hsd_baseline.xml ##############
##################### 47f8e57177d97a8585a9e44caca86fea ##############################
from __future__ import absolute_import
from casashell.private.stack_manip import find_local as __sf__
from casashell.private.stack_manip import find_frame as _find_frame
from casatools.typecheck import validator as _pc
from casatools.coercetype import coerce as _coerce
from pipeline.hsd.cli import hsd_baseline as _hsd_baseline_t
from collections import OrderedDict
import numpy
import sys
import os
import shutil
[docs]def static_var(varname, value):
def decorate(func):
setattr(func, varname, value)
return func
return decorate
class _hsd_baseline:
"""
hsd_baseline ---- Detect and validate spectral lines, subtract baseline by masking detected lines
The hsd_baseline task subtracts baseline from calibrated spectra.
By default, the task tries to find spectral line feature using
line detection and validation algorithms. Then, the task puts a
mask on detected lines and perform baseline subtraction.
The user is able to turn off automatic line masking by setting
linewindow parameter, which specifies pre-defined line window.
Fitting order is automatically determined by default. It can be
disabled by specifying fitorder as non-negative value. In this
case, the value specified by fitorder will be used.
***WARNING***
Currently, hsd_baseline overwrites the result obtained by the
previous run. Due to this behavior, users need to be careful
about an order of the task execution when they run hsd_baseline
multiple times with different data selection. Suppose there are
two spectral windows (0 and 1) and hsd_baseline is executed
separately for each spw as below,
hsd_baseline(pipelinemode="interactive", spw="0")
hsd_baseline(pipelinemode="interactive", spw="1")
hsd_blflag(pipelinemode="automatic")
hsd_imaging(pipelinemode="automatic")
Since the second run of hsd_baseline overwrites the result for
spw 0 with the data before baseline subtraction, this will not
produce correct result for spw 0. Proper sequence for this use
case is to process each spw to the imaging stage separately,
which looks like as follows:
hsd_baseline(pipelinemode="interactive", spw="0")
hsd_blflag(pipelinemode="interactive", spw="0")
hsd_imaging(pipelinemode="interactive", spw="0"))
hsd_baseline(pipelinemode="interactive", spw="1")
hsd_blflag(pipelinemode="interactive", spw="1")
hsd_imaging(pipelinemode="interactive", spw="1")
Output:
results -- If pipeline mode is 'getinputs' then None is returned.
Otherwise the results object for the pipeline task is
returned.
--------- parameter descriptions ---------------------------------------------
fitfunc fitting function for baseline subtraction. You can only
choose cubic spline ('spline' or 'cspline')
fitorder Fitting order for polynomial. For cubic spline, it is used
to determine how much the spectrum is segmented into.
Default (-1) is to determine the order automatically.
switchpoly If True, switch to 1st or 2nd order polynomial fit when
large mask exists at edge regardless of whatever fitfunc
or fitorder are specified. Condition for switching is as
follows:
if nmask > nchan/2 => 1st order polynomial
else if nmask > nchan/4 => 2nd order polynomial
else => use fitfunc and fitorder
where nmask is a number of channels for mask at edge while
nchan is a number of channels of entire spectral window.
linewindow Pre-defined line window. If this is set, specified line
windows are used as a line mask for baseline subtraction
instead to determine masks based on line detection and
validation stage. Several types of format are acceptable.
One is channel-based window,
[min_chan, max_chan]
where min_chan and max_chan should be an integer. For
multiple windows, nested list is also acceptable,
[[min_chan0, max_chan0], [min_chan1, max_chan1], ...]
Another way is frequency-based window,
[min_freq, max_freq]
where min_freq and max_freq should be either a float or
a string. If float value is given, it is interpreted as
a frequency in Hz. String should be a quantity consisting
of "value" and "unit",
e.g., '100GHz'. Multiple windows are also supported.
[[min_freq0, max_freq0], [min_freq1, max_freq1], ...]
Note that the specified frequencies are assumed to be
the value in LSRK frame. Note also that there is a
limitation when multiple MSes are processed.
If native frequency frame of the data is not LSRK
(e.g. TOPO), frequencies need to be converted to that
frame. As a result, corresponding channel range may vary
between MSes. However, current implementation is not
able to handle such case. Frequencies are converted to
desired frame using representative MS (time, position,
direction).
In the above cases, specified line windows are applied
to all science spws. In case when line windows vary with
spw, line windows can be specified by a dictionary whose
key is spw id while value is line window.
For example, the following dictionary gives different
line windows to spws 17 and 19. Other spws, if available,
will have an empty line window.
{17: [[100, 200], [1200, 1400]], 19: ['112115MHz', '112116MHz']}
Furthermore, linewindow accepts MS selection string.
The following string gives [[100,200],[1200,1400]] for
spw 17 while [1000,1500] for spw 21.
"17:100~200;1200~1400,21:1000~1500"
The string also accepts frequency with units. Note,
however, that frequency reference frame in this case is
not fixed to LSRK. Instead, the frame will be taken from
the MS (typically TOPO for ALMA).
Thus, the following two frequency-based line windows
result different channel selections.
{19: ['112115MHz', '112116MHz']} # frequency frame is LSRK
"19:11215MHz~11216MHz" # frequency frame is taken from the data
# (TOPO for ALMA)
example: [100,200] (channel), [115e9, 115.1e9] (frequency in Hz)
['115GHz', '115.1GHz'], see above for more examples
linewindowmode Merge or replace given manual line window with line
detection/validation result. If 'replace' is given, line
detection and validation will not be performed.
On the other hand, when 'merge' is specified, line
detection/validation will be performed and manually
specified line windows are added to the result.
Note that this has no effect when linewindow for target
spw is empty. In that case, line detection/validation
will be performed regardless of the value of
linewindowmode.
edge Number of edge channels to be dropped from baseline
subtraction. The value must be a list with length of 2,
whose values specify left and right edge channels,
respectively.
example: [10,10]
broadline Try to detect broad component of spectral line if True.
clusteringalgorithm Selection of the algorithm used in the clustering
analysis to check the validity of detected line features.
'kmean' algorithm and hierarchical clustering algorithm
'hierarchy', and their combination ('both') are so far
implemented.
deviationmask Apply deviation mask in addition to masks determined by
the automatic line detection.
pipelinemode The pipeline operating mode. In 'automatic' mode the
pipeline determines the values of all context defined
pipeline inputs automatically. In 'interactive' mode
the user can set the pipeline context defined parameters
manually. In 'getinputs' mode the user can check the
settings of all pipeline parameters without running the
task.
infiles List of data files. These must be a name of
MeasurementSets that are registered to context via
hsd_importdata task.
example: vis=['X227.ms', 'X228.ms']
field Data selection by field.
example: '1' (select by FIELD_ID)
'M100*' (select by field name)
'' (all fields)
antenna Data selection by antenna.
example: '1' (select by ANTENNA_ID)
'PM03' (select by antenna name)
'' (all antennas)
spw Data selection by spw.
example: '3,4' (generate caltable for spw 3 and 4)
['0','2'] (spw 0 for first data, 2 for second)
'' (all spws)
pol Data selection by polarizations.
example: '0' (generate caltable for pol 0)
['0~1','0'] (pol 0 and 1 for first data, only 0 for second)
'' (all polarizations)
dryrun Run the commands (True) or generate the commands to be
run but do not execute (False).
acceptresults Add the results of the task to the pipeline context (True)
or reject them (False).
parallel Execute using CASA HPC functionality, if available.
--------- examples -----------------------------------------------------------
"""
_info_group_ = """pipeline"""
_info_desc_ = """Detect and validate spectral lines, subtract baseline by masking detected lines"""
__schema = {'fitfunc': {'type': 'cStr', 'coerce': _coerce.to_str, 'allowed': [ 'cspline', 'spline', 'CSPLINE', 'SPLINE' ]}, 'fitorder': {'type': 'cInt'}, 'switchpoly': {'type': 'cBool'}, 'linewindow': {'type': 'cVariant', 'coerce': [_coerce.to_variant]}, 'linewindowmode': {'type': 'cStr', 'coerce': _coerce.to_str, 'allowed': [ 'replace', 'merge' ]}, 'edge': {'type': 'cIntVec', 'coerce': [_coerce.to_list,_coerce.to_intvec]}, 'broadline': {'type': 'cBool'}, 'clusteringalgorithm': {'type': 'cStr', 'coerce': _coerce.to_str, 'allowed': [ 'hierarchy', 'kmean', 'both' ]}, 'deviationmask': {'type': 'cBool'}, 'pipelinemode': {'type': 'cStr', 'coerce': _coerce.to_str, 'allowed': [ 'automatic', 'interactive', 'getinputs' ]}, 'infiles': {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, 'field': {'type': 'cStr', 'coerce': _coerce.to_str}, 'antenna': {'type': 'cStr', 'coerce': _coerce.to_str}, 'spw': {'anyof': [{'type': 'cStr', 'coerce': _coerce.to_str}, {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}]}, 'pol': {'anyof': [{'type': 'cStr', 'coerce': _coerce.to_str}, {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}]}, 'dryrun': {'type': 'cBool'}, 'acceptresults': {'type': 'cBool'}, 'parallel': {'type': 'cStr', 'coerce': _coerce.to_str, 'allowed': [ 'automatic', 'true', 'false' ]}}
def __init__(self):
self.__stdout = None
self.__stderr = None
self.__root_frame_ = None
def __globals_(self):
if self.__root_frame_ is None:
self.__root_frame_ = _find_frame( )
assert self.__root_frame_ is not None, "could not find CASAshell global frame"
return self.__root_frame_
def __to_string_(self,value):
if type(value) is str:
return "'%s'" % value
else:
return str(value)
def __validate_(self,doc,schema):
return _pc.validate(doc,schema)
def __do_inp_output(self,param_prefix,description_str,formatting_chars):
out = self.__stdout or sys.stdout
description = description_str.split( )
prefix_width = 23 + 19 + 4
output = [ ]
addon = ''
first_addon = True
while len(description) > 0:
## starting a new line.....................................................................
if len(output) == 0:
## for first line add parameter information............................................
if len(param_prefix)-formatting_chars > prefix_width - 1:
output.append(param_prefix)
continue
addon = param_prefix + ' #'
first_addon = True
addon_formatting = formatting_chars
else:
## for subsequent lines space over prefix width........................................
addon = (' ' * prefix_width) + '#'
first_addon = False
addon_formatting = 0
## if first word of description puts us over the screen width, bail........................
if len(addon + description[0]) - addon_formatting + 1 > self.term_width:
## if we're doing the first line make sure it's output.................................
if first_addon: output.append(addon)
break
while len(description) > 0:
## if the next description word puts us over break for the next line...................
if len(addon + description[0]) - addon_formatting + 1 > self.term_width: break
addon = addon + ' ' + description[0]
description.pop(0)
output.append(addon)
out.write('\n'.join(output) + '\n')
#--------- return nonsubparam values ----------------------------------------------
def __broadline_dflt( self, glb ):
return True
def __broadline( self, glb ):
if 'broadline' in glb: return glb['broadline']
return True
def __deviationmask_dflt( self, glb ):
return True
def __deviationmask( self, glb ):
if 'deviationmask' in glb: return glb['deviationmask']
return True
def __edge_dflt( self, glb ):
return [ ]
def __edge( self, glb ):
if 'edge' in glb: return glb['edge']
return [ ]
def __linewindow_dflt( self, glb ):
return ''
def __linewindow( self, glb ):
if 'linewindow' in glb: return glb['linewindow']
return ''
def __fitorder_dflt( self, glb ):
return int(-1)
def __fitorder( self, glb ):
if 'fitorder' in glb: return glb['fitorder']
return int(-1)
def __clusteringalgorithm_dflt( self, glb ):
return 'hierarchy'
def __clusteringalgorithm( self, glb ):
if 'clusteringalgorithm' in glb: return glb['clusteringalgorithm']
return 'hierarchy'
def __switchpoly_dflt( self, glb ):
return True
def __switchpoly( self, glb ):
if 'switchpoly' in glb: return glb['switchpoly']
return True
def __fitfunc_dflt( self, glb ):
return 'cspline'
def __fitfunc( self, glb ):
if 'fitfunc' in glb: return glb['fitfunc']
return 'cspline'
def __pipelinemode_dflt( self, glb ):
return 'automatic'
def __pipelinemode( self, glb ):
if 'pipelinemode' in glb: return glb['pipelinemode']
return 'automatic'
#--------- return inp/go default --------------------------------------------------
def __antenna_dflt( self, glb ):
if self.__pipelinemode( glb ) == "interactive": return ""
if self.__pipelinemode( glb ) == "getinputs": return ""
return None
def __dryrun_dflt( self, glb ):
if self.__pipelinemode( glb ) == "interactive": return bool(False)
return None
def __field_dflt( self, glb ):
if self.__pipelinemode( glb ) == "interactive": return ""
if self.__pipelinemode( glb ) == "getinputs": return ""
return None
def __acceptresults_dflt( self, glb ):
if self.__pipelinemode( glb ) == "interactive": return bool(True)
return None
def __linewindowmode_dflt( self, glb ):
if self.__linewindow( glb ) != "": return "replace"
return None
def __pol_dflt( self, glb ):
if self.__pipelinemode( glb ) == "interactive": return ""
if self.__pipelinemode( glb ) == "getinputs": return ""
return None
def __spw_dflt( self, glb ):
if self.__pipelinemode( glb ) == "interactive": return ""
if self.__pipelinemode( glb ) == "getinputs": return ""
return None
def __parallel_dflt( self, glb ):
if self.__pipelinemode( glb ) == "interactive": return "automatic"
return None
def __infiles_dflt( self, glb ):
if self.__pipelinemode( glb ) == "interactive": return []
if self.__pipelinemode( glb ) == "getinputs": return []
return None
#--------- return subparam values -------------------------------------------------
def __linewindowmode( self, glb ):
if 'linewindowmode' in glb: return glb['linewindowmode']
dflt = self.__linewindowmode_dflt( glb )
if dflt is not None: return dflt
return 'replace'
def __infiles( self, glb ):
if 'infiles' in glb: return glb['infiles']
dflt = self.__infiles_dflt( glb )
if dflt is not None: return dflt
return [ ]
def __field( self, glb ):
if 'field' in glb: return glb['field']
dflt = self.__field_dflt( glb )
if dflt is not None: return dflt
return ''
def __antenna( self, glb ):
if 'antenna' in glb: return glb['antenna']
dflt = self.__antenna_dflt( glb )
if dflt is not None: return dflt
return ''
def __spw( self, glb ):
if 'spw' in glb: return glb['spw']
dflt = self.__spw_dflt( glb )
if dflt is not None: return dflt
return ''
def __pol( self, glb ):
if 'pol' in glb: return glb['pol']
dflt = self.__pol_dflt( glb )
if dflt is not None: return dflt
return ''
def __dryrun( self, glb ):
if 'dryrun' in glb: return glb['dryrun']
dflt = self.__dryrun_dflt( glb )
if dflt is not None: return dflt
return False
def __acceptresults( self, glb ):
if 'acceptresults' in glb: return glb['acceptresults']
dflt = self.__acceptresults_dflt( glb )
if dflt is not None: return dflt
return True
def __parallel( self, glb ):
if 'parallel' in glb: return glb['parallel']
dflt = self.__parallel_dflt( glb )
if dflt is not None: return dflt
return 'automatic'
#--------- subparam inp output ----------------------------------------------------
def __fitfunc_inp(self):
description = 'Fitting function for baseline subtraction'
value = self.__fitfunc( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'fitfunc': value},{'fitfunc': self.__schema['fitfunc']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('%-19.19s = %s%-23s%s' % ('fitfunc',pre,self.__to_string_(value),post),description,0+len(pre)+len(post))
def __fitorder_inp(self):
description = 'Fitting order for baseline subtraction'
value = self.__fitorder( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'fitorder': value},{'fitorder': self.__schema['fitorder']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('%-19.19s = %s%-23s%s' % ('fitorder',pre,self.__to_string_(value),post),description,0+len(pre)+len(post))
def __switchpoly_inp(self):
description = 'Switch to polynomial fit when large mask exists at edge'
value = self.__switchpoly( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'switchpoly': value},{'switchpoly': self.__schema['switchpoly']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('%-19.19s = %s%-23s%s' % ('switchpoly',pre,self.__to_string_(value),post),description,0+len(pre)+len(post))
def __linewindow_inp(self):
description = 'Pre-defined line window'
value = self.__linewindow( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'linewindow': value},{'linewindow': self.__schema['linewindow']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('\x1B[1m\x1B[47m%-19.19s =\x1B[0m %s%-23s%s' % ('linewindow',pre,self.__to_string_(value),post),description,13+len(pre)+len(post))
def __linewindowmode_inp(self):
if self.__linewindowmode_dflt( self.__globals_( ) ) is not None:
description = 'Merge or replace given manual line window with line detection/validation result'
value = self.__linewindowmode( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'linewindowmode': value},{'linewindowmode': self.__schema['linewindowmode']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-16.16s =\x1B[0m %s%-23s%s' % ('linewindowmode',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __edge_inp(self):
description = 'Edge channels to be dropped'
value = self.__edge( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'edge': value},{'edge': self.__schema['edge']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('%-19.19s = %s%-23s%s' % ('edge',pre,self.__to_string_(value),post),description,0+len(pre)+len(post))
def __broadline_inp(self):
description = 'Try to detect broad component of the line'
value = self.__broadline( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'broadline': value},{'broadline': self.__schema['broadline']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('%-19.19s = %s%-23s%s' % ('broadline',pre,self.__to_string_(value),post),description,0+len(pre)+len(post))
def __clusteringalgorithm_inp(self):
description = 'Algorithm for line validation clustering algorithm'
value = self.__clusteringalgorithm( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'clusteringalgorithm': value},{'clusteringalgorithm': self.__schema['clusteringalgorithm']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('%-19.19s = %s%-23s%s' % ('clusteringalgorithm',pre,self.__to_string_(value),post),description,0+len(pre)+len(post))
def __deviationmask_inp(self):
description = 'Apply deviation mask in addition to detected line masks'
value = self.__deviationmask( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'deviationmask': value},{'deviationmask': self.__schema['deviationmask']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('%-19.19s = %s%-23s%s' % ('deviationmask',pre,self.__to_string_(value),post),description,0+len(pre)+len(post))
def __pipelinemode_inp(self):
description = 'The pipeline operating mode'
value = self.__pipelinemode( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'pipelinemode': value},{'pipelinemode': self.__schema['pipelinemode']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('\x1B[1m\x1B[47m%-19.19s =\x1B[0m %s%-23s%s' % ('pipelinemode',pre,self.__to_string_(value),post),description,13+len(pre)+len(post))
def __infiles_inp(self):
if self.__infiles_dflt( self.__globals_( ) ) is not None:
description = 'List of input files to be calibrated (default all)'
value = self.__infiles( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'infiles': value},{'infiles': self.__schema['infiles']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-16.16s =\x1B[0m %s%-23s%s' % ('infiles',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __field_inp(self):
if self.__field_dflt( self.__globals_( ) ) is not None:
description = 'select data by field'
value = self.__field( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'field': value},{'field': self.__schema['field']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-16.16s =\x1B[0m %s%-23s%s' % ('field',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __antenna_inp(self):
if self.__antenna_dflt( self.__globals_( ) ) is not None:
description = 'select data by antenna'
value = self.__antenna( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'antenna': value},{'antenna': self.__schema['antenna']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-16.16s =\x1B[0m %s%-23s%s' % ('antenna',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __spw_inp(self):
if self.__spw_dflt( self.__globals_( ) ) is not None:
description = 'select data by spw ids, e.g. \'3,5,7\' (\'\'=all)'
value = self.__spw( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'spw': value},{'spw': self.__schema['spw']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-16.16s =\x1B[0m %s%-23s%s' % ('spw',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __pol_inp(self):
if self.__pol_dflt( self.__globals_( ) ) is not None:
description = 'select data by polarizations, e.g. \'0~1\' (\'\'=all)'
value = self.__pol( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'pol': value},{'pol': self.__schema['pol']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-16.16s =\x1B[0m %s%-23s%s' % ('pol',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __dryrun_inp(self):
if self.__dryrun_dflt( self.__globals_( ) ) is not None:
description = 'Run the task (False) or display task command (True)'
value = self.__dryrun( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'dryrun': value},{'dryrun': self.__schema['dryrun']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-16.16s =\x1B[0m %s%-23s%s' % ('dryrun',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __acceptresults_inp(self):
if self.__acceptresults_dflt( self.__globals_( ) ) is not None:
description = 'Add the results into the pipeline context'
value = self.__acceptresults( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'acceptresults': value},{'acceptresults': self.__schema['acceptresults']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-16.16s =\x1B[0m %s%-23s%s' % ('acceptresults',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __parallel_inp(self):
if self.__parallel_dflt( self.__globals_( ) ) is not None:
description = 'Execute using CASA HPC functionality, if available.'
value = self.__parallel( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'parallel': value},{'parallel': self.__schema['parallel']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-16.16s =\x1B[0m %s%-23s%s' % ('parallel',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
#--------- global default implementation-------------------------------------------
@static_var('state', __sf__('casa_inp_go_state'))
def set_global_defaults(self):
self.set_global_defaults.state['last'] = self
glb = self.__globals_( )
if 'antenna' in glb: del glb['antenna']
if 'dryrun' in glb: del glb['dryrun']
if 'field' in glb: del glb['field']
if 'pipelinemode' in glb: del glb['pipelinemode']
if 'linewindow' in glb: del glb['linewindow']
if 'acceptresults' in glb: del glb['acceptresults']
if 'fitorder' in glb: del glb['fitorder']
if 'deviationmask' in glb: del glb['deviationmask']
if 'linewindowmode' in glb: del glb['linewindowmode']
if 'clusteringalgorithm' in glb: del glb['clusteringalgorithm']
if 'broadline' in glb: del glb['broadline']
if 'edge' in glb: del glb['edge']
if 'pol' in glb: del glb['pol']
if 'fitfunc' in glb: del glb['fitfunc']
if 'spw' in glb: del glb['spw']
if 'parallel' in glb: del glb['parallel']
if 'infiles' in glb: del glb['infiles']
if 'switchpoly' in glb: del glb['switchpoly']
#--------- inp function -----------------------------------------------------------
def inp(self):
print("# hsd_baseline -- %s" % self._info_desc_)
self.term_width, self.term_height = shutil.get_terminal_size(fallback=(80, 24))
self.__fitfunc_inp( )
self.__fitorder_inp( )
self.__switchpoly_inp( )
self.__linewindow_inp( )
self.__linewindowmode_inp( )
self.__edge_inp( )
self.__broadline_inp( )
self.__clusteringalgorithm_inp( )
self.__deviationmask_inp( )
self.__pipelinemode_inp( )
self.__infiles_inp( )
self.__field_inp( )
self.__antenna_inp( )
self.__spw_inp( )
self.__pol_inp( )
self.__dryrun_inp( )
self.__acceptresults_inp( )
self.__parallel_inp( )
#--------- tget function ----------------------------------------------------------
@static_var('state', __sf__('casa_inp_go_state'))
def tget(self,file=None):
from casashell.private.stack_manip import find_frame
from runpy import run_path
filename = None
if file is None:
if os.path.isfile("hsd_baseline.last"):
filename = "hsd_baseline.last"
elif isinstance(file, str):
if os.path.isfile(file):
filename = file
if filename is not None:
glob = find_frame( )
newglob = run_path( filename, init_globals={ } )
for i in newglob:
glob[i] = newglob[i]
self.tget.state['last'] = self
else:
print("could not find last file, setting defaults instead...")
self.set_global_defaults( )
def __call__( self, fitfunc=None, fitorder=None, switchpoly=None, linewindow=None, linewindowmode=None, edge=None, broadline=None, clusteringalgorithm=None, deviationmask=None, pipelinemode=None, infiles=None, field=None, antenna=None, spw=None, pol=None, dryrun=None, acceptresults=None, parallel=None ):
def noobj(s):
if s.startswith('<') and s.endswith('>'):
return "None"
else:
return s
_prefile = os.path.realpath('hsd_baseline.pre')
_postfile = os.path.realpath('hsd_baseline.last')
_return_result_ = None
_arguments = [fitfunc,fitorder,switchpoly,linewindow,linewindowmode,edge,broadline,clusteringalgorithm,deviationmask,pipelinemode,infiles,field,antenna,spw,pol,dryrun,acceptresults,parallel]
_invocation_parameters = OrderedDict( )
if any(map(lambda x: x is not None,_arguments)):
# invoke python style
# set the non sub-parameters that are not None
local_global = { }
if fitfunc is not None: local_global['fitfunc'] = fitfunc
if fitorder is not None: local_global['fitorder'] = fitorder
if switchpoly is not None: local_global['switchpoly'] = switchpoly
if linewindow is not None: local_global['linewindow'] = linewindow
if edge is not None: local_global['edge'] = edge
if broadline is not None: local_global['broadline'] = broadline
if clusteringalgorithm is not None: local_global['clusteringalgorithm'] = clusteringalgorithm
if deviationmask is not None: local_global['deviationmask'] = deviationmask
if pipelinemode is not None: local_global['pipelinemode'] = pipelinemode
# the invocation parameters for the non-subparameters can now be set - this picks up those defaults
_invocation_parameters['fitfunc'] = self.__fitfunc( local_global )
_invocation_parameters['fitorder'] = self.__fitorder( local_global )
_invocation_parameters['switchpoly'] = self.__switchpoly( local_global )
_invocation_parameters['linewindow'] = self.__linewindow( local_global )
_invocation_parameters['edge'] = self.__edge( local_global )
_invocation_parameters['broadline'] = self.__broadline( local_global )
_invocation_parameters['clusteringalgorithm'] = self.__clusteringalgorithm( local_global )
_invocation_parameters['deviationmask'] = self.__deviationmask( local_global )
_invocation_parameters['pipelinemode'] = self.__pipelinemode( local_global )
# the sub-parameters can then be set. Use the supplied value if not None, else the function, which gets the appropriate default
_invocation_parameters['linewindowmode'] = self.__linewindowmode( _invocation_parameters ) if linewindowmode is None else linewindowmode
_invocation_parameters['infiles'] = self.__infiles( _invocation_parameters ) if infiles is None else infiles
_invocation_parameters['field'] = self.__field( _invocation_parameters ) if field is None else field
_invocation_parameters['antenna'] = self.__antenna( _invocation_parameters ) if antenna is None else antenna
_invocation_parameters['spw'] = self.__spw( _invocation_parameters ) if spw is None else spw
_invocation_parameters['pol'] = self.__pol( _invocation_parameters ) if pol is None else pol
_invocation_parameters['dryrun'] = self.__dryrun( _invocation_parameters ) if dryrun is None else dryrun
_invocation_parameters['acceptresults'] = self.__acceptresults( _invocation_parameters ) if acceptresults is None else acceptresults
_invocation_parameters['parallel'] = self.__parallel( _invocation_parameters ) if parallel is None else parallel
else:
# invoke with inp/go semantics
_invocation_parameters['fitfunc'] = self.__fitfunc( self.__globals_( ) )
_invocation_parameters['fitorder'] = self.__fitorder( self.__globals_( ) )
_invocation_parameters['switchpoly'] = self.__switchpoly( self.__globals_( ) )
_invocation_parameters['linewindow'] = self.__linewindow( self.__globals_( ) )
_invocation_parameters['linewindowmode'] = self.__linewindowmode( self.__globals_( ) )
_invocation_parameters['edge'] = self.__edge( self.__globals_( ) )
_invocation_parameters['broadline'] = self.__broadline( self.__globals_( ) )
_invocation_parameters['clusteringalgorithm'] = self.__clusteringalgorithm( self.__globals_( ) )
_invocation_parameters['deviationmask'] = self.__deviationmask( self.__globals_( ) )
_invocation_parameters['pipelinemode'] = self.__pipelinemode( self.__globals_( ) )
_invocation_parameters['infiles'] = self.__infiles( self.__globals_( ) )
_invocation_parameters['field'] = self.__field( self.__globals_( ) )
_invocation_parameters['antenna'] = self.__antenna( self.__globals_( ) )
_invocation_parameters['spw'] = self.__spw( self.__globals_( ) )
_invocation_parameters['pol'] = self.__pol( self.__globals_( ) )
_invocation_parameters['dryrun'] = self.__dryrun( self.__globals_( ) )
_invocation_parameters['acceptresults'] = self.__acceptresults( self.__globals_( ) )
_invocation_parameters['parallel'] = self.__parallel( self.__globals_( ) )
try:
with open(_prefile,'w') as _f:
for _i in _invocation_parameters:
_f.write("%-19s = %s\n" % (_i,noobj(repr(_invocation_parameters[_i]))))
_f.write("#hsd_baseline( ")
count = 0
for _i in _invocation_parameters:
_f.write("%s=%s" % (_i,noobj(repr(_invocation_parameters[_i]))))
count += 1
if count < len(_invocation_parameters): _f.write(",")
_f.write(" )\n")
except: pass
try:
_return_result_ = _hsd_baseline_t( _invocation_parameters['fitfunc'],_invocation_parameters['fitorder'],_invocation_parameters['switchpoly'],_invocation_parameters['linewindow'],_invocation_parameters['linewindowmode'],_invocation_parameters['edge'],_invocation_parameters['broadline'],_invocation_parameters['clusteringalgorithm'],_invocation_parameters['deviationmask'],_invocation_parameters['pipelinemode'],_invocation_parameters['infiles'],_invocation_parameters['field'],_invocation_parameters['antenna'],_invocation_parameters['spw'],_invocation_parameters['pol'],_invocation_parameters['dryrun'],_invocation_parameters['acceptresults'],_invocation_parameters['parallel'] )
except Exception as e:
from traceback import format_exc
from casatasks import casalog
casalog.origin('hsd_baseline')
casalog.post("Exception Reported: Error in hsd_baseline: %s" % str(e),'SEVERE')
casalog.post(format_exc( ))
_return_result_ = False
try:
os.rename(_prefile,_postfile)
except: pass
return _return_result_
hsd_baseline = _hsd_baseline( )