Skip to content
Snippets Groups Projects
Commit 9c634fa5 authored by Malte Nyhuis's avatar Malte Nyhuis
Browse files

minor progress

parent 4072d698
No related branches found
No related tags found
No related merge requests found
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:
......
......@@ -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)
case_params:
case_type: trace-compressor-cascade-ras
parameters:
haha : nope
......@@ -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"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment