def test_plot_sensitivity(self):
        """Test plot sensitivity indices first oder"""

        exp_unc, _, haz_unc = make_imp_uncs()
        samples = pd.DataFrame({
            'x_exp': [1, 2, 3, 4],
            'x_haz': [0.1, 0.2, 0.3, 0.4]
        })
        metrics = {
            'freq_curve':
            pd.DataFrame({
                'rp100': [9, 10, 11, 12],
                'rp250': [100, 110, 120, 130]
            })
        }

        unc = Uncertainty(unc_vars={
            'exp': exp_unc,
            'haz': haz_unc
        },
                          samples=samples,
                          metrics=metrics)

        unc.calc_sensitivity(method_kwargs={'calc_second_order': False})
        unc.plot_sensitivity()
        plt.close()

        unc.calc_sensitivity(salib_method='rbd_fast', method_kwargs={'M': 8})
        unc.plot_sensitivity()
        plt.close()
    def test_calc_sensitivty_XY_pass(self):
        """Test compute sensitvity method rbd_fast (variables names different
        from default)"""

        exp_unc, _, haz_unc = make_imp_uncs()
        samples = pd.DataFrame({
            'x_exp': [1, 2, 3, 4],
            'x_haz': [0.1, 0.2, 0.3, 0.4]
        })
        metrics = {
            'rp':
            pd.DataFrame({
                'rp100': [9.0, 10.0, 11.0, 12.0],
                'rp250': [100.0, 110.0, 120.0, 130.0]
            })
        }

        unc = Uncertainty(unc_vars={
            'exp': exp_unc,
            'haz': haz_unc
        },
                          samples=samples,
                          metrics=metrics)

        sens = unc.calc_sensitivity(salib_method='rbd_fast',
                                    method_kwargs={'M': 8})
        self.assertSetEqual(set(sens.keys()), {'rp'})
        self.assertSetEqual(set(sens['rp'].keys()), {'rp100', 'rp250'})
        self.assertSetEqual(set(sens['rp']['rp100'].keys()), {'S1', 'names'})
        self.assertTrue(
            np.allclose(sens['rp']['rp100']['S1'], np.array([1.0, 1.0])))
    def test_calc_sensitivty_pass(self):
        """Test compute sensitivity default"""

        exp_unc, _, haz_unc = make_imp_uncs()
        samples = pd.DataFrame({
            'x_exp': [1, 2, 3, 4],
            'x_haz': [0.1, 0.2, 0.3, 0.4]
        })
        metrics = {
            'rp':
            pd.DataFrame({
                'rp100': [9, 10, 11, 12],
                'rp250': [100, 110, 120, 130]
            })
        }

        unc = Uncertainty(unc_vars={
            'exp': exp_unc,
            'haz': haz_unc
        },
                          samples=samples,
                          metrics=metrics)

        sens = unc.calc_sensitivity(method_kwargs={'calc_second_order': False})
        self.assertSetEqual(set(sens.keys()), {'rp'})
        self.assertSetEqual(set(sens['rp'].keys()), {'rp100', 'rp250'})
        self.assertSetEqual(set(sens['rp']['rp100'].keys()),
                            {'S1', 'S1_conf', 'ST', 'ST_conf'})
        self.assertTrue(
            np.allclose(sens['rp']['rp100']['S1'],
                        np.array([0.66666667, 1.33333333])))