Пример #1
0
 def test_stog_plot_df(self, mock_show):
     df = pd.DataFrame(np.random.randn(10, 2),
                       index=np.arange(10),
                       columns=list('XY'))
     stog = StoG()
     stog._plot_df(df, 'x', 'y', 'title', None)
     mock_show.assert_called_with()
Пример #2
0
 def test_stog_real_space_function_setter(self):
     stog = StoG()
     stog.real_space_function = "GK(r)"
     self.assertEqual(stog.real_space_function, "GK(r)")
     self.assertEqual(stog.gr_title, "GK(r) Merged")
     self.assertEqual(stog.real_space_function, "GK(r)")
     self.assertEqual(stog.gr_ft_title, "GK(r) FT")
     self.assertEqual(stog.gr_lorch_title, "GK(r) FT Lorched")
Пример #3
0
    def test_stog_read_all_data_for_files_length(self):
        # Load S(Q) for Argon from test data
        stog = StoG()
        stog.files = self.kwargs_for_files['Files']
        stog.read_all_data()

        # Check S(Q) data against targets
        self.assertEqual(len(stog.files), len(self.kwargs_for_files['Files']))
Пример #4
0
 def test_stog_add_dataset_default_reciprocal_space_function(self):
     # Checks the default reciprocal space function is S(Q) and the index is
     # set
     stog = StoG()
     index = 300
     info = {'data': pd.DataFrame({'x': self.q, 'y': self.sq})}
     stog.add_dataset(info, index=index)
     self.assertEqual(list(stog.df_individuals.columns.values),
                      ['S(Q)_%d' % index])
Пример #5
0
 def test_stog_plotting_kwargs_setter(self):
     stog = StoG()
     new_kwargs = {
         'figsize': (4, 4),
         'style': 'o',
         'ms': 2,
         'lw': 2,
     }
     stog.plotting_kwargs = new_kwargs
     self.assertEqual(stog.plotting_kwargs, new_kwargs)
Пример #6
0
    def setUp(self):
        super(TestStogPlottingDataFrameMethods, self).setUp()
        stog = StoG(**self.kwargs_for_stog_input)
        stog.files = self.kwargs_for_files['Files']
        stog.read_all_data()
        stog.merge_data()
        stog.transform_merged()

        self.stog = stog
Пример #7
0
    def test_stog_transform_merged_for_nan_after_filter(self):
        # Load S(Q) for Argon from test data
        stog = StoG(**self.kwargs_for_stog_input)
        stog.files = self.kwargs_for_files['Files']
        stog.real_space_function = "GK(r)"
        stog.read_all_data()
        stog.merge_data()
        stog.transform_merged()

        self.assertFalse(
            np.isnan(stog.df_sq_master[stog.sq_title].values).any())
        self.assertFalse(
            np.isnan(stog.df_gr_master[stog.gr_title].values).any())
Пример #8
0
 def test_stog_add_dataset_wrong_reciprocal_space_function_exception(self):
     # Check qmin and qmax apply cropping
     stog = StoG()
     index = 0
     info = {
         'data': pd.DataFrame({
             'x': self.q,
             'y': self.sq
         }),
         'ReciprocalFunction': 'ABCDEFG(Q)'
     }
     with self.assertRaises(ValueError):
         stog.add_dataset(info, index=index)
Пример #9
0
 def test_stog_add_dataset_xoffset(self):
     # Offset Q from 1.96 -> 2.14
     stog = StoG()
     index = 0
     info = {
         'data': pd.DataFrame({
             'x': self.q,
             'y': self.sq
         }),
         'ReciprocalFunction': 'S(Q)',
         'X': {
             'Offset': 0.2
         }
     }
     stog.add_dataset(info, index=index)
     self.assertEqual(stog.df_individuals.iloc[self.first].name, 2.14)
Пример #10
0
    def test_stog_read_all_data_assertion(self):
        stog = StoG()
        with self.assertRaises(AssertionError):
            stog.read_all_data()

        stog.files = list()
        with self.assertRaises(AssertionError):
            stog.read_all_data()
Пример #11
0
    def test_stog_fourier_filter_before_transform_merged_call(self):
        # Number of decimal places for precision
        places = 1

        # Load S(Q) for Argon from test data
        stog = StoG(**self.kwargs_for_stog_input)
        stog.files = self.kwargs_for_files['Files']
        stog.plot_flag = False
        stog.read_all_data()
        stog.merge_data()
        stog.fourier_filter()

        # Check g(r) data against targets
        self.assertAlmostEqual(
            stog.df_gr_master.iloc[self.real_space_first].name,
            self.real_xtarget,
            places=places)
        self.assertAlmostEqual(
            stog.df_gr_master.iloc[self.real_space_first][stog.gr_ft_title],
            self.gofr_ff_target[0],
            places=places)
Пример #12
0
 def test_stog_add_dataset_yoffset(self):
     # Offset S(Q) and make sure it does not equal original target values
     stog = StoG()
     index = 0
     info = {
         'data': pd.DataFrame({
             'x': self.q,
             'y': self.sq
         }),
         'ReciprocalFunction': 'S(Q)',
         'Y': {
             'Offset': 2.0
         }
     }
     stog.add_dataset(info, index=index)
     self.assertNotEqual(
         stog.df_individuals.iloc[self.first]['S(Q)_%d' % index],
         self.sq_target[0])
     self.assertNotEqual(
         stog.df_sq_individuals.iloc[self.first]['S(Q)_%d' % index],
         self.sq_target[0])
Пример #13
0
    def test_stog_transform_merged_GKofR(self):
        # Number of decimal places for precision
        places = 2

        # Load S(Q) for Argon from test data
        stog = StoG(**self.kwargs_for_stog_input)
        stog.files = self.kwargs_for_files['Files']
        stog.real_space_function = "GK(r)"
        stog.read_all_data()
        stog.merge_data()
        stog.transform_merged()

        # Check GK(r) data against targets
        self.assertAlmostEqual(
            stog.df_gr_master.iloc[self.real_space_first].name,
            self.real_xtarget,
            places=places)
        self.assertAlmostEqual(
            stog.df_gr_master.iloc[self.real_space_first][stog.gr_title],
            self.GKofR_target[0],
            places=places)
Пример #14
0
    def test_stog_read_all_data(self):
        # Number of decimal places for precision
        places = 5

        # Load S(Q) for Argon from test data
        stog = StoG()
        stog.files = self.kwargs_for_files['Files']
        stog.read_all_data()

        # Check S(Q) data against targets
        self.assertEqual(stog.df_individuals.iloc[self.first].name,
                         self.reciprocal_xtarget)
        for index in range(len(stog.files)):
            self.assertAlmostEqual(
                stog.df_individuals.iloc[self.first]['S(Q)_%d' % index],
                self.sq_target[0],
                places=places)
            self.assertAlmostEqual(
                stog.df_sq_individuals.iloc[self.first]['S(Q)_%d' % index],
                self.sq_target[0],
                places=places)
Пример #15
0
    def test_stog_read_dataset(self):
        # Number of decimal places for precision
        places = 5

        # Load S(Q) for Argon from test data
        stog = StoG(
            **{
                '<b_coh>^2': self.kwargs['<b_coh>^2'],
                '<b_tot^2>': self.kwargs['<b_tot^2>']
            })
        info = {
            'Filename': get_data_path(self.material.reciprocal_space_filename),
            'ReciprocalFunction': 'S(Q)',
            'Qmin': 0.02,
            'Qmax': 35.2,
            'Y': {
                'Offset': 0.0,
                'Scale': 1.0
            },
            'X': {
                'Offset': 0.0
            }
        }

        info['index'] = 0
        stog.read_dataset(info)

        # Check S(Q) data against targets
        self.assertEqual(stog.df_individuals.iloc[self.first].name,
                         self.reciprocal_xtarget)
        self.assertAlmostEqual(
            stog.df_individuals.iloc[self.first]['S(Q)_%d' % info['index']],
            self.sq_target[0],
            places=places)
        self.assertAlmostEqual(
            stog.df_sq_individuals.iloc[self.first]['S(Q)_%d' % info['index']],
            self.sq_target[0],
            places=places)
Пример #16
0
    def test_stog_merge_data_qsq_opts_offset(self):
        # Number of decimal places for precision
        places = 5

        # Load S(Q) for Argon from test data
        stog = StoG()
        stog.files = self.kwargs_for_files['Files']
        stog.read_all_data()
        qsq_opts = {'Y': {'Offset': 1.0}}

        # Test Q[S(Q)-1] scale
        stog.merged_opts['Q[S(Q)-1]'] = qsq_opts
        stog.merge_data()
        self.assertAlmostEqual(
            stog.df_sq_master.iloc[self.first][stog.qsq_minus_one_title],
            qsq_opts['Y']['Offset'] + self.fq_target[0],
            places=places)
Пример #17
0
    def test_stog_merge_data(self):
        # Number of decimal places for precision
        places = 5

        # Load S(Q) for Argon from test data
        stog = StoG()
        stog.files = self.kwargs_for_files['Files']
        stog.read_all_data()
        stog.merge_data()

        # Check S(Q) data against targets
        self.assertEqual(stog.df_sq_master.iloc[self.first].name,
                         self.reciprocal_xtarget)
        self.assertAlmostEqual(
            stog.df_sq_master.iloc[self.first][stog.sq_title],
            self.sq_target[0],
            places=places)
Пример #18
0
 def test_stog_init(self):
     stog = StoG()
     self.assertEqual(stog.xmin, 100)
     self.assertEqual(stog.xmax, 0)
     self.assertEqual(stog.qmin, None)
     self.assertEqual(stog.qmax, None)
     self.assertEqual(stog.files, None)
     self.assertEqual(stog.sq_title, "S(Q) Merged")
     self.assertEqual(stog.qsq_minus_one_title, "Q[S(Q)-1] Merged")
     self.assertEqual(stog.sq_ft_title, "S(Q) FT")
     self.assertEqual(stog.fq_title, "F(Q) Merged")
     self.assertEqual(stog.real_space_function, "g(r)")
     self.assertEqual(stog.gr_title, "g(r) Merged")
     self.assertEqual(stog.gr_ft_title, "g(r) FT")
     self.assertEqual(stog.gr_lorch_title, "g(r) FT Lorched")
     self.assertEqual(stog.GKofR_title, "G(r) (Keen Version)")
     self.assertEqual(stog.rmin, 0.0)
     self.assertEqual(stog.rmax, 50.0)
     self.assertEqual(stog.rdelta, 0.01)
     self.assertEqual(stog.density, 1.0)
     self.assertEqual(stog.bcoh_sqrd, 1.0)
     self.assertEqual(stog.btot_sqrd, 1.0)
     self.assertEqual(stog.low_q_correction, False)
     self.assertEqual(stog.lorch_flag, False)
     self.assertEqual(stog.fourier_filter_cutoff, None)
     self.assertEqual(stog.plot_flag, True)
     self.assertEqual(stog.plotting_kwargs, {
         'figsize': (16, 8),
         'style': '-',
         'ms': 1,
         'lw': 1,
     })
     self.assertEqual(stog.merged_opts,
                      {"Y": {
                          "Offset": 0.0,
                          "Scale": 1.0
                      }})
     self.assertEqual(stog.stem_name, "out")
     self.assertTrue(stog.df_individuals.empty)
     self.assertTrue(stog.df_sq_master.empty)
     self.assertTrue(stog.df_sq_individuals.empty)
     self.assertTrue(stog.df_gr_master.empty)
Пример #19
0
 def test_stog_add_dataset_qmin_qmax_crop(self):
     # Check qmin and qmax apply cropping
     stog = StoG()
     index = 0
     info = {
         'data': pd.DataFrame({
             'x': self.q,
             'y': self.sq
         }),
         'ReciprocalFunction': 'S(Q)'
     }
     stog.qmin = 1.5
     stog.qmax = 12.0
     stog.add_dataset(info, index=index)
     self.assertEqual(stog.df_individuals.iloc[0].name, stog.qmin)
     self.assertEqual(stog.df_individuals.iloc[-1].name, stog.qmax)
Пример #20
0
    def test_stog_fourier_filter_for_nan_after_filter(self):
        # Load S(Q) for Argon from test data
        stog = StoG(**self.kwargs_for_stog_input)
        stog.files = self.kwargs_for_files['Files']
        stog.plot_flag = False
        stog.read_all_data()
        stog.merge_data()
        stog.transform_merged()
        stog.fourier_filter()

        self.assertFalse(
            np.isnan(stog.df_gr_master[stog.gr_title].values).any())
        self.assertFalse(
            np.isnan(stog.df_sq_master[stog.sq_title].values).any())
        self.assertFalse(
            np.isnan(stog.df_sq_master[stog._ft_title].values).any())
        self.assertFalse(
            np.isnan(stog.df_sq_master[stog.sq_ft_title].values).any())
Пример #21
0
    def test_stog_apply_lorch_GofR(self):
        # Number of decimal places for precision
        places = 5

        # Load S(Q) for Argon from test data
        stog = StoG(**self.kwargs_for_stog_input)
        stog.files = self.kwargs_for_files['Files']
        stog.plot_flag = False
        stog.real_space_function = "G(r)"
        stog.read_all_data()
        stog.merge_data()
        stog.transform_merged()
        q, sq, r, gr = stog.fourier_filter()
        stog.apply_lorch(q, sq, r)

        self.assertAlmostEqual(
            stog.df_gr_master.iloc[self.real_space_first][stog.gr_lorch_title],
            self.GofR_lorch_target[0],
            places=places)
Пример #22
0
 def test_stog_low_q_correction_exception(self):
     stog = StoG()
     with self.assertRaises(TypeError):
         stog.low_q_correction = 1.0
Пример #23
0
 def test_stog_fourier_filter_with_plot_flag(self, mock_show):
     # Load S(Q) for Argon from test data
     stog = StoG(**self.kwargs_for_stog_input)
     stog.files = self.kwargs_for_files['Files']
     stog.plot_flag = True
     stog.read_all_data()
     stog.merge_data()
     stog.transform_merged()
     stog.fourier_filter()
     mock_show.assert_called_with()
Пример #24
0
 def test_stog_real_space_function_exception(self):
     stog = StoG()
     with self.assertRaises(ValueError):
         stog.real_space_function = "Dog"
Пример #25
0
 def test_stog_plot_flag_exception(self):
     stog = StoG()
     with self.assertRaises(TypeError):
         stog.plot_flag = 1.0
Пример #26
0
 def test_stog_df_sq_individuals_setter(self):
     stog = StoG()
     stog.df_sq_individuals = self.df_target
     self.assertTrue(stog.df_sq_individuals.equals(self.df_target))
Пример #27
0
 def test_stog_df_gr_master_setter(self):
     stog = StoG()
     stog.df_gr_master = self.df_target
     self.assertTrue(stog.df_gr_master.equals(self.df_target))
Пример #28
0
 def test_stog_append_file(self):
     stog = StoG(**{'Files': ['file1.txt', 'file2.txt']})
     stog.append_file('file3.txt')
     self.assertEqual(stog.files, ['file1.txt', 'file2.txt', 'file3.txt'])
Пример #29
0
 def test_stog_extend_file_list(self):
     stog = StoG(**{'Files': ['file1.txt', 'file2.txt']})
     stog.extend_file_list(['file3.txt', 'file4.txt'])
     self.assertEqual(stog.files,
                      ['file1.txt', 'file2.txt', 'file3.txt', 'file4.txt'])
Пример #30
0
    def test_stog_add_dataset(self):
        # Number of decimal places for precision
        places = 5

        # Initialize with material info for Argon
        stog = StoG(
            **{
                '<b_coh>^2': self.kwargs['<b_coh>^2'],
                '<b_tot^2>': self.kwargs['<b_tot^2>']
            })

        # Add the S(Q) data set and check values against targets
        index = 0
        info = {
            'data': pd.DataFrame({
                'x': self.q,
                'y': self.sq
            }),
            'ReciprocalFunction': 'S(Q)'
        }
        stog.add_dataset(info, index=index)
        self.assertEqual(stog.df_individuals.iloc[self.first].name,
                         self.reciprocal_xtarget)
        self.assertAlmostEqual(stog.df_individuals.iloc[self.first]['S(Q)_%d' %
                                                                    index],
                               self.sq_target[0],
                               places=places)
        self.assertAlmostEqual(
            stog.df_sq_individuals.iloc[self.first]['S(Q)_%d' % index],
            self.sq_target[0],
            places=places)

        # Add the Q[S(Q)-1] data set and check values for it and S(Q) against
        # targets
        index = 1
        info = {
            'data': pd.DataFrame({
                'x': self.q,
                'y': self.fq
            }),
            'ReciprocalFunction': 'Q[S(Q)-1]'
        }
        stog.add_dataset(info, index=index)
        self.assertAlmostEqual(
            stog.df_individuals.iloc[self.first]['Q[S(Q)-1]_%d' % index],
            self.fq_target[0],
            places=places)
        self.assertAlmostEqual(
            stog.df_sq_individuals.iloc[self.first]['S(Q)_%d' % index],
            self.sq_target[0],
            places=places)

        # Add the FK(Q) data set and check values for it and S(Q) against
        # targets
        index = 2
        info = {
            'data': pd.DataFrame({
                'x': self.q,
                'y': self.fq_keen
            }),
            'ReciprocalFunction': 'FK(Q)'
        }
        stog.add_dataset(info, index=index)
        self.assertAlmostEqual(
            stog.df_individuals.iloc[self.first]['FK(Q)_%d' % index],
            self.fq_keen_target[0],
            places=places)
        self.assertAlmostEqual(
            stog.df_sq_individuals.iloc[self.first]['S(Q)_%d' % index],
            self.sq_target[0],
            places=places)

        # Add the DCS(Q) data set and check values for it and S(Q) against
        # targets
        index = 3
        info = {
            'data': pd.DataFrame({
                'x': self.q,
                'y': self.dcs
            }),
            'ReciprocalFunction': 'DCS(Q)'
        }
        stog.add_dataset(info, index=index)
        self.assertAlmostEqual(
            stog.df_individuals.iloc[self.first]['DCS(Q)_%d' % index],
            self.dcs_target[0],
            places=places)
        self.assertAlmostEqual(
            stog.df_sq_individuals.iloc[self.first]['S(Q)_%d' % index],
            self.sq_target[0],
            places=places)