How to use the oggm.core.flowline.FluxBasedModel function in oggm

To help you get started, we’ve selected a few oggm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github OGGM / oggm / oggm / sandbox / ideas.py View on Github external
'big of %.2f %%. Continue', 0,
                 utils.rel_err(ref_area, prev_area) * 100)
        sign_mb = 1.

    # Log prefix
    logtxt = 'iterative_initial_glacier_search'

    # Loop until 100 iterations
    c = 0
    bias_step = 0.1
    mb_bias = init_bias - bias_step
    reduce_step = 0.01

    mb = copy.deepcopy(firstguess_mb)
    mb.temp_bias = sign_mb * mb_bias
    grow_model = FluxBasedModel(copy.deepcopy(final_model.fls), mb_model=mb,
                                fs=final_model.fs,
                                glen_a=final_model.glen_a,
                                min_dt=final_model.min_dt,
                                max_dt=final_model.max_dt)
    while True and (c < max_ite):
        c += 1

        # Grow
        mb_bias += bias_step
        mb.temp_bias = sign_mb * mb_bias
        log.info(logtxt + ', ite: %d. New bias: %.2f', c, sign_mb * mb_bias)
        grow_model.reset_flowlines(copy.deepcopy(prev_fls))
        grow_model.reset_y0(0.)
        grow_model.run_until_equilibrium(rate=equi_rate)
        log.info(logtxt + ', ite: %d. Grew to equilibrium for %d years, '
                          'new area: %.3f km2', c, grow_model.yr,
github OGGM / oggm-edu / oggm_edu / funcs.py View on Github external
Returns
   -------
   model : oggm.core.flowline.FluxBasedModel
       the initialized model

   TODO: return also length and volume steps (they are calculated for every
         time step)
   """
    if not glen_a:
        glen_a = cfg.PARAMS['glen_a']

    if not fs:
        fs = 0

    model = FluxBasedModel(init_flowline, mb_model=mb_model, y0=0.,
                           glen_a=glen_a, fs=fs)
    # Year 0 to 600 in 5 years step
    yrs = np.arange(0, years, 5)
    # Array to fill with data
    nsteps = len(yrs)
    length = np.zeros(nsteps)
    vol = np.zeros(nsteps)
    # Loop
    for i, yr in enumerate(yrs):
        model.run_until(yr)
        length[i] = model.length_m
        vol[i] = model.volume_km3

    return model  # , length, vol
github OGGM / oggm / benchmarks / hef_dynamics.py View on Github external
def time_hef_run_until_and_store_with_nc():

    mb_mod = massbalance.RandomMassBalance(gdir, bias=0, seed=0)
    fls = gdir.read_pickle('model_flowlines')
    model = flowline.FluxBasedModel(fls, mb_model=mb_mod, y0=0.)
    model.run_until_and_store(200, run_path=os.path.join(testdir, 'run.nc'),
                              diag_path=os.path.join(testdir, 'diag.nc'))
github OGGM / oggm / benchmarks / hef_dynamics.py View on Github external
def time_hef_run_until_in_steps():

    mb_mod = massbalance.RandomMassBalance(gdir, bias=0, seed=0)
    fls = gdir.read_pickle('model_flowlines')
    model = flowline.FluxBasedModel(fls, mb_model=mb_mod, y0=0.)
    for yr in np.linspace(0, 200, 400):
        model.run_until(yr)
github OGGM / oggm / oggm / core / flowline.py View on Github external
time_stepping : str
            let OGGM choose default values for the parameters above for you.
            Possible settings are: 'ambitious', 'default', 'conservative',
            'ultra-conservative'.
        is_tidewater: bool, default: False
            use the very basic parameterization for tidewater glaciers
        mb_elev_feedback : str, default: 'annual'
            'never', 'always', 'annual', or 'monthly': how often the
            mass-balance should be recomputed from the mass balance model.
            'Never' is equivalent to 'annual' but without elevation feedback
            at all (the heights are taken from the first call).
        check_for_boundaries: bool, default: True
            raise an error when the glacier grows bigger than the domain
            boundaries
        """
        super(FluxBasedModel, self).__init__(flowlines, mb_model=mb_model,
                                             y0=y0, glen_a=glen_a, fs=fs,
                                             inplace=inplace, **kwargs)

        if time_stepping == 'ambitious':
            cfl_number = 0.1
            min_dt = 1*SEC_IN_DAY
            max_dt = 15*SEC_IN_DAY
        elif time_stepping == 'default':
            cfl_number = 0.05
            min_dt = 1*SEC_IN_HOUR
            max_dt = 10*SEC_IN_DAY
        elif time_stepping == 'conservative':
            cfl_number = 0.01
            min_dt = SEC_IN_HOUR
            max_dt = 5*SEC_IN_DAY
        elif time_stepping == 'ultra-conservative':
github OGGM / oggm / oggm / core / flowline.py View on Github external
delete=True)
    diag_path = gdir.get_filepath('model_diagnostics',
                                  filesuffix=output_filesuffix,
                                  delete=True)

    steps = ['default', 'conservative', 'ultra-conservative']
    for step in steps:
        log.info('(%s) trying %s time stepping scheme.', gdir.rgi_id, step)
        if init_model_fls is None:
            fls = gdir.read_pickle('model_flowlines')
        else:
            fls = copy.deepcopy(init_model_fls)
        if zero_initial_glacier:
            for fl in fls:
                fl.thick = fl.thick * 0.
        model = FluxBasedModel(fls, mb_model=mb_model, y0=ys,
                               inplace=True,
                               time_stepping=step,
                               is_tidewater=gdir.is_tidewater,
                               **kwargs)

        with np.warnings.catch_warnings():
            # For operational runs we ignore the warnings
            np.warnings.filterwarnings('ignore', category=RuntimeWarning)
            try:
                model.run_until_and_store(ye, run_path=run_path,
                                          diag_path=diag_path,
                                          store_monthly_step=store_monthly_step
                                          )
            except (RuntimeError, FloatingPointError):
                if step == 'ultra-conservative':
                    raise
github OGGM / oggm / benchmarks / numerics.py View on Github external
def time_1d_flux_multiple_flow_fixed_dt():

        fls = dummy_width_bed_tributary(n_trib=5)
        mb = massbalance.LinearMassBalance(2600.)

        model = flowline.FluxBasedModel(fls, mb_model=mb, y0=0.,
                                        fixed_dt=5 * cfg.SEC_IN_DAY)
        model.run_until(800)
github OGGM / oggm / benchmarks / hef_dynamics.py View on Github external
def time_hef_run_until_and_store():

    mb_mod = massbalance.RandomMassBalance(gdir, bias=0, seed=0)
    fls = gdir.read_pickle('model_flowlines')
    model = flowline.FluxBasedModel(fls, mb_model=mb_mod, y0=0.)
    model.run_until_and_store(200)
github OGGM / oggm / oggm / sandbox / ideas.py View on Github external
write_steps=True):
    """Iterative search for the glacier in year y0.

    this is outdated and doesn't really work.
    """

    fs = cfg.PARAMS['fs']
    glen_a = cfg.PARAMS['glen_a']

    if y0 is None:
        y0 = cfg.PARAMS['y0']
    y1 = gdir.rgi_date.year
    mb = mbmods.PastMassBalance(gdir)
    fls = gdir.read_pickle('model_flowlines')

    model = FluxBasedModel(fls, mb_model=mb, y0=0., fs=fs, glen_a=glen_a)
    assert np.isclose(model.area_km2, gdir.rgi_area_km2, rtol=0.05)

    mb = mbmods.BackwardsMassBalanceModel(gdir)
    ref_area = gdir.rgi_area_m2
    ite, bias, past_model = _find_inital_glacier(model, mb, y0, y1,
                                                 rtol=rtol,
                                                 init_bias=init_bias,
                                                 ref_area=ref_area)

    path = gdir.get_filepath('model_run', delete=True)
    if write_steps:
        past_model.run_until_and_store(y1, path=path)
    else:
        past_model.to_netcdf(path)