Exemple #1
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 = pydarn.DmapWrite()
     rawacf_stream = rawacf_write.write_dmap_stream(rawacf_data)
     rawacf_read = pydarn.DmapRead(rawacf_stream, True)
     rawacf_read_data = rawacf_read.read_records()
     self.dmap_compare(rawacf_read_data, rawacf_data)
Exemple #2
0
 def test_DmapWrite_DmapRead_int8_scalar(self):
     """
     Test integration DmapWrite and DmapRead to write char array.
     """
     scalar = pydarn.DmapScalar('channel', 4, 1, 'c')
     dmap_write = pydarn.DmapWrite([{'channel': scalar}])
     dmap_scalar_bytes = dmap_write.dmap_scalar_to_bytes(scalar)
     dmap = pydarn.DmapRead(dmap_scalar_bytes, True)
     dmap_scalar = dmap.read_scalar()
     self.assertEqual(scalar, dmap_scalar)
Exemple #3
0
    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)
Exemple #4
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(pydarn.dmap_exceptions.DmapDataError):
            dmap_write = pydarn.DmapWrite(filename="test.test")
            dmap_write.write_dmap()
Exemple #5
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 = pydarn.DmapWrite(rawacf_data, "test_rawacf.rawacf")
     rawacf_write.write_dmap()
     rawacf_read = pydarn.DmapRead("test_rawacf.rawacf")
     rawacf_read_data = rawacf_read.read_records()
     self.dmap_compare(rawacf_read_data, rawacf_data)
Exemple #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 = pydarn.DmapRead(rawacf_file)
        dmap_data = dmap.read_records()
        writer = pydarn.DmapWrite(dmap_data, "test_rawacf.rawacf")
        writer.write_dmap()
        self.assertTrue(os.path.isfile("test_rawacf.rawacf"))
        os.remove("test_rawacf.rawacf")

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

        dmap_read = pydarn.DmapRead("test_rawacf.rawacf")
        _ = dmap_read.read_records()
        _ = dmap_read.get_dmap_records
        os.remove("test_rawacf.rawacf")
Exemple #7
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 = pydarn.DmapWrite()
        grid_stream = grid_write.write_dmap_stream(grid_data)

        grid_read = pydarn.SDarnRead(grid_stream, True)
        grid_read_data = grid_read.read_grid()
        self.dmap_compare(grid_read_data, grid_data)
Exemple #8
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 = pydarn.DmapWrite()
        iqdat_stream = iqdat_write.write_dmap_stream(iqdat_data)

        iqdat_read = pydarn.SDarnRead(iqdat_stream, True)
        iqdat_read_data = iqdat_read.read_iqdat()
        self.dmap_compare(iqdat_read_data, iqdat_data)
Exemple #9
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 = pydarn.DmapWrite()
        fitacf_stream = fitacf_write.write_dmap_stream(fitacf_data)

        fitacf_read = pydarn.SDarnRead(fitacf_stream, True)
        fitacf_read_data = fitacf_read.read_fitacf()
        self.dmap_compare(fitacf_read_data, fitacf_data)
Exemple #10
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 = 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)
Exemple #11
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 = pydarn.DmapWrite()
        map_stream = map_write.write_dmap_stream(map_data)

        map_read = pydarn.SDarnRead(map_stream, True)
        map_read_data = map_read.read_map()
        self.dmap_compare(map_read_data, map_data)
Exemple #12
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 = pydarn.DmapScalar('channel', 'c', 1, 'c')
        dmap_write = pydarn.DmapWrite([{'channel': scalar}])
        with self.assertRaises(pydarn.dmap_exceptions.DmapCharError):
            dmap_write.dmap_scalar_to_bytes(scalar)
Exemple #13
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 = pydarn.DmapWrite(rawacf_data)
        with self.assertRaises(pydarn.dmap_exceptions.FilenameRequiredError):
            dmap_data.write_dmap()
Exemple #14
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 = pydarn.DmapWrite(grid_data, "test_grid.grid")
        grid_write.write_dmap()

        grid_read = pydarn.SDarnRead("test_grid.grid")
        grid_read_data = grid_read.read_grid()
        self.dmap_compare(grid_read_data, grid_data)
        os.remove("test_grid.grid")
Exemple #15
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 = pydarn.DmapWrite(map_data, "test_map.map")
        map_write.write_dmap()

        map_read = pydarn.SDarnRead("test_map.map")
        map_read_data = map_read.read_map()
        self.dmap_compare(map_read_data, map_data)
        os.remove("test_map.map")
Exemple #16
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 = pydarn.DmapWrite(iqdat_data, "test_iqdat.iqdat")
        iqdat_write.write_dmap()

        iqdat_read = pydarn.SDarnRead("test_iqdat.iqdat")
        iqdat_read_data = iqdat_read.read_iqdat()
        self.dmap_compare(iqdat_read_data, iqdat_data)
        os.remove("test_iqdat.iqdat")
Exemple #17
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 = pydarn.DmapWrite(fitacf_data, "test_fitacf.fitacf")
        fitacf_write.write_dmap()

        fitacf_read = pydarn.SDarnRead("test_fitacf.fitacf")
        fitacf_read_data = fitacf_read.read_fitacf()
        self.dmap_compare(fitacf_read_data, fitacf_data)
        os.remove("test_fitacf.fitacf")
Exemple #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 = 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)
Exemple #19
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 = pydarn.DmapScalar('stid', 5, 3, 'i')
        dmap_write = pydarn.DmapWrite([{'stid': scalar}])
        dmap_scalar_bytes = dmap_write.dmap_scalar_to_bytes(scalar)
        dmap = pydarn.DmapRead(dmap_scalar_bytes, True)
        dmap = dmap.read_scalar()
        self.assertEqual(scalar, dmap)
Exemple #20
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 = pydarn.DmapRead(dmap_stream, True)
     stream_data = dmap.read_records()
     dmap_write = pydarn.DmapWrite()
     dmap_write_stream = dmap_write.write_dmap_stream(stream_data)
     dmap_read = pydarn.DmapRead(dmap_write_stream, True)
     dmap_read_data = dmap_read.read_records()
     self.dmap_compare(stream_data, dmap_read_data)
Exemple #21
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 = pydarn.SDarnRead(dmap_stream, True)
     dmap_stream_data = dmap.read_map()
     dmap_write = pydarn.DmapWrite()
     dmap_write_stream = dmap_write.write_dmap_stream(dmap_stream_data)
     dmap_read = pydarn.SDarnRead(dmap_write_stream, True)
     dmap_read_data = dmap_read.read_map()
     self.dmap_compare(dmap_stream_data, dmap_read_data)
Exemple #22
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 = 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)
Exemple #23
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 = pydarn.SDarnRead(dmap_stream, True)
        stream_data = dmap.read_fitacf()
        dmap_stream_data = dmap.get_dmap_records
        dmap_write = pydarn.DmapWrite()
        dmap_write_stream = dmap_write.write_dmap_stream(stream_data)
        dmap_read = pydarn.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)
Exemple #24
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 = pydarn.dict2dmap(rawacf_dict_data)
        dmap_write = pydarn.DmapWrite(dmap_rawacf)
        dmap_write.write_dmap("test_incorrect_rawacf.rawacf")

        darn_read = pydarn.SDarnRead("test_incorrect_rawacf.rawacf")
        with self.assertRaises(pydarn.superdarn_exceptions.
                               SuperDARNDataFormatTypeError):
            darn_read.read_rawacf()
Exemple #25
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 = pydarn.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")
Exemple #26
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 = pydarn.DmapRead(dmap_stream, True)
        stream_data = dmap.read_records()
        dmap_stream_data = dmap.get_dmap_records
        dmap_write = pydarn.DmapWrite(stream_data)
        dmap_write.write_dmap("test_rawacf.rawacf")
        self.assertTrue(os.path.isfile("test_rawacf.rawacf"))

        dmap = pydarn.DmapRead("test_rawacf.rawacf")
        _ = dmap.read_records()
        dmap_read_data = dmap.get_dmap_records
        self.dmap_compare(dmap_stream_data, dmap_read_data)
Exemple #27
0
    def test_DmapWrite_missing_SDarnRead_map(self):
        """
        Test DmapWrite writes a fitacf file missing the field nave in record 2
        and SDarnRead reads the file

        Behaviour: Raise SuperDARNFieldMissingError
        """
        map_missing_field = copy.deepcopy(map_data_sets.map_data)
        del map_missing_field[0]['stid']
        dmap_write = pydarn.DmapWrite(map_missing_field)
        dmap_write.write_dmap("test_missing_map.map")

        darn_read = pydarn.SDarnRead("test_missing_map.map")
        try:
            darn_read.read_map()
        except pydarn.superdarn_exceptions.SuperDARNFieldMissingError as err:
            self.assertEqual(err.fields, {'stid'})
            self.assertEqual(err.record_number, 0)

        os.remove("test_missing_map.map")
Exemple #28
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 = pydarn.DmapWrite(map_extra_field, )
        dmap_write.write_dmap("test_extra_map.map")

        darn_read = pydarn.SDarnRead("test_extra_map.map")
        try:
            darn_read.read_map()
        except pydarn.superdarn_exceptions.SuperDARNExtraFieldError as err:
            self.assertEqual(err.fields, {'dummy'})
            self.assertEqual(err.record_number, 0)
        os.remove("test_extra_map.map")
Exemple #29
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 = pydarn.dict2dmap(dmap_dict)
     dmap_write = pydarn.DmapWrite(dmap_records, 'test_dmap.dmap')
     dmap_write.write_dmap()
     dmap_read = pydarn.DmapRead("test_dmap.dmap")
     records = dmap_read.read_records()
     self.dmap_compare(dmap_dict, records)
     dmap_dict2 = pydarn.dict2dmap(records)
     self.dmap_compare(dmap_records, dmap_dict2)
Exemple #30
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 = pydarn.dict2dmap(dmap_dict)
     dmap_write = pydarn.DmapWrite(dmap_records)
     dmap_stream = dmap_write.write_dmap_stream()
     dmap_read = pydarn.DmapRead(dmap_stream, True)
     records = dmap_read.read_records()
     self.dmap_compare(dmap_dict, records)
     dmap_dict2 = pydarn.dict2dmap(records)
     self.dmap_compare(dmap_records, dmap_dict2)