Skip to content

folderpath Inconsistent behaviour - "input" needs to be inserted in the path to the worldprice file #94

Description

@paulrougieux

The two error messages explained below are contradictory:

  1. Either folderpath defines the "Path to directory with Input/Output folder.", then it should be at the parent of the input directory and the first error shouldn't happen. See how to reproduce this error with the sample python code below.
  2. Or folderpath defines the input directory level, then it seems strange that the second error happens, asking for something in input / input.

Current behaviour

TiMBA/cli/cli.py specifies that folderpath should be the "Path to directory with Input/Output folder":

@click.option('-FP', '--folderpath', 'folderpath', required=False, type=click.Path(
     file_okay=False, writable=True, path_type=Path), help="Path to directory with Input/Output folder.")

Defining it at the wrong level returns DataManager.py returns this error

folderpath = "/home/paul/eu_cbm/TiMBA_Data/"
# FileNotFoundError: [Errno 2] No such file or directory: '/home/paul/eu_cbm/TiMBA_Data/02_Additional_Information/worldprice_world500.xlsx'

Changing it to one level below DataManager.py returns this next error

folderpath = "/home/paul/eu_cbm/TiMBA_Data/input"
# FileNotFoundError: [Errno 2] No such file or directory: '/home/paul/eu_cbm/TiMBA_Data/input/input/01_Input_Files'

Reproduce error 1

This is the error that appears when defining folderpath to a parent directory that contains both the input and output directories, in the example below: folderpath = "/home/paul/eu_cbm/TiMBA_Data/" .

"""
Run this example:

    conda activate timbaenv
    cd /tmp
    ipython -i run_timba.py

"""

from pathlib import Path
import datetime as dt
import importlib
from TiMBA.main_runner.main_runner import main
from TiMBA.data_management.ParameterCollector import ParameterCollector

folderpath = "/home/paul/eu_cbm/TiMBA_Data/"

user_input_cli = {
    "year": 2020,
    # Periods lengths are defined in the ExogChange sheet, first column.
    "max_period": 10,
    "product_price": "shadow_PP",
    "world_price": "shadow_WP",
    "transportation_factor": 1.0,
    "material_balance": "C_specific_MB",
    "global_material_balance": False,
    "serialization": False,
    "constants": [False, False, False],
    "dynamization_activated": True,
    "cleaned_opt_quantity": False,
    "capped_prices": False,
    "verbose_optimization_logger": True,
    "verbose_calculation_logger": False,
    "addInfo": True,
}

Parameters = ParameterCollector(user_input=user_input_cli, folderpath=folderpath)
world = "scenario_input_SSP2v3_2020_2050_new.xlsx"
current_dt = dt.datetime.now().strftime("%Y%m%dT%H-%M-%S")
PACKAGEDIR = Path("/home/paul/eu_cbm/TiMBA/TiMBA")

main(
    UserIO=Parameters,
    world_version=world,
    time_stamp=current_dt,
    package_dir=PACKAGEDIR,
    sc_name=world[: len(world) - 5],
)

Will return the following error:

FileNotFoundError: [Errno 2] No such file or directory: '/home/paul/eu_cbm/TiMBA_Data/02_Additional_Information/worldprice_world500.xlsx'

In [1]: # Path("/home/paul/eu_cbm/TiMBA_Data/02_Additional_Information/worldprice_world500.xlsx").exists()

In [2]: Path("/home/paul/eu_cbm/TiMBA_Data/02_Additional_Information/worldprice_world500.xlsx").exists()
Out[2]: False

In [3]: Path("/home/paul/eu_cbm/TiMBA_Data/input/02_Additional_Information/worldprice_world500.xlsx").exists()
Out[3]: True

Proposal

folderpath should define the parent directory of both the input and output directory.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions