Exemple #1
0
    def testGetDataReturnObject(self):
        """Make sure correct data object type is returned"""
        from pyfusion.acquisition.FakeData.acq import FakeDataAcquisition
        from pyfusion import conf

        # make sure the requested data type is returned using config reference
        test_acq = FakeDataAcquisition('test_fakedata')
        from pyfusion.data.timeseries import TimeseriesData
        data_instance_1 = test_acq.getdata(self.shot_number,
                                           timeseries_test_channel_1)
        self.assertTrue(isinstance(data_instance_1, TimeseriesData))

        # ...and for kwargs
        # read config as dict and pass as kwargs
        config_dict = conf.utils.get_config_as_dict('Diagnostic',
                                                    timeseries_test_channel_1)
        data_instance_2 = test_acq.getdata(self.shot_number, **config_dict)
        self.assertTrue(isinstance(data_instance_2, TimeseriesData))

        # check that the two signals are the same
        from numpy.testing import assert_array_almost_equal
        assert_array_almost_equal(data_instance_1.signal,
                                  data_instance_2.signal)
        assert_array_almost_equal(data_instance_1.timebase,
                                  data_instance_2.timebase)
Exemple #2
0
    def test_single_channel_fakedata(self):
        test_acq = FakeDataAcquisition('test_fakedata')
        channel_data = test_acq.getdata(self.shot_number, "test_timeseries_channel_2")
        channel_data_norm_no_arg = test_acq.getdata(self.shot_number, "test_timeseries_channel_2").normalise()
        channel_data_rms_norm_by_arg = test_acq.getdata(self.shot_number, "test_timeseries_channel_2").normalise(method='rms')
        channel_data_peak_norm_by_arg = test_acq.getdata(self.shot_number, "test_timeseries_channel_2").normalise(method='peak')
        channel_data_var_norm_by_arg = test_acq.getdata(self.shot_number, "test_timeseries_channel_2").normalise(method='var')
        rms_value = np.sqrt(np.mean(channel_data.signal**2))
        peak_value = max(abs(channel_data.signal))
        var_value = np.var(channel_data.signal)


        assert_array_almost_equal(channel_data.signal/rms_value, channel_data_rms_norm_by_arg.signal)
        assert_array_almost_equal(channel_data.signal/peak_value, channel_data_peak_norm_by_arg.signal)
        assert_array_almost_equal(channel_data.signal/var_value, channel_data_var_norm_by_arg.signal)

        # check that default is peak
        assert_array_almost_equal(channel_data_peak_norm_by_arg.signal, channel_data_norm_no_arg.signal)


        # try for dataset
        channel_data_for_set = test_acq.getdata(self.shot_number, "test_timeseries_channel_2")

        test_dataset = DataSet('test_dataset')
        test_dataset.add(channel_data_for_set)
        test_dataset.normalise(method='rms')
        for d in test_dataset:
            assert_array_almost_equal(channel_data.signal/rms_value, d.signal)
Exemple #3
0
    def test_multichannel_single_channels(self):
        from pyfusion.acquisition.FakeData.acq import FakeDataAcquisition
        from pyfusion import config

        test_acq = FakeDataAcquisition("test_fakedata")
        multichannel_data = test_acq.getdata(self.shot_number, multichannel_name)
        channel_1_data = test_acq.getdata(self.shot_number, timeseries_test_channel_1)
        channel_2_data = test_acq.getdata(self.shot_number, timeseries_test_channel_2)
        from numpy.testing import assert_array_almost_equal

        assert_array_almost_equal(multichannel_data.signal[0, :], channel_1_data.signal)
        assert_array_almost_equal(multichannel_data.signal[1, :], channel_2_data.signal)
        self.assertEqual(channel_1_data.meta.get("shot"), self.shot_number)
        assert_array_almost_equal(multichannel_data.signal.get_channel(0), channel_1_data.signal)
Exemple #4
0
    def test_multichannel_fakedata(self):
        test_acq = FakeDataAcquisition('test_fakedata')
        multichannel_data = test_acq.getdata(self.shot_number, "test_multichannel_timeseries")

        mcd_ch_0 = multichannel_data.signal.get_channel(0)
        mcd_ch_0_peak = max(abs(mcd_ch_0))
        mcd_ch_0_rms = np.sqrt(np.mean(mcd_ch_0**2))
        mcd_ch_0_var = np.var(mcd_ch_0)
        
        mcd_ch_1 = multichannel_data.signal.get_channel(1)
        mcd_ch_1_peak = max(abs(mcd_ch_1))
        mcd_ch_1_rms = np.sqrt(np.mean(mcd_ch_1**2))
        mcd_ch_1_var = np.var(mcd_ch_1)
        
        mcd_peak_separate = test_acq.getdata(self.shot_number,
                                             "test_multichannel_timeseries").normalise(method='peak', separate=True)
        mcd_peak_whole = test_acq.getdata(self.shot_number,
                                          "test_multichannel_timeseries").normalise(method='peak', separate=False)
        mcd_rms_separate = test_acq.getdata(self.shot_number,
                                            "test_multichannel_timeseries").normalise(method='rms', separate=True)
        mcd_rms_whole = test_acq.getdata(self.shot_number,
                                         "test_multichannel_timeseries").normalise(method='rms', separate=False)
        mcd_var_separate = test_acq.getdata(self.shot_number,
                                            "test_multichannel_timeseries").normalise(method='var', separate=True)
        mcd_var_whole = test_acq.getdata(self.shot_number,
                                         "test_multichannel_timeseries").normalise(method='var', separate=False)
        
        # peak - separate
        assert_array_almost_equal(mcd_peak_separate.signal.get_channel(0), mcd_ch_0/mcd_ch_0_peak)
        assert_array_almost_equal(mcd_peak_separate.signal.get_channel(1), mcd_ch_1/mcd_ch_1_peak)
        # peak - whole
        max_peak = max(mcd_ch_0_peak, mcd_ch_1_peak)
        assert_array_almost_equal(mcd_peak_whole.signal.get_channel(0), mcd_ch_0/max_peak)
        assert_array_almost_equal(mcd_peak_whole.signal.get_channel(1), mcd_ch_1/max_peak)
        
        # rms - separate
        assert_array_almost_equal(mcd_rms_separate.signal.get_channel(0), mcd_ch_0/mcd_ch_0_rms)
        assert_array_almost_equal(mcd_rms_separate.signal.get_channel(1), mcd_ch_1/mcd_ch_1_rms)
        # rms - whole
        max_rms = max(mcd_ch_0_rms, mcd_ch_1_rms)
        assert_array_almost_equal(mcd_rms_whole.signal.get_channel(0), mcd_ch_0/max_rms)
        assert_array_almost_equal(mcd_rms_whole.signal.get_channel(1), mcd_ch_1/max_rms)

        # var - separate
        assert_array_almost_equal(mcd_var_separate.signal.get_channel(0), mcd_ch_0/mcd_ch_0_var)
        assert_array_almost_equal(mcd_var_separate.signal.get_channel(1), mcd_ch_1/mcd_ch_1_var)
        # var - whole
        max_var = max(mcd_ch_0_var, mcd_ch_1_var)
        assert_array_almost_equal(mcd_var_whole.signal.get_channel(0), mcd_ch_0/max_var)
        assert_array_almost_equal(mcd_var_whole.signal.get_channel(1), mcd_ch_1/max_var)
Exemple #5
0
 def test_multichannel_single_channels(self):
     from pyfusion.acquisition.FakeData.acq import FakeDataAcquisition
     from pyfusion import config
     test_acq = FakeDataAcquisition('test_fakedata')
     multichannel_data = test_acq.getdata(self.shot_number,
                                          multichannel_name)
     channel_1_data = test_acq.getdata(self.shot_number,
                                       timeseries_test_channel_1)
     channel_2_data = test_acq.getdata(self.shot_number,
                                       timeseries_test_channel_2)
     from numpy.testing import assert_array_almost_equal
     assert_array_almost_equal(multichannel_data.signal[0, :],
                               channel_1_data.signal)
     assert_array_almost_equal(multichannel_data.signal[1, :],
                               channel_2_data.signal)
     self.assertEqual(channel_1_data.meta.get('shot'), self.shot_number)
     assert_array_almost_equal(multichannel_data.signal.get_channel(0),
                               channel_1_data.signal)
Exemple #6
0
    def testGetDataReturnObject(self):
        """Make sure correct data object type is returned"""
        from pyfusion.acquisition.FakeData.acq import FakeDataAcquisition
        from pyfusion import conf

        # make sure the requested data type is returned using config reference
        test_acq = FakeDataAcquisition("test_fakedata")
        from pyfusion.data.timeseries import TimeseriesData

        data_instance_1 = test_acq.getdata(self.shot_number, timeseries_test_channel_1)
        self.assertTrue(isinstance(data_instance_1, TimeseriesData))

        # ...and for kwargs
        # read config as dict and pass as kwargs
        config_dict = conf.utils.get_config_as_dict("Diagnostic", timeseries_test_channel_1)
        data_instance_2 = test_acq.getdata(self.shot_number, **config_dict)
        self.assertTrue(isinstance(data_instance_2, TimeseriesData))

        # check that the two signals are the same
        from numpy.testing import assert_array_almost_equal

        assert_array_almost_equal(data_instance_1.signal, data_instance_2.signal)
        assert_array_almost_equal(data_instance_1.timebase, data_instance_2.timebase)
Exemple #7
0
 def test_get_acquistion(self):
     test_acq_1 = getAcquisition('test_fakedata')
     test_acq_2 = FakeDataAcquisition('test_fakedata')
     self.assertEqual(test_acq_1.__class__, test_acq_2.__class__)
     self.assertEqual(test_acq_1.__dict__, test_acq_2.__dict__)