# Path: tkp/quality/rms.py
# def rms_invalid(rms, noise, low_bound=1, high_bound=50):
#     """
#     Is the RMS value of an image outside the plausible range?
# 
#     :param rms: RMS value of an image, can be computed with
#                 tkp.quality.statistics.rms
#     :param noise: Theoretical noise level of instrument, can be calculated with
#                   tkp.lofar.noise.noise_level
#     :param low_bound: multiplied with noise to define lower threshold
#     :param high_bound: multiplied with noise to define upper threshold
#     :returns: True/False
#     """
#     if (rms < noise * low_bound) or (rms > noise * high_bound):
#         ratio = rms / noise
#         return "rms value (%s) is %s times theoretical noise (%s)" % \
#                     (nice_format(rms), nice_format(ratio), nice_format(noise))
#     else:
#         return False
# 
# Path: tkp/testutil/decorators.py
# def requires_data(*args):
#     for filename in args:
#         if not os.path.exists(filename):
#             return unittest.skip("Test data (%s) not available" % filename)
#     return lambda func: func


import os
import numpy
import tkp.quality.rms
import unittest
import tkp.quality
import tkp.telescope.lofar as lofar
from numpy.testing import assert_array_equal, assert_array_almost_equal
from tkp.quality.rms import rms_invalid
from tkp.testutil.decorators import requires_data
from tkp.testutil.data import DATAPATH
        integration_time = 18654.3 # s
        bandwidth = 200 * 10**3 # Hz
        frequency = 66308593.75 # Hz
        ncore = 23
        nremote = 8
        nintl = 0
        configuration = "LBA_INNER"

        self.assertAlmostEqual(
            lofar.noise.noise_level(frequency, bandwidth, integration_time,
                                    configuration, ncore, nremote, nintl),
            0.01590154516819521 ,# with a calculator!
            places=7
        )

    def test_rms_too_low(self):
        theoretical_noise = 1
        measured_rms = 1e-9
        self.assertTrue(rms_invalid(measured_rms, theoretical_noise))

    def test_rms_too_high(self):
        theoretical_noise = 1
        measured_rms = 1e9
        self.assertTrue(rms_invalid(measured_rms, theoretical_noise))

    def test_rms_valid(self):
        measured_rms = theoretical_noise = 1
        self.assertFalse(rms_invalid(measured_rms, theoretical_noise))



# Path: tkp/quality/rms.py
# def rms_invalid(rms, noise, low_bound=1, high_bound=50):
#     """
#     Is the RMS value of an image outside the plausible range?
# 
#     :param rms: RMS value of an image, can be computed with
#                 tkp.quality.statistics.rms
#     :param noise: Theoretical noise level of instrument, can be calculated with
#                   tkp.lofar.noise.noise_level
#     :param low_bound: multiplied with noise to define lower threshold
#     :param high_bound: multiplied with noise to define upper threshold
#     :returns: True/False
#     """
#     if (rms < noise * low_bound) or (rms > noise * high_bound):
#         ratio = rms / noise
#         return "rms value (%s) is %s times theoretical noise (%s)" % \
#                     (nice_format(rms), nice_format(ratio), nice_format(noise))
#     else:
#         return False
# 
# Path: tkp/testutil/decorators.py
# def requires_data(*args):
#     for filename in args:
#         if not os.path.exists(filename):
#             return unittest.skip("Test data (%s) not available" % filename)
#     return lambda func: func


# Path: tests/test_quality/test_rms.py
import os
import numpy
import tkp.quality.rms
import unittest
import tkp.quality
import tkp.telescope.lofar as lofar
from numpy.testing import assert_array_equal, assert_array_almost_equal
from tkp.quality.rms import rms_invalid
from tkp.testutil.decorators import requires_data
from tkp.testutil.data import DATAPATH

        integration_time = 18654.3 # s
        bandwidth = 200 * 10**3 # Hz
        frequency = 66308593.75 # Hz
        ncore = 23
        nremote = 8
        nintl = 0
        configuration = "LBA_INNER"

        self.assertAlmostEqual(
            lofar.noise.noise_level(frequency, bandwidth, integration_time,
                                    configuration, ncore, nremote, nintl),
            0.01590154516819521 ,# with a calculator!
            places=7
        )

    def test_rms_too_low(self):
        theoretical_noise = 1
        measured_rms = 1e-9
        self.assertTrue(rms_invalid(measured_rms, theoretical_noise))

    def test_rms_too_high(self):
        theoretical_noise = 1
        measured_rms = 1e9
        self.assertTrue(rms_invalid(measured_rms, theoretical_noise))

    def test_rms_valid(self):
        measured_rms = theoretical_noise = 1
        self.assertFalse(rms_invalid(measured_rms, theoretical_noise))



@requires_data(core_antennas)