OSeMOSYS / otoole

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

Add `otoole setup` commands #144

Closed trevorb1 closed 1 year ago

trevorb1 commented 1 year ago

Overview

In this PR I have added setup functionality to create a template user configuration file and template CSV files. If the user tries to create the template file(s) and an existing version already exists, they must pass an --overwrite flag. This prevents the accidental overwrite of data that is not backed up! Tests have been added for the new functionality.

Completes one of the tasks in issue #56

Help info

(otoole) ~/repositories/otoole$ otoole setup --help
usage: otoole setup [-h] [--write_defaults] [--overwrite] {config,csv} data_path

positional arguments:
  {config,csv}      Type of file to setup
  data_path         Path to file or folder to save to

optional arguments:
  -h, --help        show this help message and exit
  --write_defaults  Writes default values
  --overwrite       Overwrites existing data

Examples

Create a template user configuration file called config.yaml

(otoole) ~$ cat config.yaml
cat: config.yaml: No such file or directory
(otoole) ~$ otoole setup config config.yaml
(otoole) ~$ cat config.yaml
AccumulatedAnnualDemand:
    indices: [REGION,FUEL,YEAR]
    type: param
    dtype: float
    default: 0
AnnualEmissionLimit:
    indices: [REGION,EMISSION,YEAR]
    type: param
    dtype: float
    default: -1
...

Create a template folder of input CSV data, in a folder called data

(otoole) ~$ ls data
ls: cannot access 'data': No such file or directory
(otoole) ~$ otoole setup csv data
(otoole) ~$ ls data
AccumulatedAnnualDemand.csv
AnnualEmissionLimit.csv
...

(otoole) ~$ cat data/AccumulatedAnnualDemand.csv
REGION,FUEL,YEAR,VALUE
(otoole) ~$ cat data/AnnualEmissionLimit.csv
REGION,EMISSION,YEAR,VALUE

Create a template configuration file called config.yaml in a location where a file called config.yaml already exists

Below demonstrates overwrite checks for the config file, but the same error will be raised if a folder of CSVs is written to and the folder name already exists

(otoole) ~$ otoole setup config config.yaml
OtooleSetupError: config.yaml -> Data already exists. Delete file/directory or pass the --overwrite flag
(otoole) ~$ otoole setup config config.yaml --overwrite
(otoole) ~$ 

Documentation

Will add to the v1.0 doc updates in PR #137