def test_incorrect_types_check_fail(self): """ Test incorrect_types_check - this method checks if the field data format type is not correct to specified SuperDARN field type. Note ---- This method only works on pydarn DMAP record data structure Expected Behaviour ------------------ Raises SuperDARNDataFormatTypeError - because the field format types should not be the same. """ dict1 = {'a': 's', 'b': 'i', 'c': 'f'} dict3 = {'fitacf': 'f', 'rawacf': 's', 'map': 'm'} test_dict = { 'a': pydarn.DmapScalar('a', 1, 1, 's'), 'b': pydarn.DmapScalar('a', 1, 1, 'i'), 'c': pydarn.DmapArray('a', np.array([2.4, 2.4]), 1, 'f', 1, [3]), 'fitacf': pydarn.DmapScalar('a', 1, 1, 's'), 'rawacf': pydarn.DmapScalar('a', 1, 1, 's'), 'map': pydarn.DmapScalar('a', 1, 1, 'm') } try: pydarn.SDarnUtilities.incorrect_types_check([dict1, dict3], test_dict, 1) except pydarn.superdarn_exceptions.SuperDARNDataFormatTypeError as err: self.assertEqual(err.incorrect_params, {'fitacf': 'f'})
def test_incorrect_types_check_pass(self): """ Test incorrect_types_check - this method checks if the field data format type is not correct to specified SuperDARN field type. Note ---- This method only works on pydarn DMAP record data structure Expected Behaviour ------------------ Nothing - should not return or raise anything if the fields are the correct data format type """ dict1 = {'a': 's', 'b': 'i', 'c': 'f'} dict3 = {'fitacf': 'f', 'rawacf': 's', 'map': 'm'} test_dict = { 'a': pydarn.DmapScalar('a', 1, 1, 's'), 'b': pydarn.DmapScalar('a', 1, 1, 'i'), 'c': pydarn.DmapArray('a', np.array([2.4, 2.4]), 1, 'f', 1, [3]), 'fitacf': pydarn.DmapScalar('a', 1, 1, 'f'), 'rawacf': pydarn.DmapScalar('a', 1, 1, 's'), 'map': pydarn.DmapScalar('a', 1, 1, 'm') } pydarn.SDarnUtilities.incorrect_types_check([dict1, dict3], test_dict, 1)
def test_character_array(self): """ Test DmapWrite writing character arrays. Behaviour: Raised DmapCharError """ array = pydarn.DmapArray('channel', np.array(['d', 'c', 'm']), 1, 'c', 1, [3]) dmap_write = pydarn.DmapWrite([{'channel': array}]) with self.assertRaises(pydarn.dmap_exceptions.DmapCharError): dmap_write.dmap_array_to_bytes(array)
def test_write_read_int8_array(self): """ Test integrates DmapWrite and DmapRead to write and read an int8 data type which is the char type for DMAP format. """ array = pydarn.DmapArray('channel', np.array([1, 0, 1], dtype=np.int8), 1, 'c', 1, [3]) dmap_write = pydarn.DmapWrite([{'channel': array}]) dmap_array_bytes = dmap_write.dmap_array_to_bytes(array) dmap = pydarn.DmapRead(dmap_array_bytes, True) dmap_array = dmap.read_array(len(dmap_array_bytes)) self.compare_dmap_array(array, dmap_array)
def test_String_array(self): """ Test DmapWrite writing string arrays Behaviour: Raised DmapDataError DmapWrite doesn't support writing string arrays because DmapRead does not support string arrays. """ array = pydarn.DmapArray('xcf', np.array(['dog', 'cat', 'mouse']), 9, 's', 1, [3]) dmap_write = pydarn.DmapWrite([{'xcf': array}]) with self.assertRaises(pydarn.dmap_exceptions.DmapDataError): dmap_write.dmap_array_to_bytes(array)
def test_DmapWrite_DmapRead_array(self): """ This test integrates DmapWrite and DmapRead for writing and reading an array. Behaviour: No change to the array """ array = pydarn.DmapArray('xcf', np.array([4.3, 3.5, 2.3], dtype=np.float32), 4, 'f', 1, [3]) dmap_write = pydarn.DmapWrite([{'xcf': array}]) dmap_array_bytes = dmap_write.dmap_array_to_bytes(array) dmap = pydarn.DmapRead(dmap_array_bytes, True) dmap_array = dmap.read_array(len(dmap_array_bytes)) self.compare_dmap_array(array, dmap_array)
def test_extra_map_field(self): """ Tests write_map method - writes a map structure file for the given data Expected behaviour ------------------ Raises SuperDARNExtraFieldError because the map data has an extra field dummy """ map_extra_field = copy.deepcopy(map_data_sets.map_data) map_extra_field[1]['dummy'] = \ pydarn.DmapArray('dummy', np.array([1, 2]), chr(1), 'c', 1, [2]) dmap = pydarn.SDarnWrite(map_extra_field) try: dmap.write_map("test_map.map") except pydarn.superdarn_exceptions.SuperDARNExtraFieldError as err: self.assertEqual(err.fields, {'dummy'}) self.assertEqual(err.record_number, 1)
def setUp(self): """ Creates the testing data Attributes ---------- dmap_list : List[dict] List of dictionaries containing fields and values dmap_records : List[dict] List of ordered dictionaries containing dmap data structure DmapScalar and DmapArray """ self.dmap_list = [{'stid': 1, 'channel': 0, 'ptab': np.array([0, 9, 12, 20, 22, 26, 27], dtype=np.int64)}, {'bmnum': np.int16(15), 'combf': "$Id: twofsound", 'pwr0': np.array([58.081821, 52.241421, 32.936508, 35.562561, 35.344330, 31.501854, 25.313326, 13.731517, 3.482957, -5.032664, -9.496454, 3.254651], dtype=np.float32)}, {'radar.revision.major': np.int8(1), 'radar.revision.minor': np.int8(18), 'float test': float(3.5), 'float2 test': 3.65, 'channel': 'a', 'double test': np.array([[2.305015, 2.0251], [16548548, 78687686]], dtype=np.float64)}, {'time.us': 508473, 'negative int': -42, 'long int': np.int64(215610516132151613), 'unsigned char': np.uint8(3), 'unsigned short': np.uint16(45), 'unsigned int': np.uint32(100), 'unsigned long': np.uint64(1250000000000), 'list test': [np.int64(1), np.int64(2), np.int64(34), np.int64(45)]}] self.dmap_records = \ [OrderedDict([('stid', pydarn.DmapScalar('stid', 1, 3, 'i')), ('channel', pydarn.DmapScalar('channel', 0, 3, 'i')), ('ptab', pydarn.DmapArray('ptab', np.array([0, 9, 12, 20, 22, 26, 27], dtype=np.int64), 10, 'q', 1, [7]))]), OrderedDict([('bmnum', pydarn.DmapScalar('bmnum', 15, 2, 'h')), ('combf', pydarn.DmapScalar('combf', "$Id: twofsound", 9, 's')), ('pwr0', pydarn.DmapArray('pwr0', np.array([58.081821, 52.241421, 32.936508, 35.562561, 35.344330, 31.501854, 25.313326, 13.731517, 3.482957, -5.032664, -9.496454, 3.254651], dtype=np.float32), 4, 'f', 1, [12]))]), OrderedDict([('radar.revision.major', pydarn.DmapScalar('radar.revision.major', np.int8(1), 1, 'c')), ('radar.revision.minor', pydarn.DmapScalar('radar.revision.minor', np.int8(18), 1, 'c')), ('float test', pydarn.DmapScalar('float test', float(3.5), 4, 'f')), ('float2 test', pydarn.DmapScalar('float2 test', 3.65, 4, 'f')), ('channel', pydarn.DmapScalar('channel', 'a', 9, 's')), ('double test', pydarn.DmapArray('double test', np.array([[2.305015, 2.0251], [16548548, 78687686]], dtype=np.float64), 8, 'd', 2, [2, 2]))]), OrderedDict([('time.us', pydarn.DmapScalar('time.us', 508473, 3, 'i')), ('negative int', pydarn.DmapScalar('negative int', -42, 3, 'i')), ('long int', pydarn.DmapScalar('long int', np.int64(215610516132151613), 10, 'q')), ('unsigned char', pydarn.DmapScalar('unsigned char', np.uint8(3), 16, 'B')), ('unsigned short', pydarn.DmapScalar('unsigned short', np.uint16(45), 17, 'H')), ('unsigned int', pydarn.DmapScalar('unsigned int', np.uint32(100), 18, 'I')), ('unsigned long', pydarn.DmapScalar('unsigned long', np.uint64(1250000000000), 19, 'Q')), ('list test', pydarn.DmapArray('list test', np.array([1, 2, 34, 45], dtype=np.int64), 10, 'q', 1, [4]))])]