def generate_runs( model_file, scenarios=None, additional_args=None, override_dict=None): """ Returns a list of "calliope run" invocations. ``scenarios`` must be specified as either a semicolon-separated list of scenarios or a semicolon-separated list of comma-separated individual override combinations, such as: ``override1,override2;override1,override3;...`` If ``scenarios`` is not given, use all scenarios in the model configuration, and if no scenarios given in the model configuration, uses all individual overrides, one by one. """ if scenarios is None: config = AttrDict.from_yaml(model_file) if override_dict: override = AttrDict.from_yaml_string(override_dict) config.union( override, allow_override=True, allow_replacement=True ) if 'scenarios' in config: runs = config.scenarios.keys() else: runs = config.overrides.keys() else: runs = scenarios.split(';') commands = [] # len(str(x)) gives us the number of digits in x, for padding i_string = '{:0>' + str(len(str(len(runs)))) + 'd}' for i, run in enumerate(runs): cmd = ( 'calliope run {model} --scenario {scenario} ' '--save_netcdf out_{i}_{scenario}.nc ' '--save_plots plots_{i}_{scenario}.html' ).format( i=i_string.format(i + 1), model=model_file, scenario=run, override_dict=override_dict, ).strip() if override_dict: cmd = cmd + ' --override_dict="{}"'.format(override_dict) if additional_args: cmd = cmd + ' ' + additional_args commands.append(cmd) return commands
def generate_runs(model_file, scenarios=None, additional_args=None, override_dict=None): """ Returns a list of "calliope run" invocations. ``scenarios`` must be specified as either a semicolon-separated list of scenarios or a semicolon-separated list of comma-separated individual override combinations, such as: ``override1,override2;override1,override3;...`` If ``scenarios`` is not given, use all scenarios in the model configuration, and if no scenarios given in the model configuration, uses all individual overrides, one by one. """ if scenarios is None: config = AttrDict.from_yaml(model_file) if override_dict: override = AttrDict.from_yaml_string(override_dict) config.union(override, allow_override=True, allow_replacement=True) if 'scenarios' in config: runs = config.scenarios.keys() else: runs = config.overrides.keys() else: runs = scenarios.split(';') commands = [] # len(str(x)) gives us the number of digits in x, for padding i_string = '{:0>' + str(len(str(len(runs)))) + 'd}' for i, run in enumerate(runs): cmd = ('calliope run {model} --scenario {scenario} ' '--save_netcdf out_{i}_{scenario}.nc ' '--save_plots plots_{i}_{scenario}.html').format( i=i_string.format(i + 1), model=model_file, scenario=run, override_dict=override_dict, ).strip() if override_dict: cmd = cmd + ' --override_dict="{}"'.format(override_dict) if additional_args: cmd = cmd + ' ' + additional_args commands.append(cmd) return commands
def generate_runs(model_file, override_file, groups=None, additional_args=None): """ Returns a list of "calliope run" invocations. groups specified as group1{,group2,...}{;group3...} if groups not specified, use all groups in the override_file, one by one """ if groups is None: overrides = AttrDict.from_yaml(override_file) runs = overrides.keys() else: runs = groups.split(';') commands = [] for i, run in enumerate(runs): cmd = 'calliope run {model} --override_file {override}:{groups} --save_netcdf out_{i}_{groups}.nc --save_plots plots_{i}_{groups}.html {other_options}'.format( i=i + 1, model=model_file, override=override_file, groups=run, other_options=additional_args).strip() commands.append(cmd) return commands