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

    from oggm.tests.funcs import init_hef
    from oggm.core import flowline
    import pandas as pd
    import matplotlib.pyplot as plt
    do_plot = True

    gdir = init_hef(border=80, invert_with_sliding=False)

    flowline.init_present_time_glacier(gdir)
    glacier = gdir.read_pickle('model_flowlines')
    df = pd.read_csv(utils.get_demo_file('hef_lengths.csv'), index_col=0)
    df.columns = ['Leclercq']
    df = df.loc[1950:]

    vol_ref = flowline.FlowlineModel(glacier).volume_km3

    init_bias = 94.  # so that "went too far" comes once on travis
    rtol = 0.005

    flowline.iterative_initial_glacier_search(gdir,
                                              y0=df.index[0],
                                              init_bias=init_bias,
                                              rtol=rtol,
                                              write_steps=True)

    past_model = flowline.FileModel(gdir.get_filepath('model_run'))

    vol_start = past_model.volume_km3
    bef_fls = copy.deepcopy(past_model.fls)

    mylen = past_model.length_m_ts()
    df['oggm'] = mylen[12::12].values
    df = df - df.iloc[-1]

    past_model.run_until(2003)

    vol_end = past_model.volume_km3
    np.testing.assert_allclose(vol_ref, vol_end, rtol=0.05)

    rmsd = utils.rmsd(df.Leclercq, df.oggm)
    self.assertTrue(rmsd < 1000.)

    if do_plot:  # pragma: no cover
        df.plot()
        plt.ylabel('Glacier length (relative to 2003)')
        plt.show()
        fig = plt.figure()
        lab = 'ref (vol={:.2f}km3)'.format(vol_ref)
        plt.plot(glacier[-1].surface_h, 'k', label=lab)
        lab = 'oggm start (vol={:.2f}km3)'.format(vol_start)
        plt.plot(bef_fls[-1].surface_h, 'b', label=lab)
        lab = 'oggm end (vol={:.2f}km3)'.format(vol_end)
        plt.plot(past_model.fls[-1].surface_h, 'r', label=lab)

        plt.plot(glacier[-1].bed_h, 'gray', linewidth=2)
        plt.legend(loc='best')
        plt.show()
Exemplo n.º 2
0
def test_modelsection_withtrib():

    gdir = init_hef()
    flowline.init_present_time_glacier(gdir)
    fls = gdir.read_pickle('model_flowlines')
    model = flowline.FlowlineModel(fls)

    fig = plt.figure(figsize=(14, 10))
    graphics.plot_modeloutput_section_withtrib(fig=fig, model=model)
    return fig
Exemplo n.º 3
0
def test_modeloutput_map():

    gdir = init_hef()
    flowline.init_present_time_glacier(gdir)
    fls = gdir.read_pickle('model_flowlines')
    model = flowline.FlowlineModel(fls)

    fig, ax = plt.subplots()
    graphics.plot_modeloutput_map(gdir, ax=ax, model=model)
    fig.tight_layout()
    return fig
Exemplo n.º 4
0
def test_modelsection():

    gdir = init_hef()
    flowline.init_present_time_glacier(gdir)
    fls = gdir.read_pickle('model_flowlines')
    model = flowline.FlowlineModel(fls)

    fig = plt.figure(figsize=(12, 6))
    ax = fig.add_axes([0.07, 0.08, 0.7, 0.84])
    graphics.plot_modeloutput_section(ax=ax, model=model)
    return fig
Exemplo n.º 5
0
def test_chhota_shigri():

    testdir = os.path.join(get_test_dir(), 'tmp_chhota')
    utils.mkdir(testdir, reset=True)

    # Init
    cfg.initialize()
    cfg.PATHS['dem_file'] = get_demo_file('dem_chhota_shigri.tif')
    cfg.PARAMS['border'] = 80
    cfg.PARAMS['use_intersects'] = False
    cfg.PATHS['working_dir'] = testdir

    hef_file = get_demo_file('divides_RGI50-14.15990.shp')
    df = gpd.read_file(hef_file)
    df['Area'] = df.Area * 1e-6  # cause it was in m2
    df['RGIId'] = ['RGI50-14.15990' + d for d in ['_d01', '_d02']]

    gdirs = workflow.init_glacier_regions(df)
    workflow.gis_prepro_tasks(gdirs)
    for gdir in gdirs:
        climate.apparent_mb_from_linear_mb(gdir)
    workflow.execute_entity_task(inversion.prepare_for_inversion, gdirs)
    workflow.execute_entity_task(inversion.volume_inversion,
                                 gdirs,
                                 glen_a=cfg.A,
                                 fs=0)
    workflow.execute_entity_task(inversion.filter_inversion_output, gdirs)
    workflow.execute_entity_task(flowline.init_present_time_glacier, gdirs)

    models = []
    for gdir in gdirs:
        flowline.init_present_time_glacier(gdir)
        fls = gdir.read_pickle('model_flowlines')
        models.append(flowline.FlowlineModel(fls))

    fig, ax = plt.subplots()
    graphics.plot_modeloutput_map(gdirs, ax=ax, model=models)
    fig.tight_layout()
    shutil.rmtree(testdir)
    return fig
Exemplo n.º 6
0
def test_multiple_models():

    # test directory
    testdir = os.path.join(get_test_dir(), 'tmp_mdir')
    utils.mkdir(testdir, reset=True)

    # Init
    cfg.initialize()
    cfg.set_intersects_db(get_demo_file('rgi_intersect_oetztal.shp'))
    cfg.PATHS['dem_file'] = get_demo_file('hef_srtm.tif')
    cfg.PATHS['climate_file'] = get_demo_file('histalp_merged_hef.nc')
    cfg.PATHS['working_dir'] = testdir
    cfg.PARAMS['baseline_climate'] = 'CUSTOM'
    cfg.PARAMS['trapezoid_lambdas'] = 1
    cfg.PARAMS['border'] = 40
    apply_test_ref_tstars()

    # Get the RGI ID
    hef_rgi = gpd.read_file(get_demo_file('divides_hef.shp'))
    hef_rgi.loc[0, 'RGIId'] = 'RGI50-11.00897'

    gdirs = workflow.init_glacier_directories(hef_rgi)
    workflow.gis_prepro_tasks(gdirs)
    workflow.climate_tasks(gdirs)
    workflow.inversion_tasks(gdirs)

    models = []
    for gdir in gdirs:
        flowline.init_present_time_glacier(gdir)
        fls = gdir.read_pickle('model_flowlines')
        models.append(flowline.FlowlineModel(fls))

    fig, ax = plt.subplots()
    graphics.plot_modeloutput_map(gdirs, ax=ax, model=models)
    fig.tight_layout()

    shutil.rmtree(testdir)
    return fig
Exemplo n.º 7
0
def test_multiple_models():

    # test directory
    testdir = os.path.join(get_test_dir(), 'tmp_mdir')
    utils.mkdir(testdir, reset=True)

    # Init
    cfg.initialize()
    cfg.PATHS['dem_file'] = get_demo_file('hef_srtm.tif')
    cfg.PARAMS['optimize_inversion_params'] = True
    cfg.PATHS['climate_file'] = get_demo_file('histalp_merged_hef.nc')
    cfg.PATHS['working_dir'] = testdir
    cfg.PARAMS['run_mb_calibration'] = True
    cfg.PARAMS['border'] = 40

    # Get the RGI ID
    hef_rgi = gpd.read_file(get_demo_file('divides_hef.shp'))
    hef_rgi.loc[0, 'RGIId'] = 'RGI50-11.00897'

    gdirs = workflow.init_glacier_regions(hef_rgi)
    workflow.gis_prepro_tasks(gdirs)
    workflow.climate_tasks(gdirs)
    workflow.inversion_tasks(gdirs)

    models = []
    for gdir in gdirs:
        flowline.init_present_time_glacier(gdir)
        fls = gdir.read_pickle('model_flowlines')
        models.append(flowline.FlowlineModel(fls))

    fig, ax = plt.subplots()
    graphics.plot_modeloutput_map(gdirs, ax=ax, model=models)
    fig.tight_layout()

    shutil.rmtree(testdir)
    return fig
Exemplo n.º 8
0
    fn = bname + '2_cls.png'
    if not os.path.exists(fn):
        graphics.plot_centerlines(gd, title_comment=demsource, reset=True)
        plt.savefig(fn)
        plt.close()

    fn = bname + '3_fls.png'
    if not os.path.exists(fn):
        graphics.plot_centerlines(gd, title_comment=demsource,
                                  use_flowlines=True, add_downstream=True,
                                  reset = True)
        plt.savefig(fn)
        plt.close()

    fn = bname + '4_widths.png'
    if not os.path.exists(fn):
        graphics.plot_catchment_width(gd, corrected=True,
                                      add_intersects=True,
                                      add_touches=True,
                                      reset=True)
        plt.savefig(fn)
        plt.close()

    fn = bname + '5_thick.png'
    if not os.path.exists(fn):
        fls = gd.read_pickle('model_flowlines')
        model = flowline.FlowlineModel(fls)
        graphics.plot_modeloutput_map(gd,  model=model, reset=True)
        plt.savefig(fn)
        plt.close()