diff --git a/setup.cfg b/setup.cfg index b410ffb8..81aa8fcd 100644 --- a/setup.cfg +++ b/setup.cfg @@ -47,7 +47,7 @@ install_requires = pydot importlib_resources; python_version<'3.7' pandas>=1.1 - amply>=0.1.4 + amply>=0.1.6 networkx flatten_dict openpyxl diff --git a/src/otoole/__init__.py b/src/otoole/__init__.py index 88e521e6..57365b0a 100644 --- a/src/otoole/__init__.py +++ b/src/otoole/__init__.py @@ -1,10 +1,7 @@ # -*- coding: utf-8 -*- import sys -from otoole.input import Context -from otoole.read_strategies import ReadCsv, ReadDatafile, ReadExcel, ReadMemory -from otoole.results.results import ReadCbc, ReadCplex, ReadGurobi -from otoole.write_strategies import WriteCsv, WriteDatafile, WriteExcel +from otoole.convert import convert, convert_results if sys.version_info[:2] >= (3, 8): # TODO: Import directly (no need for conditional) when `python_requires = >= 3.8` @@ -21,17 +18,7 @@ finally: del version, PackageNotFoundError +convert = convert +convert_results = convert_results -__all__ = [ - "Context", - "ReadCbc", - "ReadCsv", - "ReadCplex", - "ReadDatafile", - "ReadExcel", - "ReadGurobi", - "ReadMemory", - "WriteCsv", - "WriteDatafile", - "WriteExcel", -] +__all__ = ["convert" "convert_results"] diff --git a/src/otoole/cli.py b/src/otoole/cli.py index 8d0ce16c..9ff2066a 100644 --- a/src/otoole/cli.py +++ b/src/otoole/cli.py @@ -44,21 +44,10 @@ import shutil import sys -from otoole import ( - ReadCbc, - ReadCplex, - ReadCsv, - ReadDatafile, - ReadExcel, - ReadGurobi, - WriteCsv, - WriteDatafile, - WriteExcel, - __version__, -) +from otoole import __version__, convert, convert_results from otoole.exceptions import OtooleSetupError -from otoole.input import Context from otoole.preprocess.setup import get_config_setup_data, get_csv_setup_data +from otoole.read_strategies import ReadCsv, ReadDatafile, ReadExcel from otoole.utils import ( _read_file, read_deprecated_datapackage, @@ -67,6 +56,7 @@ ) from otoole.validate import main as validate from otoole.visualise import create_res +from otoole.write_strategies import WriteCsv logger = logging.getLogger(__name__) @@ -104,70 +94,21 @@ def validate_model(args): validate(input_data) -def cplex2cbc(args): - ReadCplex()._convert_cplex_file( - args.cplex_file, - args.output_file, - args.start_year, - args.end_year, - args.output_format, +def _result_matrix(args): + convert_results( + args.config, + args.input_datapackage, + args.input_csvs, + args.input_datafile, + args.to_path, + args.from_path, + args.from_format, + args.to_format, + args.write_defaults, ) -def result_matrix(args): - """Post-process results from CBC solution file into CSV format""" - msg = "Conversion from {} to {} is not yet implemented".format( - args.from_format, args.to_format - ) - - read_strategy = None - write_strategy = None - - config = None - if args.config: - _, ending = os.path.splitext(args.config) - with open(args.config, "r") as config_file: - config = _read_file(config_file, ending) - logger.info("Reading config from {}".format(args.config)) - logger.info("Validating config from {}".format(args.config)) - validate_config(config) - - # set read strategy - - if args.from_format == "cbc": - read_strategy = ReadCbc(user_config=config) - elif args.from_format == "cplex": - read_strategy = ReadCplex(user_config=config) - elif args.from_format == "gurobi": - read_strategy = ReadGurobi(user_config=config) - - # set write strategy - - write_defaults = True if args.write_defaults else False - - if args.to_format == "csv": - write_strategy = WriteCsv(user_config=config, write_defaults=write_defaults) - - if args.input_datapackage: - logger.warning( - "Reading from datapackage is deprecated, trying to read from CSVs" - ) - input_csvs = read_deprecated_datapackage(args.input_datapackage) - logger.info("Successfully read folder of CSVs") - input_data, _ = ReadCsv(user_config=config).read(input_csvs) - elif args.input_datafile: - input_data, _ = ReadDatafile(user_config=config).read(args.input_datafile) - else: - input_data = {} - - if read_strategy and write_strategy: - context = Context(read_strategy, write_strategy) - context.convert(args.from_path, args.to_path, input_data=input_data) - else: - raise NotImplementedError(msg) - - -def conversion_matrix(args): +def _conversion_matrix(args): """Convert from one format to another Implemented conversion functions:: @@ -179,71 +120,15 @@ def conversion_matrix(args): datafile nn -- -- """ - - msg = "Conversion from {} to {} is not yet implemented".format( - args.from_format, args.to_format + convert( + args.config, + args.from_format, + args.to_format, + args.from_path, + args.to_path, + args.write_defaults, ) - read_strategy = None - write_strategy = None - - from_path = args.from_path - to_path = args.to_path - - config = None - if args.config: - _, ending = os.path.splitext(args.config) - with open(args.config, "r") as config_file: - config = _read_file(config_file, ending) - logger.info("Reading config from {}".format(args.config)) - logger.info("Validating config from {}".format(args.config)) - validate_config(config) - - # set read strategy - - keep_whitespace = True if args.keep_whitespace else False - - if args.from_format == "datafile": - read_strategy = ReadDatafile(user_config=config) - elif args.from_format == "datapackage": - logger.warning( - "Reading from datapackage is deprecated, trying to read from CSVs" - ) - from_path = read_deprecated_datapackage(from_path) - logger.info("Successfully read folder of CSVs") - read_strategy = ReadCsv(user_config=config, keep_whitespace=keep_whitespace) - elif args.from_format == "csv": - read_strategy = ReadCsv(user_config=config, keep_whitespace=keep_whitespace) - elif args.from_format == "excel": - read_strategy = ReadExcel(user_config=config, keep_whitespace=keep_whitespace) - - input_data, _ = read_strategy.read(args.from_path) - - # set write strategy - - write_defaults = True if args.write_defaults else False - - if args.to_format == "datapackage": - logger.warning("Writing to datapackage is deprecated, writing to CSVs") - to_path = os.path.join(os.path.dirname(to_path), "data") - write_strategy = WriteCsv(user_config=config, write_defaults=write_defaults) - elif args.to_format == "excel": - write_strategy = WriteExcel( - user_config=config, write_defaults=write_defaults, input_data=input_data - ) - elif args.to_format == "datafile": - write_strategy = WriteDatafile( - user_config=config, write_defaults=write_defaults - ) - elif args.to_format == "csv": - write_strategy = WriteCsv(user_config=config, write_defaults=write_defaults) - - if read_strategy and write_strategy: - context = Context(read_strategy, write_strategy) - context.convert(from_path, to_path) - else: - raise NotImplementedError(msg) - def data2res(args): """Get input data and call res creation.""" @@ -349,7 +234,7 @@ def get_parser(): default=False, action="store_true", ) - result_parser.set_defaults(func=result_matrix) + result_parser.set_defaults(func=_result_matrix) # Parser for conversion convert_parser = subparsers.add_parser( @@ -382,7 +267,7 @@ def get_parser(): default=False, action="store_true", ) - convert_parser.set_defaults(func=conversion_matrix) + convert_parser.set_defaults(func=_conversion_matrix) # Parser for validation valid_parser = subparsers.add_parser("validate", help="Validate an OSeMOSYS model") diff --git a/src/otoole/convert.py b/src/otoole/convert.py new file mode 100644 index 00000000..068a66cd --- /dev/null +++ b/src/otoole/convert.py @@ -0,0 +1,210 @@ +"""This module implements the public API of the otoole package + +Use the otoole ``convert`` function to convert between different file formats. +Import the convert function from the otoole package:: + +>>> from otoole import convert +>>> convert('config.yaml', 'excel', 'datafile', 'input.xlsx', 'output.dat') + +""" +import logging +import os +from typing import Union + +from otoole.input import Context, ReadStrategy, WriteStrategy +from otoole.read_strategies import ReadCsv, ReadDatafile, ReadExcel +from otoole.results.results import ReadCbc, ReadCplex, ReadGurobi +from otoole.utils import _read_file, read_deprecated_datapackage, validate_config +from otoole.write_strategies import WriteCsv, WriteDatafile, WriteExcel + +logger = logging.getLogger(__name__) + + +def convert_results( + config, + from_format, + to_format, + from_path, + to_path, + input_datapackage=None, + input_csvs=None, + input_datafile=None, + write_defaults=False, +): + """Post-process results from a CBC, CPLEX or Gurobi solution file into CSV format + + Arguments + --------- + config : str + input_datapackage : str + input_csvs : str + input_datafile : str + to_path : str + from_path : str + from_format : str + to_format : str + write_defaults : str + """ + msg = "Conversion from {} to {} is not yet implemented".format( + from_format, to_format + ) + + read_strategy = None + write_strategy = None + + if config: + _, ending = os.path.splitext(config) + with open(config, "r") as config_file: + user_config = _read_file(config_file, ending) + logger.info("Reading config from {}".format(config)) + logger.info("Validating config from {}".format(config)) + validate_config(user_config) + + # set read strategy + + if from_format == "cbc": + read_strategy = ReadCbc(user_config=user_config) + elif from_format == "cplex": + read_strategy = ReadCplex(user_config=user_config) + elif from_format == "gurobi": + read_strategy = ReadGurobi(user_config=user_config) + + # set write strategy + + write_defaults = True if write_defaults else False + + if to_format == "csv": + write_strategy = WriteCsv( + user_config=user_config, write_defaults=write_defaults + ) + + if input_datapackage: + logger.warning( + "Reading from datapackage is deprecated, trying to read from CSVs" + ) + input_csvs = read_deprecated_datapackage(input_datapackage) + logger.info("Successfully read folder of CSVs") + input_data, _ = ReadCsv(user_config=user_config).read(input_csvs) + elif input_datafile: + input_data, _ = ReadDatafile(user_config=user_config).read(input_datafile) + elif input_csvs: + input_data, _ = ReadCsv(user_config=user_config).read(input_csvs) + else: + input_data = {} + + if read_strategy and write_strategy: + context = Context(read_strategy, write_strategy) + context.convert(from_path, to_path, input_data=input_data) + else: + raise NotImplementedError(msg) + return False + + return True + + +def convert( + config, + from_format, + to_format, + from_path, + to_path, + write_defaults=False, + keep_whitespace=False, +) -> bool: + """Convert OSeMOSYS data from/to datafile, csv and Excel formats + + Arguments + --------- + config : str + Path to config file + from_format : str + Available options are 'datafile', 'datapackage', 'csv' and 'excel' + to_format : str + Available options are 'datafile', 'datapackage', 'csv' and 'excel' + from_path : str + Path to destination file (if datafile or excel) or folder (csv or datapackage) + write_defaults: bool, default: False + keep_whitespace: bool, default: False + + Returns + ------- + bool + True if conversion was successful + """ + + msg = "Conversion from {} to {} is not yet implemented".format( + from_format, to_format + ) + + if config: + _, ending = os.path.splitext(config) + with open(config, "r") as config_file: + user_config = _read_file(config_file, ending) + logger.info("Reading config from {}".format(config)) + logger.info("Validating config from {}".format(config)) + validate_config(user_config) + + # set read strategy + + keep_whitespace = True if keep_whitespace else False + + if from_format == "datafile": + read_strategy: Union[ReadStrategy, None] = ReadDatafile(user_config=user_config) + elif from_format == "datapackage": + logger.warning( + "Reading from datapackage is deprecated, trying to read from CSVs" + ) + from_path = read_deprecated_datapackage(from_path) + logger.info("Successfully read folder of CSVs") + read_strategy = ReadCsv( + user_config=user_config, keep_whitespace=keep_whitespace + ) # typing: ReadStrategy + elif from_format == "csv": + read_strategy = ReadCsv( + user_config=user_config, keep_whitespace=keep_whitespace + ) # typing: ReadStrategy + elif from_format == "excel": + read_strategy = ReadExcel( + user_config=user_config, keep_whitespace=keep_whitespace + ) # typing: ReadStrategy + else: + read_strategy = None + + if read_strategy: + input_data, _ = read_strategy.read(from_path) + + # set write strategy + + write_defaults = True if write_defaults else False + + if to_format == "datapackage": + logger.warning("Writing to datapackage is deprecated, writing to CSVs") + to_path = os.path.join(os.path.dirname(to_path), "data") + write_strategy: Union[WriteStrategy, None] = WriteCsv( + user_config=user_config, write_defaults=write_defaults + ) + elif to_format == "excel": + write_strategy = WriteExcel( + user_config=user_config, + write_defaults=write_defaults, + input_data=input_data, + ) + elif to_format == "datafile": + write_strategy = WriteDatafile( + user_config=user_config, write_defaults=write_defaults + ) + elif to_format == "csv": + write_strategy = WriteCsv( + user_config=user_config, write_defaults=write_defaults + ) + else: + write_strategy = None + + if read_strategy and write_strategy: + context = Context(read_strategy, write_strategy) + context.convert(from_path, to_path) + else: + raise NotImplementedError(msg) + return False + + return True diff --git a/src/otoole/input.py b/src/otoole/input.py index fcdc4e6e..fe04b1a4 100644 --- a/src/otoole/input.py +++ b/src/otoole/input.py @@ -174,9 +174,11 @@ class WriteStrategy(Strategy): Arguments --------- + user_config: dict, default=None filepath: str, default=None default_values: dict, default=None - user_config: dict, default=None + write_defaults: bool, default=False + input_data: dict, default=None """ @@ -296,7 +298,7 @@ def _expand_defaults( Raises ------ KeyError - If set defenitons are not in input_data and input_data is not supplied + If set definitons are not in input_data and input_data is not supplied """ sets = [x for x in self.user_config if self.user_config[x]["type"] == "set"] @@ -389,7 +391,10 @@ def _check_index( elif details["type"] == "set": self._check_set_index_names(name=name, df=df) - df = self._check_index_dtypes(name=name, config=details, df=df) + try: + df = self._check_index_dtypes(name=name, config=details, df=df) + except ValueError as ex: + raise ValueError(f"{name}: {ex}") input_data[name] = df @@ -454,7 +459,7 @@ def _check_set_index_names(name: str, df: pd.DataFrame) -> None: OtooleIndexError If actual indices do not match expected indices """ - if not df.columns == ["VALUE"]: + if not list(df.columns) == ["VALUE"]: raise OtooleIndexError( resource=name, config_indices=["VALUE"], diff --git a/src/otoole/read_strategies.py b/src/otoole/read_strategies.py index 2d680efb..01f05f5a 100644 --- a/src/otoole/read_strategies.py +++ b/src/otoole/read_strategies.py @@ -58,6 +58,7 @@ def _convert_wide_2_narrow(self, df: pd.DataFrame, name: str): if "MODEOFOPERATION" in actual_headers: df = df.rename(columns={"MODEOFOPERATION": "MODE_OF_OPERATION"}) + actual_headers = list(df.columns) if actual_headers[-1] == "VALUE": logger.info( @@ -87,6 +88,11 @@ def _convert_wide_2_narrow(self, df: pd.DataFrame, name: str): except IndexError as ex: logger.debug(f"Could not reshape {name}") raise ex + except KeyError as ex: + logger.debug( + f"Actual headers: {actual_headers}\nConverted headers: {converted_headers}" + ) + raise ex all_headers = converted_headers + ["VALUE"] return narrow[all_headers].set_index(converted_headers) @@ -166,9 +172,13 @@ def read( input_data = {} self._check_for_default_values_csv(filepath) - self._compare_read_to_expected( - names=[f.split(".csv")[0] for f in os.listdir(filepath)] - ) + names = [ + f.split(".csv")[0] + for f in os.listdir(filepath) + if f.split(".")[-1] == "csv" + ] + logger.debug(names) + self._compare_read_to_expected(names=names) default_values = self._read_default_values(self.user_config) @@ -278,12 +288,19 @@ def read( config = self.user_config default_values = self._read_default_values(config) - amply_datafile = self.read_in_datafile(filepath, config) - inputs = self._convert_amply_to_dataframe(amply_datafile, config) - for config_type in ["param", "set"]: - inputs = self._get_missing_input_dataframes(inputs, config_type=config_type) - inputs = self._check_index(inputs) - return inputs, default_values + + # Check filepath exists + if os.path.exists(filepath): + amply_datafile = self.read_in_datafile(filepath, config) + inputs = self._convert_amply_to_dataframe(amply_datafile, config) + for config_type in ["param", "set"]: + inputs = self._get_missing_input_dataframes( + inputs, config_type=config_type + ) + inputs = self._check_index(inputs) + return inputs, default_values + else: + raise FileNotFoundError(f"File not found: {filepath}") def read_in_datafile(self, path_to_datafile: str, config: Dict) -> Amply: """Read in a datafile using the Amply parsing class @@ -322,6 +339,7 @@ def _load_parameter_definitions(self, config: dict) -> str: elif attributes["type"] == "set": elements += "set {};\n".format(name) + logger.debug("Amply Elements: %s", elements) return elements def _convert_amply_to_dataframe( diff --git a/src/otoole/utils.py b/src/otoole/utils.py index 99fc7a0e..3fedc367 100644 --- a/src/otoole/utils.py +++ b/src/otoole/utils.py @@ -26,7 +26,7 @@ def _read_file(open_file, ending): if ending == ".yaml" or ending == ".yml": - contents = load(open_file, Loader=UniqueKeyLoader) # typing: Dict + contents = load(open_file, Loader=UniqueKeyLoader) # typing: Dict[str, Any] elif ending == ".json": contents = json.load(open_file) # typing: Dict else: diff --git a/tests/fixtures/super_simple/csv/AccumulatedAnnualDemand.csv b/tests/fixtures/super_simple/csv/AccumulatedAnnualDemand.csv new file mode 100644 index 00000000..326b28c6 --- /dev/null +++ b/tests/fixtures/super_simple/csv/AccumulatedAnnualDemand.csv @@ -0,0 +1 @@ +REGION,FUEL,YEAR,VALUE diff --git a/tests/fixtures/super_simple/csv/AnnualEmissionLimit.csv b/tests/fixtures/super_simple/csv/AnnualEmissionLimit.csv new file mode 100644 index 00000000..1fa535a0 --- /dev/null +++ b/tests/fixtures/super_simple/csv/AnnualEmissionLimit.csv @@ -0,0 +1 @@ +REGION,EMISSION,YEAR,VALUE diff --git a/tests/fixtures/super_simple/csv/AnnualExogenousEmission.csv b/tests/fixtures/super_simple/csv/AnnualExogenousEmission.csv new file mode 100644 index 00000000..1fa535a0 --- /dev/null +++ b/tests/fixtures/super_simple/csv/AnnualExogenousEmission.csv @@ -0,0 +1 @@ +REGION,EMISSION,YEAR,VALUE diff --git a/tests/fixtures/super_simple/csv/AvailabilityFactor.csv b/tests/fixtures/super_simple/csv/AvailabilityFactor.csv new file mode 100644 index 00000000..6a91e609 --- /dev/null +++ b/tests/fixtures/super_simple/csv/AvailabilityFactor.csv @@ -0,0 +1 @@ +REGION,TECHNOLOGY,YEAR,VALUE diff --git a/tests/fixtures/super_simple/csv/CapacityFactor.csv b/tests/fixtures/super_simple/csv/CapacityFactor.csv new file mode 100644 index 00000000..ba3be6ef --- /dev/null +++ b/tests/fixtures/super_simple/csv/CapacityFactor.csv @@ -0,0 +1 @@ +REGION,TECHNOLOGY,TIMESLICE,YEAR,VALUE diff --git a/tests/fixtures/super_simple/csv/CapacityOfOneTechnologyUnit.csv b/tests/fixtures/super_simple/csv/CapacityOfOneTechnologyUnit.csv new file mode 100644 index 00000000..6a91e609 --- /dev/null +++ b/tests/fixtures/super_simple/csv/CapacityOfOneTechnologyUnit.csv @@ -0,0 +1 @@ +REGION,TECHNOLOGY,YEAR,VALUE diff --git a/tests/fixtures/super_simple/csv/CapacityToActivityUnit.csv b/tests/fixtures/super_simple/csv/CapacityToActivityUnit.csv new file mode 100644 index 00000000..98b90656 --- /dev/null +++ b/tests/fixtures/super_simple/csv/CapacityToActivityUnit.csv @@ -0,0 +1,2 @@ +REGION,TECHNOLOGY,VALUE +BB,gas_plant,1.0 diff --git a/tests/fixtures/super_simple/csv/CapitalCost.csv b/tests/fixtures/super_simple/csv/CapitalCost.csv new file mode 100644 index 00000000..95879aba --- /dev/null +++ b/tests/fixtures/super_simple/csv/CapitalCost.csv @@ -0,0 +1,2 @@ +REGION,TECHNOLOGY,YEAR,VALUE +BB,gas_plant,2016,1.03456 diff --git a/tests/fixtures/super_simple/csv/CapitalCostStorage.csv b/tests/fixtures/super_simple/csv/CapitalCostStorage.csv new file mode 100644 index 00000000..a7bcbd7f --- /dev/null +++ b/tests/fixtures/super_simple/csv/CapitalCostStorage.csv @@ -0,0 +1 @@ +REGION,STORAGE,YEAR,VALUE diff --git a/tests/fixtures/super_simple/csv/Conversionld.csv b/tests/fixtures/super_simple/csv/Conversionld.csv new file mode 100644 index 00000000..360887ad --- /dev/null +++ b/tests/fixtures/super_simple/csv/Conversionld.csv @@ -0,0 +1 @@ +TIMESLICE,DAYTYPE,VALUE diff --git a/tests/fixtures/super_simple/csv/Conversionlh.csv b/tests/fixtures/super_simple/csv/Conversionlh.csv new file mode 100644 index 00000000..6fc0a297 --- /dev/null +++ b/tests/fixtures/super_simple/csv/Conversionlh.csv @@ -0,0 +1 @@ +TIMESLICE,DAILYTIMEBRACKET,VALUE diff --git a/tests/fixtures/super_simple/csv/Conversionls.csv b/tests/fixtures/super_simple/csv/Conversionls.csv new file mode 100644 index 00000000..47b6ebde --- /dev/null +++ b/tests/fixtures/super_simple/csv/Conversionls.csv @@ -0,0 +1 @@ +TIMESLICE,SEASON,VALUE diff --git a/tests/fixtures/super_simple/csv/DAILYTIMEBRACKET.csv b/tests/fixtures/super_simple/csv/DAILYTIMEBRACKET.csv new file mode 100644 index 00000000..2dfe6a37 --- /dev/null +++ b/tests/fixtures/super_simple/csv/DAILYTIMEBRACKET.csv @@ -0,0 +1 @@ +VALUE diff --git a/tests/fixtures/super_simple/csv/DAYTYPE.csv b/tests/fixtures/super_simple/csv/DAYTYPE.csv new file mode 100644 index 00000000..2dfe6a37 --- /dev/null +++ b/tests/fixtures/super_simple/csv/DAYTYPE.csv @@ -0,0 +1 @@ +VALUE diff --git a/tests/fixtures/super_simple/csv/DaySplit.csv b/tests/fixtures/super_simple/csv/DaySplit.csv new file mode 100644 index 00000000..83dab5c1 --- /dev/null +++ b/tests/fixtures/super_simple/csv/DaySplit.csv @@ -0,0 +1 @@ +DAILYTIMEBRACKET,YEAR,VALUE diff --git a/tests/fixtures/super_simple/csv/DaysInDayType.csv b/tests/fixtures/super_simple/csv/DaysInDayType.csv new file mode 100644 index 00000000..7e5dd712 --- /dev/null +++ b/tests/fixtures/super_simple/csv/DaysInDayType.csv @@ -0,0 +1 @@ +SEASON,DAYTYPE,YEAR,VALUE diff --git a/tests/fixtures/super_simple/csv/DepreciationMethod.csv b/tests/fixtures/super_simple/csv/DepreciationMethod.csv new file mode 100644 index 00000000..8f1fa36c --- /dev/null +++ b/tests/fixtures/super_simple/csv/DepreciationMethod.csv @@ -0,0 +1 @@ +REGION,VALUE diff --git a/tests/fixtures/super_simple/csv/DiscountRate.csv b/tests/fixtures/super_simple/csv/DiscountRate.csv new file mode 100644 index 00000000..8f1fa36c --- /dev/null +++ b/tests/fixtures/super_simple/csv/DiscountRate.csv @@ -0,0 +1 @@ +REGION,VALUE diff --git a/tests/fixtures/super_simple/csv/DiscountRateIdv.csv b/tests/fixtures/super_simple/csv/DiscountRateIdv.csv new file mode 100644 index 00000000..1ca1a8e9 --- /dev/null +++ b/tests/fixtures/super_simple/csv/DiscountRateIdv.csv @@ -0,0 +1 @@ +REGION,TECHNOLOGY,VALUE diff --git a/tests/fixtures/super_simple/csv/DiscountRateStorage.csv b/tests/fixtures/super_simple/csv/DiscountRateStorage.csv new file mode 100644 index 00000000..2176c14c --- /dev/null +++ b/tests/fixtures/super_simple/csv/DiscountRateStorage.csv @@ -0,0 +1 @@ +REGION,STORAGE,VALUE diff --git a/tests/fixtures/super_simple/csv/EMISSION.csv b/tests/fixtures/super_simple/csv/EMISSION.csv new file mode 100644 index 00000000..2dfe6a37 --- /dev/null +++ b/tests/fixtures/super_simple/csv/EMISSION.csv @@ -0,0 +1 @@ +VALUE diff --git a/tests/fixtures/super_simple/csv/EmissionActivityRatio.csv b/tests/fixtures/super_simple/csv/EmissionActivityRatio.csv new file mode 100644 index 00000000..7c1c3ffc --- /dev/null +++ b/tests/fixtures/super_simple/csv/EmissionActivityRatio.csv @@ -0,0 +1 @@ +REGION,TECHNOLOGY,EMISSION,MODE_OF_OPERATION,YEAR,VALUE diff --git a/tests/fixtures/super_simple/csv/EmissionsPenalty.csv b/tests/fixtures/super_simple/csv/EmissionsPenalty.csv new file mode 100644 index 00000000..1fa535a0 --- /dev/null +++ b/tests/fixtures/super_simple/csv/EmissionsPenalty.csv @@ -0,0 +1 @@ +REGION,EMISSION,YEAR,VALUE diff --git a/tests/fixtures/super_simple/csv/FUEL.csv b/tests/fixtures/super_simple/csv/FUEL.csv new file mode 100644 index 00000000..0173ebb5 --- /dev/null +++ b/tests/fixtures/super_simple/csv/FUEL.csv @@ -0,0 +1,3 @@ +VALUE +natural_gas +electricity diff --git a/tests/fixtures/super_simple/csv/FixedCost.csv b/tests/fixtures/super_simple/csv/FixedCost.csv new file mode 100644 index 00000000..eff99453 --- /dev/null +++ b/tests/fixtures/super_simple/csv/FixedCost.csv @@ -0,0 +1,2 @@ +REGION,TECHNOLOGY,YEAR,VALUE +BB,gas_plant,2016,9.1101 diff --git a/tests/fixtures/super_simple/csv/InputActivityRatio.csv b/tests/fixtures/super_simple/csv/InputActivityRatio.csv new file mode 100644 index 00000000..cc36f0b5 --- /dev/null +++ b/tests/fixtures/super_simple/csv/InputActivityRatio.csv @@ -0,0 +1,2 @@ +REGION,TECHNOLOGY,FUEL,MODE_OF_OPERATION,YEAR,VALUE +BB,gas_plant,natural_gas,1,2016,1.1101 diff --git a/tests/fixtures/super_simple/csv/MODE_OF_OPERATION.csv b/tests/fixtures/super_simple/csv/MODE_OF_OPERATION.csv new file mode 100644 index 00000000..69e52e5d --- /dev/null +++ b/tests/fixtures/super_simple/csv/MODE_OF_OPERATION.csv @@ -0,0 +1,2 @@ +VALUE +1 diff --git a/tests/fixtures/super_simple/csv/MinStorageCharge.csv b/tests/fixtures/super_simple/csv/MinStorageCharge.csv new file mode 100644 index 00000000..a7bcbd7f --- /dev/null +++ b/tests/fixtures/super_simple/csv/MinStorageCharge.csv @@ -0,0 +1 @@ +REGION,STORAGE,YEAR,VALUE diff --git a/tests/fixtures/super_simple/csv/ModelPeriodEmissionLimit.csv b/tests/fixtures/super_simple/csv/ModelPeriodEmissionLimit.csv new file mode 100644 index 00000000..ccd4bcb3 --- /dev/null +++ b/tests/fixtures/super_simple/csv/ModelPeriodEmissionLimit.csv @@ -0,0 +1 @@ +REGION,EMISSION,VALUE diff --git a/tests/fixtures/super_simple/csv/ModelPeriodExogenousEmission.csv b/tests/fixtures/super_simple/csv/ModelPeriodExogenousEmission.csv new file mode 100644 index 00000000..ccd4bcb3 --- /dev/null +++ b/tests/fixtures/super_simple/csv/ModelPeriodExogenousEmission.csv @@ -0,0 +1 @@ +REGION,EMISSION,VALUE diff --git a/tests/fixtures/super_simple/csv/OperationalLife.csv b/tests/fixtures/super_simple/csv/OperationalLife.csv new file mode 100644 index 00000000..1ca1a8e9 --- /dev/null +++ b/tests/fixtures/super_simple/csv/OperationalLife.csv @@ -0,0 +1 @@ +REGION,TECHNOLOGY,VALUE diff --git a/tests/fixtures/super_simple/csv/OperationalLifeStorage.csv b/tests/fixtures/super_simple/csv/OperationalLifeStorage.csv new file mode 100644 index 00000000..2176c14c --- /dev/null +++ b/tests/fixtures/super_simple/csv/OperationalLifeStorage.csv @@ -0,0 +1 @@ +REGION,STORAGE,VALUE diff --git a/tests/fixtures/super_simple/csv/OutputActivityRatio.csv b/tests/fixtures/super_simple/csv/OutputActivityRatio.csv new file mode 100644 index 00000000..37406935 --- /dev/null +++ b/tests/fixtures/super_simple/csv/OutputActivityRatio.csv @@ -0,0 +1,3 @@ +REGION,TECHNOLOGY,FUEL,MODE_OF_OPERATION,YEAR,VALUE +BB,gas_import,natural_gas,1,2016,1.0 +BB,gas_plant,electricity,1,2016,1.0 diff --git a/tests/fixtures/super_simple/csv/REGION.csv b/tests/fixtures/super_simple/csv/REGION.csv new file mode 100644 index 00000000..016ac8fc --- /dev/null +++ b/tests/fixtures/super_simple/csv/REGION.csv @@ -0,0 +1,2 @@ +VALUE +BB diff --git a/tests/fixtures/super_simple/csv/REMinProductionTarget.csv b/tests/fixtures/super_simple/csv/REMinProductionTarget.csv new file mode 100644 index 00000000..b55c2264 --- /dev/null +++ b/tests/fixtures/super_simple/csv/REMinProductionTarget.csv @@ -0,0 +1 @@ +REGION,YEAR,VALUE diff --git a/tests/fixtures/super_simple/csv/RETagFuel.csv b/tests/fixtures/super_simple/csv/RETagFuel.csv new file mode 100644 index 00000000..326b28c6 --- /dev/null +++ b/tests/fixtures/super_simple/csv/RETagFuel.csv @@ -0,0 +1 @@ +REGION,FUEL,YEAR,VALUE diff --git a/tests/fixtures/super_simple/csv/RETagTechnology.csv b/tests/fixtures/super_simple/csv/RETagTechnology.csv new file mode 100644 index 00000000..6a91e609 --- /dev/null +++ b/tests/fixtures/super_simple/csv/RETagTechnology.csv @@ -0,0 +1 @@ +REGION,TECHNOLOGY,YEAR,VALUE diff --git a/tests/fixtures/super_simple/csv/ReserveMargin.csv b/tests/fixtures/super_simple/csv/ReserveMargin.csv new file mode 100644 index 00000000..b55c2264 --- /dev/null +++ b/tests/fixtures/super_simple/csv/ReserveMargin.csv @@ -0,0 +1 @@ +REGION,YEAR,VALUE diff --git a/tests/fixtures/super_simple/csv/ReserveMarginTagFuel.csv b/tests/fixtures/super_simple/csv/ReserveMarginTagFuel.csv new file mode 100644 index 00000000..326b28c6 --- /dev/null +++ b/tests/fixtures/super_simple/csv/ReserveMarginTagFuel.csv @@ -0,0 +1 @@ +REGION,FUEL,YEAR,VALUE diff --git a/tests/fixtures/super_simple/csv/ReserveMarginTagTechnology.csv b/tests/fixtures/super_simple/csv/ReserveMarginTagTechnology.csv new file mode 100644 index 00000000..6a91e609 --- /dev/null +++ b/tests/fixtures/super_simple/csv/ReserveMarginTagTechnology.csv @@ -0,0 +1 @@ +REGION,TECHNOLOGY,YEAR,VALUE diff --git a/tests/fixtures/super_simple/csv/ResidualCapacity.csv b/tests/fixtures/super_simple/csv/ResidualCapacity.csv new file mode 100644 index 00000000..1b3716cf --- /dev/null +++ b/tests/fixtures/super_simple/csv/ResidualCapacity.csv @@ -0,0 +1,2 @@ +REGION,TECHNOLOGY,YEAR,VALUE +BB,gas_plant,2016,3.1101 diff --git a/tests/fixtures/super_simple/csv/ResidualStorageCapacity.csv b/tests/fixtures/super_simple/csv/ResidualStorageCapacity.csv new file mode 100644 index 00000000..a7bcbd7f --- /dev/null +++ b/tests/fixtures/super_simple/csv/ResidualStorageCapacity.csv @@ -0,0 +1 @@ +REGION,STORAGE,YEAR,VALUE diff --git a/tests/fixtures/super_simple/csv/SEASON.csv b/tests/fixtures/super_simple/csv/SEASON.csv new file mode 100644 index 00000000..2dfe6a37 --- /dev/null +++ b/tests/fixtures/super_simple/csv/SEASON.csv @@ -0,0 +1 @@ +VALUE diff --git a/tests/fixtures/super_simple/csv/STORAGE.csv b/tests/fixtures/super_simple/csv/STORAGE.csv new file mode 100644 index 00000000..2dfe6a37 --- /dev/null +++ b/tests/fixtures/super_simple/csv/STORAGE.csv @@ -0,0 +1 @@ +VALUE diff --git a/tests/fixtures/super_simple/csv/SpecifiedAnnualDemand.csv b/tests/fixtures/super_simple/csv/SpecifiedAnnualDemand.csv new file mode 100644 index 00000000..b19cdc44 --- /dev/null +++ b/tests/fixtures/super_simple/csv/SpecifiedAnnualDemand.csv @@ -0,0 +1,2 @@ +REGION,FUEL,YEAR,VALUE +BB,electricity,2016,2.1101 diff --git a/tests/fixtures/super_simple/csv/SpecifiedDemandProfile.csv b/tests/fixtures/super_simple/csv/SpecifiedDemandProfile.csv new file mode 100644 index 00000000..dc17f3e9 --- /dev/null +++ b/tests/fixtures/super_simple/csv/SpecifiedDemandProfile.csv @@ -0,0 +1,2 @@ +REGION,FUEL,TIMESLICE,YEAR,VALUE +BB,electricity,x,2016,1.0 diff --git a/tests/fixtures/super_simple/csv/StorageLevelStart.csv b/tests/fixtures/super_simple/csv/StorageLevelStart.csv new file mode 100644 index 00000000..2176c14c --- /dev/null +++ b/tests/fixtures/super_simple/csv/StorageLevelStart.csv @@ -0,0 +1 @@ +REGION,STORAGE,VALUE diff --git a/tests/fixtures/super_simple/csv/StorageMaxChargeRate.csv b/tests/fixtures/super_simple/csv/StorageMaxChargeRate.csv new file mode 100644 index 00000000..2176c14c --- /dev/null +++ b/tests/fixtures/super_simple/csv/StorageMaxChargeRate.csv @@ -0,0 +1 @@ +REGION,STORAGE,VALUE diff --git a/tests/fixtures/super_simple/csv/StorageMaxDischargeRate.csv b/tests/fixtures/super_simple/csv/StorageMaxDischargeRate.csv new file mode 100644 index 00000000..2176c14c --- /dev/null +++ b/tests/fixtures/super_simple/csv/StorageMaxDischargeRate.csv @@ -0,0 +1 @@ +REGION,STORAGE,VALUE diff --git a/tests/fixtures/super_simple/csv/TECHNOLOGY.csv b/tests/fixtures/super_simple/csv/TECHNOLOGY.csv new file mode 100644 index 00000000..f563cf92 --- /dev/null +++ b/tests/fixtures/super_simple/csv/TECHNOLOGY.csv @@ -0,0 +1,3 @@ +VALUE +gas_import +gas_plant diff --git a/tests/fixtures/super_simple/csv/TIMESLICE.csv b/tests/fixtures/super_simple/csv/TIMESLICE.csv new file mode 100644 index 00000000..9480ca01 --- /dev/null +++ b/tests/fixtures/super_simple/csv/TIMESLICE.csv @@ -0,0 +1,2 @@ +VALUE +x diff --git a/tests/fixtures/super_simple/csv/TechnologyFromStorage.csv b/tests/fixtures/super_simple/csv/TechnologyFromStorage.csv new file mode 100644 index 00000000..384c871b --- /dev/null +++ b/tests/fixtures/super_simple/csv/TechnologyFromStorage.csv @@ -0,0 +1 @@ +REGION,TECHNOLOGY,STORAGE,MODE_OF_OPERATION,VALUE diff --git a/tests/fixtures/super_simple/csv/TechnologyToStorage.csv b/tests/fixtures/super_simple/csv/TechnologyToStorage.csv new file mode 100644 index 00000000..384c871b --- /dev/null +++ b/tests/fixtures/super_simple/csv/TechnologyToStorage.csv @@ -0,0 +1 @@ +REGION,TECHNOLOGY,STORAGE,MODE_OF_OPERATION,VALUE diff --git a/tests/fixtures/super_simple/csv/TotalAnnualMaxCapacity.csv b/tests/fixtures/super_simple/csv/TotalAnnualMaxCapacity.csv new file mode 100644 index 00000000..6a91e609 --- /dev/null +++ b/tests/fixtures/super_simple/csv/TotalAnnualMaxCapacity.csv @@ -0,0 +1 @@ +REGION,TECHNOLOGY,YEAR,VALUE diff --git a/tests/fixtures/super_simple/csv/TotalAnnualMaxCapacityInvestment.csv b/tests/fixtures/super_simple/csv/TotalAnnualMaxCapacityInvestment.csv new file mode 100644 index 00000000..6a91e609 --- /dev/null +++ b/tests/fixtures/super_simple/csv/TotalAnnualMaxCapacityInvestment.csv @@ -0,0 +1 @@ +REGION,TECHNOLOGY,YEAR,VALUE diff --git a/tests/fixtures/super_simple/csv/TotalAnnualMinCapacity.csv b/tests/fixtures/super_simple/csv/TotalAnnualMinCapacity.csv new file mode 100644 index 00000000..6a91e609 --- /dev/null +++ b/tests/fixtures/super_simple/csv/TotalAnnualMinCapacity.csv @@ -0,0 +1 @@ +REGION,TECHNOLOGY,YEAR,VALUE diff --git a/tests/fixtures/super_simple/csv/TotalAnnualMinCapacityInvestment.csv b/tests/fixtures/super_simple/csv/TotalAnnualMinCapacityInvestment.csv new file mode 100644 index 00000000..6a91e609 --- /dev/null +++ b/tests/fixtures/super_simple/csv/TotalAnnualMinCapacityInvestment.csv @@ -0,0 +1 @@ +REGION,TECHNOLOGY,YEAR,VALUE diff --git a/tests/fixtures/super_simple/csv/TotalTechnologyAnnualActivityLowerLimit.csv b/tests/fixtures/super_simple/csv/TotalTechnologyAnnualActivityLowerLimit.csv new file mode 100644 index 00000000..6a91e609 --- /dev/null +++ b/tests/fixtures/super_simple/csv/TotalTechnologyAnnualActivityLowerLimit.csv @@ -0,0 +1 @@ +REGION,TECHNOLOGY,YEAR,VALUE diff --git a/tests/fixtures/super_simple/csv/TotalTechnologyAnnualActivityUpperLimit.csv b/tests/fixtures/super_simple/csv/TotalTechnologyAnnualActivityUpperLimit.csv new file mode 100644 index 00000000..6a91e609 --- /dev/null +++ b/tests/fixtures/super_simple/csv/TotalTechnologyAnnualActivityUpperLimit.csv @@ -0,0 +1 @@ +REGION,TECHNOLOGY,YEAR,VALUE diff --git a/tests/fixtures/super_simple/csv/TotalTechnologyModelPeriodActivityLowerLimit.csv b/tests/fixtures/super_simple/csv/TotalTechnologyModelPeriodActivityLowerLimit.csv new file mode 100644 index 00000000..1ca1a8e9 --- /dev/null +++ b/tests/fixtures/super_simple/csv/TotalTechnologyModelPeriodActivityLowerLimit.csv @@ -0,0 +1 @@ +REGION,TECHNOLOGY,VALUE diff --git a/tests/fixtures/super_simple/csv/TotalTechnologyModelPeriodActivityUpperLimit.csv b/tests/fixtures/super_simple/csv/TotalTechnologyModelPeriodActivityUpperLimit.csv new file mode 100644 index 00000000..1ca1a8e9 --- /dev/null +++ b/tests/fixtures/super_simple/csv/TotalTechnologyModelPeriodActivityUpperLimit.csv @@ -0,0 +1 @@ +REGION,TECHNOLOGY,VALUE diff --git a/tests/fixtures/super_simple/csv/TradeRoute.csv b/tests/fixtures/super_simple/csv/TradeRoute.csv new file mode 100644 index 00000000..11316319 --- /dev/null +++ b/tests/fixtures/super_simple/csv/TradeRoute.csv @@ -0,0 +1 @@ +REGION,_REGION,FUEL,YEAR,VALUE diff --git a/tests/fixtures/super_simple/csv/VariableCost.csv b/tests/fixtures/super_simple/csv/VariableCost.csv new file mode 100644 index 00000000..6948a628 --- /dev/null +++ b/tests/fixtures/super_simple/csv/VariableCost.csv @@ -0,0 +1,2 @@ +REGION,TECHNOLOGY,MODE_OF_OPERATION,YEAR,VALUE +BB,gas_plant,1,2016,9.1202 diff --git a/tests/fixtures/super_simple/csv/YEAR.csv b/tests/fixtures/super_simple/csv/YEAR.csv new file mode 100644 index 00000000..55c26cd2 --- /dev/null +++ b/tests/fixtures/super_simple/csv/YEAR.csv @@ -0,0 +1,2 @@ +VALUE +2016 diff --git a/tests/fixtures/super_simple/csv/YearSplit.csv b/tests/fixtures/super_simple/csv/YearSplit.csv new file mode 100644 index 00000000..9656554c --- /dev/null +++ b/tests/fixtures/super_simple/csv/YearSplit.csv @@ -0,0 +1,2 @@ +TIMESLICE,YEAR,VALUE +x,2016,1.0 diff --git a/tests/fixtures/super_simple/csv/_REGION.csv b/tests/fixtures/super_simple/csv/_REGION.csv new file mode 100644 index 00000000..016ac8fc --- /dev/null +++ b/tests/fixtures/super_simple/csv/_REGION.csv @@ -0,0 +1,2 @@ +VALUE +BB diff --git a/tests/fixtures/super_simple/super_simple.txt b/tests/fixtures/super_simple/super_simple.txt new file mode 100644 index 00000000..6bde7831 --- /dev/null +++ b/tests/fixtures/super_simple/super_simple.txt @@ -0,0 +1,153 @@ +# Model file written by *otoole* +param default 0 : AccumulatedAnnualDemand := +; +param default -1 : AnnualEmissionLimit := +; +param default 0 : AnnualExogenousEmission := +; +param default 1 : AvailabilityFactor := +; +param default 1 : CapacityFactor := +; +param default 0 : CapacityOfOneTechnologyUnit := +; +param default 1 : CapacityToActivityUnit := +; +param default 0 : CapitalCost := +BB gas_plant 2016 1.03456 +; +param default 0 : CapitalCostStorage := +; +param default 0 : Conversionld := +; +param default 0 : Conversionlh := +; +param default 0 : Conversionls := +; +set DAILYTIMEBRACKET := +; +set DAYTYPE := +; +param default 0.00137 : DaySplit := +; +param default 7 : DaysInDayType := +; +param default 1 : DepreciationMethod := +; +param default 0.05 : DiscountRate := +; +param default 0.05 : DiscountRateIdv := +; +param default 0.05 : DiscountRateStorage := +; +set EMISSION := +; +param default 0 : EmissionActivityRatio := +; +param default 0 : EmissionsPenalty := +; +set FUEL := +natural_gas +electricity +; +param default 0 : FixedCost := +BB gas_plant 2016 9.1101 +; +param default 0 : InputActivityRatio := +BB gas_plant natural_gas 1 2016 1.1101 +; +set MODE_OF_OPERATION := +1 +; +param default 0 : MinStorageCharge := +; +param default -1 : ModelPeriodEmissionLimit := +; +param default 0 : ModelPeriodExogenousEmission := +; +param default 1 : OperationalLife := +; +param default 0 : OperationalLifeStorage := +; +param default 0 : OutputActivityRatio := +BB gas_import natural_gas 1 2016 1 +BB gas_plant electricity 1 2016 1 +; +set REGION := +BB +; +param default 0 : REMinProductionTarget := +; +param default 0 : RETagFuel := +; +param default 0 : RETagTechnology := +; +param default 1 : ReserveMargin := +; +param default 0 : ReserveMarginTagFuel := +; +param default 0 : ReserveMarginTagTechnology := +; +param default 0 : ResidualCapacity := +BB gas_plant 2016 3.1101 +; +param default 999 : ResidualStorageCapacity := +; +set SEASON := +; +set STORAGE := +; +param default 0 : SpecifiedAnnualDemand := +BB electricity 2016 2.1101 +; +param default 0 : SpecifiedDemandProfile := +BB electricity x 2016 1 +; +param default 0 : StorageLevelStart := +; +param default 0 : StorageMaxChargeRate := +; +param default 0 : StorageMaxDischargeRate := +; +set TECHNOLOGY := +gas_import +gas_plant +; +set TIMESLICE := +x +; +param default 0 : TechnologyFromStorage := +; +param default 0 : TechnologyToStorage := +; +param default -1 : TotalAnnualMaxCapacity := +; +param default -1 : TotalAnnualMaxCapacityInvestment := +; +param default 0 : TotalAnnualMinCapacity := +; +param default 0 : TotalAnnualMinCapacityInvestment := +; +param default 0 : TotalTechnologyAnnualActivityLowerLimit := +; +param default -1 : TotalTechnologyAnnualActivityUpperLimit := +; +param default 0 : TotalTechnologyModelPeriodActivityLowerLimit := +; +param default -1 : TotalTechnologyModelPeriodActivityUpperLimit := +; +param default 0 : TradeRoute := +; +param default 0 : VariableCost := +BB gas_plant 1 2016 9.1202 +; +set YEAR := +2016 +; +param default 0 : YearSplit := +x 2016 1 +; +set _REGION := +BB +; +end; diff --git a/tests/fixtures/super_simple/super_simple.yaml b/tests/fixtures/super_simple/super_simple.yaml new file mode 100644 index 00000000..6fcf713e --- /dev/null +++ b/tests/fixtures/super_simple/super_simple.yaml @@ -0,0 +1,520 @@ +AccumulatedAnnualDemand: + indices: [REGION,FUEL,YEAR] + type: param + dtype: float + default: 0 +AnnualEmissionLimit: + indices: [REGION,EMISSION,YEAR] + type: param + dtype: float + default: -1 +AnnualExogenousEmission: + indices: [REGION,EMISSION,YEAR] + type: param + dtype: float + default: 0 +AvailabilityFactor: + indices: [REGION,TECHNOLOGY,YEAR] + type: param + dtype: float + default: 1 +CapacityFactor: + indices: [REGION,TECHNOLOGY,TIMESLICE,YEAR] + type: param + dtype: float + default: 1 +CapacityOfOneTechnologyUnit: + indices: [REGION,TECHNOLOGY,YEAR] + type: param + dtype: float + default: 0 +CapacityToActivityUnit: + indices: [REGION,TECHNOLOGY] + type: param + dtype: float + default: 1 +CapitalCost: + indices: [REGION,TECHNOLOGY,YEAR] + type: param + dtype: float + default: 0 +CapitalCostStorage: + indices: [REGION,STORAGE,YEAR] + type: param + dtype: float + default: 0 +Conversionld: + indices: [TIMESLICE,DAYTYPE] + type: param + dtype: float + default: 0 +Conversionlh: + indices: [TIMESLICE,DAILYTIMEBRACKET] + type: param + dtype: float + default: 0 +Conversionls: + indices: [TIMESLICE,SEASON] + type: param + dtype: float + default: 0 +DAILYTIMEBRACKET: + dtype: int + type: set +DaysInDayType: + indices: [SEASON,DAYTYPE,YEAR] + type: param + dtype: float + default: 7 +DaySplit: + indices: [DAILYTIMEBRACKET,YEAR] + type: param + dtype: float + default: 0.00137 +DAYTYPE: + dtype: int + type: set +DepreciationMethod: + indices: [REGION] + type: param + dtype: float + default: 1 +DiscountRate: + indices: [REGION] + type: param + dtype: float + default: 0.05 +DiscountRateIdv: + indices: [REGION,TECHNOLOGY] + type: param + dtype: float + default: 0.05 +DiscountRateStorage: + indices: [REGION,STORAGE] + type: param + dtype: float + default: 0.05 +EMISSION: + dtype: str + type: set +EmissionActivityRatio: + indices: [REGION,TECHNOLOGY,EMISSION,MODE_OF_OPERATION,YEAR] + type: param + dtype: float + default: 0 +EmissionsPenalty: + indices: [REGION,EMISSION,YEAR] + type: param + dtype: float + default: 0 +FixedCost: + indices: [REGION,TECHNOLOGY,YEAR] + type: param + dtype: float + default: 0 +FUEL: + dtype: str + type: set +InputActivityRatio: + indices: [REGION,TECHNOLOGY,FUEL,MODE_OF_OPERATION,YEAR] + type: param + dtype: float + default: 0 +MinStorageCharge: + indices: [REGION,STORAGE,YEAR] + type: param + dtype: float + default: 0 +MODE_OF_OPERATION: + dtype: int + type: set +ModelPeriodEmissionLimit: + indices: [REGION,EMISSION] + type: param + dtype: float + default: -1 +ModelPeriodExogenousEmission: + indices: [REGION,EMISSION] + type: param + dtype: float + default: 0 +OperationalLife: + indices: [REGION,TECHNOLOGY] + type: param + dtype: float + default: 1 +OperationalLifeStorage: + indices: [REGION,STORAGE] + type: param + dtype: float + default: 0 +OutputActivityRatio: + indices: [REGION,TECHNOLOGY,FUEL,MODE_OF_OPERATION,YEAR] + type: param + dtype: float + default: 0 +REGION: + dtype: str + type: set +_REGION: + dtype: str + type: set +REMinProductionTarget: + indices: [REGION,YEAR] + type: param + dtype: float + default: 0 +ReserveMargin: + indices: [REGION,YEAR] + type: param + dtype: float + default: 1 +ReserveMarginTagFuel: + indices: [REGION,FUEL,YEAR] + type: param + dtype: float + default: 0 +ReserveMarginTagTechnology: + indices: [REGION,TECHNOLOGY,YEAR] + type: param + dtype: float + default: 0 +ResidualCapacity: + indices: [REGION,TECHNOLOGY,YEAR] + type: param + dtype: float + default: 0 +ResidualStorageCapacity: + indices: [REGION,STORAGE,YEAR] + type: param + dtype: float + default: 999 +RETagFuel: + indices: [REGION,FUEL,YEAR] + type: param + dtype: float + default: 0 +RETagTechnology: + indices: [REGION,TECHNOLOGY,YEAR] + type: param + dtype: float + default: 0 +SEASON: + dtype: int + type: set +SpecifiedAnnualDemand: + indices: [REGION,FUEL,YEAR] + type: param + dtype: float + default: 0 +SpecifiedDemandProfile: + indices: [REGION,FUEL,TIMESLICE,YEAR] + type: param + dtype: float + default: 0 +STORAGE: + dtype: str + type: set +StorageLevelStart: + indices: [REGION,STORAGE] + type: param + dtype: float + default: 0 +StorageMaxChargeRate: + indices: [REGION,STORAGE] + type: param + dtype: float + default: 0 +StorageMaxDischargeRate: + indices: [REGION,STORAGE] + type: param + dtype: float + default: 0 +TECHNOLOGY: + dtype: str + type: set +TechnologyFromStorage: + indices: [REGION,TECHNOLOGY,STORAGE,MODE_OF_OPERATION] + type: param + dtype: float + default: 0 +TechnologyToStorage: + indices: [REGION,TECHNOLOGY,STORAGE,MODE_OF_OPERATION] + type: param + dtype: float + default: 0 +TIMESLICE: + dtype: str + type: set +TotalAnnualMaxCapacity: + indices: [REGION,TECHNOLOGY,YEAR] + type: param + dtype: float + default: -1 +TotalAnnualMaxCapacityInvestment: + short_name: TotalAnnualMaxCapacityInvestmen + indices: [REGION,TECHNOLOGY,YEAR] + type: param + dtype: float + default: -1 +TotalAnnualMinCapacity: + indices: [REGION,TECHNOLOGY,YEAR] + type: param + dtype: float + default: 0 +TotalAnnualMinCapacityInvestment: + short_name: TotalAnnualMinCapacityInvestmen + indices: [REGION,TECHNOLOGY,YEAR] + type: param + dtype: float + default: 0 +TotalTechnologyAnnualActivityLowerLimit: + short_name: TotalTechnologyAnnualActivityLo + indices: [REGION,TECHNOLOGY,YEAR] + type: param + dtype: float + default: 0 +TotalTechnologyAnnualActivityUpperLimit: + short_name: TotalTechnologyAnnualActivityUp + indices: [REGION,TECHNOLOGY,YEAR] + type: param + dtype: float + default: -1 +TotalTechnologyModelPeriodActivityLowerLimit: + short_name: TotalTechnologyModelPeriodActLo + indices: [REGION,TECHNOLOGY] + type: param + dtype: float + default: 0 +TotalTechnologyModelPeriodActivityUpperLimit: + short_name: TotalTechnologyModelPeriodActUp + indices: [REGION,TECHNOLOGY] + type: param + dtype: float + default: -1 +TradeRoute: + indices: [REGION,_REGION,FUEL,YEAR] + type: param + dtype: float + default: 0 +VariableCost: + indices: [REGION,TECHNOLOGY,MODE_OF_OPERATION,YEAR] + type: param + dtype: float + default: 0 +YEAR: + dtype: int + type: set +YearSplit: + indices: [TIMESLICE,YEAR] + type: param + dtype: float + default: 0 +AnnualEmissions: + indices: [REGION,EMISSION,YEAR] + type: result + dtype: float + default: 0 + calculated: True +AccumulatedNewCapacity: + indices: [REGION, TECHNOLOGY, YEAR] + type: result + dtype: float + default: 0 + calculated: True +AnnualFixedOperatingCost: + indices: [REGION, TECHNOLOGY, YEAR] + type: result + dtype: float + default: 0 + calculated: True +AnnualTechnologyEmission: + indices: [REGION, TECHNOLOGY, EMISSION, YEAR] + type: result + dtype: float + default: 0 + calculated: True +AnnualTechnologyEmissionByMode: + indices: [REGION, TECHNOLOGY, EMISSION, MODE_OF_OPERATION, YEAR] + type: result + dtype: float + default: 0 + calculated: True +AnnualVariableOperatingCost: + indices: [REGION, TECHNOLOGY, YEAR] + type: result + dtype: float + default: 0 + calculated: True +CapitalInvestment: + indices: [REGION, TECHNOLOGY, YEAR] + type: result + dtype: float + default: 0 + calculated: True +Demand: + indices: [REGION, TIMESLICE, FUEL, YEAR] + type: result + dtype: float + default: 0 + calculated: True +DiscountedSalvageValue: + indices: [REGION, TECHNOLOGY, YEAR] + type: result + dtype: float + default: 0 + calculated: False +DiscountedTechnologyEmissionsPenalty: + short_name: DiscountedTechEmissionsPenalty + indices: [REGION, TECHNOLOGY, YEAR] + type: result + dtype: float + default: 0 + calculated: False +NewCapacity: + indices: [REGION, TECHNOLOGY, YEAR] + type: result + dtype: float + default: 0 + calculated: False +NewStorageCapacity: + indices: [REGION, STORAGE, YEAR] + type: result + dtype: float + default: 0 + calculated: False +NumberOfNewTechnologyUnits: + indices: [REGION, TECHNOLOGY, YEAR] + type: result + dtype: float + default: 0 + calculated: False +ProductionByTechnology: + indices: [REGION, TIMESLICE, TECHNOLOGY, FUEL, YEAR] + type: result + dtype: float + default: 0 + calculated: True +ProductionByTechnologyAnnual: + indices: [REGION, TECHNOLOGY, FUEL, YEAR] + type: result + dtype: float + default: 0 + calculated: True +RateOfActivity: + indices: [REGION, TIMESLICE, TECHNOLOGY, MODE_OF_OPERATION, YEAR] + type: result + dtype: float + default: 0 + calculated: False +RateOfProductionByTechnology: + indices: [REGION, TIMESLICE, TECHNOLOGY, FUEL, YEAR] + type: result + dtype: float + default: 0 + calculated: True +RateOfProductionByTechnologyByMode: + short_name: RateOfProductionByTechByMode + indices: [REGION, TIMESLICE, TECHNOLOGY, MODE_OF_OPERATION, FUEL, YEAR] + type: result + dtype: float + default: 0 + calculated: True +RateOfUseByTechnology: + indices: [REGION, TIMESLICE, TECHNOLOGY, FUEL, YEAR] + type: result + dtype: float + default: 0 + calculated: True +RateOfUseByTechnologyByMode: + indices: [REGION, TIMESLICE, TECHNOLOGY, MODE_OF_OPERATION, FUEL, YEAR] + type: result + dtype: float + default: 0 + calculated: True +SalvageValue: + indices: [REGION, TECHNOLOGY, YEAR] + type: result + dtype: float + default: 0 + calculated: False +SalvageValueStorage: + indices: [REGION, STORAGE, YEAR] + type: result + dtype: float + default: 0 + calculated: False +StorageLevelDayTypeFinish: + indices: [REGION, STORAGE, SEASON, DAYTYPE, YEAR] + type: result + dtype: float + default: 0 + calculated: False +StorageLevelDayTypeStart: + indices: [REGION, STORAGE, SEASON, DAYTYPE, YEAR] + type: result + dtype: float + default: 0 + calculated: False +StorageLevelSeasonStart: + indices: [REGION, STORAGE, SEASON, YEAR] + type: result + dtype: float + default: 0 + calculated: False +StorageLevelYearStart: + indices: [REGION, STORAGE, YEAR] + type: result + dtype: float + default: 0 + calculated: False +StorageLevelYearFinish: + indices: [REGION, STORAGE, YEAR] + type: result + dtype: float + default: 0 + calculated: False +TotalAnnualTechnologyActivityByMode: + short_name: TotalAnnualTechActivityByMode + indices: [REGION, TECHNOLOGY, MODE_OF_OPERATION, YEAR] + type: result + dtype: float + default: 0 + calculated: True +TotalCapacityAnnual: + indices: [REGION, TECHNOLOGY, YEAR] + type: result + dtype: float + default: 0 + calculated: True +TotalDiscountedCost: + indices: [REGION,YEAR] + type: result + dtype: float + default: 0 + calculated: True +TotalTechnologyAnnualActivity: + indices: [REGION, TECHNOLOGY, YEAR] + type: result + dtype: float + default: 0 + calculated: True +TotalTechnologyModelPeriodActivity: + short_name: TotalTechModelPeriodActivity + indices: [REGION, TECHNOLOGY] + type: result + dtype: float + default: 0 + calculated: True +Trade: + indices: [REGION,TIMESLICE,FUEL,YEAR] + type: result + dtype: float + default: 0 + calculated: False +UseByTechnology: + indices: [REGION,TIMESLICE,TECHNOLOGY,FUEL,YEAR] + type: result + dtype: float + default: 0 + calculated: False diff --git a/tests/fixtures/super_simple/super_simple_gnu.lp b/tests/fixtures/super_simple/super_simple_gnu.lp new file mode 100644 index 00000000..ba9e2917 --- /dev/null +++ b/tests/fixtures/super_simple/super_simple_gnu.lp @@ -0,0 +1,222 @@ +\* Problem: OSeMOSYS *\ + +Minimize + cost: + TotalDiscountedCost(BB,2016) + +Subject To + EQ_SpecifiedDemand(BB,x,electricity,2016): + - RateOfDemand(BB,x,electricity,2016) = -2.1101 + CAa1_TotalNewCapacity(BB,gas_import,2016): + - NewCapacity(BB,gas_import,2016) + + AccumulatedNewCapacity(BB,gas_import,2016) = -0 + CAa1_TotalNewCapacity(BB,gas_plant,2016): + - NewCapacity(BB,gas_plant,2016) + + AccumulatedNewCapacity(BB,gas_plant,2016) = -0 + CAa2_TotalAnnualCapacity(BB,gas_import,2016): + + AccumulatedNewCapacity(BB,gas_import,2016) + - TotalCapacityAnnual(BB,gas_import,2016) = -0 + CAa2_TotalAnnualCapacity(BB,gas_plant,2016): + + AccumulatedNewCapacity(BB,gas_plant,2016) + - TotalCapacityAnnual(BB,gas_plant,2016) = -3.1101 + CAa3_TotalActivityOfEachTechnology(BB,gas_import,x,2016): + + RateOfActivity(BB,x,gas_import,1,2016) + - RateOfTotalActivity(BB,gas_import,x,2016) = -0 + CAa3_TotalActivityOfEachTechnology(BB,gas_plant,x,2016): + + RateOfActivity(BB,x,gas_plant,1,2016) + - RateOfTotalActivity(BB,gas_plant,x,2016) = -0 + CAa4_Constraint_Capacity(BB,x,gas_import,2016): + - TotalCapacityAnnual(BB,gas_import,2016) + + RateOfTotalActivity(BB,gas_import,x,2016) <= -0 + CAa4_Constraint_Capacity(BB,x,gas_plant,2016): + - TotalCapacityAnnual(BB,gas_plant,2016) + + RateOfTotalActivity(BB,gas_plant,x,2016) <= -0 + EBa1_RateOfFuelProduction1(BB,x,natural_gas,gas_import,1,2016): + + RateOfActivity(BB,x,gas_import,1,2016) + - RateOfProductionByTechnologyByMode(BB,x,gas_import,1,natural_gas,2016) + = -0 + EBa1_RateOfFuelProduction1(BB,x,electricity,gas_plant,1,2016): + + RateOfActivity(BB,x,gas_plant,1,2016) + - RateOfProductionByTechnologyByMode(BB,x,gas_plant,1,electricity,2016) + = -0 + EBa2_RateOfFuelProduction2(BB,x,natural_gas,gas_import,2016): + + RateOfProductionByTechnologyByMode(BB,x,gas_import,1,natural_gas,2016) + - RateOfProductionByTechnology(BB,x,gas_import,natural_gas,2016) = -0 + EBa2_RateOfFuelProduction2(BB,x,electricity,gas_plant,2016): + + RateOfProductionByTechnologyByMode(BB,x,gas_plant,1,electricity,2016) + - RateOfProductionByTechnology(BB,x,gas_plant,electricity,2016) = -0 + EBa3_RateOfFuelProduction3(BB,x,natural_gas,2016): + + RateOfProductionByTechnology(BB,x,gas_import,natural_gas,2016) + - RateOfProduction(BB,x,natural_gas,2016) = -0 + EBa3_RateOfFuelProduction3(BB,x,electricity,2016): + + RateOfProductionByTechnology(BB,x,gas_plant,electricity,2016) + - RateOfProduction(BB,x,electricity,2016) = -0 + EBa4_RateOfFuelUse1(BB,x,natural_gas,gas_plant,1,2016): + + 1.1101 RateOfActivity(BB,x,gas_plant,1,2016) + - RateOfUseByTechnologyByMode(BB,x,gas_plant,1,natural_gas,2016) = -0 + EBa5_RateOfFuelUse2(BB,x,natural_gas,gas_plant,2016): + + RateOfUseByTechnologyByMode(BB,x,gas_plant,1,natural_gas,2016) + - RateOfUseByTechnology(BB,x,gas_plant,natural_gas,2016) = -0 + EBa6_RateOfFuelUse3(BB,x,natural_gas,2016): + + RateOfUseByTechnology(BB,x,gas_plant,natural_gas,2016) + + RateOfUseByTechnology(BB,x,gas_import,natural_gas,2016) + - RateOfUse(BB,x,natural_gas,2016) = -0 + EBa7_EnergyBalanceEachTS1(BB,x,natural_gas,2016): + + RateOfProduction(BB,x,natural_gas,2016) + - Production(BB,x,natural_gas,2016) = -0 + EBa7_EnergyBalanceEachTS1(BB,x,electricity,2016): + + RateOfProduction(BB,x,electricity,2016) + - Production(BB,x,electricity,2016) = -0 + EBa8_EnergyBalanceEachTS2(BB,x,natural_gas,2016): + + RateOfUse(BB,x,natural_gas,2016) - Use(BB,x,natural_gas,2016) = -0 + EBa9_EnergyBalanceEachTS3(BB,x,electricity,2016): + + RateOfDemand(BB,x,electricity,2016) - Demand(BB,x,electricity,2016) + = -0 + EBa11_EnergyBalanceEachTS5(BB,x,natural_gas,2016): + - Demand(BB,x,natural_gas,2016) + Production(BB,x,natural_gas,2016) + - Use(BB,x,natural_gas,2016) >= -0 + EBa11_EnergyBalanceEachTS5(BB,x,electricity,2016): + - Demand(BB,x,electricity,2016) + Production(BB,x,electricity,2016) + - Use(BB,x,electricity,2016) >= -0 + EBb1_EnergyBalanceEachYear1(BB,natural_gas,2016): + + Production(BB,x,natural_gas,2016) + - ProductionAnnual(BB,natural_gas,2016) = -0 + EBb1_EnergyBalanceEachYear1(BB,electricity,2016): + + Production(BB,x,electricity,2016) + - ProductionAnnual(BB,electricity,2016) = -0 + EBb2_EnergyBalanceEachYear2(BB,natural_gas,2016): + + Use(BB,x,natural_gas,2016) - UseAnnual(BB,natural_gas,2016) = -0 + EBb2_EnergyBalanceEachYear2(BB,electricity,2016): + + Use(BB,x,electricity,2016) - UseAnnual(BB,electricity,2016) = -0 + EBb4_EnergyBalanceEachYear4(BB,natural_gas,2016): + + ProductionAnnual(BB,natural_gas,2016) + - UseAnnual(BB,natural_gas,2016) >= -0 + EBb4_EnergyBalanceEachYear4(BB,electricity,2016): + + ProductionAnnual(BB,electricity,2016) + - UseAnnual(BB,electricity,2016) >= -0 + Acc1_FuelProductionByTechnology(BB,x,gas_import,natural_gas,2016): + + RateOfProductionByTechnology(BB,x,gas_import,natural_gas,2016) + - ProductionByTechnology(BB,x,gas_import,natural_gas,2016) = -0 + Acc1_FuelProductionByTechnology(BB,x,gas_plant,electricity,2016): + + RateOfProductionByTechnology(BB,x,gas_plant,electricity,2016) + - ProductionByTechnology(BB,x,gas_plant,electricity,2016) = -0 + Acc2_FuelUseByTechnology(BB,x,gas_plant,natural_gas,2016): + + RateOfUseByTechnology(BB,x,gas_plant,natural_gas,2016) + - UseByTechnology(BB,x,gas_plant,natural_gas,2016) = -0 + Acc3_AverageAnnualRateOfActivity(BB,gas_import,1,2016): + + RateOfActivity(BB,x,gas_import,1,2016) + - TotalAnnualTechnologyActivityByMode(BB,gas_import,1,2016) = -0 + Acc3_AverageAnnualRateOfActivity(BB,gas_plant,1,2016): + + RateOfActivity(BB,x,gas_plant,1,2016) + - TotalAnnualTechnologyActivityByMode(BB,gas_plant,1,2016) = -0 + Acc4_ModelPeriodCostByRegion(BB): + TotalDiscountedCost(BB,2016) + - ModelPeriodCostByRegion(BB) = -0 + CC1_UndiscountedCapitalInvestment(BB,gas_import,2016): + + 1e-05 NewCapacity(BB,gas_import,2016) + - CapitalInvestment(BB,gas_import,2016) = -0 + CC1_UndiscountedCapitalInvestment(BB,gas_plant,2016): + + 1.03456 NewCapacity(BB,gas_plant,2016) + - CapitalInvestment(BB,gas_plant,2016) = -0 + CC2_DiscountingCapitalInvestment(BB,gas_import,2016): + + CapitalInvestment(BB,gas_import,2016) + - DiscountedCapitalInvestment(BB,gas_import,2016) = -0 + CC2_DiscountingCapitalInvestment(BB,gas_plant,2016): + + CapitalInvestment(BB,gas_plant,2016) + - DiscountedCapitalInvestment(BB,gas_plant,2016) = -0 + SV3_SalvageValueAtEndOfPeriod3(BB,gas_import,2016): + + SalvageValue(BB,gas_import,2016) = -0 + SV3_SalvageValueAtEndOfPeriod3(BB,gas_plant,2016): + + SalvageValue(BB,gas_plant,2016) = -0 + SV4_SalvageValueDiscountedToStartYear(BB,gas_import,2016): + - 0.952380952380952 SalvageValue(BB,gas_import,2016) + + DiscountedSalvageValue(BB,gas_import,2016) = -0 + SV4_SalvageValueDiscountedToStartYear(BB,gas_plant,2016): + - 0.952380952380952 SalvageValue(BB,gas_plant,2016) + + DiscountedSalvageValue(BB,gas_plant,2016) = -0 + OC1_OperatingCostsVariable(BB,gas_plant,x,2016): + + 9.1202 TotalAnnualTechnologyActivityByMode(BB,gas_plant,1,2016) + - AnnualVariableOperatingCost(BB,gas_plant,2016) = -0 + OC2_OperatingCostsFixedAnnual(BB,gas_import,2016): + - AnnualFixedOperatingCost(BB,gas_import,2016) = -0 + OC2_OperatingCostsFixedAnnual(BB,gas_plant,2016): + + 9.1101 TotalCapacityAnnual(BB,gas_plant,2016) + - AnnualFixedOperatingCost(BB,gas_plant,2016) = -0 + OC3_OperatingCostsTotalAnnual(BB,gas_import,2016): + - OperatingCost(BB,gas_import,2016) + + AnnualVariableOperatingCost(BB,gas_import,2016) + + AnnualFixedOperatingCost(BB,gas_import,2016) = -0 + OC3_OperatingCostsTotalAnnual(BB,gas_plant,2016): + - OperatingCost(BB,gas_plant,2016) + + AnnualVariableOperatingCost(BB,gas_plant,2016) + + AnnualFixedOperatingCost(BB,gas_plant,2016) = -0 + OC4_DiscountedOperatingCostsTotalAnnual(BB,gas_import,2016): + + 0.975900072948533 OperatingCost(BB,gas_import,2016) + - DiscountedOperatingCost(BB,gas_import,2016) = -0 + OC4_DiscountedOperatingCostsTotalAnnual(BB,gas_plant,2016): + + 0.975900072948533 OperatingCost(BB,gas_plant,2016) + - DiscountedOperatingCost(BB,gas_plant,2016) = -0 + TDC1_TotalDiscountedCostByTechnology(BB,gas_import,2016): + + DiscountedCapitalInvestment(BB,gas_import,2016) + - DiscountedSalvageValue(BB,gas_import,2016) + + DiscountedOperatingCost(BB,gas_import,2016) + - TotalDiscountedCostByTechnology(BB,gas_import,2016) + + DiscountedTechnologyEmissionsPenalty(BB,gas_import,2016) = -0 + TDC1_TotalDiscountedCostByTechnology(BB,gas_plant,2016): + + DiscountedCapitalInvestment(BB,gas_plant,2016) + - DiscountedSalvageValue(BB,gas_plant,2016) + + DiscountedOperatingCost(BB,gas_plant,2016) + - TotalDiscountedCostByTechnology(BB,gas_plant,2016) + + DiscountedTechnologyEmissionsPenalty(BB,gas_plant,2016) = -0 + TDC2_TotalDiscountedCost(BB,2016): + + TotalDiscountedCostByTechnology(BB,gas_import,2016) + + TotalDiscountedCostByTechnology(BB,gas_plant,2016) + - TotalDiscountedCost(BB,2016) = -0 + AAC1_TotalAnnualTechnologyActivity(BB,gas_import,2016): + + RateOfTotalActivity(BB,gas_import,x,2016) + - TotalTechnologyAnnualActivity(BB,gas_import,2016) = -0 + AAC1_TotalAnnualTechnologyActivity(BB,gas_plant,2016): + + RateOfTotalActivity(BB,gas_plant,x,2016) + - TotalTechnologyAnnualActivity(BB,gas_plant,2016) = -0 + TAC1_TotalModelHorizonTechnologyActivity(BB,gas_import): + + TotalTechnologyAnnualActivity(BB,gas_import,2016) + - TotalTechnologyModelPeriodActivity(BB,gas_import) = -0 + TAC1_TotalModelHorizonTechnologyActivity(BB,gas_plant): + + TotalTechnologyAnnualActivity(BB,gas_plant,2016) + - TotalTechnologyModelPeriodActivity(BB,gas_plant) = -0 + RM1_ReserveMargin_TechnologiesIncluded_In_Activity_Units(BB,x,2016): + - TotalCapacityInReserveMargin(BB,2016) = -0 + RM2_ReserveMargin_FuelsIncluded(BB,x,2016): + - DemandNeedingReserveMargin(BB,x,2016) = -0 + RM3_ReserveMargin_Constraint(BB,x,2016): + - TotalCapacityInReserveMargin(BB,2016) + + DemandNeedingReserveMargin(BB,x,2016) <= -0 + RE1_FuelProductionByTechnologyAnnual(BB,gas_import,natural_gas,2016): + + ProductionByTechnology(BB,x,gas_import,natural_gas,2016) + - ProductionByTechnologyAnnual(BB,gas_import,natural_gas,2016) = -0 + RE1_FuelProductionByTechnologyAnnual(BB,gas_plant,electricity,2016): + + ProductionByTechnology(BB,x,gas_plant,electricity,2016) + - ProductionByTechnologyAnnual(BB,gas_plant,electricity,2016) = -0 + RE2_TechIncluded(BB,2016): - TotalREProductionAnnual(BB,2016) = -0 + RE3_FuelIncluded(BB,2016): + - RETotalProductionOfTargetFuelAnnual(BB,2016) = -0 + RE4_EnergyConstraint(BB,2016): - TotalREProductionAnnual(BB,2016) <= -0 + RE5_FuelUseByTechnologyAnnual(BB,gas_plant,natural_gas,2016): + + RateOfUseByTechnology(BB,x,gas_plant,natural_gas,2016) + - UseByTechnologyAnnual(BB,gas_plant,natural_gas,2016) = -0 + E4_EmissionsPenaltyByTechnology(BB,gas_import,2016): + - AnnualTechnologyEmissionsPenalty(BB,gas_import,2016) = -0 + E4_EmissionsPenaltyByTechnology(BB,gas_plant,2016): + - AnnualTechnologyEmissionsPenalty(BB,gas_plant,2016) = -0 + E5_DiscountedEmissionsPenaltyByTechnology(BB,gas_import,2016): + + 0.975900072948533 AnnualTechnologyEmissionsPenalty(BB,gas_import,2016) + - DiscountedTechnologyEmissionsPenalty(BB,gas_import,2016) = -0 + E5_DiscountedEmissionsPenaltyByTechnology(BB,gas_plant,2016): + + 0.975900072948533 AnnualTechnologyEmissionsPenalty(BB,gas_plant,2016) + - DiscountedTechnologyEmissionsPenalty(BB,gas_plant,2016) = -0 + +Bounds + TotalTechnologyModelPeriodActivity(BB,gas_import) free + TotalTechnologyModelPeriodActivity(BB,gas_plant) free + TotalREProductionAnnual(BB,2016) free + RETotalProductionOfTargetFuelAnnual(BB,2016) free + +End diff --git a/tests/fixtures/super_simple/super_simple_gnu.sol b/tests/fixtures/super_simple/super_simple_gnu.sol new file mode 100644 index 00000000..f87af1b1 --- /dev/null +++ b/tests/fixtures/super_simple/super_simple_gnu.sol @@ -0,0 +1,48 @@ +Optimal - objective value 46.43125659 + 0 TotalDiscountedCost(BB,2016) 46.431257 0 + 1 RateOfDemand(BB,x,electricity,2016) 2.1101 0 + 2 NewCapacity(BB,gas_import,2016) 2.342422 0 + 3 AccumulatedNewCapacity(BB,gas_import,2016) 2.342422 0 + 6 TotalCapacityAnnual(BB,gas_import,2016) 2.342422 0 + 7 TotalCapacityAnnual(BB,gas_plant,2016) 3.1101 0 + 8 RateOfActivity(BB,x,gas_import,1,2016) 2.342422 0 + 9 RateOfTotalActivity(BB,gas_import,x,2016) 2.342422 0 + 10 RateOfActivity(BB,x,gas_plant,1,2016) 2.1101 0 + 11 RateOfTotalActivity(BB,gas_plant,x,2016) 2.1101 0 + 12 RateOfProductionByTechnologyByMode(BB,x,gas_import,1,natural_gas,2016) 2.342422 0 + 13 RateOfProductionByTechnologyByMode(BB,x,gas_plant,1,electricity,2016) 2.1101 0 + 14 RateOfProductionByTechnology(BB,x,gas_import,natural_gas,2016) 2.342422 0 + 15 RateOfProductionByTechnology(BB,x,gas_plant,electricity,2016) 2.1101 0 + 16 RateOfProduction(BB,x,natural_gas,2016) 2.342422 0 + 17 RateOfProduction(BB,x,electricity,2016) 2.1101 0 + 18 RateOfUseByTechnologyByMode(BB,x,gas_plant,1,natural_gas,2016) 2.342422 0 + 19 RateOfUseByTechnology(BB,x,gas_plant,natural_gas,2016) 2.342422 0 + 21 RateOfUse(BB,x,natural_gas,2016) 2.342422 0 + 22 Production(BB,x,natural_gas,2016) 2.342422 0 + 23 Production(BB,x,electricity,2016) 2.1101 0 + 24 Use(BB,x,natural_gas,2016) 2.342422 0 + 25 Demand(BB,x,electricity,2016) 2.1101 0 + 28 ProductionAnnual(BB,natural_gas,2016) 2.342422 0 + 29 ProductionAnnual(BB,electricity,2016) 2.1101 0 + 30 UseAnnual(BB,natural_gas,2016) 2.342422 0 + 32 ProductionByTechnology(BB,x,gas_import,natural_gas,2016) 2.342422 0 + 33 ProductionByTechnology(BB,x,gas_plant,electricity,2016) 2.1101 0 + 34 UseByTechnology(BB,x,gas_plant,natural_gas,2016) 2.342422 0 + 35 TotalAnnualTechnologyActivityByMode(BB,gas_import,1,2016) 2.342422 0 + 36 TotalAnnualTechnologyActivityByMode(BB,gas_plant,1,2016) 2.1101 0 + 37 ModelPeriodCostByRegion(BB) 46.431257 0 + 38 CapitalInvestment(BB,gas_import,2016) 2.342422e-05 0 + 40 DiscountedCapitalInvestment(BB,gas_import,2016) 2.342422e-05 0 + 46 AnnualVariableOperatingCost(BB,gas_plant,2016) 19.244534 0 + 48 AnnualFixedOperatingCost(BB,gas_plant,2016) 28.333322 0 + 51 OperatingCost(BB,gas_plant,2016) 47.577856 0 + 53 DiscountedOperatingCost(BB,gas_plant,2016) 46.431233 1.110223e-16 + 54 TotalDiscountedCostByTechnology(BB,gas_import,2016) 2.342422e-05 0 + 56 TotalDiscountedCostByTechnology(BB,gas_plant,2016) 46.431233 0 + 58 TotalTechnologyAnnualActivity(BB,gas_import,2016) 2.342422 0 + 59 TotalTechnologyAnnualActivity(BB,gas_plant,2016) 2.1101 0 + 60 TotalTechnologyModelPeriodActivity(BB,gas_import) 2.342422 0 + 61 TotalTechnologyModelPeriodActivity(BB,gas_plant) 2.1101 0 + 64 ProductionByTechnologyAnnual(BB,gas_import,natural_gas,2016) 2.342422 0 + 65 ProductionByTechnologyAnnual(BB,gas_plant,electricity,2016) 2.1101 0 + 68 UseByTechnologyAnnual(BB,gas_plant,natural_gas,2016) 2.342422 0 diff --git a/tests/test_convert.py b/tests/test_convert.py index 39b3ed69..00a95249 100644 --- a/tests/test_convert.py +++ b/tests/test_convert.py @@ -1,46 +1,25 @@ -""" - -read_strategy = None -write_strategy = None - -if args.from_format == "datafile": - read_strategy = ReadDatafile() -elif args.from_format == "csv": - read_strategy = ReadCsv() -elif args.from_format == "excel": - read_strategy = ReadExcel() - -if args.to_format == "excel": - write_strategy = WriteExcel() -elif args.to_format == "datafile": - write_strategy = WriteDatafile() -elif args.to_format == "csv": - write_strategy = WriteCsv() - -if read_strategy and write_strategy: - context = Context(read_strategy, write_strategy) - context.convert(args.from_path, args.to_path) -else: - raise NotImplementedError(msg) +"""This module tests the public API of the otoole package """ import os from tempfile import NamedTemporaryFile, TemporaryDirectory -from otoole import Context, ReadExcel, WriteCsv, WriteDatafile +from pytest import raises + +from otoole import convert, convert_results class TestConvert: - def test_convert_excel_to_datafile(self, user_config): + """Test the convert function""" - read_strategy = ReadExcel(user_config) - write_strategy = WriteDatafile(user_config) - context = Context(read_strategy, write_strategy) + def test_convert_excel_to_datafile(self): + """Test converting from Excel to datafile""" + user_config = os.path.join("tests", "fixtures", "config.yaml") tmpfile = NamedTemporaryFile() from_path = os.path.join("tests", "fixtures", "combined_inputs.xlsx") - context.convert(from_path, tmpfile.name) + convert(user_config, "excel", "datafile", from_path, tmpfile.name) tmpfile.seek(0) actual = tmpfile.readlines() @@ -51,16 +30,14 @@ def test_convert_excel_to_datafile(self, user_config): assert actual[2] == b"09_ROK d_bld_2_coal_products 2017 20.8921\n" assert actual[8996] == b"param default 1 : DepreciationMethod :=\n" - def test_convert_excel_to_csv(self, user_config): - - read_strategy = ReadExcel(user_config) - write_strategy = WriteCsv(user_config) - context = Context(read_strategy, write_strategy) + def test_convert_excel_to_csv(self): + """Test converting from Excel to CSV""" tmpfile = TemporaryDirectory() + user_config = os.path.join("tests", "fixtures", "config.yaml") from_path = os.path.join("tests", "fixtures", "combined_inputs.xlsx") - context.convert(from_path, tmpfile.name) + convert(user_config, "excel", "csv", from_path, tmpfile.name) with open(os.path.join(tmpfile.name, "EMISSION.csv")) as csv_file: csv_file.seek(0) @@ -69,3 +46,83 @@ def test_convert_excel_to_csv(self, user_config): assert actual[-1] == "NOX\n" assert actual[0] == "VALUE\n" assert actual[1] == "CO2\n" + + +class TestConvertResults: + """Test the convert_results function""" + + def test_convert_results_cbc_csv(self): + """Test converting CBC solution file to folder of CSVs""" + config = os.path.join("tests", "fixtures", "super_simple", "super_simple.yaml") + from_format = "cbc" + to_format = "csv" + from_path = os.path.join( + "tests", "fixtures", "super_simple", "super_simple_gnu.sol" + ) + tmpfile = TemporaryDirectory() + to_path = tmpfile.name + input_csvs = os.path.join("tests", "fixtures", "super_simple", "csv") + + result = convert_results( + config, from_format, to_format, from_path, to_path, input_csvs=input_csvs + ) + assert result is True + + with open(os.path.join(tmpfile.name, "NewCapacity.csv")) as csv_file: + csv_file.seek(0) + actual = csv_file.readlines() + + assert actual[0] == "REGION,TECHNOLOGY,YEAR,VALUE\n" + assert actual[-1] == "BB,gas_import,2016,2.342422\n" + + def test_convert_results_cbc_csv_datafile(self): + """Test converting CBC solution file to folder of CSVs""" + config = os.path.join("tests", "fixtures", "super_simple", "super_simple.yaml") + from_format = "cbc" + to_format = "csv" + from_path = os.path.join( + "tests", "fixtures", "super_simple", "super_simple_gnu.sol" + ) + tmpfile = TemporaryDirectory() + to_path = tmpfile.name + input_datafile = os.path.join( + "tests", "fixtures", "super_simple", "super_simple.txt" + ) + + result = convert_results( + config, + from_format, + to_format, + from_path, + to_path, + input_datafile=input_datafile, + ) + assert result is True + + with open(os.path.join(tmpfile.name, "NewCapacity.csv")) as csv_file: + csv_file.seek(0) + actual = csv_file.readlines() + + assert actual[0] == "REGION,TECHNOLOGY,YEAR,VALUE\n" + assert actual[-1] == "BB,gas_import,2016,2.342422\n" + + def test_convert_results_cbc_csv_raises(self): + """Test converting CBC solution file to folder of CSVs""" + config = os.path.join("tests", "fixtures", "super_simple", "super_simple.yaml") + from_format = "cbc" + to_format = "csv" + from_path = os.path.join( + "tests", "fixtures", "super_simple", "super_simple_gnu.sol" + ) + tmpfile = TemporaryDirectory() + to_path = tmpfile.name + + with raises(FileNotFoundError): + convert_results( + config, + from_format, + to_format, + from_path, + to_path, + input_csvs="not_a_path", + ) diff --git a/tests/test_read_strategies.py b/tests/test_read_strategies.py index b962a157..39cbd5a9 100644 --- a/tests/test_read_strategies.py +++ b/tests/test_read_strategies.py @@ -7,9 +7,9 @@ from amply import Amply from pytest import mark, raises -from otoole import ReadCsv, ReadDatafile, ReadExcel, ReadMemory from otoole.exceptions import OtooleDeprecationError, OtooleError from otoole.preprocess.longify_data import check_datatypes +from otoole.read_strategies import ReadCsv, ReadDatafile, ReadExcel, ReadMemory from otoole.results.results import ( ReadCbc, ReadCplex,