Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
t_holography_dataset_class.py 2.18 KiB
import logging
import unittest
import tempfile
import os
from lofar.calibration.common.datacontainers import HolographyDataset, HolographySpecification
from lofar.calibration.common.datacontainers import HolographyObservation


logger = logging.getLogger('t_holography_dataset_class')
path_to_test_data = '/data/test/HolographyObservation'
path_to_test_data = '/home/thomas/workspace.astron/data/holography'


class TestHolographyDatasetClass(unittest.TestCase):
    new_test_data_file = None

    def tearDown(self):
        if self.new_test_data_file is not None:
            os.unlink(self.new_test_data_file)

#     def test_one(self):
#         holist = HolographyObservation.list_observations_in_path(path_to_test_data)
#         hbsflist = HolographySpecification.list_bsf_files_in_path(path_to_test_data)
#         for hbsf in hbsflist:
#             hbsf.read_file()
#         ho_per_ms = [(hbsf, ho) for hbsf, ho in zip(hbsflist, holist)]
# 
#         holography_dataset = HolographyDataset()
# 
#         holography_dataset.load_from_beam_specification_and_ms('CS013HBA0', ho_per_ms)
#         self.assertEqual(holography_dataset.source_name, '3C 147')

    def test_two(self):
        holist = HolographyObservation.list_observations_in_path(path_to_test_data)
        hbsflist = HolographySpecification.list_bsf_files_in_path(path_to_test_data)
        for hbsf in hbsflist:
            hbsf.read_file()
        ho_per_ms = [(hbsf, ho) for hbsf, ho in zip(hbsflist, holist)]
 
        holography_dataset = HolographyDataset()
 
        holography_dataset.load_from_beam_specification_and_ms('CS013HBA0', ho_per_ms)

        # Create an empty temporary data file
        (fd, self.new_test_data_file) = tempfile.mkstemp()
        print "**** %s " % (self.new_test_data_file)
        os.close(fd)
        # Now store the MS data in an HDF5 file.
        holography_dataset.store_to_file(self.new_test_data_file)

#     def test_three(self):
#         # Read the MS data from an HDF5 file.
#         holography_dataset = HolographyDataset.load_from_file(self.new_test_data_file)
#         print holography_dataset


if __name__ == '__main__':
    logging.basicConfig(format='%(name)s : %(message)s')
    unittest.main()