else:
                w_depth = thick - t_altitude

            fl = gdir.read_pickle('inversion_flowlines')[-1]
            width = fl.widths[-1] * gdir.grid.dx

            # Lets compute the theoretical calving out of it
            pre_calving = k * thick * w_depth * width / 1e9
            gdir.inversion_calving_rate = pre_calving
            print('pre_calving', pre_calving)

            # Recompute all with calving
            tasks.distribute_t_stars([gdir], minimum_mustar=0.)
            tasks.apparent_mb(gdir)
            tasks.prepare_for_inversion(gdir, add_debug_var=True)
            tasks.volume_inversion(gdir, glen_a=cfg.A, fs=cfg.FS)
            df = pd.read_csv(gdir.get_filepath('local_mustar')).iloc[0]
            mu_star = df['mu_star']

            while i < 50:
                # First calculates a calving flux from model output

                F_calving, new_depth, new_thick, t_width = calving_from_depth(
                    gdir, k)

                # Stores the data, and we see it
                data_calving += [F_calving]
                w_depth = np.append(w_depth, new_depth)
                thick = np.append(thick, new_thick)
                t_width = t_width
                # print('Calving rate calculated', F_calving)
Beispiel #2
0
            else:
                # we read the McNabb width
                width = dfwidth[index[0][0]]
                # print('width',width)

            # Lets compute the theoretical calving out of it
            pre_calving = 2 * thick * w_depth * width / 1e9
            gdir.inversion_calving_rate = pre_calving
            print('pre_calving', pre_calving)

            # Recompute all with calving
            tasks.distribute_t_stars([gdir])
            tasks.apparent_mb(gdir)
            tasks.prepare_for_inversion(gdir, add_debug_var=True)
            tasks.volume_inversion(gdir)

            while i < 50:
                # First calculates a calving flux from model output

                F_calving, new_depth, new_thick, t_width = calving_from_depth(
                    gdir)

                # Stores the data, and we see it
                data_calving += [F_calving]
                w_depth += [new_depth]
                thick += [new_thick]
                t_width = t_width
                # print('Calving rate calculated', F_calving)

                # We put the calving function output into the Model
Beispiel #3
0
        tasks.catchment_width_geom,
        tasks.catchment_width_correction
    ]
    for task in task_list:
        execute_entity_task(task, gdirs)

    # "Climate related tasks"
    for gd in gdirs:
        itmix.synth_apparent_mb(gd)

    # Inversion
    execute_entity_task(tasks.prepare_for_inversion, gdirs)
    fac = 3.22268124479468
    use_cfg_params = {'glen_a':fac * cfg.A, 'fs':0.}
    for gd in gdirs:
        tasks.volume_inversion(gd, use_cfg_params=use_cfg_params)


if do_itmix:

    done = False

    # 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:
Beispiel #4
0
            # print('t_altitude', t_altitude)
            # print('depth', w_depth)
            # print('thick', thick)
            fl = gdir.read_pickle('inversion_flowlines')[-1]
            width = fl.widths[-1] * gdir.grid.dx

            # Lets compute the theoretical calving out of it
            pre_calving = k * thick * w_depth * width / 1e9
            gdir.inversion_calving_rate = pre_calving
            print('pre_calving', pre_calving)

            # Recompute all with calving
            tasks.distribute_t_stars([gdir], minimum_mustar=0.)
            tasks.apparent_mb(gdir)
            tasks.prepare_for_inversion(gdir, add_debug_var=True)
            tasks.volume_inversion(gdir, glen_a=1.611e-24, fs=cfg.FS)
            df = pd.read_csv(gdir.get_filepath('local_mustar')).iloc[0]
            mu_star = df['mu_star']

            while i < 50:
                # First calculates a calving flux from model output

                F_calving, new_depth, new_thick, t_width = calving_from_depth(
                    gdir, k)

                # Stores the data, and we see it
                data_calving += [F_calving]
                w_depth = np.append(w_depth, new_depth)
                thick = np.append(thick, new_thick)
                t_width = t_width
                # print('Calving rate calculated', F_calving)
Beispiel #5
0
diff = mb_per_mu - ref_mb
pdf = pd.DataFrame()
pdf[r'$\mu (t)$'] = mu_yr_clim
pdf['bias'] = diff
res = t_star_from_refmb(gdir, mbdf.ANNUAL_BALANCE)

# For the mass flux
cl = gdir.read_pickle('inversion_input')[-1]
mbmod = ConstantMassBalance(gdir)
mbx = mbmod.get_annual_mb(cl['hgt']) * cfg.SEC_IN_YEAR * cfg.RHO
fdf = pd.DataFrame(index=np.arange(len(mbx)) * cl['dx'])
fdf['Flux'] = cl['flux']
fdf['Mass balance'] = mbx

# For the distributed thickness
tasks.volume_inversion(gdir, glen_a=cfg.A * 3, fs=0)
tasks.distribute_thickness_per_altitude(gdir)


# plot functions
def example_plot_temp_ts():
    d = xr.open_dataset(gdir.get_filepath('climate_monthly'))
    temp = d.temp.resample(time='12MS').mean('time').to_series()
    del temp.index.name
    ax = temp.plot(figsize=(8, 4), label='Annual temp')
    temp.rolling(31, center=True,
                 min_periods=15).mean().plot(label='31-yr avg')
    plt.legend(loc='best')
    plt.title('HISTALP annual temperature, Hintereisferner')
    plt.ylabel(r'degC')
    plt.tight_layout()
Beispiel #6
0
            # print('t_altitude', t_altitude)
            # print('depth', w_depth)
            # print('thick', thick)
            fl = gdir.read_pickle('inversion_flowlines')[-1]
            width = fl.widths[-1] * gdir.grid.dx

            # Lets compute the theoretical calving out of it
            pre_calving = k * thick * w_depth * width / 1e9
            gdir.inversion_calving_rate = pre_calving
            print('pre_calving', pre_calving)

            # Recompute all with calving
            tasks.distribute_t_stars([gdir], minimum_mustar=0.)
            tasks.apparent_mb(gdir)
            tasks.prepare_for_inversion(gdir, add_debug_var=True)
            tasks.volume_inversion(gdir, glen_a=3.339e-24, fs=0.0)
            df = pd.read_csv(gdir.get_filepath('local_mustar')).iloc[0]
            mu_star = df['mu_star']

            while i < 50:
                # First calculates a calving flux from model output

                F_calving, new_depth, new_thick, t_width = calving_from_depth(
                    gdir, k)

                # Stores the data, and we see it
                data_calving += [F_calving]
                w_depth = np.append(w_depth, new_depth)
                thick = np.append(thick, new_thick)
                t_width = t_width
                # print('Calving rate calculated', F_calving)
Beispiel #7
0
            # print('t_altitude', t_altitude)
            # print('depth', w_depth)
            # print('thick', thick)
            fl = gdir.read_pickle('inversion_flowlines')[-1]
            width = fl.widths[-1] * gdir.grid.dx

            # Lets compute the theoretical calving out of it
            pre_calving = k * thick * w_depth * width / 1e9
            gdir.inversion_calving_rate = pre_calving
            print('pre_calving', pre_calving)

            # Recompute all with calving
            tasks.distribute_t_stars([gdir], minimum_mustar=0.)
            tasks.apparent_mb(gdir)
            tasks.prepare_for_inversion(gdir, add_debug_var=True)
            tasks.volume_inversion(gdir, glen_a=2.3435e-24, fs=0.0)
            df = pd.read_csv(gdir.get_filepath('local_mustar')).iloc[0]
            mu_star = df['mu_star']

            while i < 50:
                # First calculates a calving flux from model output

                F_calving, new_depth, new_thick, t_width = calving_from_depth(
                    gdir, k)

                # Stores the data, and we see it
                data_calving += [F_calving]
                w_depth = np.append(w_depth, new_depth)
                thick = np.append(thick, new_thick)
                t_width = t_width
                # print('Calving rate calculated', F_calving)
Beispiel #8
0
thick = cl['volume'][-1] / cl['dx'] / width
print('Without calving the width is {} m and the thick is {} m'.format(width, thick))

# Try many C's (they should make sense in comparison to the size of the glacier)
c_candidates = np.linspace(0, 0.1, 10)
for c in c_candidates:

    # First guess calving
    gdir.inversion_calving_rate = c

    # Recompute mu
    tasks.distribute_t_stars([gdir])

    # Inversion
    tasks.prepare_for_inversion(gdir)
    tasks.volume_inversion(gdir)

    # We read the output, last pixel of the inversion
    cl = gdir.read_pickle('inversion_output', div_id=1)[-1]
    width = cl['width'][-1]
    thick = cl['volume'][-1] / cl['dx'] / width
    print('With calving of {} km3 a-1 the width is {} m  and the thick is {} m'.format(gdir.inversion_calving_rate, width, thick))

    # Now compute the calving rate that would come from H and width
    # Compare to the old calving and see if it has to be reduced or increased


# And in the very end, alle these steps should be automatized with
# an optimisation function

Beispiel #9
0
        tasks.catchment_area, tasks.initialize_flowlines,
        tasks.catchment_width_geom, tasks.catchment_width_correction
    ]
    for task in task_list:
        execute_entity_task(task, gdirs)

    # "Climate related tasks"
    for gd in gdirs:
        itmix.synth_apparent_mb(gd)

    # Inversion
    execute_entity_task(tasks.prepare_for_inversion, gdirs)
    fac = 3.22268124479468
    use_cfg_params = {'glen_a': fac * cfg.A, 'fs': 0.}
    for gd in gdirs:
        tasks.volume_inversion(gd, use_cfg_params=use_cfg_params)

if do_itmix:

    done = False

    # 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:
            # print('t_altitude', t_altitude)
            # print('depth', w_depth)
            # print('thick', thick)
            fl = gdir.read_pickle('inversion_flowlines')[-1]
            width = fl.widths[-1] * gdir.grid.dx

            # Lets compute the theoretical calving out of it
            pre_calving = k * thick * w_depth * width / 1e9
            gdir.inversion_calving_rate = pre_calving
            print('pre_calving', pre_calving)

            # Recompute all with calving
            tasks.distribute_t_stars([gdir], minimum_mustar=0.)
            tasks.apparent_mb(gdir)
            tasks.prepare_for_inversion(gdir, add_debug_var=True)
            tasks.volume_inversion(gdir, glen_a=2.3346e-24, fs=cfg.FS)
            df = pd.read_csv(gdir.get_filepath('local_mustar')).iloc[0]
            mu_star = df['mu_star']

            while i < 50:
                # First calculates a calving flux from model output

                F_calving, new_depth, new_thick, t_width = calving_from_depth(
                    gdir, k)

                # Stores the data, and we see it
                data_calving += [F_calving]
                w_depth = np.append(w_depth, new_depth)
                thick = np.append(thick, new_thick)
                t_width = t_width
                # print('Calving rate calculated', F_calving)