コード例 #1
0
ファイル: test_dmap.py プロジェクト: lkilcommons/pyDARNio
 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)
コード例 #2
0
ファイル: test_dmap.py プロジェクト: lkilcommons/pyDARNio
 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)
コード例 #3
0
ファイル: test_dmap.py プロジェクト: lkilcommons/pyDARNio
 def test_DmapRead_dmap2dict_dict2dmap(self):
     """
     Test DmapRead from a file and convert to a dictionary.
     """
     dmap_read = pydarnio.DmapRead(rawacf_file)
     records = dmap_read.read_records()
     records = dmap_read.get_dmap_records
     dict_records = pydarnio.dmap2dict(records)
     records_2 = pydarnio.dict2dmap(dict_records)
     self.dmap_compare(records, records_2)
コード例 #4
0
    def test_SDarnWrite_incorrect_rawacf_from_dict(self):
        """
        Test convert dictionary with incorrect type to dmap and SDarnWrite
        write the rawacf file

        Behaviour: Raise 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)
        darn_write = pydarnio.SDarnWrite(dmap_rawacf)
        with self.assertRaises(pydarnio.superdarn_exceptions.
                               SuperDARNDataFormatTypeError):
            darn_write.write_rawacf("test_rawacf.rawacf")
コード例 #5
0
 def test_dict2dmap_SDarnWrite_rawacf(self):
     """
     Test dict2dmap to convert a dictionary to dmap then SDarnWrite write
     rawacf file
     """
     rawacf_dict_data = copy.deepcopy(rawacf_dict_sets.rawacf_dict_data)
     dmap_rawacf = pydarnio.dict2dmap(rawacf_dict_data)
     darn_read = pydarnio.SDarnWrite(dmap_rawacf)
     darn_read.write_rawacf("test_rawacf.rawacf")
     dmap_read = pydarnio.DmapRead("test_rawacf.rawacf")
     dmap_data = dmap_read.read_records()
     dmap_data = dmap_read.get_dmap_records
     self.dmap_compare(dmap_data, dmap_rawacf)
     os.remove("test_rawacf.rawacf")
コード例 #6
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()
コード例 #7
0
ファイル: dmap.py プロジェクト: lkilcommons/pyDARNio
    def __check_dmap_dict(self, dmap_records):
        """
        Checks if the dmap data is a dict, if so, converts to a dmap_structure

        Parameter:
            dmap_data : List[dict]
                dmap_data structure to test if it is a dict of value or dmap
                structure
        Returns:
            dmap_structure : List[dict]
                returns the dmap structure of dmap_data
        """
        try:
            first_value = list(dmap_records[0].values())[0]
            if isinstance(first_value, DmapScalar) or isinstance(first_value,
                                                                 DmapArray):
                return dmap_records
            else:
                return dict2dmap(dmap_records)
        except IndexError:
            return dmap_records
コード例 #8
0
 def test_dict2dmap(self):
     """
     From utils package, testing dict2dmap function
     """
     dmap_records_test = pydarnio.dict2dmap(self.dmap_list)
     self.dmap_compare(dmap_records_test, self.dmap_records)