OSeMOSYS / otoole

OSeMOSYS Tools for Energy
https://otoole.readthedocs.io
MIT License
25 stars 19 forks source link

FileNotFoundError: data/DiscountRateStorage.csv #115

Closed HauHe closed 1 year ago

HauHe commented 3 years ago

When trying to convert from datapackage to datafile or excel I get the below error. Since I'm not using storage the DiscountRateStorageis indeed not defined. Perhaps this is related to the introduction of the new DiscountRate in OSeMOSYS not too long ago?


otoole convert datapackage datafile datapackage.json osembe_data_re50.txt
Error in sys.excepthook:
Traceback (most recent call last):
  File "/Users/cotti/GitHub/HauHe/otoole/src/otoole/cli.py", line 282, in exception_handler
    print("{}: {}".format(exception_type.__name__, exception.message))
AttributeError: 'FileNotFoundError' object has no attribute 'message'

Original exception was:
Traceback (most recent call last):
  File "/opt/anaconda3/envs/HauHe_otoole/bin/otoole", line 33, in <module>
    sys.exit(load_entry_point('otoole', 'console_scripts', 'otoole')())
  File "/Users/cotti/GitHub/HauHe/otoole/src/otoole/cli.py", line 287, in main
    args.func(args)
  File "/Users/cotti/GitHub/HauHe/otoole/src/otoole/cli.py", line 164, in conversion_matrix
    context.convert(args.from_path, args.to_path)
  File "/Users/cotti/GitHub/HauHe/otoole/src/otoole/input.py", line 122, in convert
    inputs, default_values = self._read(input_filepath, **kwargs)
  File "/Users/cotti/GitHub/HauHe/otoole/src/otoole/input.py", line 106, in _read
    return self._read_strategy.read(filepath, **kwargs)
  File "/Users/cotti/GitHub/HauHe/otoole/src/otoole/read_strategies.py", line 198, in read
    inputs = read_datapackage(filepath)
  File "/opt/anaconda3/envs/HauHe_otoole/lib/python3.7/site-packages/pandas_datapackage_reader-0.17.0-py3.7.egg/pandas_datapackage_reader/__init__.py", line 123, in read_datapackage
    decimal=decimal_char,
  File "/opt/anaconda3/envs/HauHe_otoole/lib/python3.7/site-packages/pandas/io/parsers.py", line 610, in read_csv
    return _read(filepath_or_buffer, kwds)
  File "/opt/anaconda3/envs/HauHe_otoole/lib/python3.7/site-packages/pandas/io/parsers.py", line 462, in _read
    parser = TextFileReader(filepath_or_buffer, **kwds)
  File "/opt/anaconda3/envs/HauHe_otoole/lib/python3.7/site-packages/pandas/io/parsers.py", line 819, in __init__
    self._engine = self._make_engine(self.engine)
  File "/opt/anaconda3/envs/HauHe_otoole/lib/python3.7/site-packages/pandas/io/parsers.py", line 1050, in _make_engine
    return mapping[engine](self.f, **self.options)  # type: ignore[call-arg]
  File "/opt/anaconda3/envs/HauHe_otoole/lib/python3.7/site-packages/pandas/io/parsers.py", line 1867, in __init__
    self._open_handles(src, kwds)
  File "/opt/anaconda3/envs/HauHe_otoole/lib/python3.7/site-packages/pandas/io/parsers.py", line 1368, in _open_handles
    storage_options=kwds.get("storage_options", None),
  File "/opt/anaconda3/envs/HauHe_otoole/lib/python3.7/site-packages/pandas/io/common.py", line 647, in get_handle
    newline="",
FileNotFoundError: [Errno 2] No such file or directory: 'data/DiscountRateStorage.csv'```
willu47 commented 3 years ago

If you created a datapackage with an earlier version of otoole which did not include the DiscountRateStorage parameter, and then try to read it with a later version of otoole where this parameter is included in the configuration (or in the datapackage.json file, you would expect this error.

However, this should be better managed in otoole, perhaps raising a more descriptive error, and could be avoided through the use of custom configurations...

HauHe commented 3 years ago

The error can be avoided by creating an empty csv called DiscountRateStorage.csvin the datapackage. Only containing one line with : REGION,STORAGE,VALUE

HauHe commented 3 years ago

Perhaps, one could create an error message that suggests to check and if not existend add the needed. csv-file.

trevorb1 commented 1 year ago

With PR #142 (otoole v1.0.0) and the introduction of the user configuration file, this should no longer be a problem! 🙂