NREL / tyche

https://nrel.github.io/tyche-docs/
MIT License
3 stars 1 forks source link

Data validation issue pathway for technology file #147

Closed tjlca closed 8 months ago

tjlca commented 1 year ago

File IO.py

Lines 171


    for _tech, _meta in functions.iterrows():
      # First check that the model exists as a .py file in the correct location
      if os.path.exists('../' + _meta['Model'] + '.py'):
        # If the file does exist, use a try/except structure to attempt import
        try:
          _model = il.import_module("." + _meta["Model"], package="technology")
        except ImportError:
          check_list.append(
            (f'Data Validation: Technology model {_tech} is not importable.\n')
          )

The path exists line assumes that the technology file is one folder up. Can this be made general so that system path is searched for the technology file? The issue cropped up when I was trying to run Tyche from the GUI functions. They are in a folder outside Tyche. So the current directory is different.

rjhanes commented 1 year ago

I'm hesitant to do a full system path search for the technology model file, but I think it would be a relatively simple fix to search two locations within the repository to catch the case where the GUI is being used.

Can you clarify a couple things:

rjhanes commented 1 year ago

@tjlca Do you still need me to address this issue?

tjlca commented 1 year ago

Rebecca, sorry for the delay in this development.

So in short its not resolved yet completely and it will be great if the solutions you recommended can be implemented. The issue has been resolved by changing the working directory to the technology directory of Tyche, every time the Tyche model is called from the GUI. You can find these change directory commands in the path change function inside run_tyche of the tyche gui directory.

Right now the GUI Dev branch is up to date.

rjhanes commented 11 months ago

@tjlca The logic below that Nicholas implemented (for IO.py) might be useful for the os.chdir call in client.py to avoid specifying the entire path.

this_script_path   = os.path.realpath(__file__)
this_script_dir    = os.path.abspath(os.path.dirname(this_script_path))

for _tech, _meta in functions.iterrows():
  # First check that the model exists as a .py file in the correct location
  _model_py_path = os.path.join(this_script_dir, 
                                os.pardir, # parent directory
                                "technology", 
                                _meta['Model'] + '.py')