예제 #1
0
 def test_DmapWrite_DmapRead_dict2dmap_dict2dmap(self):
     """
     Test Convert dictionary to dmap from dict2dmap then
     write with DmapWrite to be read in with DmapRead and
     converted back to a dictionary with dmap2dict.
     """
     dmap_dict = [{
         'stid':
         56,
         'channel':
         0,
         'software':
         'RST',
         'xcf':
         np.array([2.5, 3.456, 34.56, -4.5], dtype=np.float32),
         'gflg':
         np.array([1, 0, 4, 2], np.int8)
     }]
     dmap_records = pydarnio.dict2dmap(dmap_dict)
     dmap_write = pydarnio.DmapWrite(dmap_records, 'test_dmap.dmap')
     dmap_write.write_dmap()
     dmap_read = pydarnio.DmapRead("test_dmap.dmap")
     records = dmap_read.read_records()
     self.dmap_compare(dmap_dict, records)
     dmap_dict2 = pydarnio.dict2dmap(records)
     self.dmap_compare(dmap_records, dmap_dict2)
예제 #2
0
 def test_dict2dmap_DmapWrite_DmapRead_stream_dmap2dict(self):
     """
     Test convert dict to dmap with dict2dmap then DmapWrite to write
     to a stream to be read in by
     DmapRead and converted back to a dictionary
     with dict2dmap
     """
     dmap_dict = [{
         'stid':
         56,
         'channel':
         0,
         'software':
         'RST',
         'xcf':
         np.array([2.5, 3.456, 34.56, -4.5], dtype=np.float32),
         'gflg':
         np.array([1, 0, 4, 2], np.int8)
     }]
     dmap_records = pydarnio.dict2dmap(dmap_dict)
     dmap_write = pydarnio.DmapWrite(dmap_records)
     dmap_stream = dmap_write.write_dmap_stream()
     dmap_read = pydarnio.DmapRead(dmap_stream, True)
     records = dmap_read.read_records()
     self.dmap_compare(dmap_dict, records)
     dmap_dict2 = pydarnio.dict2dmap(records)
     self.dmap_compare(dmap_records, dmap_dict2)
예제 #3
0
 def test_DmapWrite_DmapRead_dmap2dict(self):
     """
     Test DmapWrite writing a dmap data set to be read in by DmapRead
     and convert to a dictionary by dmap2dict and compared.
     """
     dmap_dict = [{
         'RST.version': '4.1',
         'stid': 3,
         'FAC.vel': np.array([2.5, 3.5, 4.0], dtype=np.float32)
     }, {
         'RST.version': '4.1',
         'stid': 3,
         'FAC.vel': np.array([1, 0, 1], dtype=np.int8)
     }, {
         'RST.version': '4.1',
         'stid': 3,
         'FAC.vel': np.array([5.7, 2.34, -0.2], dtype=np.float32)
     }]
     dmap_data = copy.deepcopy(dmap_data_sets.dmap_data)
     dmap_write = pydarnio.DmapWrite(dmap_data)
     dmap_stream = dmap_write.write_dmap_stream()
     dmap_read = pydarnio.DmapRead(dmap_stream, True)
     dmap_records = dmap_read.read_records()
     dmap_records = dmap_read.get_dmap_records
     self.dmap_compare(dmap_records, dmap_data)
     dmap_dict2 = pydarnio.dmap2dict(dmap_records)
     self.dict_compare(dmap_dict, dmap_dict2)
예제 #4
0
 def test_DmapWrite_stream_DmapRead_dmap(self):
     """
     Test DmapWrite write data to a stream, DmapRead read the stream.
     """
     rawacf_data = copy.deepcopy(rawacf_data_sets.rawacf_data)
     rawacf_write = pydarnio.DmapWrite()
     rawacf_stream = rawacf_write.write_dmap_stream(rawacf_data)
     rawacf_read = pydarnio.DmapRead(rawacf_stream, True)
     rawacf_read_data = rawacf_read.read_records()
     self.dmap_compare(rawacf_read_data, rawacf_data)
예제 #5
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)
예제 #6
0
    def test_DmapRead_DmapWrite_dmap_file(self):
        """
        Test integration between DmapRead reading a file and DmapWrite
        writing the file then reading it again to ensure the data didn't
        change.
        """
        dmap = pydarnio.DmapRead(rawacf_file)
        dmap_data = dmap.read_records()
        writer = pydarnio.DmapWrite(dmap_data, "test_rawacf.rawacf")
        writer.write_dmap()
        self.assertTrue(os.path.isfile("test_rawacf.rawacf"))
        os.remove("test_rawacf.rawacf")

        dmap_write = pydarnio.DmapWrite(dmap_data)
        dmap_write.write_dmap("test_rawacf.rawacf")

        dmap_read = pydarnio.DmapRead("test_rawacf.rawacf")
        _ = dmap_read.read_records()
        _ = dmap_read.get_dmap_records
        os.remove("test_rawacf.rawacf")
예제 #7
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)
예제 #8
0
 def test_DmapWrite_DmapRead_dmap_file(self):
     """
     Test integration between DmapWrite and DmapRead from
     a rawacf data written as file then read in and compared against.
     """
     rawacf_data = copy.deepcopy(rawacf_data_sets.rawacf_data)
     rawacf_write = pydarnio.DmapWrite(rawacf_data, "test_rawacf.rawacf")
     rawacf_write.write_dmap()
     rawacf_read = pydarnio.DmapRead("test_rawacf.rawacf")
     rawacf_read_data = rawacf_read.read_records()
     self.dmap_compare(rawacf_read_data, rawacf_data)
예제 #9
0
    def test_empty_data_check(self):
        """
        Testing if no data is given to DmapWrite

        Expected behaviour
        ------------------
        Raise DmapDataError - no data is given to write
        """
        with self.assertRaises(pydarnio.dmap_exceptions.DmapDataError):
            dmap_write = pydarnio.DmapWrite(filename="test.test")
            dmap_write.write_dmap()
예제 #10
0
    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)
예제 #11
0
    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)
예제 #12
0
    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)
예제 #13
0
    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)
예제 #14
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)
예제 #15
0
    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")
예제 #16
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)
예제 #17
0
    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")
예제 #18
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)
예제 #19
0
    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")
예제 #20
0
    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")
예제 #21
0
    def test_incorrect_filename_input_using_write_methods(self):
        """
        Testing if a filename is not given to DmapWrite

        Expected behaviour
        ------------------
        Raises FilenameRequiredError - no filename was given to write and
        constructor
        """
        rawacf_data = copy.deepcopy(dmap_data_sets.dmap_data)
        dmap_data = pydarnio.DmapWrite(rawacf_data)
        with self.assertRaises(pydarnio.dmap_exceptions.FilenameRequiredError):
            dmap_data.write_dmap()
예제 #22
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)
예제 #23
0
 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)
예제 #24
0
 def test_DmapRead_DmapWrite_stream_dmap(self):
     """
     Test DmapRead and DmapWrite to read in a stream and write to a stream
     to be read in again and compared.
     """
     with bz2.open(rawacf_stream) as fp:
         dmap_stream = fp.read()
     dmap = pydarnio.DmapRead(dmap_stream, True)
     stream_data = dmap.read_records()
     dmap_write = pydarnio.DmapWrite()
     dmap_write_stream = dmap_write.write_dmap_stream(stream_data)
     dmap_read = pydarnio.DmapRead(dmap_write_stream, True)
     dmap_read_data = dmap_read.read_records()
     self.dmap_compare(stream_data, dmap_read_data)
예제 #25
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)
예제 #26
0
    def test_DmapWrite_incorrect_SDarnRead_rawacf_from_dict(self):
        """
        Test write an incorrect data type from a dict converting from dict2dmap
        with DmapWrite then SDarnRead reads the file

        Behaviour: Raises SuperDARNDataFormatTypeError
        """
        rawacf_dict_data = copy.deepcopy(rawacf_dict_sets.rawacf_dict_data)
        rawacf_dict_data[0]['stid'] = np.int8(rawacf_dict_data[0]['stid'])
        dmap_rawacf = pydarnio.dict2dmap(rawacf_dict_data)
        dmap_write = pydarnio.DmapWrite(dmap_rawacf)
        dmap_write.write_dmap("test_incorrect_rawacf.rawacf")

        darn_read = pydarnio.SDarnRead("test_incorrect_rawacf.rawacf")
        with self.assertRaises(pydarnio.superdarn_exceptions.
                               SuperDARNDataFormatTypeError):
            darn_read.read_rawacf()
예제 #27
0
    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)
예제 #28
0
    def test_writing_dmap(self):
        """
        Testing write_dmap method

        Expected behaviour
        ------------------
        File is produced
        """
        dmap_data = copy.deepcopy(dmap_data_sets.dmap_data)
        dmap = pydarnio.DmapWrite(dmap_data)

        # Integration testing will test the integrity of the
        # writing procedure.
        dmap.write_dmap("test_dmap.dmap")
        self.assertTrue(os.path.isfile("test_dmap.dmap"))

        os.remove("test_dmap.dmap")
예제 #29
0
    def test_DmapRead_stream_DmapWrite_file(self):
        """
        Test DmapRead a stream in and DmapWrite to a file. DmapRead is
        used to read the file to compare values.
        """
        with bz2.open(rawacf_stream) as fp:
            dmap_stream = fp.read()
        dmap = pydarnio.DmapRead(dmap_stream, True)
        stream_data = dmap.read_records()
        dmap_stream_data = dmap.get_dmap_records
        dmap_write = pydarnio.DmapWrite(stream_data)
        dmap_write.write_dmap("test_rawacf.rawacf")
        self.assertTrue(os.path.isfile("test_rawacf.rawacf"))

        dmap = pydarnio.DmapRead("test_rawacf.rawacf")
        _ = dmap.read_records()
        dmap_read_data = dmap.get_dmap_records
        self.dmap_compare(dmap_stream_data, dmap_read_data)
예제 #30
0
    def test_DmapWrite_extra_SDarnRead_map(self):
        """
        Test DmapWrite writes a map file with an extra field and SDarnRead
        reads the file

        Behaviour: Raised SuperDARNExtraFieldError
        """
        map_extra_field = copy.deepcopy(map_data_sets.map_data)
        map_extra_field[0].update({'dummy': 'dummy'})
        map_extra_field[0].move_to_end('dummy', last=False)
        dmap_write = pydarnio.DmapWrite(map_extra_field, )
        dmap_write.write_dmap("test_extra_map.map")

        darn_read = pydarnio.SDarnRead("test_extra_map.map")
        try:
            darn_read.read_map()
        except pydarnio.superdarn_exceptions.SuperDARNExtraFieldError as err:
            self.assertEqual(err.fields, {'dummy'})
            self.assertEqual(err.record_number, 0)
        os.remove("test_extra_map.map")