def test_read_array_write_site_antennas_iq(self): """ Test reading, restructuring, writing, restructuring antennas_iq. Checks: - arrays that pass the read from a file can then be written as records - arrays restructured, written as records, read as records, restructured back to arrays are the same as original arrays """ dm = pydarn.BorealisRead(self.source_antennas_iq_array_file, 'antennas_iq', 'array') arrays = dm.arrays writer = pydarn.BorealisWrite(self.write_antennas_iq_site_file, dm.records, 'antennas_iq', 'site') del dm, writer gc.collect() self.assertTrue(os.path.isfile(self.write_antennas_iq_site_file)) dm2 = pydarn.BorealisRead(self.write_antennas_iq_site_file, 'antennas_iq', 'site') new_arrays = dm2.arrays # restructuring happens here dictionaries_are_same = self.check_dictionaries_are_same( arrays, new_arrays) self.assertTrue(dictionaries_are_same) os.remove(self.write_antennas_iq_site_file) del dm2, arrays, new_arrays
def test_read_site_write_array_bfiq(self): """ Test reading, restructuring, writing, restructuring bfiq. Checks: - records that pass the read from a file can then be written as arrays - records restructured, written as arrays, read as arrays, restructured back to records are the same as original records """ dm = pydarn.BorealisRead(self.source_bfiq_site_file, 'bfiq', 'site') records = dm.records arrays = dm.arrays # restructuring happens here _ = pydarn.BorealisWrite(self.write_bfiq_array_file, arrays, 'bfiq', 'array') del dm, arrays self.assertTrue(os.path.isfile(self.write_bfiq_array_file)) dm2 = pydarn.BorealisRead(self.write_bfiq_array_file, 'bfiq', 'array') new_records = dm2.records # restructuring happens here dictionaries_are_same = self.check_dictionaries_are_same( records, new_records) self.assertTrue(dictionaries_are_same) os.remove(self.write_bfiq_array_file) del dm2, records, new_records
def test_return_reader(self): """ Test the internal BorealisRead return_reader function which should be able to determine which structure of file to use if none is provided. """ site_reader = pydarn.BorealisRead(self.bfiq_site_file_path, 'bfiq') record_data = site_reader.records random_key = random.choice(list(record_data.keys())) self.assertIsInstance(record_data[random_key]['num_slices'], np.int64) array_reader = pydarn.BorealisRead(self.bfiq_array_file_path, 'bfiq') array_data = array_reader.arrays self.assertIsInstance(array_data['num_slices'], np.ndarray)
def test_read_write_array_bfiq(self): """ Test reading and then writing array structured bfiq data to a file. Checks: - arrays that pass the read from a file can then be written - arrays written and then read are the same as original """ dm = pydarn.BorealisRead(self.source_bfiq_array_file, 'bfiq', 'array') arrays = dm.arrays _ = pydarn.BorealisWrite(self.write_bfiq_array_file, arrays, 'bfiq', 'array') self.assertTrue(os.path.isfile(self.write_bfiq_array_file)) dm2 = pydarn.BorealisRead(self.write_bfiq_array_file, 'bfiq', 'array') new_arrays = dm2.arrays dictionaries_are_same = self.check_dictionaries_are_same( arrays, new_arrays) self.assertTrue(dictionaries_are_same) os.remove(self.write_bfiq_array_file) del dm, dm2, arrays, new_arrays
def test_read_write_site_bfiq(self): """ Test reading and then writing site bfiq data to a file. Checks: - records that pass the read from a file can then be written - records written and then read are the same as original """ dm = pydarn.BorealisRead(self.source_bfiq_site_file, 'bfiq', 'site') records = dm.records _ = pydarn.BorealisWrite(self.write_bfiq_site_file, records, 'bfiq', 'site') self.assertTrue(os.path.isfile(self.write_bfiq_site_file)) dm2 = pydarn.BorealisRead(self.write_bfiq_site_file, 'bfiq', 'site') new_records = dm2.records dictionaries_are_same = self.check_dictionaries_are_same( records, new_records) self.assertTrue(dictionaries_are_same) os.remove(self.write_bfiq_site_file) del dm, dm2, records, new_records
def setUp(self): self.rawacf_array_data = copy.deepcopy(borealis_array_rawacf_data) self.bfiq_array_data = copy.deepcopy(borealis_array_bfiq_data) self.bfiq_file = 'test_bfiq.bfiq.hdf5' self.rawacf_file = 'test_rawacf.rawacf.hdf5' self.iqdat_array_darn_file = './test_iqdat_array_file.dmap' self.rawacf_array_darn_file = './test_rawacf_array_file.dmap' _ = pydarn.BorealisWrite(self.bfiq_file, self.bfiq_array_data, 'bfiq', 'array') bfiq_reader = pydarn.BorealisRead(self.bfiq_file, 'bfiq', 'array') self.bfiq_site_data = bfiq_reader.records self.iqdat_site_darn_file = './test_iqdat_site_file.dmap' _ = pydarn.BorealisWrite(self.rawacf_file, self.rawacf_array_data, 'rawacf', 'array') rawacf_reader = pydarn.BorealisRead(self.rawacf_file, 'rawacf', 'array') self.rawacf_site_data = rawacf_reader.records self.rawacf_site_darn_file = './test_rawacf_site_file.dmap'
def test_writing_array_rawacf(self): """ Tests write_rawacf method - writes a rawacf file Expected behaviour ------------------ Rawacf file is produced """ test_file = "test_rawacf.rawacf.hdf5" _ = pydarn.BorealisWrite(test_file, self.rawacf_array_data, 'rawacf', 'array') self.assertTrue(os.path.isfile(test_file)) reader = pydarn.BorealisRead(test_file, 'rawacf', 'array') data = reader.arrays dictionaries_are_same =\ self.check_dictionaries_are_same(data, self.rawacf_array_data) self.assertTrue(dictionaries_are_same) os.remove(test_file)
def test_read_site_bfiq(self): """ Test reading records from bfiq. Checks: - returns correct data structures, both records and arrays (restructuring happens internally) - returns expected values """ dm = pydarn.BorealisRead(self.bfiq_site_file_path, 'bfiq', 'site') records = dm.records first_record = records[dm.record_names[0]] self.assertIsInstance(records, collections.OrderedDict) self.assertIsInstance(first_record, dict) self.assertIsInstance(first_record['num_slices'], np.int64) arrays = dm.arrays self.assertIsInstance(arrays, dict) self.assertIsInstance(arrays['num_slices'], np.ndarray) self.assertIsInstance(arrays['num_slices'][0], np.int64) del dm, records, arrays
def test_writing_site_bfiq(self): """ Tests write_bfiq method - writes a bfiq file Expected behaviour ------------------ bfiq file is produced """ test_file = "./test_bfiq.bfiq.hdf5" pydarn.BorealisWrite(test_file, self.bfiq_site_data, 'bfiq', 'site') # only testing the file is created since it should only be created # at the last step after all checks have passed # Testing the integrity of the insides of the file will be part of # integration testing since we need BorealisSiteRead for that. self.assertTrue(os.path.isfile(test_file)) reader = pydarn.BorealisRead(test_file, 'bfiq', 'site') records = reader.records dictionaries_are_same = \ self.check_dictionaries_are_same(records, self.bfiq_site_data) self.assertTrue(dictionaries_are_same) os.remove(test_file)