コード例 #1
0
    def test_random(self):

        # Fake Reset (all these tests are horribly coded)
        with open(CLI_LOGF, 'wb') as f:
            pickle.dump('none', f)
        gdirs = up_to_inversion()

        workflow.execute_entity_task(flowline.init_present_time_glacier, gdirs)
        rand_glac = partial(flowline.random_glacier_evolution,
                            nyears=200,
                            seed=0,
                            filesuffix='_test')
        workflow.execute_entity_task(rand_glac, gdirs)

        for gd in gdirs:

            path = gd.get_filepath('past_model', filesuffix='_test')

            # See that we are running ok
            with flowline.FileModel(path) as model:
                vol = model.volume_km3_ts()
                area = model.area_km2_ts()
                length = model.length_m_ts()

                self.assertTrue(np.all(np.isfinite(vol) & vol != 0.))
                self.assertTrue(np.all(np.isfinite(area) & area != 0.))
                self.assertTrue(np.all(np.isfinite(length) & length != 0.))

        # Test output
        ds = utils.compile_run_output(gdirs, filesuffix='_test')
        assert_allclose(vol, ds.volume.sel(rgi_id=gd.rgi_id) * 1e-9)
        assert_allclose(area, ds.area.sel(rgi_id=gd.rgi_id) * 1e-6)
        assert_allclose(length, ds.length.sel(rgi_id=gd.rgi_id))
コード例 #2
0
    def test_random(self):

        gdirs = up_to_inversion()

        workflow.execute_entity_task(flowline.init_present_time_glacier, gdirs)
        rand_glac = partial(flowline.random_glacier_evolution, nyears=200,
                            seed=0, filesuffix='_test')
        workflow.execute_entity_task(rand_glac, gdirs)

        for gd in gdirs:

            path = gd.get_filepath('past_model', filesuffix='_test')

            # See that we are running ok
            with flowline.FileModel(path) as model:
                vol = model.volume_km3_ts()
                area = model.area_km2_ts()
                length = model.length_m_ts()

                self.assertTrue(np.all(np.isfinite(vol) & vol != 0.))
                self.assertTrue(np.all(np.isfinite(area) & area != 0.))
                self.assertTrue(np.all(np.isfinite(length) & length != 0.))

        # Test output
        utils.compile_run_output(gdirs, filesuffix='_test')
        path = os.path.join(cfg.PATHS['working_dir'],
                            'run_output_test.nc')
        ds = xr.open_dataset(path)
        assert_allclose(vol, ds.volume.sel(rgi_id=gd.rgi_id) * 1e-9)
        assert_allclose(area, ds.area.sel(rgi_id=gd.rgi_id) * 1e-6)
        assert_allclose(length, ds.length.sel(rgi_id=gd.rgi_id))
コード例 #3
0
ファイル: test_workflow.py プロジェクト: MachineAi/oggm
    def test_random(self):

        gdirs = up_to_inversion()

        workflow.execute_entity_task(flowline.init_present_time_glacier, gdirs)
        rand_glac = partial(flowline.random_glacier_evolution, nyears=200)
        workflow.execute_entity_task(rand_glac, gdirs)

        for gd in gdirs:

            path = gd.get_filepath('past_model')

            # See that we are running ok
            with flowline.FileModel(path) as model:
                vol = model.volume_km3_ts()
                area = model.area_km2_ts()
                len = model.length_m_ts()

                self.assertTrue(np.all(np.isfinite(vol) & vol != 0.))
                self.assertTrue(np.all(np.isfinite(area) & area != 0.))
                self.assertTrue(np.all(np.isfinite(len) & len != 0.))