from __future__ import absolute_import
from functools import cmp_to_key
from casatasks.private.casa_transition import *
from casatasks import casalog
from taskinit import casalog
def is_rflag_report(item):
Is this an item from a flagdata report dictionary?
:param item: an object, normally an item from a dictionary
:returns: whether item looks like a report from Rflag (type and name = rflag).
return 'type' in item and item['type'] == 'rflag'\
and 'name' in item and item['name'] == 'Rflag'
def combine_rflag_subreport(sub_dict, agg_dict):
""" Produces an aggregated RFlag return dictionary by adding in a sub-report.
You normally call this function on a sequence of per-subMS RFlag return dictionaries
to aggregate all the (sub-)reports into an overall report. Then call
finalize_agg_rflag_thresholds() to calculate overall timedev/freqdev thresholds.
The output from this function has the threshold vectors in a list-of-list-of-list
format which needs to be finalized using finalize_agg_rflag_thresholds().
Example RFlag return dictionary:
{'freqdev': array([[1, 0, 3.12e-02], [1, 3, 2.19e-02], [1, 4, 2.42e-02]]),
'type': 'rflag', 'name': 'Rflag', 'timedev':
array([[1, 0, 7.09e-03], [1, 3, 5.43e-03], [1, 4, 7.83e-03]]) }
:param sub_dict: (sub-)report/dictionary returned by RFlag (from one subMS)
:param agg_dict: aggregated report or dictionary to aggregate 'sub_dict' into
:returns: RFlag dictionary after aggregating sub_dict into agg_dict
for key, item in sub_dict.items():
agg_dict[key] = _aggregate_rflag_item(key, item, agg_dict)
def _aggregate_rflag_item(key, item, ret_dict):
Aggregates a key-item pair into ret_dict, both from RFlag return dictionaries.
def aggregate_rflag_thresholds(item, ret_item):
RFlag produces threshold vectors (freqdev or timedev vector) as a 2D numpy
[spw_id, field_id, value]
array([[1, 0, 3.12e-02], [1, 3, 2.19e-02], [1, 4, 2.42e-02]])