def plot_sensitivity_second_order(self):
        """Test plot sensitivity indices 2nd order"""

        exp_unc, impf_unc, _ = make_imp_uncs()
        haz = haz_dem()
        unc = UncImpact(exp_unc, impf_unc, haz)
        unc.make_sample(N=1)

        unc.calc_distribution()
        unc.calc_sensitivity()
        unc.plot_sensitivity2d()
        plt.close()
Exemplo n.º 2
0
    def test_plot_distribution_pass(self):

        exp_unc, impf_unc, _ = make_imp_uncs()
        haz = haz_dem()
        unc = UncImpact(exp_unc, impf_unc, haz)
        unc.make_sample(N=1)
        unc.calc_distribution()
        unc.plot_rp_distribution()
        plt.close()
    def test_plot_distribution_pass(self):
        """Test plot the distribution (uncertainty) of the impact metrics)"""

        exp_unc, impf_unc, _ = make_imp_uncs()
        haz = haz_dem()
        unc = UncImpact(exp_unc, impf_unc, haz)
        unc.make_sample(N=1)
        unc.calc_distribution()
        unc.plot_rp_distribution()
        plt.close()
Exemplo n.º 4
0
    def test_init_pass(self):

        exp_unc, impf_unc, _ = make_imp_uncs()
        haz = haz_dem()

        unc = UncImpact(exp_unc, impf_unc, haz)

        self.assertSetEqual(set(unc.metrics.keys()),
                            {'aai_agg', 'freq_curve', 'eai_exp', 'at_event'})
        self.assertSetEqual(set(unc.unc_vars.keys()), {'exp', 'impf', 'haz'})
    def test_calc_distribution_pass(self):
        """Test compute the uncertainty distribution for an impact"""

        exp_unc, impf_unc, _ = make_imp_uncs()
        haz = haz_dem()
        unc = UncImpact(exp_unc, impf_unc, haz)
        unc.make_sample(N=1)

        unc.calc_distribution(calc_eai_exp=False, calc_at_event=False)

        self.assertListEqual(unc.rp, [5, 10, 20, 50, 100, 250])
        self.assertEqual(unc.calc_eai_exp, False)
        self.assertEqual(unc.calc_at_event, False)

        self.assertTrue(
            np.allclose(
                unc.metrics['aai_agg'].aai_agg,
                np.array([
                    9.600984e+07, 1.668144e+08, 8.068803e+08, 1.274945e+08,
                    1.071482e+09, 2.215182e+08, 1.401932e+09, 1.861671e+09
                ])))
        self.assertTrue(np.allclose(unc.metrics['freq_curve'].rp5,
                                    np.zeros(8)))
        self.assertTrue(
            np.allclose(
                unc.metrics['freq_curve'].rp250,
                np.array([
                    2.880990e+09, 5.005640e+09, 2.421225e+10, 3.825758e+09,
                    3.215222e+10, 6.647149e+09, 4.206811e+10, 5.586359e+10
                ])))
        self.assertTrue(unc.metrics['eai_exp'].empty)
        self.assertTrue(unc.metrics['at_event'].empty)
    def test_save_pass(self):
        """Test save samples"""

        exp_unc, impf_unc, haz_unc = make_imp_uncs()

        unc = Uncertainty({'exp': exp_unc, 'impf': impf_unc, 'haz': haz_unc})
        unc.make_sample(1)
        filename = unc.save_samples_df()

        unc_imp = UncImpact(exp_unc, impf_unc, haz_unc)
        unc_imp.load_samples_df(filename)

        unc_imp.calc_distribution()
        unc_imp.calc_sensitivity()
    def test_plot_sensitivity_map_pass(self):
        """Test plot the map of the largest sensitivity index for eai_exp"""

        exp_unc, impf_unc, _ = make_imp_uncs()
        haz = haz_dem()

        #Default parameters
        unc = UncImpact(exp_unc, impf_unc, haz)
        unc.make_sample(N=1)
        unc.calc_distribution(calc_eai_exp=True)
        unc.calc_sensitivity()
        unc.plot_sensitivity_map(exp_unc.uncvar_func(x_exp=1))
        plt.close()

        #Non-default parameters
        unc = UncImpact(exp_unc, impf_unc, haz)
        unc.make_sample(N=1, sampling_method='morris')
        unc.calc_distribution(calc_eai_exp=True)
        unc.calc_sensitivity(salib_method='morris')
        unc.plot_sensitivity_map(exp_unc.uncvar_func(x_exp=1), salib_si='mu')
        plt.close()