# Path: cubical/param_db.py
# def create(filename, metadata={}, backup=True):
# def load(filename):
#     G = db['G']
#     B = db['B']
# 
# 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():


import numpy as np
from numpy.ma import masked_array
from cubical import param_db
from cubical.tools import logger, ModColor
        from cubical.main import expand_templated_name
        if not self.is_computing():
            return
        ## if not per-channel, then sum over channels
        if not self._ifrgains_per_chan:
            self._ddh_sum = self._ddh_sum.sum(0)
            self._mdh_sum = self._mdh_sum.sum(0)

        # mask out null values
        self._ddh_sum.mask |= (self._ddh_sum==0)
        with np.errstate(under='ignore'): # work around https://github.com/numpy/numpy/issues/4895
            ifrgain = self._mdh_sum/self._ddh_sum
        ifrgain.data[self._ddh_sum.mask] = 1
        ifrgain.fill_value = 1

        # promote freq axis back out
        if not self._ifrgains_per_chan:
            ifrgain = np.ma.vstack([ifrgain]*len(self._nfreq))

        # multiply by previous IFR gain, if that was set. This will promote a frequency axis
        if self._ifrgain is not None:
            ifrgain *= self._ifrgain

        # if not 2x2, then reset off-diagonals
        if not self._compute_2x2:
            ifrgain[...,0,1] = ifrgain[...,1,0] = 1

        self.gmfactory.get_solution_db("BBC").add_chunk("BBC", ifrgain, self._ifrgains_grid)

    def reload(self):
        """Reloads saved IFR gain solutions from database"""

# Path: cubical/param_db.py
# def create(filename, metadata={}, backup=True):
# def load(filename):
#     G = db['G']
#     B = db['B']
# 
# 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/machines/ifr_gain_machine.py
import numpy as np
from numpy.ma import masked_array
from cubical import param_db
from cubical.tools import logger, ModColor
        from cubical.main import expand_templated_name

        if not self.is_computing():
            return
        ## if not per-channel, then sum over channels
        if not self._ifrgains_per_chan:
            self._ddh_sum = self._ddh_sum.sum(0)
            self._mdh_sum = self._mdh_sum.sum(0)

        # mask out null values
        self._ddh_sum.mask |= (self._ddh_sum==0)
        with np.errstate(under='ignore'): # work around https://github.com/numpy/numpy/issues/4895
            ifrgain = self._mdh_sum/self._ddh_sum
        ifrgain.data[self._ddh_sum.mask] = 1
        ifrgain.fill_value = 1

        # promote freq axis back out
        if not self._ifrgains_per_chan:
            ifrgain = np.ma.vstack([ifrgain]*len(self._nfreq))

        # multiply by previous IFR gain, if that was set. This will promote a frequency axis
        if self._ifrgain is not None:
            ifrgain *= self._ifrgain

        # if not 2x2, then reset off-diagonals
        if not self._compute_2x2:
            ifrgain[...,0,1] = ifrgain[...,1,0] = 1

        self.gmfactory.get_solution_db("BBC").add_chunk("BBC", ifrgain, self._ifrgains_grid)

    def reload(self):
        """Reloads saved IFR gain solutions from database"""

        return param_db.load(self._save_filename)["BBC"].get_cube()