Пример #1
0
    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 pydarnio 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': pydarnio.DmapScalar('a', 1, 1, 's'),
                     'b': pydarnio.DmapScalar('a', 1, 1, 'i'),
                     'c': pydarnio.DmapArray('a', np.array([2.4, 2.4]),
                                           1, 'f', 1, [3]),
                     'fitacf': pydarnio.DmapScalar('a', 1, 1, 's'),
                     'rawacf': pydarnio.DmapScalar('a', 1, 1, 's'),
                     'map': pydarnio.DmapScalar('a', 1, 1, 'm')}
        try:
            pydarnio.SDarnUtilities.incorrect_types_check([dict1, dict3],
                                                        test_dict, 1)
        except pydarnio.superdarn_exceptions.SuperDARNDataFormatTypeError as err:
            self.assertEqual(err.incorrect_params, {'fitacf': 'f'})
Пример #2
0
    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 pydarnio 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': pydarnio.DmapScalar('a', 1, 1, 's'),
                     'b': pydarnio.DmapScalar('a', 1, 1, 'i'),
                     'c': pydarnio.DmapArray('a', np.array([2.4, 2.4]), 1,
                                           'f', 1, [3]),
                     'fitacf': pydarnio.DmapScalar('a', 1, 1, 'f'),
                     'rawacf': pydarnio.DmapScalar('a', 1, 1, 's'),
                     'map': pydarnio.DmapScalar('a', 1, 1, 'm')}

        pydarnio.SDarnUtilities.incorrect_types_check([dict1, dict3],
                                                    test_dict, 1)
Пример #3
0
    def test_character_array(self):
        """
        Test DmapWrite writing character arrays.

        Behaviour: Raised DmapCharError
        """
        array = pydarnio.DmapArray('channel', np.array(['d', 'c', 'm']),
                                 1, 'c', 1, [3])
        dmap_write = pydarnio.DmapWrite([{'channel': array}])
        with self.assertRaises(pydarnio.dmap_exceptions.DmapCharError):
            dmap_write.dmap_array_to_bytes(array)
Пример #4
0
 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 = pydarnio.DmapArray('channel', np.array([1, 0, 1],
                                                    dtype=np.int8), 1, 'c',
                                1, [3])
     dmap_write = pydarnio.DmapWrite([{'channel': array}])
     dmap_array_bytes = dmap_write.dmap_array_to_bytes(array)
     dmap = pydarnio.DmapRead(dmap_array_bytes, True)
     dmap_array = dmap.read_array(len(dmap_array_bytes))
     self.compare_dmap_array(array, dmap_array)
Пример #5
0
    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 = pydarnio.DmapArray('xcf', np.array(['dog', 'cat', 'mouse']),
                                 9, 's', 1, [3])
        dmap_write = pydarnio.DmapWrite([{'xcf': array}])
        with self.assertRaises(pydarnio.dmap_exceptions.DmapDataError):
            dmap_write.dmap_array_to_bytes(array)
Пример #6
0
    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 = pydarnio.DmapArray('xcf',
                                   np.array([4.3, 3.5, 2.3], dtype=np.float32),
                                   4, 'f', 1, [3])
        dmap_write = pydarnio.DmapWrite([{'xcf': array}])
        dmap_array_bytes = dmap_write.dmap_array_to_bytes(array)
        dmap = pydarnio.DmapRead(dmap_array_bytes, True)
        dmap_array = dmap.read_array(len(dmap_array_bytes))
        self.compare_dmap_array(array, dmap_array)
Пример #7
0
    def test_extra_grid_field(self):
        """
        Tests write_grid method - writes a grid structure file for the
        given data

        Expected behaviour
        ------------------
        Raises SuperDARNExtraFieldError because the grid data
        has an extra field dummy
        """
        grid_extra_field = copy.deepcopy(grid_data_sets.grid_data)
        grid_extra_field[0]['dummy'] = \
            pydarnio.DmapArray('dummy', np.array([1, 2]), chr(1), 'c', 1, [2])
        dmap = pydarnio.SDarnWrite(grid_extra_field)

        try:
            dmap.write_grid("test_grid.grid")
        except pydarnio.superdarn_exceptions.SuperDARNExtraFieldError as err:
            self.assertEqual(err.fields, {'dummy'})
            self.assertEqual(err.record_number, 0)
Пример #8
0
    def test_extra_fitacf_field(self):
        """
        Tests write_fitacf method - writes a fitacf structure file for the
        given data

        Expected behaviour
        ------------------
        Raises SuperDARNExtraFieldError because the fitacf data
        has an extra field dummy
        """
        fitacf_extra_field = copy.deepcopy(fitacf_data_sets.fitacf_data)
        fitacf_extra_field[1]['dummy'] = pydarnio.DmapArray('dummy',
                                                          np.array([1, 2]),
                                                          chr(1), 'c', 1, [2])
        dmap = pydarnio.SDarnWrite(fitacf_extra_field)

        try:
            dmap.write_fitacf("test_fitacf.fitacf")
        except pydarnio.superdarn_exceptions.SuperDARNExtraFieldError as err:
            self.assertEqual(err.fields, {'dummy'})
            self.assertEqual(err.record_number, 1)
Пример #9
0
    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', pydarnio.DmapScalar('stid', 1, 3, 'i')),
                          ('channel', pydarnio.DmapScalar('channel', 0, 3, 'i')),
                          ('ptab', pydarnio.DmapArray('ptab',
                                                    np.array([0, 9, 12, 20, 22,
                                                              26, 27],
                                                             dtype=np.int64),
                                                    10, 'q', 1, [7]))]),
             OrderedDict([('bmnum', pydarnio.DmapScalar('bmnum', 15, 2, 'h')),
                          ('combf', pydarnio.DmapScalar('combf',
                                                      "$Id: twofsound", 9,
                                                      's')),
                          ('pwr0', pydarnio.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',
                           pydarnio.DmapScalar('radar.revision.major',
                                             np.int8(1), 1, 'c')),
                          ('radar.revision.minor',
                           pydarnio.DmapScalar('radar.revision.minor',
                                             np.int8(18), 1, 'c')),
                          ('float test',
                           pydarnio.DmapScalar('float test',
                                             float(3.5), 4, 'f')),
                          ('float2 test',
                           pydarnio.DmapScalar('float2 test', 3.65, 4, 'f')),
                          ('channel', pydarnio.DmapScalar('channel', 'a', 9,
                                                        's')),
                          ('double test',
                           pydarnio.DmapArray('double test',
                                            np.array([[2.305015, 2.0251],
                                                     [16548548, 78687686]],
                                                     dtype=np.float64), 8,
                                            'd', 2, [2, 2]))]),
             OrderedDict([('time.us', pydarnio.DmapScalar('time.us', 508473,
                                                        3, 'i')),
                          ('negative int',
                           pydarnio.DmapScalar('negative int', -42, 3, 'i')),
                          ('long int',
                           pydarnio.DmapScalar('long int',
                                             np.int64(215610516132151613),
                                             10, 'q')),
                          ('unsigned char', pydarnio.DmapScalar('unsigned char',
                                                              np.uint8(3),
                                                              16, 'B')),
                          ('unsigned short',
                           pydarnio.DmapScalar('unsigned short', np.uint16(45),
                                             17, 'H')),
                          ('unsigned int',
                           pydarnio.DmapScalar('unsigned int', np.uint32(100),
                                             18, 'I')),
                          ('unsigned long',
                           pydarnio.DmapScalar('unsigned long',
                                             np.uint64(1250000000000),
                                             19, 'Q')),
                          ('list test',
                           pydarnio.DmapArray('list test',
                                            np.array([1, 2, 34, 45],
                                                     dtype=np.int64),
                                            10, 'q', 1, [4]))])]