Ejemplo n.º 1
0
def test_mem():
    run_pasture_growth(storyline_key='test100',
                       outdir=os.path.join(ksl_env.slmmac_dir_unbacked,
                                           'test_full_model'),
                       nsims='all',
                       padock_rest=True,
                       mode_sites=[
                           ('irrigated', 'eyrewell'),
                           ('irrigated', 'oxford'),
                       ],
                       save_daily=False,
                       description='to test functinality')
Ejemplo n.º 2
0
def run_pasture_growth_normal():
    base_outdir = os.path.join(default_pasture_growth_dir, 'lauras')
    if not os.path.exists(base_outdir):
        os.makedirs(base_outdir)

    nsims = 1
    paths = [os.path.join(default_lauras_story_dir, e) for e in os.listdir(default_lauras_story_dir)]
    outdirs = [base_outdir for e in paths]

    for p, od in zip(paths, outdirs):
        print(p)
        run_pasture_growth(storyline_path=p, outdir=od, nsims=nsims, padock_rest=False,
                           save_daily=True, description='', verbose=True,
                           n_parallel=1)
def check_full_model_run_time():
    out = pd.DataFrame(index=range(5),
                       columns=['nsims', 'time', 'paddock_res', 'save_daily'])
    t = time.time()

    run_pasture_growth(storyline_path=os.path.join(storyline_dir,
                                                   '0-baseline.csv'),
                       outdir=os.path.join(ksl_env.slmmac_dir_unbacked,
                                           'test_full_modelbase_10000'),
                       nsims=10000,
                       padock_rest=False,
                       mode_sites=[('irrigated', 'eyrewell')],
                       save_daily=True,
                       description='to test functinality')

    out.loc[0, 'time'] = time.time() - t
    out.loc[0, 'nsims'] = 10000
    out.loc[0, 'paddock_res'] = False
    out.loc[0, 'save_daily'] = True

    for i, (num, pad, daily) in enumerate(
            itertools.product([100, 1000], [True, False], [True, False])):
        t = time.time()
        if pad:
            val = 'paddock'
        else:
            val = 'simple'
        if daily:
            dval = 'daily'
        else:
            dval = 'monthly'
        run_pasture_growth(storyline_path=os.path.join(storyline_dir,
                                                       '0-baseline.csv'),
                           outdir=os.path.join(
                               ksl_env.slmmac_dir_unbacked,
                               'test_full_model0-base{}_{}_{}'.format(
                                   num, val, dval)),
                           nsims=num,
                           padock_rest=pad,
                           mode_sites=[('irrigated', 'eyrewell')],
                           save_daily=daily,
                           description='to test functinality')

        out.loc[i + 1, 'time'] = time.time() - t
        out.loc[i + 1, 'nsims'] = num
        out.loc[i + 1, 'paddock_res'] = pad
        out.loc[i + 1, 'save_daily'] = daily

    out.to_csv(os.path.join(ksl_env.slmmac_dir, 'time_test_basgra_.csv'))
def _rpg_mp(kwargs):
    storyline_id = os.path.basename(kwargs['storyline_path']).split('.')[0]
    kwargs['nsims'] = int(kwargs['nsims'])

    success = True
    v = 'no error'

    print('starting to run {}'.format(storyline_id))
    try:
        run_pasture_growth(**kwargs)
    except Exception as val:
        v = val
        success = False
    kwargs['success'] = success
    kwargs['error_v'] = v
    kwargs['mode_sites'] = '; '.join(['-'.join(e)  for e in kwargs['mode_sites']])
    print('finished storyline: {},  success: {}, error: {}'.format(storyline_id, success, v))
    return [kwargs[e] for e in kwarg_keys]
Ejemplo n.º 5
0
import warnings
warnings.warn('this is the old baseline, it is depreciated!!!!')

if __name__ == '__main__':
    run_basgra = True  # to stop accidental re-run
    plot_results = False
    export = True
    prob_pg = True
    if run_basgra:
        # run basgra
        print('running BASGRA')
        run_pasture_growth(
            storyline_path=os.path.join(storyline_dir, '0-baseline_1yr.csv'),
            outdir=os.path.join(default_pasture_growth_dir,
                                'baseline_sim_no_pad'),
            nsims=10000,
            padock_rest=False,
            save_daily=True,
            description='initial baseline run after the realisation cleaning',
            verbose=True)

    if plot_results:
        path_list = [
            r"D:\mh_unbacked\SLMACC_2020\pasture_growth_sims\baseline_sim_no_pad\0-baseline-eyrewell-irrigated.nc",
            r"D:\mh_unbacked\SLMACC_2020\pasture_growth_sims\baseline_sim_no_pad\0-baseline-oxford-irrigated.nc",
            r"D:\mh_unbacked\SLMACC_2020\pasture_growth_sims\baseline_sim_no_pad\0-baseline-oxford-dryland.nc",
        ]
        for p in path_list:
            plot_sims(
                data_paths=p,
                plot_ind=True,
Ejemplo n.º 6
0
    run_mp = True
    run_norm = False
    num = 20
    spaths = np.repeat([os.path.join(storyline_dir, '0-baseline.csv')], (num))
    odirs = [
        os.path.join(default_pasture_growth_dir, 'test_mp_f', f't{e}')
        for e in range(num)
    ]

    if run_mp:
        run_full_model_mp(storyline_path_mult=spaths,
                          outdir_mult=odirs,
                          nsims_mult=num,
                          log_path=r"C:\Users\dumon\Downloads\test_log",
                          description_mult='just a test',
                          padock_rest_mult=True,
                          save_daily_mult=False,
                          verbose=False)
    if run_norm:
        for p, od in zip(spaths, odirs):
            print(p)
            run_pasture_growth(storyline_path=p,
                               outdir=od,
                               nsims=nsims,
                               padock_rest=True,
                               save_daily=True,
                               description='',
                               verbose=True,
                               n_parallel=1)
"""
 Author: Matt Hanson
 Created: 26/02/2021 8:57 AM
 """

from Pasture_Growth_Modelling.full_model_implementation import run_pasture_growth, default_pasture_growth_dir
from Climate_Shocks import climate_shocks_env
import os

if __name__ == '__main__':
    run_pasture_growth(
        storyline_path=os.path.join(climate_shocks_env.storyline_dir, '0-baseline.csv'),
        outdir=os.path.join(default_pasture_growth_dir, 'test_pg_ex_swg'), nsims=100, padock_rest=True,
        save_daily=True, description='', verbose=False)
Ejemplo n.º 8
0
                           save_daily=True, description='', verbose=True,
                           n_parallel=1)


if __name__ == '__main__':
    run = False
    run_missing = False
    plot = False
    export_csv = True
    if run:
        run_pasture_growth_mp()
    if run_missing:
        inital_laura_dir = os.path.join(default_pasture_growth_dir, 'lauras')
        sp = r'D:/mh_unbacked\SLMACC_2020\temp_storyline_files\lauras_run\Event Every Season Y1 and Y3-rest-50-95.csv'
        run_pasture_growth(storyline_path=sp, outdir=inital_laura_dir, nsims=10000, padock_rest=False,
                           save_daily=True, description='', verbose=True,
                           n_parallel=1)

    if plot:
        data_paths = []

        inital_laura_dir = os.path.join(default_pasture_growth_dir, 'lauras')
        for sm in ['eyrewell-irrigated', 'oxford-dryland', 'oxford-irrigated']:
            data_paths = glob.glob(os.path.join(inital_laura_dir, f'*{sm}.nc')) + [
                f"D:/mh_unbacked/SLMACC_2020/pasture_growth_sims/baseline_sim_no_pad/0-baseline-{sm}.nc"]
            outdir = os.path.join(inital_laura_dir, 'plots', sm)
            if not os.path.exists(outdir):
                os.makedirs(outdir)
            plot_sims(data_paths,
                      plot_ind=False, nindv=100, save_dir=outdir, show=False, figsize=(20, 20),
                      daily=False)
Ejemplo n.º 9
0
from Pasture_Growth_Modelling.full_model_implementation import run_pasture_growth, default_pasture_growth_dir
from Pasture_Growth_Modelling.plot_full_model import plot_sims
from BS_work.SWG.SWG_wrapper import *

if __name__ == '__main__':
    run_basgra = False  # to stop accidental re-run
    plot_results = True

    if run_basgra:
        # run basgra
        print('running BASGRA')
        run_pasture_growth(
            storyline_path=os.path.join(storyline_dir, '0-long-baseline.csv'),
            outdir=os.path.join(default_pasture_growth_dir, 'long_baseline'),
            nsims=1000,
            padock_rest=False,
            save_daily=False,
            description='initial long baseline run to help set ibasal',
            verbose=True,
            fix_leap=True)

    path_list = [
        r"D:\mh_unbacked\SLMACC_2020\pasture_growth_sims\long_baseline\0-long-baseline-eyrewell-irrigated.nc",
        r"D:\mh_unbacked\SLMACC_2020\pasture_growth_sims\long_baseline\0-long-baseline-oxford-irrigated.nc",
        r"D:\mh_unbacked\SLMACC_2020\pasture_growth_sims\long_baseline\0-long-baseline-oxford-dryland.nc"
    ]
    out = {}
    for p in path_list:
        test = nc.Dataset(p)
        idx = (np.array(test.variables['m_year']) > 2040) & (np.array(
            test.variables['m_month']) == 7)