diff --git a/examples/gwk_compressor_casegeneration/Snakefile b/examples/gwk_compressor_casegeneration/Snakefile index da9480dfa827c9c0181e0bea1b795a90abb51469..506d364564638449e180d7ab37c0936a0106c6fc 100644 --- a/examples/gwk_compressor_casegeneration/Snakefile +++ b/examples/gwk_compressor_casegeneration/Snakefile @@ -1,10 +1,11 @@ from snakemake.utils import validate - +import os #todo move this snakepipe to according dir in sourcecode configfile : "casesettings.yaml" validate(config,"config.schema.yaml") +basedir = workflow.current_basedir rule all: input: @@ -13,18 +14,22 @@ rule all: rule copy_template: output: #todo: is there a readable dataformat alternative (csv) instead of pickle? - dynamic("01_case/{case_type}/{case_files}") + #dynamic("01_case/{case_type}/{case_files}"), + dynamic("01_case/{level_1}/{level_2}"), + "01_case/check.txt" params: case_type = config["case_params"]["case_type"], - + case_parameters = config["case_params"]["parameters"] run: from case_creation import create_case_fromtemplate + create_case_fromtemplate(params["case_type"],params["case_parameters"],os.path.join(basedir,"01_case")) + - create_case_fromtemplate(params["case_type"]) rule check_template: input: - dynamic("01_case/{case_type}/{case_files}"), + #dynamic("01_case/{case_type}/{case_files}") + dynamic("01_case/{level_1}/{level_2}") output: "done.txt" run: diff --git a/examples/gwk_compressor_casegeneration/case_creation.py b/examples/gwk_compressor_casegeneration/case_creation.py index a3dba3e6b8e339760b2ac7aae05970c4029aa638..690bc713741aa324d29a676134a16aa538665a94 100644 --- a/examples/gwk_compressor_casegeneration/case_creation.py +++ b/examples/gwk_compressor_casegeneration/case_creation.py @@ -83,32 +83,49 @@ def writeout_simulation(case_structure_parameters, path_to_sim, settings): with open(fpath, "w") as fobj: fobj.write(newText) -"""def check_settings_necessarities(case_structure, settings_dict): +def check_settings_necessarities(case_structure, settings_dict): - #todo not used yet, might be handy! necessarities = list(nested_dict_pairs_iterator(case_structure)) necessarity_vars = [] for item in necessarities: if item[-1] == "var": necessarity_vars.append(item[-2]) - assert "variables" in settings_dict["simcase_settings"].keys(), "variables not set simcase_settings" - if settings_dict["simcase_settings"]["variables"]: - settings_variables = list(settings_dict["simcase_settings"]["variables"].keys()) - else: - settings_variables = [] + defined_variables = list(settings_dict.keys()) + defined = [] + undefined = [] + unused = [] + used = [] for variable in necessarity_vars: - assert variable in settings_variables, "variable " + variable + " not set in configuration file" -""" + #assert variable in settings_variables, "variable " + variable + " not set in configuration file" + if variable in defined_variables: + defined.append(variable) + else: + undefined.append(variable) + for variable in defined_variables: + if not variable in necessarity_vars: + unused.append(variable) + else: + used.append(variable) + return defined, undefined, used, unused + def create_case_fromtemplate(template, settings, path_to_sim): + """ + + :param template: str - template-name + :param settings: dict - dict-settings + :param path_to_sim: path - path to case-directory + :return: + """ #todo docstring and test method found = template in TEMPLATES assert found, "template unknown. check ntrfc.database.casetemplates directory" case_structure = get_directory_structure(os.path.join(TEMPLATEDIR, template)) case_files = [i[:-1] for i in list(nested_dict_pairs_iterator(case_structure)) if os.path.isfile(os.path.join(TEMPLATEDIR,*list(i[:-1])))] + variables = find_vars_opts(case_structure, "var", list(nested_dict_pairs_iterator(case_structure)),os.path.join(TEMPLATEDIR)) for fpath in case_files: filename = fpath[-1] @@ -123,11 +140,15 @@ def create_case_fromtemplate(template, settings, path_to_sim): sim_fpath = os.path.join(path_to_sim, *dirstructure) shutil.copyfile(template_fpath, os.path.join(sim_fpath,filename)) - variables = find_vars_opts(case_structure, "var", list(nested_dict_pairs_iterator(case_structure)),"01_case") - nov = len(list(nested_dict_pairs_iterator(variables))) - print("found ", str(nov), "parameters of type var in copied template") - #check_settings_necessarities(variables, settings) - return case_files + + defined, undefined, used, unused = check_settings_necessarities(variables, settings) + print("found ", str(len(defined)), " defined parameters") + print("found ", str(len(undefined)), " undefined parameters") + print("used ", str(len(used)), " parameters") + print("unused ", str(len(unused)), " parameters") + + + settings = {} case_structure = create_case_fromtemplate('trace-compressor-cascade-ras', settings, path_to_sim) diff --git a/examples/gwk_compressor_casegeneration/casesettings.yaml b/examples/gwk_compressor_casegeneration/casesettings.yaml index 5f348db2fd21e827724ac6dd53a9a7cafac77e0f..b70478afab7f7212fc477ea5f8b3836e1c45969b 100644 --- a/examples/gwk_compressor_casegeneration/casesettings.yaml +++ b/examples/gwk_compressor_casegeneration/casesettings.yaml @@ -1,2 +1,4 @@ case_params: case_type: trace-compressor-cascade-ras + parameters: + haha : nope diff --git a/tests/test_ntrfc.py b/tests/test_ntrfc.py index fa410f39d2ced8438c73872c15609ba4976fa2fe..9a162d53eeeb6e8e9c6e8733df11b08c70881967 100644 --- a/tests/test_ntrfc.py +++ b/tests/test_ntrfc.py @@ -107,6 +107,11 @@ def test_vtkFLUENTReader(): def test_pickle_operations(tmpdir): + """ + checks if the pickle-operators are working + :param tmpdir: + :return: + """ from ntrfc.utils.filehandling.datafiles import write_pickle, read_pickle, write_pickle_protocolzero fname = tmpdir / "test.pkl" @@ -120,6 +125,9 @@ def test_pickle_operations(tmpdir): def test_refine_spline(): + """ + tests if you can refine a spline by checking the number of points and the length of the spline + """ from ntrfc.utils.pyvista_utils.line import refine_spline coarseres = 2 @@ -132,6 +140,11 @@ def test_refine_spline(): def test_nested_dict_pairs_iterator(): + """ + tests if nested_dict_pairs_iterator returns the right list for a nested dict + nested_dict_pairs_iterator is used for returning a nested dict as a list + which comes in handy when handling nested directories with files + """ testdict = {"0":{"0":0,"1":1},"1":1} check = [('0', '0', 0), ('0', '1', 1), ('1', 1)] assert check == list(nested_dict_pairs_iterator(testdict)), "error"