# Path: cubical/plots/gainsols.py
# class PlotLimits(object):
# class PlotOptions(PlotLimits):
#     def __init__(self):
#     def __init__(self):
#     def populate_argparse(parser):
# def get_plot_limits(options, sols, time0=0):
# def get_plot_counts(nsols, plots_per_sol):
# def plot_bandpass(sols, plot_diag='ap', plot_offdiag='', gaintype=("Bandpass", "Offdiag bandpass"), figtitle=None):
#     def _prep_plot(nplot, ant, num_gaintype, plot_type):
#     def _make_reim_plot(ax, freq, x1, x2, corrs, legend):
#     def _make_ap_plot(ax, ax2, freq, x1, x2, corrs, legend):
# def plot_gain(sols, plot_diag='ap', plot_offdiag='', gaintype=("Gain", "Offdiag gain"), figtitle=None):
#     def _prep_plot(nplot, ant, num_gaintype, plot_type):
#     def _make_real_plot(ax, time, x1, x2, corrs, legend):
#     def _make_reim_plot(ax, time, x1, x2, corrs, legend):
#     def _make_ap_plot(ax, AX2, time, x1, x2, corrs, legend):
# def get_freq_slice(FS, all_freqs):
# def get_time_slice(TS, all_times):
# def _get_jones_element_index(G, ant, corr1=0, corr2=0, dir=0):
# def _get_jones_element_slice(G, ant, corr1=0, corr2=0, dir=0):
# def prepare_sols_dict(G, FS=None, TS=None):
# def plot_bandpass_cc(G, FS=None, TS=None,
#                         plot_diag='ap', plot_offdiag='', figtitle=None, component='gain'):
# def plot_gain_cc(G, FS=None, TS=None,
#                         plot_diag='ap', plot_offdiag='', figtitle=None, component='gain'):
# def read_cubical_gains(filename, label=None, component="gain"):
#             FS = slice(if0 or 0, if1)
#             FS = slice(None)
#     FS = get_freq_slice(FS, G.grid[G.ax.freq])
#     TS = get_freq_slice(TS, G.grid[G.ax.time])


from collections import OrderedDict
from pylab import *
from cubical.plots import gainsols
    from collections import OrderedDict
import matplotlib.patches as mpatches
    import re, cmath
#!/usr/bin/env python
from __future__ import print_function


def plot_leakages_cc(D, FS=None, TS=None, ANTS=slice(None), refant=None,
                     plot_diag='ap', plot_offdiag='ri', figtitle=None):
    """Plots leakages from a CubiCal database"""
    sols, have_offdiag, is_complex = gainsols.prepare_sols_dict(D, FS, TS)
    if not have_offdiag:
        plot_offdiag = ''
    if not is_complex:
        plot_diag = plot_diag and 'r'
        plot_offdiag = plot_offdiag and 'r'

    # renormalize
    sols = OrderedDict([(ant, (t, f, d00, d01/d00, d10/d11, d11))
                        for ant, (t, f, d00, d01, d10, d11) in sols.items()])

    # apply new reference antenna
    if refant is not None:
        d01ref = sols[refant][3]
        sols = OrderedDict([(ant, (t, f, d00, d01 - d01ref, d10 + np.conj(d01ref), d11))
                            for ant, (t, f, d00, d01, d10, d11) in sols.items()])


# Path: cubical/plots/gainsols.py
# class PlotLimits(object):
# class PlotOptions(PlotLimits):
#     def __init__(self):
#     def __init__(self):
#     def populate_argparse(parser):
# def get_plot_limits(options, sols, time0=0):
# def get_plot_counts(nsols, plots_per_sol):
# def plot_bandpass(sols, plot_diag='ap', plot_offdiag='', gaintype=("Bandpass", "Offdiag bandpass"), figtitle=None):
#     def _prep_plot(nplot, ant, num_gaintype, plot_type):
#     def _make_reim_plot(ax, freq, x1, x2, corrs, legend):
#     def _make_ap_plot(ax, ax2, freq, x1, x2, corrs, legend):
# def plot_gain(sols, plot_diag='ap', plot_offdiag='', gaintype=("Gain", "Offdiag gain"), figtitle=None):
#     def _prep_plot(nplot, ant, num_gaintype, plot_type):
#     def _make_real_plot(ax, time, x1, x2, corrs, legend):
#     def _make_reim_plot(ax, time, x1, x2, corrs, legend):
#     def _make_ap_plot(ax, AX2, time, x1, x2, corrs, legend):
# def get_freq_slice(FS, all_freqs):
# def get_time_slice(TS, all_times):
# def _get_jones_element_index(G, ant, corr1=0, corr2=0, dir=0):
# def _get_jones_element_slice(G, ant, corr1=0, corr2=0, dir=0):
# def prepare_sols_dict(G, FS=None, TS=None):
# def plot_bandpass_cc(G, FS=None, TS=None,
#                         plot_diag='ap', plot_offdiag='', figtitle=None, component='gain'):
# def plot_gain_cc(G, FS=None, TS=None,
#                         plot_diag='ap', plot_offdiag='', figtitle=None, component='gain'):
# def read_cubical_gains(filename, label=None, component="gain"):
#             FS = slice(if0 or 0, if1)
#             FS = slice(None)
#     FS = get_freq_slice(FS, G.grid[G.ax.freq])
#     TS = get_freq_slice(TS, G.grid[G.ax.time])


# Path: cubical/plots/leakages.py
from collections import OrderedDict
from pylab import *
from cubical.plots import gainsols
    from collections import OrderedDict
import matplotlib.patches as mpatches
    import re, cmath

#!/usr/bin/env python
from __future__ import print_function


def plot_leakages_cc(D, FS=None, TS=None, ANTS=slice(None), refant=None,
                     plot_diag='ap', plot_offdiag='ri', figtitle=None):
    """Plots leakages from a CubiCal database"""
    sols, have_offdiag, is_complex = gainsols.prepare_sols_dict(D, FS, TS)
    if not have_offdiag:
        plot_offdiag = ''
    if not is_complex:
        plot_diag = plot_diag and 'r'
        plot_offdiag = plot_offdiag and 'r'

    # renormalize
    sols = OrderedDict([(ant, (t, f, d00, d01/d00, d10/d11, d11))
                        for ant, (t, f, d00, d01, d10, d11) in sols.items()])

    # apply new reference antenna
    if refant is not None:
        d01ref = sols[refant][3]
        sols = OrderedDict([(ant, (t, f, d00, d01 - d01ref, d10 + np.conj(d01ref), d11))
                            for ant, (t, f, d00, d01, d10, d11) in sols.items()])


    return gainsols.plot_bandpass(sols, plot_diag=plot_diag, plot_offdiag=plot_offdiag,