<commit_before><commit_msg>Add flowline benchmarks (#489)<commit_after># Write the benchmarking functions here.
# See "Writing benchmarks" in the asv docs for more information.
import os
import shutil
import numpy as np
import oggm
from oggm.tests.funcs import init_hef, get_test_dir
from oggm import utils, tasks
from oggm.core import massbalance, flowline


testdir = os.path.join(get_test_dir(), 'benchmarks')
utils.mkdir(testdir, reset=True)
heights = np.linspace(2200, 3600, 120)
years = np.arange(151) + 1850


def teardown():
    if os.path.exists(testdir):
        shutil.rmtree(testdir)


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)


def time_hef_run_until():

    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(200)


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)


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)


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


time_hef_run_until.setup = setup
time_hef_run_until.teardown = teardown

time_hef_run_until_in_steps.setup = setup
time_hef_run_until_in_steps.teardown = teardown

time_hef_run_until_and_store.setup = setup
time_hef_run_until_and_store.teardown = teardown

time_hef_run_until_and_store_with_nc.setup = setup
time_hef_run_until_and_store_with_nc.teardown = teardown
{'fraction_non_alphanumeric': 0.10411198600174978, 'fraction_numerical': 0.024059492563429572, 'mean_word_length': 5.002624671916011, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '773458', 'n_tokens_mistral': 928, 'n_tokens_neox': 882, 'n_words': 151}