deflex.search_input_scenarios

deflex.search_input_scenarios(path, csv=True, xlsx=False, exclude=None)[source]

Search for files with an .xlsx extension or directories ending with ‘_csv’.

By now it is not possible to distinguish between valid deflex scenarios and other xlsx-files or directories ending with ‘_csv’. Therefore, the given directory should only contain valid scenarios.

The function will not search recursively.

Parameters:
  • path (str) – Directory with valid deflex scenarios.
  • csv (bool) – Search for csv directories.
  • xlsx (bool) – Search for xls files.
  • exclude (str) – A string that is not allowed in the filename. Filenames containing this strings will be excluded.
Returns:

Scenarios found in the given directory

Return type:

list

Examples

>>> import shutil
>>> from deflex import fetch_test_files, search_input_scenarios
>>> test_file = fetch_test_files("de02_heat.xlsx")
>>> test_path = os.path.dirname(test_file)
>>> my_csv = search_input_scenarios(test_path)
>>> len(my_csv)
16
>>> os.path.basename(my_csv[0])
'de02_heat_csv'
>>> my_xlsx = search_input_scenarios(test_path, csv=False, xlsx=True)
>>> len(my_xlsx)
17
>>> os.path.basename([e for e in my_xlsx][0])
'de02_heat.xlsx'
>>> len(search_input_scenarios(test_path, xlsx=True))
33
>>> scenario = create_scenario([e for e in my_xlsx][0])
>>> csv_path = os.path.join(test_path, "de02_new_csv")
>>> scenario.to_csv(csv_path)
>>> len(search_input_scenarios(test_path, xlsx=True))
34
>>> len(search_input_scenarios(test_path, xlsx=True, exclude="de02"))
25
>>> len(search_input_scenarios(test_path, xlsx=True, exclude="test"))
34
>>> shutil.rmtree(csv_path)  # remove test results, skip this line to go on