Beispiel #1
0
    def test_plot_allmodelruns(self):
        from spotpy.examples.spot_setup_hymod_python import spot_setup as sp
        sp = sp()

        sampler = spotpy.algorithms.dream(sp,
                                          parallel="seq",
                                          dbname='test_plot_allmodelruns',
                                          dbformat="ram",
                                          sim_timeout=5)

        sampler.sample(50)

        modelruns = []
        for run in sampler.getdata():
            on_run = []
            for i in run:
                on_run.append(i)
            on_run = np.array(on_run)[:-9]
            print(on_run)
            modelruns.append(on_run.tolist())

        test_plot_allmodelruns = spotpy.analyser.plot_allmodelruns(
            modelruns,
            sp.evaluation(),
            dates=range(1,
                        len(sp.evaluation()) + 1))

        fig_name = "bestmodel.png"

        # approximately 8855 KB is the size of an empty matplotlib.pyplot.plot, so
        # we expecting a plot with some content without testing the structure of the pot just
        # the size
        self.assertGreaterEqual(os.path.getsize(fig_name), 8855)

        os.remove(fig_name)
Beispiel #2
0
    def test_compare_different_objectivefunctions(self):

        from spotpy.examples.spot_setup_hymod_python import spot_setup as sp
        sp = sp()

        sampler = spotpy.algorithms.dream(
            sp,
            parallel="seq",
            dbname='test_compare_different_objectivefunctions',
            dbformat="ram",
            sim_timeout=5)

        sampler_mcmc = spotpy.algorithms.mcmc(
            sp,
            parallel="seq",
            dbname='test_compare_different_objectivefunctions',
            dbformat="ram",
            sim_timeout=5)

        sampler.sample(50)
        sampler_mcmc.sample(50)
        compare_different_objectivefunctions = spotpy.analyser.compare_different_objectivefunctions(
            sampler_mcmc.bestlike, sampler.bestlike)

        self.assertEqual(type(compare_different_objectivefunctions[1]),
                         type(np.array([0.5])[0]))
Beispiel #3
0
    def setup_MC_results(self):

        picklefilename = "test_analyser_MC_results"
        if not os.path.isfile(picklefilename):
            from spotpy.examples.spot_setup_hymod_python import spot_setup as sp
            sp = sp()

            sampler = spotpy.algorithms.mc(sp,
                                           parallel="seq",
                                           dbname='test_plot_autocorellation',
                                           dbformat="csv",
                                           sim_timeout=5)
            sampler.sample(100)
            pickfil = open(picklefilename, "wb")
            pickle.dump(sampler.getdata(), pickfil)
Beispiel #4
0
    def test_plot_gelman_rubin(self):
        from spotpy.examples.spot_setup_hymod_python import spot_setup as sp
        sp = sp()
        sampler = spotpy.algorithms.dream(sp,
                                          parallel="seq",
                                          dbname='test_plot_autocorellation',
                                          dbformat="csv",
                                          sim_timeout=5)

        r_hat = sampler.sample(100)

        fig_name = "gelman_rubin.png"
        spotpy.analyser.plot_gelman_rubin(r_hat)
        plt.savefig(fig_name)
        self.assertGreaterEqual(abs(os.path.getsize(fig_name)), 100)

        os.remove(fig_name)