Beispiel #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'})
Beispiel #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)
Beispiel #3
0
 def test_DmapWrite_DmapRead_int8_scalar(self):
     """
     Test integration DmapWrite and DmapRead to write char array.
     """
     scalar = pydarnio.DmapScalar('channel', 4, 1, 'c')
     dmap_write = pydarnio.DmapWrite([{'channel': scalar}])
     dmap_scalar_bytes = dmap_write.dmap_scalar_to_bytes(scalar)
     dmap = pydarnio.DmapRead(dmap_scalar_bytes, True)
     dmap_scalar = dmap.read_scalar()
     self.assertEqual(scalar, dmap_scalar)
Beispiel #4
0
    def test_scalar(self):
        """
        Test DmapWrite writing a character scalar type.

        Behaviour: Raised DmapCharError
        Dmap cannot write characters as they are treated as strings and not
        int8 - RST standard for char types.
        """
        scalar = pydarnio.DmapScalar('channel', 'c', 1, 'c')
        dmap_write = pydarnio.DmapWrite([{'channel': scalar}])
        with self.assertRaises(pydarnio.dmap_exceptions.DmapCharError):
            dmap_write.dmap_scalar_to_bytes(scalar)
Beispiel #5
0
    def test_DmapWrite_DmapRead_scalar(self):
        """
        This test integrates DmapWrite and DmapRead for
        writing a single scalar and then reading it in.

        Behaviour: No change to the scalar being written then read in.
        """
        scalar = pydarnio.DmapScalar('stid', 5, 3, 'i')
        dmap_write = pydarnio.DmapWrite([{'stid': scalar}])
        dmap_scalar_bytes = dmap_write.dmap_scalar_to_bytes(scalar)
        dmap = pydarnio.DmapRead(dmap_scalar_bytes, True)
        dmap = dmap.read_scalar()
        self.assertEqual(scalar, dmap)
Beispiel #6
0
    def test_extra_field_rawacf(self):
        """
        Tests write_rawacf method - writes a rawacf structure file for the
        given data

        Expected behaviour
        ------------------
        Raises SuperDARNExtraFieldError because the rawacf data
        has an extra field dummy
        """
        rawacf_extra_field = copy.deepcopy(rawacf_data_sets.rawacf_data)
        rawacf_extra_field[1]['dummy'] = pydarnio.DmapScalar('dummy', 'nothing',
                                                           chr(1), 's')
        dmap = pydarnio.SDarnWrite(rawacf_extra_field)

        try:
            dmap.write_rawacf("test_rawacf.rawacf")
        except pydarnio.superdarn_exceptions.SuperDARNExtraFieldError as err:
            self.assertEqual(err.fields, {'dummy'})
            self.assertEqual(err.record_number, 1)
Beispiel #7
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]))])]