Exemple #1
0
    def test_rawacf2darnrawacf(self):
        """
        Test BorealisConvert by providing both site data and array data.
        Test that the dmap records are the same for both (site data and
        array data are from the same source, should produce same dmap output.)
        This tests that the restructuring is working before the dmap conversion
        """
        # self.rawacf_file already written in setUp
        array_converter =\
            pydarn.BorealisConvert(self.rawacf_file, "rawacf",
                                   self.rawacf_array_darn_file, 0,
                                   borealis_file_structure='array')
        self.assertTrue(os.path.isfile(self.rawacf_array_darn_file))
        darn_reader = pydarn.SDarnRead(self.rawacf_array_darn_file)
        rawacf_array_records = darn_reader.read_rawacf()
        os.remove(self.rawacf_array_darn_file)
        os.remove(self.rawacf_file)

        _ = pydarn.BorealisWrite(self.rawacf_file, self.rawacf_site_data,
                                 'rawacf', 'site')
        site_converter =\
            pydarn.BorealisConvert(self.rawacf_file, "rawacf",
                                   self.rawacf_site_darn_file, 0,
                                   borealis_file_structure='site')
        self.assertTrue(os.path.isfile(self.rawacf_site_darn_file))
        darn_reader = pydarn.SDarnRead(self.rawacf_site_darn_file)
        rawacf_site_records = darn_reader.read_rawacf()
        os.remove(self.rawacf_site_darn_file)
        os.remove(self.rawacf_file)

        for record_num, record in enumerate(array_converter.sdarn_dict):
            dictionaries_are_same =\
                    self.check_dictionaries_are_same(record,
                                                     site_converter.
                                                     sdarn_dict[record_num])
            self.assertTrue(dictionaries_are_same)

        del (array_converter, site_converter, darn_reader, rawacf_site_records,
             rawacf_array_records)
Exemple #2
0
    def test_borealis_convert_to_rawacf(self):
        """
        Tests BorealisConvert to rawacf

        Expected behaviour
        ------------------
        write a SDARN DMap rawacf
        """
        _ = pydarn.BorealisConvert(self.rawacf_test_file,
                                   "rawacf",
                                   "test_rawacf.rawacf.dmap",
                                   0,
                                   borealis_file_structure='array')
        self.assertTrue(os.path.isfile("test_rawacf.rawacf.dmap"))
        os.remove("test_rawacf.rawacf.dmap")
Exemple #3
0
    def test_borealis_convert_to_iqdat(self):
        """
        Tests BorealisConvert to iqdat

        Expected behaviour
        ------------------
        write a SDARN DMap iqdat
        """
        _ = pydarn.BorealisConvert(self.bfiq_test_file,
                                   "bfiq",
                                   "test_bfiq.bfiq.dmap",
                                   0,
                                   borealis_file_structure='array')
        self.assertTrue(os.path.isfile("test_bfiq.bfiq.dmap"))
        os.remove("test_bfiq.bfiq.dmap")
Exemple #4
0
    def get_temp_file_from_datawrite():
        last_file_time = None
        while True:
            filename = so.recv_data(data_write_to_realtime,
                                    opts.dw_to_rt_identity, rt_print)

            if "rawacf" in filename:
                #Read and convert data
                fields = filename.split(".")
                file_time = fields[0] + fields[1] + fields[2] + fields[3]

                # Make sure we only process the first slice for simulatenous multislice data for now
                if file_time == last_file_time:
                    os.remove(filename)
                    continue

                last_file_time = file_time

                slice_num = int(fields[5])
                try:
                    rt_print("Using pyDARN to convert {}".format(filename))
                    converted = pydarn.BorealisConvert(filename, "rawacf",
                                                       "/dev/null", slice_num,
                                                       "site")
                    os.remove(filename)
                except pydarn.exceptions.borealis_exceptions.BorealisConvert2RawacfError as e:
                    rt_print("Error converting {}".format(filename))
                    os.remove(filename)
                    continue

                data = converted.sdarn_dict

                fit_data = fitacf._fit(data[0])
                tmp = fit_data.copy()

                # Can't jsonify numpy so we convert to native types for rt purposes.
                for k, v in fit_data.items():
                    if hasattr(v, 'dtype'):
                        if isinstance(v, np.ndarray):
                            tmp[k] = v.tolist()
                        else:
                            tmp[k] = v.item()

                q.put(tmp)
            else:
                os.remove(filename)