##################### generated by xml-casa (v2) from hifa_spwphaseup.xml ###########
##################### 5c0718d79f445991a56ee17558899930 ##############################
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.hifa.cli import hifa_spwphaseup as _hifa_spwphaseup_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 _hifa_spwphaseup:
"""
hifa_spwphaseup ---- Compute phase calibration spw map and per spw phase offsets
The spw map for phase calibration is computed. Phase offsets as a function of spectral
window are computed using high signal to noise calibration observations.
Previous calibrations are applied on the fly.
hifa_spwphaseup performs two functions:
o determines the spectral window mapping mode for the phase vs time
calibrations and computes spectral window map that will be used to
apply those calibrations
o computes the per spectral window phase offset table that will be
applied to the data to remove mean phase differences between
the spectral windows
If hm_spwmapmode = 'auto' the spectral window map is computed using the
following algorithm:
o estimate the per spectral window per scan signal to noise ratio of the phase
calibrator observations
o if the signal to noise of any single phase calibration spectral window is
less than the value of 'phasesnr' hm_spwmapmode defaults to 'combine'
o if all phase calibrator spectral windows meet the low signal to noise
criterion then hm_spwmapmode defaults to default'
o if the phase calibrator signal to noise values cannot be computed for any
reason, for example there is no flux information, then hm_spwmapmode defaults
to 'combine'
If hm_spwmapmode = 'combine' hifa_spwphaseup maps all the science windows to a
single science spectral window. For example if the list of science spectral
windows is [9, 11, 13, 15] then all the science spectral windows in the data
will be combined and mapped to the science window 9 in the combined phase vs
time calibration table.
If hm_spwmapmode = 'simple', a mapping from narrow science to wider science
spectral windows is computed using the following algorithm:
o construct a list of the bandwidths of all the science spectral windows
o determine the maximum bandwidth in this list maxbandwidth
o for each science spectral window with bandwidth less than maxbandwidth
o construct a list of spectral windows with bandwidths greater than
minfracmaxbw * maxbandwidth
o select the spectral window in this list whose band center most closely
matches the band center of the narrow spectral window
o preferentially match within the same baseband if samebb is True
If hm_spwmapmode = 'default' the spw mapping is assumed to be one to one.
Phase offsets per spectral window are determined by computing a phase only gain
calibration on the selected data, normally the high signal to noise bandpass
calibrator observations, using the solution interval 'inf'.
At the end of the task the spectral window map and the phase offset calibration
table in the pipeline are stored in the context for use by later tasks.
Output
results -- If pipeline mode is 'getinputs' then None is returned. Otherwise
the results object for the pipeline task is returned.
--------- parameter descriptions ---------------------------------------------
vis The list of input MeasurementSets. Defaults to the list of
MeasurementSets specified in the pipeline context.
example: vis=['M82A.ms', 'M82B.ms']
caltable The list of output calibration tables. Defaults to the standard
pipeline naming convention.
example: caltable=['M82.gcal', 'M82B.gcal']
field The list of field names or field ids for which phase offset solutions
are to be computed. Defaults to all fields with the default intent.
example: field='3C279', field='3C279, M82'
intent A string containing a comma delimited list of intents against
which the selected fields are matched. Defaults to the BANDPASS
observations.
example: intent='PHASE'
spw The list of spectral windows and channels for which gain solutions are
computed. Defaults to all the science spectral windows.
example: spw='13,15'
hm_spwmapmode The spectral window mapping mode. The options are: 'auto',
'combine', 'simple', and 'default'. In 'auto' mode hifa_spwphaseup
estimates the SNR of the phase calibrator observations and uses these
estimates to choose between 'combine' mode (low SNR) and 'default' mode
(high SNR). In combine mode all spectral windows are combined and mapped to
one spectral window. In 'simple' mode narrow spectral windows are mapped to
wider ones using an algorithm defined by 'maxnarrowbw', 'minfracmaxbw', and
'samebb'. In 'default' mode the spectral window map defaults to the
standard one to one mapping.
example: hm_spwmapmode='combine'
maxnarrowbw The maximum bandwidth defining narrow spectral windows. Values
must be in CASA compatible frequency units.
example: maxnarrowbw=''
minfracmaxbw The minimum fraction of the maximum bandwidth in the set of
spws to use for matching.
example: minfracmaxbw=0.75
samebb Match within the same baseband if possible.
example: samebb=False
phasesnr The required gaincal solution signal to noise.
example: phaseupsnr=20.0
bwedgefrac The fraction of the bandwidth edges that is flagged.
example: bwedgefrac=0.0
hm_nantennas The heuristics for determines the number of antennas to use
in the signal to noise estimate. The options are 'all' and 'unflagged'.
The 'unflagged' options is not currently supported.
example: hm_nantennas='unflagged'
maxfracflagged The maximum fraction of an antenna that can be flagged
before it is excluded from the signal to noise estimate.
example: maxfracflagged=0.80
combine Data axes to combine for solving. Options are '', 'scan', 'spw',
'field' or any comma-separated combination.
example: combine=''
refant Reference antenna name(s) in priority order. Defaults to most recent
values set in the pipeline context. If no reference antenna is defined in
the pipeline context the CASA defaults are used.
example: refant='DV01', refant='DV05,DV07'
minblperant Minimum number of baselines required per antenna for each solve.
Antennas with fewer baselines are excluded from solutions.
example: minblperant=2
minsnr Solutions below this SNR are rejected.
unregister_existing Unregister previous spwphaseup calibrations from the pipeline context
before registering the new calibrations from this task.
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.
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).
--------- examples -----------------------------------------------------------
Examples
1. Compute the default spectral window map and the per spectral window phase
offsets:
hifa_spwphaseup()
2. Compute the default spectral window map and the per spectral window phase
offsets set the spectral window mapping mode to 'simple':
hifa_spwphaseup(hm_spwmapmode='simple')
"""
_info_group_ = """pipeline"""
_info_desc_ = """Compute phase calibration spw map and per spw phase offsets"""
__schema = {'vis': {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, 'caltable': {'type': 'cStrVec', 'coerce': [_coerce.to_list,_coerce.to_strvec]}, 'field': {'type': 'cStr', 'coerce': _coerce.to_str}, 'intent': {'type': 'cStr', 'coerce': _coerce.to_str}, 'spw': {'type': 'cStr', 'coerce': _coerce.to_str}, 'hm_spwmapmode': {'type': 'cStr', 'coerce': _coerce.to_str, 'allowed': [ 'auto', 'combine', 'simple', 'default' ]}, 'maxnarrowbw': {'type': 'cStr', 'coerce': _coerce.to_str}, 'minfracmaxbw': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'samebb': {'type': 'cBool'}, 'phasesnr': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'bwedgefrac': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'hm_nantennas': {'type': 'cStr', 'coerce': _coerce.to_str, 'allowed': [ 'all', 'unflagged' ]}, 'maxfracflagged': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'combine': {'type': 'cStr', 'coerce': _coerce.to_str}, 'refant': {'type': 'cStr', 'coerce': _coerce.to_str}, 'minblperant': {'type': 'cInt'}, 'minsnr': {'type': 'cFloat', 'coerce': _coerce.to_float}, 'unregister_existing': {'type': 'cBool'}, 'pipelinemode': {'type': 'cStr', 'coerce': _coerce.to_str, 'allowed': [ 'automatic', 'interactive', 'getinputs' ]}, 'dryrun': {'type': 'cBool'}, 'acceptresults': {'type': 'cBool'}}
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 __combine_dflt( self, glb ):
return ''
def __combine( self, glb ):
if 'combine' in glb: return glb['combine']
return ''
def __hm_spwmapmode_dflt( self, glb ):
return 'auto'
def __hm_spwmapmode( self, glb ):
if 'hm_spwmapmode' in glb: return glb['hm_spwmapmode']
return 'auto'
def __unregister_existing_dflt( self, glb ):
return False
def __unregister_existing( self, glb ):
if 'unregister_existing' in glb: return glb['unregister_existing']
return False
def __minblperant_dflt( self, glb ):
return int(4)
def __minblperant( self, glb ):
if 'minblperant' in glb: return glb['minblperant']
return int(4)
def __minsnr_dflt( self, glb ):
return float(3.0)
def __minsnr( self, glb ):
if 'minsnr' in glb: return glb['minsnr']
return float(3.0)
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 __maxfracflagged_dflt( self, glb ):
if self.__hm_spwmapmode( glb ) == "auto": return float(0.90)
return None
def __minfracmaxbw_dflt( self, glb ):
if self.__hm_spwmapmode( glb ) == "simple": return float(0.8)
return None
def __dryrun_dflt( self, glb ):
if self.__pipelinemode( glb ) == "interactive": return bool(False)
return None
def __bwedgefrac_dflt( self, glb ):
if self.__hm_spwmapmode( glb ) == "auto": return float(0.03125)
return None
def __field_dflt( self, glb ):
if self.__pipelinemode( glb ) == "interactive": return ""
if self.__pipelinemode( glb ) == "getinputs": return ""
return None
def __intent_dflt( self, glb ):
if self.__pipelinemode( glb ) == "interactive": return ""
if self.__pipelinemode( glb ) == "getinputs": return ""
return None
def __phasesnr_dflt( self, glb ):
if self.__hm_spwmapmode( glb ) == "auto": return float(32.0)
return None
def __refant_dflt( self, glb ):
if self.__pipelinemode( glb ) == "interactive": return ""
if self.__pipelinemode( glb ) == "getinputs": return ""
return None
def __vis_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 __maxnarrowbw_dflt( self, glb ):
if self.__hm_spwmapmode( glb ) == "simple": return "300MHz"
return None
def __samebb_dflt( self, glb ):
if self.__hm_spwmapmode( glb ) == "simple": return bool(True)
return None
def __hm_nantennas_dflt( self, glb ):
if self.__hm_spwmapmode( glb ) == "auto": return "all"
return None
def __caltable_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
#--------- return subparam values -------------------------------------------------
def __vis( self, glb ):
if 'vis' in glb: return glb['vis']
dflt = self.__vis_dflt( glb )
if dflt is not None: return dflt
return [ ]
def __caltable( self, glb ):
if 'caltable' in glb: return glb['caltable']
dflt = self.__caltable_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 __intent( self, glb ):
if 'intent' in glb: return glb['intent']
dflt = self.__intent_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 __maxnarrowbw( self, glb ):
if 'maxnarrowbw' in glb: return glb['maxnarrowbw']
dflt = self.__maxnarrowbw_dflt( glb )
if dflt is not None: return dflt
return '300MHz'
def __minfracmaxbw( self, glb ):
if 'minfracmaxbw' in glb: return glb['minfracmaxbw']
dflt = self.__minfracmaxbw_dflt( glb )
if dflt is not None: return dflt
return float(0.8)
def __samebb( self, glb ):
if 'samebb' in glb: return glb['samebb']
dflt = self.__samebb_dflt( glb )
if dflt is not None: return dflt
return True
def __phasesnr( self, glb ):
if 'phasesnr' in glb: return glb['phasesnr']
dflt = self.__phasesnr_dflt( glb )
if dflt is not None: return dflt
return float(32.0)
def __bwedgefrac( self, glb ):
if 'bwedgefrac' in glb: return glb['bwedgefrac']
dflt = self.__bwedgefrac_dflt( glb )
if dflt is not None: return dflt
return float(0.03125)
def __hm_nantennas( self, glb ):
if 'hm_nantennas' in glb: return glb['hm_nantennas']
dflt = self.__hm_nantennas_dflt( glb )
if dflt is not None: return dflt
return 'all'
def __maxfracflagged( self, glb ):
if 'maxfracflagged' in glb: return glb['maxfracflagged']
dflt = self.__maxfracflagged_dflt( glb )
if dflt is not None: return dflt
return float(0.90)
def __refant( self, glb ):
if 'refant' in glb: return glb['refant']
dflt = self.__refant_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
#--------- subparam inp output ----------------------------------------------------
def __vis_inp(self):
if self.__vis_dflt( self.__globals_( ) ) is not None:
description = 'List of input MeasurementSets'
value = self.__vis( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'vis': value},{'vis': self.__schema['vis']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-16.16s =\x1B[0m %s%-23s%s' % ('vis',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __caltable_inp(self):
if self.__caltable_dflt( self.__globals_( ) ) is not None:
description = 'List of output caltables'
value = self.__caltable( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'caltable': value},{'caltable': self.__schema['caltable']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-16.16s =\x1B[0m %s%-23s%s' % ('caltable',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 = 'Set of data selection field names or ids'
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 __intent_inp(self):
if self.__intent_dflt( self.__globals_( ) ) is not None:
description = 'Set of data selection observing intents'
value = self.__intent( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'intent': value},{'intent': self.__schema['intent']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-16.16s =\x1B[0m %s%-23s%s' % ('intent',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 = 'Set of data selection spectral window/channels'
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 __hm_spwmapmode_inp(self):
description = 'The spw mapping mode'
value = self.__hm_spwmapmode( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'hm_spwmapmode': value},{'hm_spwmapmode': self.__schema['hm_spwmapmode']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('\x1B[1m\x1B[47m%-19.19s =\x1B[0m %s%-23s%s' % ('hm_spwmapmode',pre,self.__to_string_(value),post),description,13+len(pre)+len(post))
def __maxnarrowbw_inp(self):
if self.__maxnarrowbw_dflt( self.__globals_( ) ) is not None:
description = 'The maximum bandwidth defining narrow spectral windows'
value = self.__maxnarrowbw( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'maxnarrowbw': value},{'maxnarrowbw': self.__schema['maxnarrowbw']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-16.16s =\x1B[0m %s%-23s%s' % ('maxnarrowbw',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __minfracmaxbw_inp(self):
if self.__minfracmaxbw_dflt( self.__globals_( ) ) is not None:
description = 'The minimum fraction of the maximum bandpass for spw matching'
value = self.__minfracmaxbw( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'minfracmaxbw': value},{'minfracmaxbw': self.__schema['minfracmaxbw']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-16.16s =\x1B[0m %s%-23s%s' % ('minfracmaxbw',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __samebb_inp(self):
if self.__samebb_dflt( self.__globals_( ) ) is not None:
description = 'Match within the same baseband if possible'
value = self.__samebb( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'samebb': value},{'samebb': self.__schema['samebb']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-16.16s =\x1B[0m %s%-23s%s' % ('samebb',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __phasesnr_inp(self):
if self.__phasesnr_dflt( self.__globals_( ) ) is not None:
description = 'The minimum snr for triggering spw combination in auto spw mapping mode'
value = self.__phasesnr( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'phasesnr': value},{'phasesnr': self.__schema['phasesnr']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-16.16s =\x1B[0m %s%-23s%s' % ('phasesnr',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __bwedgefrac_inp(self):
if self.__bwedgefrac_dflt( self.__globals_( ) ) is not None:
description = 'The fraction of the bandwidth edge that is flagged'
value = self.__bwedgefrac( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'bwedgefrac': value},{'bwedgefrac': self.__schema['bwedgefrac']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-16.16s =\x1B[0m %s%-23s%s' % ('bwedgefrac',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __hm_nantennas_inp(self):
if self.__hm_nantennas_dflt( self.__globals_( ) ) is not None:
description = 'The antenna selection heuristic'
value = self.__hm_nantennas( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'hm_nantennas': value},{'hm_nantennas': self.__schema['hm_nantennas']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-16.16s =\x1B[0m %s%-23s%s' % ('hm_nantennas',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __maxfracflagged_inp(self):
if self.__maxfracflagged_dflt( self.__globals_( ) ) is not None:
description = 'The maximum fraction of data flagged per antenna'
value = self.__maxfracflagged( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'maxfracflagged': value},{'maxfracflagged': self.__schema['maxfracflagged']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-16.16s =\x1B[0m %s%-23s%s' % ('maxfracflagged',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __combine_inp(self):
description = 'Data axes which to combine for solve (scan, spw, and/or field)'
value = self.__combine( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'combine': value},{'combine': self.__schema['combine']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('%-19.19s = %s%-23s%s' % ('combine',pre,self.__to_string_(value),post),description,0+len(pre)+len(post))
def __refant_inp(self):
if self.__refant_dflt( self.__globals_( ) ) is not None:
description = 'Reference antenna names'
value = self.__refant( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'refant': value},{'refant': self.__schema['refant']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output(' \x1B[92m%-16.16s =\x1B[0m %s%-23s%s' % ('refant',pre,self.__to_string_(value),post),description,9+len(pre)+len(post))
def __minblperant_inp(self):
description = 'Minimum baselines per antenna required for solve'
value = self.__minblperant( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'minblperant': value},{'minblperant': self.__schema['minblperant']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('%-19.19s = %s%-23s%s' % ('minblperant',pre,self.__to_string_(value),post),description,0+len(pre)+len(post))
def __minsnr_inp(self):
description = 'Reject solutions below this SNR'
value = self.__minsnr( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'minsnr': value},{'minsnr': self.__schema['minsnr']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('%-19.19s = %s%-23s%s' % ('minsnr',pre,self.__to_string_(value),post),description,0+len(pre)+len(post))
def __unregister_existing_inp(self):
description = 'Unregister previous spwphaseup calibrations'
value = self.__unregister_existing( self.__globals_( ) )
(pre,post) = ('','') if self.__validate_({'unregister_existing': value},{'unregister_existing': self.__schema['unregister_existing']}) else ('\x1B[91m','\x1B[0m')
self.__do_inp_output('%-19.19s = %s%-23s%s' % ('unregister_existing',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 __dryrun_inp(self):
if self.__dryrun_dflt( self.__globals_( ) ) is not None:
description = 'Run task (False) or display the 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 = 'Automatically accept results into the 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))
#--------- 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 'maxfracflagged' in glb: del glb['maxfracflagged']
if 'minfracmaxbw' in glb: del glb['minfracmaxbw']
if 'dryrun' in glb: del glb['dryrun']
if 'bwedgefrac' in glb: del glb['bwedgefrac']
if 'unregister_existing' in glb: del glb['unregister_existing']
if 'field' in glb: del glb['field']
if 'pipelinemode' in glb: del glb['pipelinemode']
if 'intent' in glb: del glb['intent']
if 'phasesnr' in glb: del glb['phasesnr']
if 'refant' in glb: del glb['refant']
if 'minsnr' in glb: del glb['minsnr']
if 'vis' in glb: del glb['vis']
if 'acceptresults' in glb: del glb['acceptresults']
if 'minblperant' in glb: del glb['minblperant']
if 'maxnarrowbw' in glb: del glb['maxnarrowbw']
if 'samebb' in glb: del glb['samebb']
if 'hm_spwmapmode' in glb: del glb['hm_spwmapmode']
if 'combine' in glb: del glb['combine']
if 'hm_nantennas' in glb: del glb['hm_nantennas']
if 'caltable' in glb: del glb['caltable']
if 'spw' in glb: del glb['spw']
#--------- inp function -----------------------------------------------------------
def inp(self):
print("# hifa_spwphaseup -- %s" % self._info_desc_)
self.term_width, self.term_height = shutil.get_terminal_size(fallback=(80, 24))
self.__vis_inp( )
self.__caltable_inp( )
self.__field_inp( )
self.__intent_inp( )
self.__spw_inp( )
self.__hm_spwmapmode_inp( )
self.__maxnarrowbw_inp( )
self.__minfracmaxbw_inp( )
self.__samebb_inp( )
self.__phasesnr_inp( )
self.__bwedgefrac_inp( )
self.__hm_nantennas_inp( )
self.__maxfracflagged_inp( )
self.__combine_inp( )
self.__refant_inp( )
self.__minblperant_inp( )
self.__minsnr_inp( )
self.__unregister_existing_inp( )
self.__pipelinemode_inp( )
self.__dryrun_inp( )
self.__acceptresults_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("hifa_spwphaseup.last"):
filename = "hifa_spwphaseup.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, vis=None, caltable=None, field=None, intent=None, spw=None, hm_spwmapmode=None, maxnarrowbw=None, minfracmaxbw=None, samebb=None, phasesnr=None, bwedgefrac=None, hm_nantennas=None, maxfracflagged=None, combine=None, refant=None, minblperant=None, minsnr=None, unregister_existing=None, pipelinemode=None, dryrun=None, acceptresults=None ):
def noobj(s):
if s.startswith('<') and s.endswith('>'):
return "None"
else:
return s
_prefile = os.path.realpath('hifa_spwphaseup.pre')
_postfile = os.path.realpath('hifa_spwphaseup.last')
_return_result_ = None
_arguments = [vis,caltable,field,intent,spw,hm_spwmapmode,maxnarrowbw,minfracmaxbw,samebb,phasesnr,bwedgefrac,hm_nantennas,maxfracflagged,combine,refant,minblperant,minsnr,unregister_existing,pipelinemode,dryrun,acceptresults]
_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 hm_spwmapmode is not None: local_global['hm_spwmapmode'] = hm_spwmapmode
if combine is not None: local_global['combine'] = combine
if minblperant is not None: local_global['minblperant'] = minblperant
if minsnr is not None: local_global['minsnr'] = minsnr
if unregister_existing is not None: local_global['unregister_existing'] = unregister_existing
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['hm_spwmapmode'] = self.__hm_spwmapmode( local_global )
_invocation_parameters['combine'] = self.__combine( local_global )
_invocation_parameters['minblperant'] = self.__minblperant( local_global )
_invocation_parameters['minsnr'] = self.__minsnr( local_global )
_invocation_parameters['unregister_existing'] = self.__unregister_existing( 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['vis'] = self.__vis( _invocation_parameters ) if vis is None else vis
_invocation_parameters['caltable'] = self.__caltable( _invocation_parameters ) if caltable is None else caltable
_invocation_parameters['field'] = self.__field( _invocation_parameters ) if field is None else field
_invocation_parameters['intent'] = self.__intent( _invocation_parameters ) if intent is None else intent
_invocation_parameters['spw'] = self.__spw( _invocation_parameters ) if spw is None else spw
_invocation_parameters['maxnarrowbw'] = self.__maxnarrowbw( _invocation_parameters ) if maxnarrowbw is None else maxnarrowbw
_invocation_parameters['minfracmaxbw'] = self.__minfracmaxbw( _invocation_parameters ) if minfracmaxbw is None else minfracmaxbw
_invocation_parameters['samebb'] = self.__samebb( _invocation_parameters ) if samebb is None else samebb
_invocation_parameters['phasesnr'] = self.__phasesnr( _invocation_parameters ) if phasesnr is None else phasesnr
_invocation_parameters['bwedgefrac'] = self.__bwedgefrac( _invocation_parameters ) if bwedgefrac is None else bwedgefrac
_invocation_parameters['hm_nantennas'] = self.__hm_nantennas( _invocation_parameters ) if hm_nantennas is None else hm_nantennas
_invocation_parameters['maxfracflagged'] = self.__maxfracflagged( _invocation_parameters ) if maxfracflagged is None else maxfracflagged
_invocation_parameters['refant'] = self.__refant( _invocation_parameters ) if refant is None else refant
_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
else:
# invoke with inp/go semantics
_invocation_parameters['vis'] = self.__vis( self.__globals_( ) )
_invocation_parameters['caltable'] = self.__caltable( self.__globals_( ) )
_invocation_parameters['field'] = self.__field( self.__globals_( ) )
_invocation_parameters['intent'] = self.__intent( self.__globals_( ) )
_invocation_parameters['spw'] = self.__spw( self.__globals_( ) )
_invocation_parameters['hm_spwmapmode'] = self.__hm_spwmapmode( self.__globals_( ) )
_invocation_parameters['maxnarrowbw'] = self.__maxnarrowbw( self.__globals_( ) )
_invocation_parameters['minfracmaxbw'] = self.__minfracmaxbw( self.__globals_( ) )
_invocation_parameters['samebb'] = self.__samebb( self.__globals_( ) )
_invocation_parameters['phasesnr'] = self.__phasesnr( self.__globals_( ) )
_invocation_parameters['bwedgefrac'] = self.__bwedgefrac( self.__globals_( ) )
_invocation_parameters['hm_nantennas'] = self.__hm_nantennas( self.__globals_( ) )
_invocation_parameters['maxfracflagged'] = self.__maxfracflagged( self.__globals_( ) )
_invocation_parameters['combine'] = self.__combine( self.__globals_( ) )
_invocation_parameters['refant'] = self.__refant( self.__globals_( ) )
_invocation_parameters['minblperant'] = self.__minblperant( self.__globals_( ) )
_invocation_parameters['minsnr'] = self.__minsnr( self.__globals_( ) )
_invocation_parameters['unregister_existing'] = self.__unregister_existing( self.__globals_( ) )
_invocation_parameters['pipelinemode'] = self.__pipelinemode( self.__globals_( ) )
_invocation_parameters['dryrun'] = self.__dryrun( self.__globals_( ) )
_invocation_parameters['acceptresults'] = self.__acceptresults( 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("#hifa_spwphaseup( ")
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_ = _hifa_spwphaseup_t( _invocation_parameters['vis'],_invocation_parameters['caltable'],_invocation_parameters['field'],_invocation_parameters['intent'],_invocation_parameters['spw'],_invocation_parameters['hm_spwmapmode'],_invocation_parameters['maxnarrowbw'],_invocation_parameters['minfracmaxbw'],_invocation_parameters['samebb'],_invocation_parameters['phasesnr'],_invocation_parameters['bwedgefrac'],_invocation_parameters['hm_nantennas'],_invocation_parameters['maxfracflagged'],_invocation_parameters['combine'],_invocation_parameters['refant'],_invocation_parameters['minblperant'],_invocation_parameters['minsnr'],_invocation_parameters['unregister_existing'],_invocation_parameters['pipelinemode'],_invocation_parameters['dryrun'],_invocation_parameters['acceptresults'] )
except Exception as e:
from traceback import format_exc
from casatasks import casalog
casalog.origin('hifa_spwphaseup')
casalog.post("Exception Reported: Error in hifa_spwphaseup: %s" % str(e),'SEVERE')
casalog.post(format_exc( ))
_return_result_ = False
try:
os.rename(_prefile,_postfile)
except: pass
return _return_result_
hifa_spwphaseup = _hifa_spwphaseup( )