示例#1
0
    def test_init_present_time_glacier(self):

        gdirs = up_to_inversion()

        # Inversion Results
        cfg.PARAMS['invert_with_sliding'] = True
        cfg.PARAMS['optimize_thick'] = 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'])
        assert r1 < 0.1

        cfg.PARAMS['invert_with_sliding'] = False
        cfg.PARAMS['optimize_thick'] = 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'])
        assert r1 < 0.12

        # Init glacier
        d = gdirs[0].read_pickle('inversion_params')
        fs = d['fs']
        glen_a = d['glen_a']
        for gdir in gdirs:
            flowline.init_present_time_glacier(gdir)
            mb_mod = massbalance.ConstantMassBalance(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
            if gdir.rgi_id in df.index:
                gldf = df.loc[gdir.rgi_id]
                assert_allclose(gldf['oggm_volume_km3'], _vol, rtol=0.05)
                assert_allclose(gldf['ref_area_km2'], _area, rtol=0.05)
                maxo = max([fl.order for fl in model.fls])
                for fl in model.fls:
                    if len(model.fls) > 1:
                        if fl.order == (maxo - 1):
                            self.assertTrue(fl.flows_to is fls[-1])

        # Test the glacier charac
        dfc = utils.glacier_characteristics(gdirs)
        self.assertTrue(np.all(dfc.terminus_type == 'Land-terminating'))
        cc = dfc[['flowline_mean_elev',
                  'tstar_avg_temp_mean_elev']].corr().values[0, 1]
        assert cc < -0.8
        assert np.all(dfc.t_star > 1900)
示例#2
0
def time_ConstantMassBalance():

    mb_mod = massbalance.ConstantMassBalance(gdir, bias=0)
    for yr in years:
        mb_mod.get_annual_mb(heights, year=yr)
示例#3
0
    def test_varying_bias_mb_model(self, case_dir):

        cfg.initialize()
        cfg.PARAMS['prcp_scaling_factor'] = 1.6
        cfg.PATHS['working_dir'] = case_dir
        cfg.PARAMS['use_multiprocessing'] = True

        # Go - get the pre-processed glacier directories
        for rid in ['RGI60-03.04384', 'RGI60-11.00897', 'RGI60-16.02207']:
            gdirs = workflow.init_glacier_directories(
                [rid],
                from_prepro_level=5,
                prepro_base_url=prepro_base_url,
                prepro_border=80,
                prepro_rgi_version='62')
            workflow.execute_entity_task(parse_dt_per_dt, gdirs)

            gdir = gdirs[0]

            exp = 'netzero_py2020_fac1.0_decr0.3'
            magicc_file = magicc_dir + exp + '.nc'
            with xr.open_dataset(utils.file_downloader(magicc_file),
                                 decode_times=False) as ds:
                ds = ds.load()
            df = ds['ens_avg'].to_dataframe()
            dt_per_dt = gdir.get_diagnostics()['magicc_dt_per_dt']
            dp_per_dt = gdir.get_diagnostics()['magicc_dp_per_dt']

            fls = gdir.read_pickle('model_flowlines')

            y0 = 2014
            hs = 5

            mbc = massbalance.ConstantMassBalance(gdir, y0=y0, halfsize=hs)
            mb_ref = massbalance.PastMassBalance(gdir)
            years = np.arange(1980, 2020, dtype=np.float64)
            df['mb_ref'] = pd.Series(index=years,
                                     data=mb_ref.get_specific_mb(fls=fls,
                                                                 year=years))

            mb = MagiccMassBalance(gdir,
                                   y0=y0,
                                   halfsize=hs,
                                   magicc_ts=df['ens_avg'],
                                   dt_per_dt=dt_per_dt)
            df['mb'] = mb.get_specific_mb(fls=fls, year=df.index)

            mb = MagiccMassBalance(gdir,
                                   y0=y0,
                                   halfsize=hs,
                                   magicc_ts=df['ens_avg'],
                                   dt_per_dt=dt_per_dt,
                                   dp_per_dt=dp_per_dt)
            df['mb_wp'] = mb.get_specific_mb(fls=fls, year=df.index)

            mb = MagiccMassBalance(gdir,
                                   y0=y0,
                                   halfsize=hs,
                                   magicc_ts=df['ens_avg'])
            df['mb_nodt'] = mb.get_specific_mb(fls=fls, year=df.index)

            assert_allclose(df.loc[y0 - hs:y0 + hs]['mb'].mean(),
                            mbc.get_specific_mb(fls=fls),
                            rtol=5e-3)
            assert_allclose(df.loc[y0 - hs:y0 + hs]['mb_ref'].mean(),
                            df.loc[y0 - hs:y0 + hs]['mb'].mean(),
                            atol=1e-2)
            assert_allclose(df.loc[y0 - hs:y0 + hs]['mb_ref'].mean(),
                            df.loc[y0 - hs:y0 + hs]['mb_wp'].mean(),
                            atol=1e-2)
            assert_allclose(df.loc[y0 - hs:y0 + hs]['mb_ref'].mean(),
                            df.loc[y0 - hs:y0 + hs]['mb_nodt'].mean(),
                            atol=1e-2)
            assert_allclose(df[['ens_avg', 'mb']].corr().min().min(),
                            -1,
                            rtol=1e-2)
            assert_allclose(df[['ens_avg', 'mb_nodt']].corr().min().min(),
                            -1,
                            rtol=1e-2)
            assert_allclose(df[['mb_wp', 'mb']].corr().min().min(),
                            1,
                            rtol=1e-2)
            assert_allclose(df['mb'], df['mb_wp'], atol=115)

            if DO_PLOT:
                plt.figure()
                df[['mb_ref', 'mb', 'mb_wp',
                    'mb_nodt']].loc[2000:2025].plot(title=rid)
                plt.figure()
                df[['mb_ref', 'mb', 'mb_wp',
                    'mb_nodt']].loc[2000:].plot(title=rid)
                plt.show()