from casatasks.private.casa_transition import is_CASA6
from casatasks import casalog
class SummaryMinor(dict):
"""A return object from tclean's minor cycles. Gathers the information together
in a way that makes it easier to query for exactly what you want.
The structure for this dictionary is:
1. To get the number of iterations done on the channel 5, first polarity, during the second minor cycle:
chan5iters = summ_min[5][summ_min.pol0]['iterDone'][1]
2. To get the number of available channels, and the ids of those channels:
avail_chans = summ_min.keys()
3. To get the available minor cycle summary statistics:
summaryKeys = summ_min.getRowDescriptions()
There are also a few additional attributes/methods:
chan0, pol0: the ids of the first channel/polarity
nCycles, nChan, nPol, nFields: number of minor cycles/channels/polarities/outlier fields logged
fieldIds: ids of the available outlier fields
getMatrix(fieldId): returns the original numpy.ndarray matrix
getAll(summary_key): returns the list of all values for the given summary key
getDict(calc_iterdone_deltas, keep_startvals): to get the iterDone stat for iterations across all channels
getOutlierField(fieldid): to get a new SummaryMinor instance the contents of an outlier field other than field 0
Extends the python dictionary interface (try the command "help(dict)" for more information on builtin python dicts).
Note that this class will be saved as a plain python dict when saved with methods like pickle.dump() or numpy.save().
This is done to prevent issues when loading later, when this class might not be available to the python interpretter."""
rowDescriptionsOldOrder = ["iterDone", "peakRes", "modelFlux", "cycleThresh", "mapperId", "chan", "pol", "cycleStartIters", "startIterDone", "startPeakRes", "startModelFlux", "startPeakResNM", "peakResNM", "masksum", "mpiServer", "peakMem", "runtime", "immod", "stopCode"]
rowDescriptions13683 = ["iterDone", "peakRes", "modelFlux", "cycleThresh", "immod", "chan"]
rowDescriptions = ["startIterDone", "iterDone", "startPeakRes", "peakRes", "startModelFlux", "modelFlux", "startPeakResNM", "peakResNM", "cycleThresh", "mapperId", "cycleStartIters", "masksum", "mpiServer", "peakMem", "runtime", "immod", "stopCode", "chan", "pol"]
rowStartDescs = ["startIterDone", "startPeakRes", "startModelFlux", "startPeakResNM"]
def __init__(self, summaryminor_matrix, summaryminor_dict = None):
self.summaryminor_matrix = summaryminor_matrix
self.singleFieldMatrix = summaryminor_matrix
self.fieldIds = SummaryMinor._getFieldIds(summaryminor_matrix)
if len(self.fieldIds) > 1:
self.singleFieldMatrix = SummaryMinor._getSingleFieldMatrix(summaryminor_matrix, self.fieldIds[0])
if (len(self.fieldIds) > 1):
for fieldId in self.fieldIds:
testMatrix = SummaryMinor._getSingleFieldMatrix(summaryminor_matrix, fieldId)
sm = SummaryMinor(testMatrix)
if (summaryminor_dict == None):
summaryminor_dict = SummaryMinor.indexMinorCycleSummaryBySubimage(self.singleFieldMatrix)
self.summaryminor_dict = summaryminor_dict
percycleiters_dict = SummaryMinor._getPerCycleDict(copy.deepcopy(summaryminor_dict))
self.update(percycleiters_dict)
self.nFields = len( self.fieldIds )
self.chan0 = list( self.keys() )[0]
self.nChan = len( self.keys() )
if len(self[self.chan0].keys()) > 0:
self.pol0 = list( self[self.chan0].keys() )[0]
self.nCycles = len( self[self.chan0][self.pol0]["iterDone"])
self.nPol = len( self[self.chan0].keys() )
def _getFieldIds(matrix):
"""Get a sorted list of available outlier field ids in the given matrix"""
availRows = SummaryMinor.getRowDescriptionsOldOrder()
if not "immod" in availRows: