Exemplo n.º 1
0
    def test_tstar_mb(self):

        gdir = init_hef(border=DOM_BORDER)
        flowline.init_present_time_glacier(gdir)

        mb_mod = massbalance.TstarMassBalanceModel(gdir)

        ofl = gdir.read_pickle('inversion_flowlines', div_id=0)
        h = np.array([])
        w = np.array([])
        for fl in ofl:
            h = np.append(h, fl.surface_h)
            w = np.append(w, fl.widths)

        ombh = mb_mod.get_mb(h, None)
        otmb = np.sum(ombh * w)
        np.testing.assert_allclose(0., otmb, atol=0.26)

        mb_mod = massbalance.TodayMassBalanceModel(gdir)

        ofl = gdir.read_pickle('inversion_flowlines', div_id=0)
        h = np.array([])
        w = np.array([])
        for fl in ofl:
            h = np.append(h, fl.surface_h)
            w = np.append(w, fl.widths)

        mbh = mb_mod.get_mb(h, None)
        tmb = np.sum(mbh * w)
        self.assertTrue(tmb < otmb)

        if do_plot:  # pragma: no cover
            plt.plot(h, ombh, 'o')
            plt.plot(h, mbh, 'o')
            plt.show()
Exemplo n.º 2
0
    def test_equilibrium(self):

        #TODO: equilibrium test only working with parabolic bed
        _tmp = cfg.PARAMS['bed_shape']
        cfg.PARAMS['bed_shape'] = 'parabolic'
        flowline.init_present_time_glacier(self.gdir)
        cfg.PARAMS['bed_shape'] = _tmp

        mb_mod = massbalance.TstarMassBalanceModel(self.gdir)

        fls = self.gdir.read_pickle('model_flowlines')
        model = flowline.FluxBasedModel(fls,
                                        mb_model=mb_mod,
                                        y0=0.,
                                        fs=self.fs,
                                        glen_a=self.glen_a)

        ref_vol = model.volume_km3
        ref_area = model.area_km2
        ref_len = model.fls[-1].length_m

        np.testing.assert_allclose(ref_area, self.gdir.rgi_area_km2, rtol=0.03)

        model.run_until(50.)
        self.assertFalse(model.dt_warning)

        after_vol = model.volume_km3
        after_area = model.area_km2
        after_len = model.fls[-1].length_m

        np.testing.assert_allclose(ref_vol, after_vol, rtol=0.03)
        np.testing.assert_allclose(ref_area, after_area, rtol=0.03)
        np.testing.assert_allclose(ref_len, after_len, atol=200.01)
Exemplo n.º 3
0
    def test_invert_and_run(self):

        from oggm.core.models import flowline, massbalance

        glen_a = cfg.A * 2

        gdir = utils.GlacierDirectory(self.rgin, base_dir=self.testdir)
        gis.glacier_masks(gdir)
        centerlines.compute_centerlines(gdir)
        centerlines.compute_downstream_lines(gdir)
        geometry.initialize_flowlines(gdir)
        geometry.catchment_area(gdir)
        geometry.catchment_width_geom(gdir)
        geometry.catchment_width_correction(gdir)
        climate.local_mustar_apparent_mb(gdir, tstar=1975, bias=0.)
        inversion.prepare_for_inversion(gdir)
        v, a = inversion.invert_parabolic_bed(gdir, glen_a=glen_a)
        cfg.PARAMS['bed_shape'] = 'parabolic'
        flowline.init_present_time_glacier(gdir)
        mb_mod = massbalance.TstarMassBalanceModel(gdir)
        fls = gdir.read_pickle('model_flowlines')
        model = flowline.FluxBasedModel(fls,
                                        mb_model=mb_mod,
                                        y0=0.,
                                        fs=0,
                                        glen_a=glen_a)
        ref_vol = model.volume_m3
        model.run_until_equilibrium()
        after_vol = model.volume_m3
        np.testing.assert_allclose(ref_vol, after_vol, rtol=0.1)
Exemplo n.º 4
0
    def test_backwards_mb(self):

        gdir = init_hef(border=DOM_BORDER)
        flowline.init_present_time_glacier(gdir)

        mb_mod_ref = massbalance.TstarMassBalanceModel(gdir)
        mb_mod = massbalance.BackwardsMassBalanceModel(gdir, use_tstar=True)

        ofl = gdir.read_pickle('inversion_flowlines', div_id=0)
        h = np.array([])
        w = np.array([])
        for fl in ofl:
            h = np.append(h, fl.surface_h)
            w = np.append(w, fl.widths)

        ombh = mb_mod_ref.get_mb(h, None) * SEC_IN_YEAR
        mbh = mb_mod.get_mb(h, None) * SEC_IN_YEAR
        mb_mod.set_bias(100.)
        mbhb = mb_mod.get_mb(h, None) * SEC_IN_YEAR

        np.testing.assert_allclose(ombh, mbh, rtol=0.001)
        self.assertTrue(np.mean(mbhb) > np.mean(mbh))

        if do_plot:  # pragma: no cover
            plt.plot(h, ombh, 'o')
            plt.plot(h, mbh, 'x')
            plt.plot(h, mbhb, 'x')
            plt.show()

        mb_mod_ref = massbalance.TodayMassBalanceModel(gdir)
        mb_mod = massbalance.BackwardsMassBalanceModel(gdir)

        ofl = gdir.read_pickle('inversion_flowlines', div_id=0)
        h = np.array([])
        w = np.array([])
        for fl in ofl:
            h = np.append(h, fl.surface_h)
            w = np.append(w, fl.widths)

        ombh = mb_mod_ref.get_mb(h, None) * SEC_IN_YEAR
        mbh = mb_mod.get_mb(h, None) * SEC_IN_YEAR
        mb_mod.set_bias(-100.)
        mbhb = mb_mod.get_mb(h, None) * SEC_IN_YEAR

        np.testing.assert_allclose(ombh, mbh, rtol=0.005)
        self.assertTrue(np.mean(mbhb) < np.mean(mbh))

        if do_plot:  # pragma: no cover
            plt.plot(h, ombh, 'o')
            plt.plot(h, mbh, 'x')
            plt.plot(h, mbhb, 'x')
            plt.show()
Exemplo n.º 5
0
    def test_init_present_time_glacier(self):

        gdirs = up_to_inversion()

        # Inversion Results
        cfg.PARAMS['invert_with_sliding'] = True
        workflow.inversion_tasks(gdirs)

        fpath = os.path.join(cfg.PATHS['working_dir'],
                             'inversion_optim_results.csv')
        df = pd.read_csv(fpath, index_col=0)
        r1 = rmsd(df['ref_volume_km3'], df['oggm_volume_km3'])
        r2 = rmsd(df['ref_volume_km3'], df['vas_volume_km3'])
        self.assertTrue(r1 < r2)

        cfg.PARAMS['invert_with_sliding'] = False
        workflow.inversion_tasks(gdirs)

        fpath = os.path.join(cfg.PATHS['working_dir'],
                             'inversion_optim_results.csv')
        df = pd.read_csv(fpath, index_col=0)
        r1 = rmsd(df['ref_volume_km3'], df['oggm_volume_km3'])
        r2 = rmsd(df['ref_volume_km3'], df['vas_volume_km3'])
        self.assertTrue(r1 < r2)

        # Init glacier
        d = gdirs[0].read_pickle('inversion_params')
        fs = d['fs']
        glen_a = d['glen_a']
        maxs = cfg.PARAMS['max_shape_param']
        for gdir in gdirs:
            flowline.init_present_time_glacier(gdir)
            mb_mod = massbalance.TstarMassBalanceModel(gdir)
            fls = gdir.read_pickle('model_flowlines')
            model = flowline.FluxBasedModel(fls,
                                            mb_model=mb_mod,
                                            y0=0.,
                                            fs=fs,
                                            glen_a=glen_a)
            _vol = model.volume_km3
            _area = model.area_km2
            gldf = df.loc[gdir.rgi_id]
            assert_allclose(gldf['oggm_volume_km3'], _vol, rtol=0.01)
            assert_allclose(gldf['ref_area_km2'], _area, rtol=0.03)
            maxo = max([fl.order for fl in model.fls])
            for fl in model.fls:
                self.assertTrue(np.all(fl.bed_shape > 0))
                self.assertTrue(np.all(fl.bed_shape <= maxs))
                if len(model.fls) > 1:
                    if fl.order == (maxo - 1):
                        self.assertTrue(fl.flows_to is fls[-1])