Functions | |
def | isCalTable |
Reading functions. | |
def | readFile |
def | addAbsPath |
def | makeDict |
def | readXML |
def | readFlagCmdTable |
def | getUnion |
def | getNumPar |
def | compressSelectionList |
def | writeFlagCmd |
def | getReason |
def | getLinePars |
def | getSelectionPars |
def | readNtime |
def | fixType |
def | purgeEmptyPars |
def | purgeParameter |
def | setupAgent |
def | backupFlags |
def | extractAntennaInfo |
Set of functions to handle antenna information for shadowing. | |
def | writeAntennaList |
def | readAntennaList |
def | writeRFlagThresholdFile |
Function to pull out RFLAG thresholds from the returned report dictionary. | |
def | readRFlagThresholdFile |
def | convertDictToString |
Note - replace all arrays by lists before coming here. | |
def | convertStringToDict |
def | extractRFlagOutputFromSummary |
Variables | |
tuple | tblocal |
some helper tools | |
debug |
def flaghelper.addAbsPath | ( | input_file | ) |
Read in the lines from an input file inputfile --> file in disk with a list of strings per line Re-writes the file changing relative file names to absolute file names
Definition at line 119 of file flaghelper.py.
def flaghelper.backupFlags | ( | aflocal = None , |
|
msfile = '' , |
|||
prename = 'flagbackup' |
|||
) |
Create a backup of the FLAG column aflocal local version of the agentflagger tool or msfile name of MS/cal table to backup prename prefix for name of flag backup file If msfile is given, aflocal will not be used Create names like this: flags.flagcmd_1, flags.flagdata_1, Generally <task>_<i>, where i is the smallest integer giving a name, which does not already exist
Definition at line 1834 of file flaghelper.py.
References taskinit.aftool.
def flaghelper.compressSelectionList | ( | vis = '' , |
|
dicpars = {} |
|||
) |
- Find a loose union of data-selection parameters, to reduce the MSSelection parsing load. - This compressed selection list is only meant to be used with af.selectdata(), because further selections are handled internally. - Use MSSelection in its 'onlyparse=True' mode to gather a list of fields, spws, antennas touched by the selection list. These are the only keys for which MSSelection does not need to parse the MS, and will cover the expensive cases where complicated antenna and spw expressions can slow MSSelection down.
Definition at line 1057 of file flaghelper.py.
References tests.test_imcontsub.list, and asap.utils.unique().
Referenced by getUnion().
def flaghelper.convertDictToString | ( | indict = {} | ) |
Note - replace all arrays by lists before coming here.
Convert dictionary to string
Definition at line 2152 of file flaghelper.py.
Referenced by writeRFlagThresholdFile().
def flaghelper.convertStringToDict | ( | instr = '' | ) |
Convert string to dictionary
Definition at line 2160 of file flaghelper.py.
Referenced by makeDict(), and readRFlagThresholdFile().
def flaghelper.extractAntennaInfo | ( | msname = '' , |
|
antnamelist = [] , |
|||
outfile = '' |
|||
) |
Set of functions to handle antenna information for shadowing.
Example : alist = extractAntennaInfo(msname='../Data/shadowtest.ms', antnamelist=['VLA1','VLA15'], outfile='ttt.txt')
alist = antListRead('ttt.txt');
Example output text file ( 'ttt.txt' )
name = VLA1 diameter = 25.0 position = [-1601144.961466915, -5041998.0197185818, 3554864.76811967] name = VLA15 diameter = 25.0 position = [-1601556.245351332, -5041990.7252590274, 3554684.6464035073]
Example output dictionary ( alist )
{'0': {'diameter ': 25.0, 'name ': 'VLA1', 'position ': [-1601144.961466915, -5041998.0197185818, 3554864.7681196001]}, '1': {'diameter ': 25.0, 'name ': 'VLA15', 'position ': [-1601556.245351332, -5041990.7252590274, 3554684.6464035069]}}
Function to extract antenna names, positions, and diameters for a specified subset of the ANTENNA subtable of the specified MS. - It writes a text file, which can be sent as input for shadow in the task - It also returns a dictionary, which can be sent as input for shadow in the tool. This dictionary can also be given as input in the task. msname : name of MS antennalist : list of strings (antenna names). Names must match exactly. Case insensitive. outfile : name of text file. Will be overwritten if exists. If outfile='', no output file is written Always returns a dictionary containing the same info as in the file Example : antinfo = extractAntennaInfo(msname='xxx.ms',antnamelist=['vla1','vla2'],outfile='out.txt');
Definition at line 1928 of file flaghelper.py.
References tests.test_imcontsub.list, and writeAntennaList().
def flaghelper.extractRFlagOutputFromSummary | ( | mode, | |
summary_stats_list, | |||
flagcmd | |||
) |
Function to pull out 'rflag' output from the long dictionary, and (1) write the output files with thresholds. If the filename is specified, use it. If filename is not specified, make one up. (2) modify entries in 'cmdline' so that it is ready for savepars. This is to ensure that 'savepars' saves the contents of the threshold-files and not just the file-names. It has to save it in the form that tflagdata accepts inline : e.g. timedev=[[1,10,0.1],[1,11,0.07]] . This way, the user need not keep track of threshold text files if they use 'savepars' with action='apply'.
Definition at line 2170 of file flaghelper.py.
References getLinePars(), and writeRFlagThresholdFile().
def flaghelper.fixType | ( | params | ) |
Give correct types to non-string parameters The types are defined in the XML file of the task tflagdata
Definition at line 1455 of file flaghelper.py.
References readRFlagThresholdFile().
Referenced by setupAgent().
def flaghelper.getLinePars | ( | cmdline, | |
mlist = [] |
|||
) |
Get a dictionary of all selection parameters from a line: cmdline --> a string with parameters mlist --> a list of mode's parameters to add to the output dictionary Returns a dictionary.
Definition at line 1268 of file flaghelper.py.
Referenced by extractRFlagOutputFromSummary(), and setupAgent().
def flaghelper.getNumPar | ( | cmddict | ) |
Get the number of occurrences of all parameter keys cmdlist --> list of strings with parameters and values
Definition at line 937 of file flaghelper.py.
Referenced by getUnion().
def flaghelper.getReason | ( | cmdline | ) |
Get the reason values from a line with strings cmdline --> a string with parameters returns a string with reason values.
Definition at line 1231 of file flaghelper.py.
Referenced by makeDict().
def flaghelper.getSelectionPars | ( | cmdline | ) |
Get a dictionary of all selection parameters from a line: cmdline --> a string with parameters
Definition at line 1348 of file flaghelper.py.
def flaghelper.getUnion | ( | vis, | |
cmddict | |||
) |
Get a dictionary of a union of all selection parameters from a list of lines: vis --> MS cmddict --> dictionary of parameters and values (par=val) such as the one returned by makeDict()
Definition at line 785 of file flaghelper.py.
References compressSelectionList(), and getNumPar().
def flaghelper.isCalTable | ( | msname | ) |
Reading functions.
Check if a file is a cal table msname --> filename Return 1 for cal table, 0 for and 2 for MMS
Definition at line 53 of file flaghelper.py.
def flaghelper.makeDict | ( | cmdlist, | |
myreason = 'any' |
|||
) |
Make a dictionary compatible with a FLAG_CMD table structure and select by reason if any is given cmdlist --> list of parameters to go into the COMMAND column myreason --> reason to select from Returns a dictionary with the the selected rows with the following structure and default values: flagd['row'] = flagd['applied'] = False flagd['command'] = '' flagd['interval'] = 0.0 flagd['level'] = 0 flagd['reason'] = '' flagd['severity'] = 0 flagd['time'] = 0.0 flagd['type'] = 'FLAG'
Definition at line 179 of file flaghelper.py.
References convertStringToDict(), getReason(), purgeEmptyPars(), and purgeParameter().
def flaghelper.purgeEmptyPars | ( | cmdline | ) |
Remove empty parameters from a string: cmdline --> a string with parameters returns a string containing only parameters with values
Definition at line 1560 of file flaghelper.py.
Referenced by makeDict().
def flaghelper.purgeParameter | ( | cmdline, | |
par | |||
) |
Remove parameter from a string: cmdline --> a string with a parameter to be removed par --> the parameter to be removed from the string returns a string containing the remaining parameters
Definition at line 1596 of file flaghelper.py.
Referenced by makeDict().
def flaghelper.readAntennaList | ( | infile = '' | ) |
Read the antlist text file and return a dictionary A return value of empty {} indicates an error (or, empty file). The file needs to have 3 entries per antenna, on separate lines. The diameter and position are in units of meters, with positions in ITRF. Multiple antennas can be specified by repeating these three lines. Blank lines are allowed. Lines can be commented with '#' as the first character. Example : name = ea05 diameter = 25.0 position = [-1601144.96146691, -5041998.01971858, 3554864.76811967]
Definition at line 1998 of file flaghelper.py.
References sdtpimaging_regression.file.
Referenced by setupAgent().
def flaghelper.readFile | ( | inputfile | ) |
Read in the lines from an input file inputfile --> file in disk with a list of strings per line Returns a list. Blank lines are skipped.
Definition at line 84 of file flaghelper.py.
def flaghelper.readFlagCmdTable | ( | msfile, | |
myflagrows = [] , |
|||
useapplied = True , |
|||
myreason = 'any' |
|||
) |
Read flag commands from rows of the FLAG_CMD table of msfile If useapplied=False then include only rows with APPLIED=False If myreason is anything other than '', then select on that
Definition at line 618 of file flaghelper.py.
def flaghelper.readNtime | ( | params | ) |
Check the value and units of ntime params --> dictionary of agent's parameters
Definition at line 1415 of file flaghelper.py.
Referenced by setupAgent().
def flaghelper.readRFlagThresholdFile | ( | infile = '' , |
|
inkey = '' |
|||
) |
Read the input RFlag threshold file, and return dictionaries.
Definition at line 2121 of file flaghelper.py.
References convertStringToDict(), and sdtpimaging_regression.file.
Referenced by fixType().
def flaghelper.readXML | ( | sdmfile, | |
mytbuff | |||
) |
# readflagxml: reads Antenna.xml and Flag.xml SDM tables and parses # into returned dictionary as flag command strings # sdmfile (string) path to SDM containing Antenna.xml and Flag.xml # mytbuff (float) time interval (start and end) padding (seconds) # # Usage: myflags = readflagxml(sdmfile,tbuff) # # Dictionary structure: # fid : 'id' (string) # 'mode' (string) flag mode ('online') # 'antenna' (string) # 'timerange' (string) # 'reason' (string) # 'time' (float) in mjd seconds # 'interval' (float) in mjd seconds # 'command' (string) string (for COMMAND col in FLAG_CMD) # 'type' (string) 'FLAG' / 'UNFLAG' # 'applied' (bool) set to True here on read-in # 'level' (int) set to 0 here on read-in # 'severity' (int) set to 0 here on read-in # # Updated STM 2011-11-02 handle new SDM Flag.xml format from ALMA # Updated STM 2012-02-14 handle spectral window indices, names, IDs # Updated STM 2012-02-21 handle polarization types # # Mode to use for spectral window selection in commands: # spwmode = 0 none (flag all spw) # spwmode = 1 use name # spwmode = -1 use index (counting rows in SpectralWindow.xml) # # Mode to use for polarization selection in commands: # polmode = 0 none (flag all pols/corrs) # polmode = 1 use polarization type # # CURRENT DEFAULT: Use spw names, flag pols
Definition at line 323 of file flaghelper.py.
References casapy.exit().
def flaghelper.setupAgent | ( | aflocal, | |
myflagcmd, | |||
myrows, | |||
apply, | |||
writeflags, | |||
display = '' |
|||
) |
Setup the parameters of each agent and call the agentflagger tool myflagcmd --> it is a dictionary coming from readFromTable, readFile, etc. myrows --> selected rows to apply/unapply flags apply --> it's a boolean to control whether to apply or unapply the flags writeflags --> used by mode=rflag only display --> used by mode='rflag only
Definition at line 1633 of file flaghelper.py.
References fixType(), getLinePars(), readAntennaList(), and readNtime().
def flaghelper.writeAntennaList | ( | outfile = '' , |
|
antlist = {} |
|||
) |
Save the antlist dictionary as a text file
Definition at line 1985 of file flaghelper.py.
References sdtpimaging_regression.file.
Referenced by extractAntennaInfo().
def flaghelper.writeFlagCmd | ( | msfile, | |
myflags, | |||
vrows, | |||
applied, | |||
add_reason, | |||
outfile | |||
) |
Writes the flag commands to FLAG_CMD or to an ASCII file msfile --> MS myflags --> dictionary of commands read from inputfile (from readFromTable, etc.) vrows --> list of valid rows from myflags dictionary to save applied --> value to update APPLIED column of FLAG_CMD add_reason --> reason to add to output (replace input reason, if any) outfile --> if not empty, save to it Returns the number of commands written to output
Definition at line 1093 of file flaghelper.py.
References casapy.exit().
def flaghelper.writeRFlagThresholdFile | ( | rflag_thresholds = {} , |
|
timedevfile = '' , |
|||
freqdevfile = '' , |
|||
agent_id = 0 |
|||
) |
Function to pull out RFLAG thresholds from the returned report dictionary.
Extract the RFLAG output thresholds from the threshold dictionary Return them as arrays, and optionally, write them into a file.
Definition at line 2079 of file flaghelper.py.
References convertDictToString(), and sdtpimaging_regression.file.
Referenced by extractRFlagOutputFromSummary().
Definition at line 46 of file flaghelper.py.
tuple flaghelper.tblocal |
some helper tools
Definition at line 43 of file flaghelper.py.