# Path: cubical/tools/logger.py
# def logToFile(filename, append=False):
# def getLogFilename():
#     def __init__(self, logger, level, color=None, bold=None):
#     def write(self, message, level_override=None, print_once=None):
#     def print(self, *args):
#     def __init__(self, logger, verbose=None, log_verbose=None):
#     def verbosity(self, set_verb=None):
#     def log_verbosity(self, set_verb=None):
#     def __call__(self, level, color=None):
#     def warn(self, msg, color=None, print_once=None):
#     def error(self, msg, color="red", print_once=None):
#     def info(self, msg, color=None, print_once=None):
#     def critical(self, msg, color=None, print_once=None):
#     def debug(self, msg, color=None, print_once=None):
#     def exception(self, msg, color=None, print_once=None):
#     def print(self, *args):
#     def write(self, message, level=logging.INFO, verbosity=0, print_once=None, color=None):
# def enableMemoryLogging(level=1):
# def set_subprocess_label(label):
# def get_subprocess_label():
# def _sigusr1_handler(signum, frame):
# def _sigusr2_handler(signum, frame):
#     def setMemoryLogging(level):
#     def filter(self, event):
#     def __init__(self, fmt, datefmt, strip=True):
#     def label(self, record):
#     def format(self, record):
# def init(app_name):
# def getLogger(name, verbose=None, log_verbose=None):
# def setBoring(boring=True):
# def setGlobalVerbosity(verbosity):
# def setGlobalLogVerbosity(verbosity):
# def setSilent(Lname):
# def setLoud(Lname):
# class _DefaultWriter(object):
# class LoggerWrapper(object):
# class LogFilter(logging.Filter):
# class ColorStrippingFormatter(logging.Formatter):
# GB = float(1024 ** 3)
#                 KEYS = _log_memory_types[memlevel]
# 
# Path: cubical/tools/ModColor.py
# HEADER = '\033[95m'
# OKBLUE = '\033[94m'
# OKGREEN = '\033[92m'
# WARNING = '\033[93m'
# FAIL = '\033[91m'
# ENDC = '\033[0m'
#     HEADER = ''
#     OKBLUE = ''
#     OKGREEN = ''
#     WARNING = ''
#     FAIL = ''
#     ENDC = ''
# def disableColors():
# def Str(strin0,col="red",Bold=True):
# def Sep(strin=None,D=1):
# def Title(strin,Big=False):
# def disable():


from DDFacet.compatibility import range
from cubical.tools import logger, ModColor
import numpy
import os
import os.path
import sys
import pyrap.tables
import numpy as np
            import Siamese.OMS.Utils as Utils
            import Siamese
            import Siamese.OMS.InterpolatedBeams as InterpolatedBeams
            import Cattery.Siamese.OMS.Utils as Utils
            import Cattery.Siamese as Siamese
            import Cattery.Siamese.OMS.InterpolatedBeams as InterpolatedBeams
        import math
            print("Applying derotation to data, since beam is sampled in time. "
                  "If you have equatorial mounts this is not what you should be doing!", file=log)
            if self.feedbasis == "linear":
                """ 2D rotation matrix according to Hales, 2017: 
                Calibration Errors in Interferometric Radio Polarimetry """
                c1, s1 = np.cos(parad + np.deg2rad(self.feedangle)), np.sin(parad + np.deg2rad(self.feedangle))
                # assume all stations has same parallactic angle
                Pjones[0, 0] = c1
                Pjones[0, 1] = s1
                Pjones[1, 0] = -s1
                Pjones[1, 1] = c1
            elif self.feedbasis == "circular":
                """ phase rotation matrix according to Hales, 2017: 
                Calibration Errors in Interferometric Radio Polarimetry """
                e1 = np.exp(1.0j * -(parad + np.deg2rad(self.feedangle)))
                e2 = np.exp(1.0j * (parad + np.deg2rad(self.feedangle)))
                # assume all stations has same parallactic angle
                Pjones[0, 0] = e1
                Pjones[0, 1] = 0
                Pjones[1, 0] = 0
                Pjones[1, 1] = e2
            else:
                raise RuntimeError("Feed basis not supported")

        # dot diagonal block matrix of P with E diagonal block vector 
        # again assuming constant P matrix across all stations
        E_vec = jones.reshape(ndir * self.station_positions.shape[0] * len(self.freqs), 2, 2)
        for i in range(E_vec.shape[0]):
            E_vec[i,:,:] = np.dot(Pjones, np.dot(E_vec[i, :, :], feedswap_jones))


# Path: cubical/tools/logger.py
# def logToFile(filename, append=False):
# def getLogFilename():
#     def __init__(self, logger, level, color=None, bold=None):
#     def write(self, message, level_override=None, print_once=None):
#     def print(self, *args):
#     def __init__(self, logger, verbose=None, log_verbose=None):
#     def verbosity(self, set_verb=None):
#     def log_verbosity(self, set_verb=None):
#     def __call__(self, level, color=None):
#     def warn(self, msg, color=None, print_once=None):
#     def error(self, msg, color="red", print_once=None):
#     def info(self, msg, color=None, print_once=None):
#     def critical(self, msg, color=None, print_once=None):
#     def debug(self, msg, color=None, print_once=None):
#     def exception(self, msg, color=None, print_once=None):
#     def print(self, *args):
#     def write(self, message, level=logging.INFO, verbosity=0, print_once=None, color=None):
# def enableMemoryLogging(level=1):
# def set_subprocess_label(label):
# def get_subprocess_label():
# def _sigusr1_handler(signum, frame):
# def _sigusr2_handler(signum, frame):
#     def setMemoryLogging(level):
#     def filter(self, event):
#     def __init__(self, fmt, datefmt, strip=True):
#     def label(self, record):
#     def format(self, record):
# def init(app_name):
# def getLogger(name, verbose=None, log_verbose=None):
# def setBoring(boring=True):
# def setGlobalVerbosity(verbosity):
# def setGlobalLogVerbosity(verbosity):
# def setSilent(Lname):
# def setLoud(Lname):
# class _DefaultWriter(object):
# class LoggerWrapper(object):
# class LogFilter(logging.Filter):
# class ColorStrippingFormatter(logging.Formatter):
# GB = float(1024 ** 3)
#                 KEYS = _log_memory_types[memlevel]
# 
# Path: cubical/tools/ModColor.py
# HEADER = '\033[95m'
# OKBLUE = '\033[94m'
# OKGREEN = '\033[92m'
# WARNING = '\033[93m'
# FAIL = '\033[91m'
# ENDC = '\033[0m'
#     HEADER = ''
#     OKBLUE = ''
#     OKGREEN = ''
#     WARNING = ''
#     FAIL = ''
#     ENDC = ''
# def disableColors():
# def Str(strin0,col="red",Bold=True):
# def Sep(strin=None,D=1):
# def Title(strin,Big=False):
# def disable():


# Path: cubical/degridder/FITSBeamInterpolator.py
from DDFacet.compatibility import range
from cubical.tools import logger, ModColor
import numpy
import os
import os.path
import sys
import pyrap.tables
import numpy as np
            import Siamese.OMS.Utils as Utils
            import Siamese
            import Siamese.OMS.InterpolatedBeams as InterpolatedBeams
            import Cattery.Siamese.OMS.Utils as Utils
            import Cattery.Siamese as Siamese
            import Cattery.Siamese.OMS.InterpolatedBeams as InterpolatedBeams
        import math

            print("Applying derotation to data, since beam is sampled in time. "
                  "If you have equatorial mounts this is not what you should be doing!", file=log)
            if self.feedbasis == "linear":
                """ 2D rotation matrix according to Hales, 2017: 
                Calibration Errors in Interferometric Radio Polarimetry """
                c1, s1 = np.cos(parad + np.deg2rad(self.feedangle)), np.sin(parad + np.deg2rad(self.feedangle))
                # assume all stations has same parallactic angle
                Pjones[0, 0] = c1
                Pjones[0, 1] = s1
                Pjones[1, 0] = -s1
                Pjones[1, 1] = c1
            elif self.feedbasis == "circular":
                """ phase rotation matrix according to Hales, 2017: 
                Calibration Errors in Interferometric Radio Polarimetry """
                e1 = np.exp(1.0j * -(parad + np.deg2rad(self.feedangle)))
                e2 = np.exp(1.0j * (parad + np.deg2rad(self.feedangle)))
                # assume all stations has same parallactic angle
                Pjones[0, 0] = e1
                Pjones[0, 1] = 0
                Pjones[1, 0] = 0
                Pjones[1, 1] = e2
            else:
                raise RuntimeError("Feed basis not supported")

        # dot diagonal block matrix of P with E diagonal block vector 
        # again assuming constant P matrix across all stations
        E_vec = jones.reshape(ndir * self.station_positions.shape[0] * len(self.freqs), 2, 2)
        for i in range(E_vec.shape[0]):
            E_vec[i,:,:] = np.dot(Pjones, np.dot(E_vec[i, :, :], feedswap_jones))


        return E_vec.reshape(ndir, self.station_positions.shape[0], len(self.freqs), 2, 2)