From 71347327ab58ffa6b802f43d00165cdd4e71586d Mon Sep 17 00:00:00 2001 From: Ivan Usov Date: Wed, 15 Jul 2020 15:29:26 +0200 Subject: [PATCH] Add algorithm property --- pyzebra/anatric.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pyzebra/anatric.py b/pyzebra/anatric.py index 6e71395..7cfefa3 100644 --- a/pyzebra/anatric.py +++ b/pyzebra/anatric.py @@ -15,6 +15,8 @@ REFLECTION_PRINTER_FORMATS = ( "oksana", ) +ALGORITHMS = ("adaptivemaxcog", "adaptivedynamic") + def anatric(config_file): subprocess.run(["anatric", config_file], check=True) @@ -30,7 +32,6 @@ class AnatricConfig: self._tree = tree alg_elem = tree.find("Algorithm") - self.algorithm = alg_elem.attrib["implementation"] if self.algorithm == "adaptivemaxcog": self.threshold = float(alg_elem.find("threshold").attrib["value"]) self.shell = float(alg_elem.find("shell").attrib["value"]) @@ -212,5 +213,16 @@ class AnatricConfig: self._tree.find("ReflectionPrinter").attrib["format"] = value + @property + def algorithm(self): + return self._tree.find("Algorithm").attrib["implementation"] + + @algorithm.setter + def algorithm(self, value): + if value not in ALGORITHMS: + raise ValueError("Unknown algorithm.") + + self._tree.find("Algorithm").attrib["implementation"] = value + def save_as(self, filename): self._tree.write(filename)