Beispiel #1
0
    def test_write_corrected_data_does_not_contain_pol(self):
        name = "test"
        station = "station"
        GainOutlierDetection = GainOutlierCorrectionWrapper()
        input_polarization_data = {
            "unknownPolarisation": [{
                'freqs': [11],
                'freqwidths': [12],
                'times': [13],
                'timewidths': [14]
            }]
        }

        input_corected_data = {
            "pol1": RealImagArray([[1], [1]], [[2], [2]]),
            "pol2": RealImagArray([[3], [3]], [[4], [4]])
        }
        # This object will be taken from the fixture: it is a recorder muck
        parmdb = WritableParmDB("parmdb")

        # call function
        GainOutlierDetection = GainOutlierCorrectionWrapper()
        self.assertRaises(PipelineRecipeFailed,
                          GainOutlierDetection._write_corrected_data, parmdb,
                          station, input_polarization_data,
                          input_corected_data)
Beispiel #2
0
    def test_convert_data_to_ComplexArray_real_imag(self):
        data = [{"values": [1]}, {"values": [1]}]
        type_pair = ["Imag", "Real"]  # Order is alphabetical
        GainOutlierDetection = GainOutlierCorrectionWrapper()
        complex_array = GainOutlierDetection._convert_data_to_ComplexArray(data, type_pair)

        goal_array = RealImagArray([1], [1])
        self.assertTrue(complex_array.real == goal_array.real)
        self.assertTrue(complex_array.imag == goal_array.imag)
Beispiel #3
0
def _convert_data_to_ComplexArray(data, type_pair):
    """
        Performs a conversion of a 2d array to a 1d complex valued array.
        with real/imag values or with amplitude phase values
        """
    if sorted(type_pair) == sorted(RealImagArray.keys):
        # The type_pair is in alphabetical order: Imag on index 0
        complex_array = RealImagArray(data[1]["values"], data[0]["values"])
    elif sorted(type_pair) == sorted(AmplPhaseArray.keys):
        complex_array = AmplPhaseArray(data[0]["values"], data[1]["values"])
    else:
        print("Incorrect data type pair provided: {0}".format(type_pair))
        raise Exception(
            "Invalid data type retrieved from parmdb: {0}".format(type_pair))
    return complex_array
Beispiel #4
0
    def test_write_corrected_data(self):
        # define input data
        name = "test"
        station = "station"
        GainOutlierDetection = GainOutlierCorrectionWrapper()
        input_polarization_data = {
            "pol1": [{
                'freqs': [11],
                'freqwidths': [12],
                'times': [13],
                'timewidths': [14]
            }]
        }

        input_corected_data = {
            "pol1": RealImagArray([[1], [1]], [[2], [2]]),
            "pol22": RealImagArray([[3], [3]], [[4], [4]])
        }
        # This object will be taken from the fixture: it is a recorder muck
        parmdb = WritableParmDB("parmdb")

        # call function
        GainOutlierDetection = GainOutlierCorrectionWrapper()
        GainOutlierDetection._write_corrected_data(parmdb, station,
                                                   input_polarization_data,
                                                   input_corected_data)

        # test output: (the calls to parmdb)
        # there is one polarization, containing a single complex array
        # when writing this should result in, 1 times 2 function calls
        # first delete the REAL entry
        expected = ['deleteValues', ['Gain:pol1:Real:station']]
        self.assertTrue(
            parmdb.called_functions_and_parameters[0] == expected,
            "result({0}) != expected({1})".format(
                parmdb.called_functions_and_parameters[0], expected))
        # then the new values should be added, with the correct values
        expected = [
            'addValues',
            [
                'Gain:pol1:Real:station',
                numpy.array([[1.], [1.]], ), 11, 11 + 12, 13, 13 + 2 * 14, True
            ]
        ]  #stat + steps*size

        # Now scan the argument array: for numpy use special compare function
        for left, right in zip(parmdb.called_functions_and_parameters[1][1],
                               expected[1]):
            error_message = "\nresult({0}) != \nexpected({1}) \n"\
                "-> {2} !=  {3}".format(
                        parmdb.called_functions_and_parameters[1], expected,
                        left, right)
            try:
                if not left == right:
                    self.assertTrue(False, error_message)
            except ValueError:
                if not numpy.array_equal(left, right):
                    self.assertTrue(False, error_message)

        # now delete the imag entry: Rememder these are on the 2nd and 3th array
        # position
        expected = ['deleteValues', ['Gain:pol1:Imag:station']]
        self.assertTrue(
            parmdb.called_functions_and_parameters[2] == expected,
            "result({0}) != expected({1})".format(
                parmdb.called_functions_and_parameters[2], expected))
        # then the new values should be added, with the correct values
        expected = [
            'addValues',
            [
                'Gain:pol1:Imag:station',
                numpy.array([[2.], [2.]], ), 11, 11 + 12, 13, 13 + 2 * 14, True
            ]
        ]  #stat + steps*size

        # Now scan the argument array: for numpy use special compare function
        for left, right in zip(parmdb.called_functions_and_parameters[3][1],
                               expected[1]):
            error_message = "\nresult({0}) != \nexpected({1}) \n"\
                "-> {2} !=  {3}".format(
                        parmdb.called_functions_and_parameters[3], expected,
                        left, right)
            try:
                if not left == right:
                    self.assertTrue(False, error_message)
            except ValueError:
                if not numpy.array_equal(left, right):
                    self.assertTrue(False, error_message)