Exemple #1
0
def test_multiple_inversion():

    # test directory
    testdir = os.path.join(get_test_dir(), 'tmp_mdir')
    if not os.path.exists(testdir):
        os.makedirs(testdir)

    # 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.PARAMS['border'] = 40
    cfg.PARAMS['run_mb_calibration'] = True
    cfg.PARAMS['baseline_climate'] = 'CUSTOM'
    cfg.PATHS['working_dir'] = testdir

    # 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)

    fig, ax = plt.subplots()
    graphics.plot_inversion(gdirs, ax=ax)
    fig.tight_layout()
    shutil.rmtree(testdir)
    return fig
Exemple #2
0
    def test_workflow(self):

        # This is a check that the inversion workflow works fine

        # Download the RGI file for the run
        # Make a new dataframe of those
        rgidf = gpd.read_file(get_demo_file('SouthGlacier.shp'))

        # Go - initialize working directories
        gdirs = workflow.init_glacier_directories(rgidf)

        # Preprocessing tasks
        task_list = [
            tasks.define_glacier_region,
            tasks.glacier_masks,
            tasks.compute_centerlines,
            tasks.initialize_flowlines,
            tasks.catchment_area,
            tasks.catchment_intersections,
            tasks.catchment_width_geom,
            tasks.catchment_width_correction,
            tasks.compute_downstream_line,
            tasks.compute_downstream_bedshape,
        ]
        for task in task_list:
            execute_entity_task(task, gdirs)

        execute_entity_task(tasks.process_cru_data,
                            gdirs,
                            tmp_file=self.tf,
                            pre_file=self.pf)
        execute_entity_task(tasks.local_t_star, gdirs)
        execute_entity_task(tasks.mu_star_calibration, gdirs)

        # Inversion tasks
        execute_entity_task(tasks.prepare_for_inversion, gdirs)
        # We use the default parameters for this run
        execute_entity_task(tasks.mass_conservation_inversion, gdirs)
        execute_entity_task(tasks.filter_inversion_output, gdirs)

        df = utils.compile_glacier_statistics(gdirs)
        df['inv_thickness_m'] = df['inv_volume_km3'] / df['rgi_area_km2'] * 1e3
        assert df.inv_thickness_m[0] < 100

        df = utils.compile_fixed_geometry_mass_balance(gdirs)
        assert len(df) > 100

        if do_plot:
            import matplotlib.pyplot as plt
            from oggm.graphics import plot_inversion
            plot_inversion(gdirs)
            plt.show()
Exemple #3
0
def test_single_flowline_glacier_directory():

    rid = 'RGI60-15.03473'
    gdir = oggm_compat.single_flowline_glacier_directory(rid)
    assert gdir.rgi_area_km2 == 61.054

    if do_plot:
        from oggm import graphics
        import matplotlib.pyplot as plt
        f, (ax1, ax2) = plt.subplots(1, 2)
        graphics.plot_googlemap(gdir, ax=ax1)
        graphics.plot_inversion(gdir, ax=ax2)
        plt.show()
Exemple #4
0
def test_plot_region_inversion():

    gdirs = up_to_inversion()

    # 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_inversion(gdirs, smap=sm, ax=ax, linewidth=1.5, vmax=250)

    fig.tight_layout()
    return fig
Exemple #5
0
def test_plot_region_inversion():

    gdirs = up_to_inversion()

    # 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_inversion(gdirs, smap=sm, ax=ax, linewidth=1.5, vmax=250)

    fig.tight_layout()
    return fig
Exemple #6
0
    def test_workflow(self):

        # This is a check that the inversion workflow works fine

        # Download the RGI file for the run
        # Make a new dataframe of those
        rgidf = gpd.read_file(get_demo_file('SouthGlacier.shp'))

        # Go - initialize working directories
        gdirs = workflow.init_glacier_regions(rgidf)

        # Preprocessing tasks
        task_list = [
            tasks.glacier_masks,
            tasks.compute_centerlines,
            tasks.initialize_flowlines,
            tasks.catchment_area,
            tasks.catchment_intersections,
            tasks.catchment_width_geom,
            tasks.catchment_width_correction,
        ]
        for task in task_list:
            execute_entity_task(task, gdirs)

        # Climate tasks -- only data IO and tstar interpolation!
        execute_entity_task(tasks.process_cru_data, gdirs)
        tasks.distribute_t_stars(gdirs)
        execute_entity_task(tasks.apparent_mb, gdirs)

        # Inversion tasks
        execute_entity_task(tasks.prepare_for_inversion, gdirs)
        # We use the default parameters for this run
        execute_entity_task(tasks.volume_inversion, gdirs, glen_a=cfg.A, fs=0)
        execute_entity_task(tasks.filter_inversion_output, gdirs)

        df = utils.glacier_characteristics(gdirs)
        assert df.inv_thickness_m[0] < 100

        if do_plot:
            import matplotlib.pyplot as plt
            from oggm.graphics import plot_inversion
            plot_inversion(gdirs)
            plt.show()
Exemple #7
0
    def test_workflow(self):

        # This is a check that the inversion workflow works fine

        # Download the RGI file for the run
        # Make a new dataframe of those
        rgidf = gpd.read_file(get_demo_file('SouthGlacier.shp'))

        # Go - initialize working directories
        gdirs = workflow.init_glacier_regions(rgidf)

        # Preprocessing tasks
        task_list = [
            tasks.glacier_masks,
            tasks.compute_centerlines,
            tasks.initialize_flowlines,
            tasks.catchment_area,
            tasks.catchment_intersections,
            tasks.catchment_width_geom,
            tasks.catchment_width_correction,
            tasks.process_cru_data,
            tasks.local_t_star,
            tasks.mu_star_calibration,
        ]
        for task in task_list:
            execute_entity_task(task, gdirs)

        # Inversion tasks
        execute_entity_task(tasks.prepare_for_inversion, gdirs)
        # We use the default parameters for this run
        execute_entity_task(tasks.mass_conservation_inversion, gdirs)
        execute_entity_task(tasks.filter_inversion_output, gdirs)

        df = utils.compile_glacier_statistics(gdirs)
        assert df.inv_thickness_m[0] < 100

        if do_plot:
            import matplotlib.pyplot as plt
            from oggm.graphics import plot_inversion
            plot_inversion(gdirs)
            plt.show()
Exemple #8
0
graphics.plot_catchment_width(gdir,
                              ax=axs[3],
                              title='',
                              corrected=True,
                              add_colorbar=False,
                              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)
Exemple #9
0
    # For final inversions - no calving
    gdirs = [gd for gd in gdirs if 'I:' in gd.name]
    col_gdir = [gd for gd in gdirs if 'Columbia' in gd.name]

    cfg.PARAMS['calving_rate'] = 0
    addt = ' no calving'
    tasks.distribute_t_stars(col_gdir)
    execute_entity_task(tasks.prepare_for_inversion, col_gdir)
    execute_entity_task(tasks.volume_inversion, gdirs)
    pdir = os.path.join(PLOTS_DIR, 'out_raw') + '/'
    if not os.path.exists(pdir):
        os.mkdir(pdir)
    for gd in gdirs:
        _addt = addt if 'Columbia' in gd.name else ''
        graphics.plot_inversion(gd, add_title_comment=_addt)
        plt.savefig(pdir + gd.name + '_' + gd.rgi_id + '_inv.png')
        plt.close()

    # V1
    distrib = partial(distribute_thickness, how='per_altitude',
                      add_slope=True,
                      smooth=True)
    execute_entity_task(distrib, gdirs)
    pdir = os.path.join(PLOTS_DIR, 'out_dis') + '/'
    if not os.path.exists(pdir):
        os.mkdir(pdir)
    for gd in gdirs:
        itmix.write_itmix_ascii(gd, 1)
        graphics.plot_distributed_thickness(gd)
        plt.savefig(pdir + gd.name + '_' + gd.rgi_id + '_d1.png')
Exemple #10
0
# While the above should work always, this here is no piece of fun
execute_entity_task(tasks.random_glacier_evolution, gdirs)

# Write out glacier statistics
df = utils.glacier_characteristics(gdirs)
fpath = os.path.join(cfg.PATHS['working_dir'], 'glacier_char.csv')
df.to_csv(fpath)

# Plots (if you want)
if PLOTS_DIR == '':
    exit()

utils.mkdir(PLOTS_DIR)
for gd in gdirs:
    bname = os.path.join(PLOTS_DIR, gd.name + '_' + gd.rgi_id + '_')
    graphics.plot_googlemap(gd)
    plt.savefig(bname + 'ggl.png')
    plt.close()
    graphics.plot_domain(gd)
    plt.savefig(bname + 'dom.png')
    plt.close()
    graphics.plot_centerlines(gd)
    plt.savefig(bname + 'cls.png')
    plt.close()
    graphics.plot_catchment_width(gd, corrected=True)
    plt.savefig(bname + 'w.png')
    plt.close()
    graphics.plot_inversion(gd)
    plt.savefig(bname + 'inv.png')
    plt.close()
Exemple #11
0
def test_inversion():
    fig, ax = plt.subplots()
    gdir = init_hef()
    graphics.plot_inversion(gdir, ax=ax)
    fig.tight_layout()
    return fig
Exemple #12
0
def test_inversion():
    gdir = init_hef()
    graphics.plot_inversion(gdir)
Exemple #13
0
def test_inversion():

    gdir = init_hef()
    graphics.plot_inversion(gdir)
                cbar_location="left",
                cbar_mode="each",
                cbar_size="7%",
                cbar_pad=1.5,
                aspect=True)


graphics.plot_centerlines(gdirs[1], ax=grid2[0], title='', add_colorbar=True,
                          lonlat_contours_kwargs=llkw,
                          cbar_ax=grid2[0].cax, add_scalebar=True)

grid2[0].text(xt, yt, 'b', **letkm)


graphics.plot_inversion(gdirs[1], ax=grid2[1], title='', add_colorbar=True,
                        linewidth=2, lonlat_contours_kwargs=llkw,
                        cbar_ax=grid2[1].cax,
                        add_scalebar=False)

grid2[1].text(xt, yt, 'd', **letkm)




grid2.axes_all

plt.tight_layout()
#plt.show()
plt.savefig(os.path.join(plot_path,'workflow_together.pdf'),
                         dpi=150, bbox_inches='tight')
Exemple #15
0
                                title='',
                                linewidth=2,
                                add_colorbar=False,
                                vmax=1600,
                                lonlat_contours_kwargs=llkw,
                                add_scalebar=False)
    xt, yt = 2.45, 2.45
    xvol, yvol = 185, 2.45
    axs[0].text(xt, yt, 'a', **letkm)
    axs[0].text(xvol, yvol, '{:.2f} km$^3$'.format(total_vol), **letkm)

    graphics.plot_inversion(gdir,
                            ax=axs[1],
                            title='',
                            linewidth=2,
                            add_colorbar=True,
                            vmax=1600,
                            lonlat_contours_kwargs=llkw,
                            cbar_ax=axs[1].cax,
                            add_scalebar=True)
    axs[1].text(xt, yt, 'b', **letkm)
    axs[1].text(xvol, yvol, '{:.2f} km$^3$'.format(total_vol_c), **letkm)

    plt.tight_layout()
    #plt.show()
    plt.savefig(os.path.join(plot_path, 'inversion_columbia.pdf'),
                dpi=150,
                bbox_inches='tight')

# figure 3 -------------
Plot_fig_3 = True
Exemple #16
0
z = sm.set_topography('/home/mowglie/disk/OGGM_INPUT/tmp/ISL.tif')
sm.set_data(z)

# Figs
f = 0.9
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()
Exemple #17
0
    for gd in gdirs:
        itmix.write_itmix_ascii(gd, 2)
        graphics.plot_distributed_thickness(gd)
        plt.savefig(pdir + gd.name + '_' + gd.rgi_id + '_d2.png')
        plt.close()


pdir = PLOTS_DIR
if not os.path.exists(pdir):
    os.makedirs(pdir)
for gd in gdirs:
    # graphics.plot_googlemap(gd)
    # plt.savefig(pdir + gd.name + '_' + gd.rgi_id + '_ggl.png')
    # plt.close()
    # graphics.plot_domain(gd)
    # plt.savefig(pdir + gd.name + '_' + gd.rgi_id + '_dom.png')
    # plt.close()
    graphics.plot_centerlines(gd)
    plt.savefig(pdir + gd.name + '_' + gd.rgi_id + '_cls.png')
    plt.close()
    graphics.plot_catchment_width(gd, corrected=True)
    plt.savefig(pdir + gd.name + '_' + gd.rgi_id + '_w.png')
    plt.close()
    graphics.plot_inversion(gd)
    plt.savefig(pdir + gd.name + '_' + gd.rgi_id + '_inv.png')
    plt.close()
    # graphics.plot_distributed_thickness(gd, how='per_altitude')
    # plt.savefig(pdir + gd.name + '_' + gd.rgi_id + '_dis1.png')
    # plt.close()
    pass
Exemple #18
0
    # For final inversions - no calving
    gdirs = [gd for gd in gdirs if 'I:' in gd.name]
    col_gdir = [gd for gd in gdirs if 'Columbia' in gd.name]

    cfg.PARAMS['calving_rate'] = 0
    addt = ' no calving'
    tasks.distribute_t_stars(col_gdir)
    execute_entity_task(tasks.prepare_for_inversion, col_gdir)
    execute_entity_task(tasks.volume_inversion, gdirs)
    pdir = os.path.join(PLOTS_DIR, 'out_raw') + '/'
    if not os.path.exists(pdir):
        os.mkdir(pdir)
    for gd in gdirs:
        _addt = addt if 'Columbia' in gd.name else ''
        graphics.plot_inversion(gd, add_title_comment=_addt)
        plt.savefig(pdir + gd.name + '_' + gd.rgi_id + '_inv.png')
        plt.close()

    # V1
    distrib = partial(distribute_thickness, how='per_altitude',
                      add_slope=True,
                      smooth=True)
    execute_entity_task(distrib, gdirs)
    pdir = os.path.join(PLOTS_DIR, 'out_dis') + '/'
    if not os.path.exists(pdir):
        os.mkdir(pdir)
    for gd in gdirs:
        itmix.write_itmix_ascii(gd, 1)
        graphics.plot_distributed_thickness(gd)
        plt.savefig(pdir + gd.name + '_' + gd.rgi_id + '_d1.png')
Exemple #19
0
#    print('Calving results:')
#    for k in ['calving_front_width', 'calving_flux', 'calving_thick',
#              'calving_free_board']:
#        print(k + ':', diags[k])
#    if do_plot:
#        from oggm import graphics
#        import matplotlib.pyplot as plt
#        f, (ax1, ax2) = plt.subplots(1, 2)
#        graphics.plot_googlemap(gdir, ax=ax1)
#        graphics.plot_inversion(gdir, ax=ax2)
#        plt.show()

rid = 'RGI60-01.03622'
gdir = oggm_compat.single_flowline_glacier_directory_with_calving(rid,
                                                                  k_calving=2)
diags = gdir.get_diagnostics()
print('Calving results:')
for k in [
        'calving_front_width', 'calving_flux', 'calving_thick',
        'calving_free_board'
]:
    print(k + ':', diags[k])

do_plot = True
if do_plot:
    from oggm import graphics
    import matplotlib.pyplot as plt
    f, (ax1, ax2) = plt.subplots(1, 2)
    graphics.plot_googlemap(gdir, ax=ax1)
    graphics.plot_inversion(gdir, ax=ax2)
    plt.show()
Exemple #20
0
def test_inversion():
    fig, ax = plt.subplots()
    gdir = init_hef()
    graphics.plot_inversion(gdir, ax=ax)
    fig.tight_layout()
    return fig