예제 #1
0
def hef_copy_gdir_base(request, test_dir):
    """same as hef_gdir but with another RGI ID (for workflow testing)
    """
    try:
        module = request.module
        border = module.DOM_BORDER if module.DOM_BORDER is not None else 40
        return init_hef(border=border, rgi_id='RGI50-11.99999')
    except AttributeError:
        return init_hef(rgi_id='RGI50-11.99999')
예제 #2
0
def hef_gdir_base(request, test_dir):
    """ Provides an initialized Hintereisferner glacier directory.
        As a module fixture, the initialization is run only once per test
        module that uses it.
        IMPORTANT: To preserve a constant starting condition, hef_gdir_base
        should almost never be directly injected into a test case. Test cases
        should use the below hef_gdir fixture to provide a directory that has
        been copied into an ephemeral case directory.
    """
    try:
        module = request.module
        border = module.DOM_BORDER if module.DOM_BORDER is not None else 40
        return init_hef(border=border)
    except AttributeError:
        return init_hef()
예제 #3
0
def test_raster():
    fig, ax = plt.subplots()
    gdir = init_hef()
    gis.gridded_attributes(gdir)
    graphics.plot_raster(gdir, var_name='aspect', cmap='twilight', ax=ax)
    fig.tight_layout()
    return fig
예제 #4
0
def test_downstream():
    fig, ax = plt.subplots()
    gdir = init_hef()
    graphics.plot_centerlines(gdir, ax=ax, add_downstream=True,
                              use_flowlines=True)
    fig.tight_layout()
    return fig
예제 #5
0
def test_thick_interp():
    fig, ax = plt.subplots()
    gdir = init_hef()
    graphics.plot_distributed_thickness(gdir, ax=ax,
                                        varname_suffix='_interp')
    fig.tight_layout()
    return fig
예제 #6
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()
예제 #7
0
def test_width_corrected():
    fig, ax = plt.subplots()
    gdir = init_hef()
    graphics.plot_catchment_width(gdir, ax=ax, corrected=True,
                                  add_intersects=True,
                                  add_touches=True)
    fig.tight_layout()
    return fig
예제 #8
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
예제 #9
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
예제 #10
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
예제 #11
0
    def test_glacier_characs(self):

        gdir = init_hef()

        df = utils.glacier_characteristics([gdir], path=False)
        assert len(df) == 1
        assert np.all(~df.isnull())
        df = df.iloc[0]
        np.testing.assert_allclose(df['dem_mean_elev'],
                                   df['flowline_mean_elev'], atol=5)
        np.testing.assert_allclose(df['tstar_avg_prcp'],
                                   2853, atol=5)
        np.testing.assert_allclose(df['tstar_avg_prcpsol_max_elev'],
                                   2811, atol=5)
예제 #12
0
    def test_glacier_characs(self):

        gdir = init_hef()

        df = utils.compile_glacier_statistics([gdir],
                                              path=False,
                                              add_climate_period=1985)
        assert len(df) == 1
        assert np.all(~df.isnull())
        df = df.iloc[0]
        np.testing.assert_allclose(df['dem_mean_elev'],
                                   df['flowline_mean_elev'],
                                   atol=5)
        np.testing.assert_allclose(df['tstar_avg_prcp'], 2853, atol=5)
        np.testing.assert_allclose(df['tstar_avg_prcpsol_max_elev'],
                                   2811,
                                   atol=5)
        np.testing.assert_allclose(df['1970-2000_avg_prcpsol_max_elev'],
                                   2811,
                                   atol=200)
예제 #13
0
def test_domain():
    fig, ax = plt.subplots()
    gdir = init_hef()
    graphics.plot_domain(gdir, ax=ax)
    fig.tight_layout()
    return fig
예제 #14
0
def test_catch_areas():
    fig, ax = plt.subplots()
    gdir = init_hef()
    graphics.plot_catchment_areas(gdir, ax=ax)
    fig.tight_layout()
    return fig
예제 #15
0
def setup():
    global gdir
    gdir = init_hef(border=80, logging_level='ERROR')
    teardown()
    gdir = tasks.copy_to_basedir(gdir, base_dir=testdir, setup='all')
예제 #16
0
def test_centerlines():
    fig, ax = plt.subplots()
    gdir = init_hef()
    graphics.plot_centerlines(gdir, ax=ax)
    fig.tight_layout()
    return fig
예제 #17
0
def setup():
    global gdir
    gdir = init_hef(border=80)
    teardown()
    gdir = tasks.copy_to_basedir(gdir, base_dir=testdir, setup='all')
    flowline.init_present_time_glacier(gdir)
예제 #18
0
def test_thick_interp():
    fig, ax = plt.subplots()
    gdir = init_hef()
    graphics.plot_distributed_thickness(gdir, ax=ax, how='per_interpolation')
    fig.tight_layout()
    return fig
예제 #19
0
def test_thick_alt():
    fig, ax = plt.subplots()
    gdir = init_hef()
    graphics.plot_distributed_thickness(gdir, ax=ax, how='per_altitude')
    fig.tight_layout()
    return fig
예제 #20
0
def setup():
    global gdir
    gdir = init_hef(border=80)
    teardown()
    gdir = tasks.copy_to_basedir(gdir, base_dir=testdir, setup='all')
예제 #21
0
def setup():
    global gdir
    gdir = init_hef(border=80)
    teardown()
    gdir = tasks.copy_to_basedir(gdir, base_dir=testdir, setup='all')