diff --git a/CAL/CalibrationCommon/test/CMakeLists.txt b/CAL/CalibrationCommon/test/CMakeLists.txt index 2a5b743bbaaabb90bf35aa52b1d951770e2e1907..ea546bf5a63622fa488458e28788e436014b1dad 100644 --- a/CAL/CalibrationCommon/test/CMakeLists.txt +++ b/CAL/CalibrationCommon/test/CMakeLists.txt @@ -21,7 +21,6 @@ include(LofarCTest) lofar_add_test(t_holography_ms_class) lofar_add_test(t_holography_beam_specification_class) -lofar_add_test(t_holography_datatable_class) lofar_add_test(t_holography_dataset_class) lofar_add_test(t_holography_dataset_class2) lofar_add_test(t_holography_observation) diff --git a/CAL/CalibrationCommon/test/t_holography_datatable_class.py b/CAL/CalibrationCommon/test/t_holography_datatable_class.py deleted file mode 100755 index 28dd6b888e4586d288d6148243c10824392e8a1c..0000000000000000000000000000000000000000 --- a/CAL/CalibrationCommon/test/t_holography_datatable_class.py +++ /dev/null @@ -1,152 +0,0 @@ -import logging -import unittest -import numpy -import tempfile -import h5py - -from lofar.calibration.common.datacontainers.holography_datatable import LazyH5Table,\ - HolographyDataTable - -logger = logging.getLogger('t_holography_datatable_class') - - -def test_data_dict_string_indexes(): - frequencies = [str(i) for i in numpy.linspace(0, 1000, 100, dtype=float)] - stations = ['CS001', 'CS002'] - beams = [str(int(i)) for i in range(100)] - - dset = numpy.random.rand(10) - data_dict = {} - for fr in frequencies: - for station in stations: - for beam in beams: - data_dict[(fr, station, beam)] = dset - return data_dict - - -class TestLazyH5Table(unittest.TestCase): - def test_create_table(self): - test_data = test_data_dict_string_indexes() - test_uri = '/mytest_uri' - temp_file_name = 'tempFile.h5' - with tempfile.TemporaryDirectory() as temporary_dir: - full_path = temporary_dir + '/' + temp_file_name - logger.info('creating temp file %s', full_path) - h5file = h5py.File(full_path) - data_table = LazyH5Table(uri=test_uri, h5_file=h5file) - - for key, value in test_data.items(): - - data_table[key] = value - - h5file.close() - - h5file = h5py.File(full_path) - - for key, value in test_data.items(): - - data_uri = '/'.join(key) - self.assertIn(test_uri + '/' + data_uri, h5file) - - -def test_data_dict_holography_index_types(): - frequencies = [i for i in numpy.linspace(0, 1000, 100, dtype=float)] - stations = ['CS001', 'CS002'] - beams = [int(i) for i in range(100)] - - dset = numpy.random.rand(10) - data_dict = {} - for station in stations: - for fr in frequencies: - for beam in beams: - data_dict[(station, fr, beam)] = dset - return data_dict - - -class TestHolographyDatasetClass(unittest.TestCase): - - def test_create_read_dataset(self): - test_data = test_data_dict_holography_index_types() - - test_uri = '/mytest_uri' - temp_file_name = 'tempFile.h5' - with tempfile.TemporaryDirectory() as temporary_dir: - full_path = temporary_dir + '/' + temp_file_name - logger.info('creating temp file %s', full_path) - h5file = h5py.File(full_path, 'w') - data_table = HolographyDataTable(uri=test_uri, h5_file=h5file) - - for key, value in test_data.items(): - data_table[key] = value - - h5file.close() - - h5file = h5py.File(full_path, 'r') - data_table = HolographyDataTable(uri=test_uri, h5_file=h5file) - - stored_keys = data_table.keys() - stations = set(key[0] for key in stored_keys) - frequencies = set(key[1] for key in stored_keys) - beams = set(key[2] for key in stored_keys) - - self.assertEqual(set(data_table.frequencies), frequencies) - self.assertEqual(set(data_table.reference_stations), stations) - self.assertEqual(set(data_table.beam_numbers), beams) - - self.assertEqual(stored_keys.difference(test_data.keys()), set()) - - for key, value in data_table.iter_items(): - self.assertIn(key, test_data) - station_name, frequency, beam = key - numpy.testing.assert_array_equal(data_table[station_name, frequency, beam], test_data[key]) - - for frequency in data_table.frequencies: - for reference_station in data_table.reference_stations: - for beam in data_table.beam_numbers: - self.assertIn((reference_station, frequency, beam), stored_keys) - - def test_wrong_index_types(self): - test_uri = '/mytest_uri' - temp_file_name = 'tempFile.h5' - with tempfile.TemporaryDirectory() as temporary_dir: - full_path = temporary_dir + '/' + temp_file_name - logger.info('creating temp file %s', full_path) - h5file = h5py.File(full_path) - data_table = HolographyDataTable(uri=test_uri, h5_file=h5file) - with self.assertRaises(IndexError): - data_table['ref', 1, 1] = 1 - with self.assertRaises(IndexError): - data_table['ref', 1., ""] = 1 - with self.assertRaises(IndexError): - data_table[1 , 1., 1] = 1 - - def test_wrong_index_number(self): - test_uri = '/mytest_uri' - temp_file_name = 'tempFile.h5' - with tempfile.TemporaryDirectory() as temporary_dir: - full_path = temporary_dir + '/' + temp_file_name - logger.info('creating temp file %s', full_path) - h5file = h5py.File(full_path) - data_table = HolographyDataTable(uri=test_uri, h5_file=h5file) - - with self.assertRaises(IndexError): - data_table[1 , 1.] = 1 - with self.assertRaises(IndexError): - data_table[1 , 1., 1, 1] = 1 - - def test_error_getting_non_existing_data(self): - test_uri = '/mytest_uri' - temp_file_name = 'tempFile.h5' - with tempfile.TemporaryDirectory() as temporary_dir: - full_path = temporary_dir + '/' + temp_file_name - logger.info('creating temp file %s', full_path) - h5file = h5py.File(full_path) - data_table = HolographyDataTable(uri=test_uri, h5_file=h5file) - - with self.assertRaises(KeyError): - _ = data_table['stat', 1., 1] - - -if __name__ == '__main__': - logging.basicConfig(format='%(name)s : %(message)s', level=logging.DEBUG) - unittest.main() diff --git a/CAL/CalibrationCommon/test/t_holography_datatable_class.run b/CAL/CalibrationCommon/test/t_holography_datatable_class.run deleted file mode 100755 index 196521525cefa3f127db8a0282f1e8270d72a5ed..0000000000000000000000000000000000000000 --- a/CAL/CalibrationCommon/test/t_holography_datatable_class.run +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -# Copyright (C) 2018 ASTRON (Netherlands Institute for Radio Astronomy) -# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# The LOFAR software suite is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. - -# Run the unit test -source python-coverage.sh -python_coverage_test "*holography_datatable*" t_holography_datatable_class.py \ No newline at end of file diff --git a/CAL/CalibrationCommon/test/t_holography_datatable_class.sh b/CAL/CalibrationCommon/test/t_holography_datatable_class.sh deleted file mode 100755 index 7969ebdd38328f2b66f3fcabc4656b2f29927373..0000000000000000000000000000000000000000 --- a/CAL/CalibrationCommon/test/t_holography_datatable_class.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh - -# Copyright (C) 2018 ASTRON (Netherlands Institute for Radio Astronomy) -# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# The LOFAR software suite is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. - -./runctest.sh t_holography_datatable_class \ No newline at end of file