示例#1
0
def test_plot_model():

    gdir = init_hef()
    flowline.init_present_time_glacier(gdir)
    model = flowline.FlowlineModel(gdir.read_pickle('model_flowlines'))
    graphics.plot_modeloutput_section(gdir, model=model)
    graphics.plot_modeloutput_map(gdir, model=model)
示例#2
0
def test_plot_region_model():

    gdirs = random_for_plot()

    dfc = utils.compile_task_log(gdirs, task_names=['run_random_climate_plot'])
    assert np.all(dfc['run_random_climate_plot'] == 'SUCCESS')

    # We prepare for the plot, which needs our own map to proceed.
    # Lets do a local mercator grid
    g = salem.mercator_grid(center_ll=(10.86, 46.85), extent=(27000, 21000))
    # And a map accordingly
    sm = salem.Map(g, countries=False)
    sm.set_topography(get_demo_file('srtm_oetztal.tif'))

    # Give this to the plot function
    fig, ax = plt.subplots()
    graphics.plot_modeloutput_map(gdirs,
                                  smap=sm,
                                  ax=ax,
                                  filesuffix='_plot',
                                  vmax=250,
                                  modelyr=10,
                                  linewidth=1.5)

    fig.tight_layout()
    return fig
示例#3
0
def test_coxe():

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

    # Init
    cfg.initialize()
    cfg.PARAMS['use_intersects'] = False
    cfg.PATHS['dem_file'] = get_demo_file('dem_RGI50-01.10299.tif')
    cfg.PARAMS['border'] = 40
    cfg.PARAMS['clip_tidewater_border'] = False
    cfg.PARAMS['use_multiple_flowlines'] = False
    cfg.PARAMS['use_kcalving_for_inversion'] = True
    cfg.PARAMS['use_kcalving_for_run'] = True
    cfg.PARAMS['trapezoid_lambdas'] = 1

    hef_file = get_demo_file('rgi_RGI50-01.10299.shp')
    entity = gpd.read_file(hef_file).iloc[0]

    gdir = oggm.GlacierDirectory(entity, base_dir=testdir, reset=True)
    gis.define_glacier_region(gdir)
    gis.glacier_masks(gdir)
    centerlines.compute_centerlines(gdir)
    centerlines.initialize_flowlines(gdir)
    centerlines.compute_downstream_line(gdir)
    centerlines.compute_downstream_bedshape(gdir)
    centerlines.catchment_area(gdir)
    centerlines.catchment_intersections(gdir)
    centerlines.catchment_width_geom(gdir)
    centerlines.catchment_width_correction(gdir)
    climate.apparent_mb_from_linear_mb(gdir)
    inversion.prepare_for_inversion(gdir)
    inversion.mass_conservation_inversion(gdir)
    inversion.filter_inversion_output(gdir)

    flowline.init_present_time_glacier(gdir)

    fls = gdir.read_pickle('model_flowlines')

    p = gdir.read_pickle('linear_mb_params')
    mb_mod = massbalance.LinearMassBalance(ela_h=p['ela_h'], grad=p['grad'])
    mb_mod.temp_bias = -0.3
    model = flowline.FluxBasedModel(fls,
                                    mb_model=mb_mod,
                                    y0=0,
                                    inplace=True,
                                    is_tidewater=True)

    # run
    model.run_until(200)
    assert model.calving_m3_since_y0 > 0

    fig, ax = plt.subplots()
    graphics.plot_modeloutput_map(gdir, ax=ax, model=model)
    fig.tight_layout()
    shutil.rmtree(testdir)
    return fig
示例#4
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
示例#5
0
def plot_largest_glacier(gdir, candidates_df, ys):
    plot_dir = '/home/juliaeis/Dokumente/OGGM/work_dir/find_initial_state/past_state_information/plots'
    candidates_df = candidates_df[candidates_df['objective'] <= 100]
    largest = int(candidates_df.model_t0.apply(lambda x: x.volume_m3).idxmax())
    model = candidates_df.loc[largest, 'model_t0']
    model.reset_y0(1850)
    graphics.plot_modeloutput_map([gdir],
                                  model=candidates_df.loc[largest, 'model_t0'])
    plt.savefig(os.path.join(
        plot_dir, 'largest_' + str(ys) + '_' + str(gdir.rgi_id) + '.png'),
                dpi=200)
    plt.show()
示例#6
0
def test_coxe():

    testdir = os.path.join(cfg.PATHS['test_dir'], 'tmp_coxe')
    utils.mkdir(testdir)

    # Init
    cfg.initialize()
    cfg.PATHS['dem_file'] = get_demo_file('dem_RGI50-01.10299.tif')
    cfg.PARAMS['border'] = 40
    cfg.PARAMS['use_multiple_flowlines'] = False

    hef_file = get_demo_file('rgi_RGI50-01.10299.shp')
    entity = gpd.GeoDataFrame.from_file(hef_file).iloc[0]

    gdir = oggm.GlacierDirectory(entity, base_dir=testdir, reset=True)
    gis.define_glacier_region(gdir, entity=entity)
    gis.glacier_masks(gdir)
    centerlines.compute_centerlines(gdir)
    centerlines.compute_downstream_lines(gdir)
    geometry.initialize_flowlines(gdir)

    # Just check if the rest runs
    centerlines.compute_downstream_bedshape(gdir)
    geometry.catchment_area(gdir)
    geometry.catchment_intersections(gdir)
    geometry.catchment_width_geom(gdir)
    geometry.catchment_width_correction(gdir)
    climate.apparent_mb_from_linear_mb(gdir)
    inversion.prepare_for_inversion(gdir)
    inversion.volume_inversion(gdir, use_cfg_params={'glen_a': cfg.A, 'fs': 0})
    inversion.filter_inversion_output(gdir)

    flowline.init_present_time_glacier(gdir)

    fls = gdir.read_pickle('model_flowlines')

    p = gdir.read_pickle('linear_mb_params')
    mb_mod = massbalance.LinearMassBalanceModel(ela_h=p['ela_h'],
                                                grad=p['grad'])
    mb_mod.temp_bias = -0.3
    model = flowline.FluxBasedModel(fls,
                                    mb_model=mb_mod,
                                    y0=0,
                                    is_tidewater=True)

    # run
    model.run_until(200)
    assert model.calving_m3_since_y0 > 0

    fig, ax = plt.subplots()
    graphics.plot_modeloutput_map(gdir, ax=ax, model=model)
    fig.tight_layout()
    return fig
示例#7
0
def test_chhota_shigri():

    testdir = os.path.join(cfg.PATHS['test_dir'], 'tmp_chhota')
    utils.mkdir(testdir)

    # Init
    cfg.initialize()
    cfg.PATHS['dem_file'] = get_demo_file('dem_chhota_shigri.tif')
    cfg.PARAMS['border'] = 60
    cfg.set_divides_db(get_demo_file('divides_RGI50-14.15990.shp'))

    hef_file = get_demo_file('RGI50-14.15990.shp')
    entity = gpd.GeoDataFrame.from_file(hef_file).iloc[0]

    gdir = oggm.GlacierDirectory(entity, base_dir=testdir)
    gis.define_glacier_region(gdir, entity=entity)
    gis.glacier_masks(gdir)
    centerlines.compute_centerlines(gdir)
    centerlines.compute_downstream_lines(gdir)
    geometry.initialize_flowlines(gdir)

    # We should have two groups
    lines = gdir.read_pickle('downstream_lines', div_id=0)
    assert len(np.unique(lines.group)) == 2

    # Just check if the rest runs
    centerlines.compute_downstream_bedshape(gdir)
    geometry.catchment_area(gdir)
    geometry.catchment_intersections(gdir)
    geometry.catchment_width_geom(gdir)
    geometry.catchment_width_correction(gdir)
    climate.apparent_mb_from_linear_mb(gdir)
    inversion.prepare_for_inversion(gdir)
    inversion.volume_inversion(gdir, use_cfg_params={'glen_a': cfg.A, 'fs': 0})
    inversion.filter_inversion_output(gdir)

    flowline.init_present_time_glacier(gdir)

    fls = gdir.read_pickle('model_flowlines')
    for fl in fls:
        fl.thick = np.clip(fl.thick, 100, 1000)
    model = flowline.FlowlineModel(fls)

    fig, ax = plt.subplots()
    graphics.plot_modeloutput_map(gdir, ax=ax, model=model)
    fig.tight_layout()
    return fig
示例#8
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
示例#9
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
示例#10
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
示例#11
0
letkm = dict(color='black',
             ha='left',
             va='top',
             fontsize=14,
             bbox=dict(facecolor='white', edgecolor='black'))
llkw = {'interval': 0}

fp = gdir.get_filepath('model_run', filesuffix='_2000_def')
model = FileModel(fp)
model.run_until(800)
ax = axs[3]
graphics.plot_modeloutput_map(gdir,
                              model=model,
                              ax=ax,
                              title='',
                              lonlat_contours_kwargs=llkw,
                              cbar_ax=ax.cax,
                              linewidth=1.5,
                              add_scalebar=False,
                              vmax=300)
ax.text(tx, ty, 'c: [1985-2015]', transform=ax.transAxes, **letkm)

fp = gdir.get_filepath('model_run', filesuffix='_1920_def')
model = FileModel(fp)
model.run_until(800)
ax = axs[2]
graphics.plot_modeloutput_map(gdir,
                              model=model,
                              ax=ax,
                              title='',
                              lonlat_contours_kwargs=llkw,
示例#12
0
                              lonlat_contours_kwargs=llkw,
                              add_scalebar=False)
axs[3].text(xt, yt, 'd', **letkm)

f.delaxes(axs[3].cax)

graphics.plot_inversion(gdir,
                        ax=axs[4],
                        title='',
                        linewidth=1.5,
                        add_colorbar=False,
                        vmax=650,
                        lonlat_contours_kwargs=llkw,
                        add_scalebar=False)
axs[4].text(xt, yt, 'e', **letkm)

graphics.plot_modeloutput_map(gdir,
                              ax=axs[5],
                              modelyr=120,
                              title='',
                              linewidth=1.5,
                              add_colorbar=True,
                              cbar_ax=axs[5].cax,
                              vmax=650,
                              lonlat_contours_kwargs=llkw,
                              add_scalebar=False)
axs[5].text(xt, yt, 'f', **letkm)

# plt.tight_layout()
plt.savefig(PLOT_DIR + 'workflow_tas.pdf', dpi=150, bbox_inches='tight')
示例#13
0
cfg.PATHS['working_dir'] = WORKING_DIR

# Initialize from existing directories
# (note that we don't need the RGI file:
# this can be slow sometimes but it works)
gdirs = workflow.init_glacier_regions()

# Plot: we will show the state of all four glaciers at the beginning and at
# the end of the commitment simulation
f, axs = plt.subplots(2, 3, figsize=(14, 6))

for i in range(3):
    ax = axs[0, i]
    gdir = gdirs[i]
    # Use the model ouptut file to simulate the glacier evolution
    model = flowline.FileModel(
        gdir.get_filepath('model_run', filesuffix='_commitment'))
    graphics.plot_modeloutput_map(gdirs[i],
                                  model=model,
                                  ax=ax,
                                  lonlat_contours_kwargs={'interval': 0})
    ax = axs[1, i]
    model.run_until(200)
    graphics.plot_modeloutput_map(gdirs[i],
                                  model=model,
                                  ax=ax,
                                  lonlat_contours_kwargs={'interval': 0})

plt.tight_layout()
plt.show()
示例#14
0
    if not os.path.exists(fn):
        graphics.plot_centerlines(gd, title_comment=demsource)
        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)
        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)
        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)
        plt.savefig(fn)
        plt.close()
示例#15
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()
示例#16
0
f, axs = plt.subplots(2, 1, figsize=(7*f, 10*f))

graphics.plot_domain(gdirs, ax=axs[0], smap=sm)


sm.set_data()
sm.set_lonlat_contours()
sm.set_geometry()
sm.set_text()
graphics.plot_inversion(gdirs, ax=axs[1], smap=sm,
                        linewidth=1, add_scalebar=False,
                              title='', vmax=250)
plt.tight_layout()
plt.savefig(PLOT_DIR + 'iceland.pdf', dpi=150, bbox_inches='tight')
exit(0)

lw = 1
graphics.plot_modeloutput_map(gdirs, smap=sm, filesuffix='_tbias',
                              modelyr=0, linewidth=lw)
plt.savefig('/home/mowglie/yr000.png', dpi=150)
plt.figure()
sm.set_geometry()
graphics.plot_modeloutput_map(gdirs, smap=sm, filesuffix='_tbias',
                              modelyr=150, linewidth=lw)
plt.savefig('/home/mowglie/yr150.png', dpi=150)
plt.figure()
sm.set_geometry()
graphics.plot_modeloutput_map(gdirs, smap=sm, filesuffix='_tbias',
                              modelyr=300, linewidth=lw)
plt.savefig('/home/mowglie/yr300.png', dpi=150)