def test_SDarnRead_SDarnWrite_fitacf(self): """ Test DmapRead reading an fitacf and SDarnWrite writing the fitacf file """ dmap = pydarnio.SDarnRead(fitacf_file) dmap_data = dmap.read_fitacf() dmap_write = pydarnio.SDarnWrite(dmap_data) dmap_write.write_fitacf("test_fitacf.fitacf") fitacf_read = pydarnio.SDarnRead("test_fitacf.fitacf") fitacf_read_data = fitacf_read.read_fitacf() self.dmap_compare(dmap_data, fitacf_read_data) os.remove("test_fitacf.fitacf")
def test_SDarnRead_SDarnWrite_iqdat(self): """ Test DmapRead reading an fitacf and SDarnWrite writing the fitacf file """ dmap = pydarnio.SDarnRead(iqdat_file) dmap_data = dmap.read_iqdat() dmap_write = pydarnio.SDarnWrite(dmap_data) dmap_write.write_iqdat("test_iqdat.iqdat") iqdat_read = pydarnio.SDarnRead("test_iqdat.iqdat") iqdat_read_data = iqdat_read.read_iqdat() self.dmap_compare(dmap_data, iqdat_read_data) os.remove("test_iqdat.iqdat")
def test_SDarnRead_SDarnWrite_grid(self): """ Test DmapRead reading an grid and SDarnWrite writing the grid file """ dmap = pydarnio.SDarnRead(grid_file) dmap_data = dmap.read_grid() dmap_write = pydarnio.SDarnWrite(dmap_data) dmap_write.write_grid("test_grid.grid") grid_read = pydarnio.SDarnRead("test_grid.grid") grid_read_data = grid_read.read_grid() self.dmap_compare(dmap_data, grid_read_data) os.remove("test_grid.grid")
def test_SDarnRead_SDarnWrite_map(self): """ Test DmapRead reading an map and SDarnWrite writing the map file """ dmap = pydarnio.SDarnRead(map_file) dmap_data = dmap.read_map() dmap_write = pydarnio.SDarnWrite(dmap_data) dmap_write.write_map("test_map.map") map_read = pydarnio.SDarnRead("test_map.map") map_read_data = map_read.read_map() self.dmap_compare(dmap_data, map_read_data) os.remove("test_map.map")
def test_SDarnRead_DmapWrite_stream_map(self): """ Test SDarnRead to read from a map stream then DmapWrite to write a map file from the stream """ with bz2.open(map_stream) as fp: dmap_stream = fp.read() dmap = pydarnio.SDarnRead(dmap_stream, True) dmap_stream_data = dmap.read_map() dmap_write = pydarnio.DmapWrite() dmap_write_stream = dmap_write.write_dmap_stream(dmap_stream_data) dmap_read = pydarnio.SDarnRead(dmap_write_stream, True) dmap_read_data = dmap_read.read_map() self.dmap_compare(dmap_stream_data, dmap_read_data)
def test_SDarnRead_stream_SDarnWrite_file_map(self): """ Test SDarnRead reads from a stream and SDarnWrite writes to a map file """ with bz2.open(map_stream) as fp: dmap_stream = fp.read() dmap = pydarnio.SDarnRead(dmap_stream, True) dmap_stream_data = dmap.read_map() dmap_write = pydarnio.SDarnWrite(dmap_stream_data) dmap_write.write_map("test_map.map") self.assertTrue(os.path.isfile("test_map.map")) dmap = pydarnio.SDarnRead("test_map.map") dmap_data = dmap.read_map() self.dmap_compare(dmap_stream_data, dmap_data)
def test_SDarnRead_stream_SDarnWrite_file_iqdat(self): """ Test SDarnRead reads from a stream and SDarnWrite writes to a iqdat file """ with bz2.open(iqdat_stream) as fp: dmap_stream = fp.read() dmap = pydarnio.SDarnRead(dmap_stream, True) stream_data = dmap.read_iqdat() dmap_stream_data = dmap.get_dmap_records dmap_write = pydarnio.SDarnWrite(stream_data) dmap_write.write_iqdat("test_iqdat.iqdat") self.assertTrue(os.path.isfile("test_iqdat.iqdat")) dmap = pydarnio.SDarnRead("test_iqdat.iqdat") _ = dmap.read_iqdat() dmap_read_data = dmap.get_dmap_records self.dmap_compare(dmap_stream_data, dmap_read_data)
def test_SDarnRead_stream_SDarnWrite_file_rawacf(self): """ Test SDarnRead reads from a stream and SDarnWrite writes to a rawacf file """ with bz2.open(rawacf_stream) as fp: dmap_stream = fp.read() dmap = pydarnio.SDarnRead(dmap_stream, True) stream_data = dmap.read_rawacf() dmap_stream_data = dmap.get_dmap_records dmap_write = pydarnio.SDarnWrite(stream_data) dmap_write.write_rawacf("test_rawacf.rawacf") dmap_read = pydarnio.SDarnRead("test_rawacf.rawacf") _ = dmap_read.read_records() dmap_data = dmap_read.get_dmap_records self.dmap_compare(dmap_stream_data, dmap_data) os.remove("test_rawacf.rawacf")
def test_SDarnRead_DmapWrite_stream_fitacf(self): """ Test SDarnRead to read from a fitacf stream then DmapWrite to write a fitacf file from the stream """ with bz2.open(fitacf_stream) as fp: dmap_stream = fp.read() dmap = pydarnio.SDarnRead(dmap_stream, True) stream_data = dmap.read_fitacf() dmap_stream_data = dmap.get_dmap_records dmap_write = pydarnio.DmapWrite() dmap_write_stream = dmap_write.write_dmap_stream(stream_data) dmap_read = pydarnio.SDarnRead(dmap_write_stream, True) dmap_read_data = dmap_read.read_fitacf() dmap_read_data = dmap_read.get_dmap_records self.dmap_compare(dmap_stream_data, dmap_read_data)
def test_read_corrupt_file1(self): """ Test read_records on a corrupt file Expected behaviour: raises pydmap exception """ dmap = pydarnio.SDarnRead(corrupt_file1) with self.assertRaises(pydarnio.dmap_exceptions.DmapDataTypeError): dmap.read_rawacf()
def test_read_currupt_file2(self): """ Test read_records on a corrupt file Expected behaviour: raises pydmap exception """ dmap = pydarnio.SDarnRead(corrupt_file2) with self.assertRaises(pydarnio.dmap_exceptions.NegativeByteError): dmap.read_rawacf()
def test_DmapWrite_stream_SDarnRead_grid(self): """ Test DmapWrite to write to a stream and have SDarnRead the grid stream """ grid_data = copy.deepcopy(grid_data_sets.grid_data) grid_write = pydarnio.DmapWrite() grid_stream = grid_write.write_dmap_stream(grid_data) grid_read = pydarnio.SDarnRead(grid_stream, True) grid_read_data = grid_read.read_grid() self.dmap_compare(grid_read_data, grid_data)
def test_SDarnWrite_SDarnRead_fitacf(self): """ Test SDarnWrite writing a fitacf file and SDarnRead reading the fitacf file """ fitacf_data = copy.deepcopy(fitacf_data_sets.fitacf_data) fitacf_write = pydarnio.SDarnWrite(fitacf_data, "test_fitacf.fitacf") fitacf_write.write_fitacf() fitacf_read = pydarnio.SDarnRead("test_fitacf.fitacf") fitacf_read_data = fitacf_read.read_fitacf() self.dmap_compare(fitacf_read_data, fitacf_data) os.remove("test_fitacf.fitacf")
def test_DmapWrite_stream_SDarnRead_iqdat(self): """ Test DmapWrite to write to a stream and have SDarnRead the iqdat stream """ iqdat_data = copy.deepcopy(iqdat_data_sets.iqdat_data) iqdat_write = pydarnio.DmapWrite() iqdat_stream = iqdat_write.write_dmap_stream(iqdat_data) iqdat_read = pydarnio.SDarnRead(iqdat_stream, True) iqdat_read_data = iqdat_read.read_iqdat() self.dmap_compare(iqdat_read_data, iqdat_data)
def test_DmapWrite_stream_SDarnRead_map(self): """ Test DmapWrite to write to a stream and have SDarnRead the map stream """ map_data = copy.deepcopy(map_data_sets.map_data) map_write = pydarnio.DmapWrite() map_stream = map_write.write_dmap_stream(map_data) map_read = pydarnio.SDarnRead(map_stream, True) map_read_data = map_read.read_map() self.dmap_compare(map_read_data, map_data)
def test_SDarnWrite_SDarnRead_iqdat(self): """ Test SDarnWrite writing a iqdat file and SDarnRead reading the iqdat file """ iqdat_data = copy.deepcopy(iqdat_data_sets.iqdat_data) iqdat_write = pydarnio.SDarnWrite(iqdat_data, "test_iqdat.iqdat") iqdat_write.write_iqdat() iqdat_read = pydarnio.SDarnRead("test_iqdat.iqdat") iqdat_read_data = iqdat_read.read_iqdat() self.dmap_compare(iqdat_read_data, iqdat_data) os.remove("test_iqdat.iqdat")
def test_DmapWrite_stream_SDarnRead_fitacf(self): """ Test DmapWrite to write to a stream and have SDarnRead the fitacf stream """ fitacf_data = copy.deepcopy(fitacf_data_sets.fitacf_data) fitacf_write = pydarnio.DmapWrite() fitacf_stream = fitacf_write.write_dmap_stream(fitacf_data) fitacf_read = pydarnio.SDarnRead(fitacf_stream, True) fitacf_read_data = fitacf_read.read_fitacf() self.dmap_compare(fitacf_read_data, fitacf_data)
def test_DmapRead_SDarnWrite_SDarnRead_map(self): """ Test DmapRead reading a map file then writing it with SDarnWrite then reading it again with SDarnRead """ dmap = pydarnio.DmapRead(map_file) dmap_data = dmap.read_records() dmap_write = pydarnio.SDarnWrite(dmap_data) dmap_write.write_map("test_map.map") darn_read = pydarnio.SDarnRead("test_map.map") map_data = darn_read.read_map() self.dmap_compare(dmap_data, map_data) os.remove("test_map.map")
def test_open_fitacf(self): """ Tests SDarnRead constructor on opening a fitacf. It should be able to open the file, read it and convert to bytearray. Checks: - bytearray instance is created from reading in the file - bytearray is not empty """ file_path = fitacf_file dm = pydarnio.SDarnRead(file_path) self.assertIsInstance(dm.dmap_bytearr, bytearray) self.assertGreater(dm.dmap_end_bytes, 0)
def test_SDarnWrite_SDarnRead_map(self): """ Test SDarnWrite writing a map file and SDarnRead reading the map file """ map_data = copy.deepcopy(map_data_sets.map_data) map_write = pydarnio.SDarnWrite(map_data, "test_map.map") map_write.write_map() map_read = pydarnio.SDarnRead("test_map.map") map_read_data = map_read.read_map() self.dmap_compare(map_read_data, map_data) os.remove("test_map.map")
def test_rawacf2darnrawacf(self): """ Test BorealisConvert by providing both site data and array data. Test that the dmap records are the same for both (site data and array data are from the same source, should produce same dmap output.) This tests that the restructuring is working before the dmap conversion """ # self.rawacf_file already written in setUp array_converter =\ pydarnio.BorealisConvert(self.rawacf_file, "rawacf", self.rawacf_array_darn_file, 0, borealis_file_structure='array') self.assertTrue(os.path.isfile(self.rawacf_array_darn_file)) darn_reader = pydarnio.SDarnRead(self.rawacf_array_darn_file) rawacf_array_records = darn_reader.read_rawacf() os.remove(self.rawacf_array_darn_file) os.remove(self.rawacf_file) _ = pydarnio.BorealisWrite(self.rawacf_file, self.rawacf_site_data, 'rawacf', 'site') site_converter =\ pydarnio.BorealisConvert(self.rawacf_file, "rawacf", self.rawacf_site_darn_file, 0, borealis_file_structure='site') self.assertTrue(os.path.isfile(self.rawacf_site_darn_file)) darn_reader = pydarnio.SDarnRead(self.rawacf_site_darn_file) rawacf_site_records = darn_reader.read_rawacf() os.remove(self.rawacf_site_darn_file) os.remove(self.rawacf_file) for record_num, record in enumerate(array_converter.sdarn_dict): dictionaries_are_same =\ self.check_dictionaries_are_same(record, site_converter. sdarn_dict[record_num]) self.assertTrue(dictionaries_are_same) del (array_converter, site_converter, darn_reader, rawacf_site_records, rawacf_array_records)
def test_DmapWrite_SDarnRead_grid(self): """ Test DmapWrite to write a grid file then using SDarnRead to read the file """ grid_data = copy.deepcopy(grid_data_sets.grid_data) grid_write = pydarnio.DmapWrite(grid_data, "test_grid.grid") grid_write.write_dmap() grid_read = pydarnio.SDarnRead("test_grid.grid") grid_read_data = grid_read.read_grid() self.dmap_compare(grid_read_data, grid_data) os.remove("test_grid.grid")
def test_DmapWrite_SDarnRead_fitacf(self): """ Test DmapWrite to write a fitacf file then using SDarnRead to read the file """ fitacf_data = copy.deepcopy(fitacf_data_sets.fitacf_data) fitacf_write = pydarnio.DmapWrite(fitacf_data, "test_fitacf.fitacf") fitacf_write.write_dmap() fitacf_read = pydarnio.SDarnRead("test_fitacf.fitacf") fitacf_read_data = fitacf_read.read_fitacf() self.dmap_compare(fitacf_read_data, fitacf_data) os.remove("test_fitacf.fitacf")
def test_SDarnWrite_SDarnRead_grid(self): """ Test SDarnWrite writing a grid file and SDarnRead reading the grid file """ grid_data = copy.deepcopy(grid_data_sets.grid_data) grid_write = pydarnio.SDarnWrite(grid_data, "test_grid.grid") grid_write.write_grid() grid_read = pydarnio.SDarnRead("test_grid.grid") grid_read_data = grid_read.read_grid() self.dmap_compare(grid_read_data, grid_data) os.remove("test_grid.grid")
def test_DmapRead_SDarnWrite_SDarnRead_fitacf(self): """ Test DmapRead reading a fitacf file then writing it with SDarnWrite then reading it again with SDarnRead """ dmap = pydarnio.DmapRead(fitacf_file) dmap_data = dmap.read_records() dmap_write = pydarnio.SDarnWrite(dmap_data) dmap_write.write_fitacf("test_fitacf.fitacf") darn_read = pydarnio.SDarnRead("test_fitacf.fitacf") fitacf_data = darn_read.read_fitacf() self.dmap_compare(dmap_data, fitacf_data) os.remove("test_fitacf.fitacf")
def test_DmapWrite_SDarnRead_map(self): """ Test DmapWrite to write a map file then using SDarnRead to read the file """ map_data = copy.deepcopy(map_data_sets.map_data) map_write = pydarnio.DmapWrite(map_data, "test_map.map") map_write.write_dmap() map_read = pydarnio.SDarnRead("test_map.map") map_read_data = map_read.read_map() self.dmap_compare(map_read_data, map_data) os.remove("test_map.map")
def test_DmapRead_SDarnWrite_SDarnRead_iqdat(self): """ Test SDarnRead reads from a stream and SDarnWrite writes to a iqdat file """ dmap = pydarnio.DmapRead(iqdat_file) dmap_data = dmap.read_records() dmap_write = pydarnio.SDarnWrite(dmap_data) dmap_write.write_iqdat("test_iqdat.iqdat") darn_read = pydarnio.SDarnRead("test_iqdat.iqdat") iqdat_data = darn_read.read_iqdat() self.dmap_compare(dmap_data, iqdat_data) os.remove("test_iqdat.iqdat")
def test_DmapRead_SDarnWrite_SDarnRead_grid(self): """ Test DmapRead reading a grid file then writing it with SDarnWrite then reading it again with SDarnRead """ dmap = pydarnio.DmapRead(grid_file) dmap_data = dmap.read_records() dmap_write = pydarnio.SDarnWrite(dmap_data) dmap_write.write_grid("test_grid.grid") darn_read = pydarnio.SDarnRead("test_grid.grid") grid_data = darn_read.read_grid() self.dmap_compare(dmap_data, grid_data) os.remove("test_grid.grid")
def test_SDarnWrite_SDarnRead_rawacf(self): """ Test SDarnWrite writing a rawacf file and SDarnRead reading the rawacf file """ rawacf_data = copy.deepcopy(rawacf_data_sets.rawacf_data) rawacf_write = pydarnio.SDarnWrite(rawacf_data, "test_rawacf.rawacf") rawacf_write.write_rawacf() rawacf_read = pydarnio.SDarnRead("test_rawacf.rawacf") rawacf_read_data = rawacf_read.read_rawacf() self.dmap_compare(rawacf_read_data, rawacf_data) os.remove("test_rawacf.rawacf")
def test_DmapWrite_SDarnRead_iqdat(self): """ Test DmapWrite to write a iqdat file then using SDarnRead to read the file """ iqdat_data = copy.deepcopy(iqdat_data_sets.iqdat_data) iqdat_write = pydarnio.DmapWrite(iqdat_data, "test_iqdat.iqdat") iqdat_write.write_dmap() iqdat_read = pydarnio.SDarnRead("test_iqdat.iqdat") iqdat_read_data = iqdat_read.read_iqdat() self.dmap_compare(iqdat_read_data, iqdat_data) os.remove("test_iqdat.iqdat")