예제 #1
0
    def setUp(self) -> None:
        """setUp method that instantiates the
           :class:`~.RIDTConfig` class and the
           :class:`~.ComputationalSpace` class."""

        this_dir = os.path.dirname(os.path.abspath(__file__))
        with ConfigFileParser(os.path.join(this_dir,
                                           "st16/explicit.json")) as cfp:
            self.e = cfp
        with ConfigFileParser(os.path.join(this_dir, "st16/tkeb.json")) as cfp:
            self.t = cfp

        self.explicit = EddyDiffusion(self.e)
        self.tkeb = EddyDiffusion(self.t)
예제 #2
0
    def __call__(self, config_file_path: str, csv_file_path: str,
                 output_file_path: str):
        """The CSVToConfigFile initialiser

        Parameters
        ----------
        csv_file_path : :obj:`str`
            The path to the csv file to be parsed.

        config_file_path : :obj:`str`
            The path to the config file to be parsed.
        
        output_file_path : :obj:`str`
            The path to save the new config file.
        
        """
        self.csv_file_path = csv_file_path
        self.config_file_path = config_file_path
        self.output_file_path = output_file_path
        self.parsed_items = {
            "INS": [],
            "INF": [],
            "FIX": [],
            "POI": [],
            "LIN": [],
            "PLA": []
        }
        self.config = ConfigFileParser(config_file_path)
        self.new = self.config.__source__
        self.parse_csv()
        self.write_new_config_file()
예제 #3
0
    def test_csv_to_config(self):
        try:
            modes = ["instantaneous", "infinite_duration", "fixed_duration"]

            ins = {"x": 1.0, "y": 1.0, "z": 1.0, "mass": 1.0, "time": 1.0}
            inf = {"x": 1.0, "y": 1.0, "z": 1.0, "rate": 1.0, "time": 1.0}
            fix = {
                "x": 1.0,
                "y": 1.0,
                "z": 1.0,
                "rate": 1.0,
                "start_time": 1.0,
                "end_time": 2.0
            }

            system(f"{self.virtualenv_path}\\Scripts\\activate")
            system(f"ridt csv-to-config {self.config_path} {self.csv_path}")

            config = ConfigFileParser(
                os.path.join(self.this_dir, "st27/new_config.json"))
            for mode in modes:
                m = getattr(config.modes, mode)
                for source in m.sources.values():
                    if isinstance(source, InstantaneousSource):
                        self.assertEqual(source.__source__, ins)
                    if isinstance(source, InfiniteDurationSource):
                        self.assertEqual(source.__source__, inf)
                    if isinstance(source, FixedDurationSource):
                        self.assertEqual(source.__source__, fix)
        except Exception:
            print("csv_to_config failure")
            self.assertEqual(True, False)
예제 #4
0
    def setUp(self) -> None:
        """setUp method that instantiates the
        :class:`~.RIDTConfig` class."""

        this_dir = os.path.dirname(os.path.abspath(__file__))
        path = os.path.join(this_dir, "../../default/config.json")
        with ConfigFileParser(path) as cfp:
            self.c = cfp
예제 #5
0
 def test_time_units(self):
     with self.assertRaises(ConfigFileParserValidationError):
         with open(self.config_path) as f:
             config = json.load(f)
         config["time_units"] = "test"
         with open(self.config_path, "w") as f:
             json.dump(config, f)
         ConfigFileParser(self.config_path)
예제 #6
0
    def test_parse(self):
        """Checks to see that the consistency check can raise
        an error in a certain circumstance."""

        self.c.consistency_check()
        with self.assertRaises(ConsistencyError):
            ConfigFileParser(
                os.path.join(self.this_dir, "st01/error_config.json"))
예제 #7
0
    def test_scale(self):

        with self.assertRaises(ConfigFileParserValidationError):
            with open(self.config_path) as f:
                config = json.load(f)
            config["models"]["eddy_diffusion"]["planes_plots"]["scale"] = "test"
            with open(self.config_path, "w") as f:
                json.dump(config, f)
            ConfigFileParser(self.config_path)
예제 #8
0
    def test_contours(self):

        with self.assertRaises(ConfigFileParserValidationError):
            with open(self.config_path) as f:
                config = json.load(f)
            config["models"]["eddy_diffusion"]["planes_plots"]["contours"]["min"] = \
                config["models"]["eddy_diffusion"]["planes_plots"]["contours"]["max"] + 1
            with open(self.config_path, "w") as f:
                json.dump(config, f)
            ConfigFileParser(self.config_path)
예제 #9
0
    def setUp(self) -> None:
        """The set up method for system test 01.
        Configures a valid config file and a config
        file with an error in."""

        self.this_dir = os.path.dirname(os.path.abspath(__file__))
        with ConfigFileParser(
                os.path.join(self.this_dir,
                             "../../default/config.json")) as cfp:
            self.c = cfp
예제 #10
0
    def setUp(self) -> None:

        this_dir = os.path.dirname(os.path.abspath(__file__))
        with ConfigFileParser(join(this_dir, "st23/config.json")) as cfp:
            self.c = cfp

        self.bds = BatchDataStore()
        self.domain = Domain(self.c)
        self.output_dir = join(this_dir, "st23/data")
        Path(self.output_dir).mkdir(parents=True, exist_ok=True)
        self.edr = EddyDiffusionRun(self.c, self.output_dir)
예제 #11
0
    def setUp(self) -> None:
        """setUp method that instantiates the
           :class:`~.RIDTConfig` class and the
           :class:`~.ComputationalSpace` class."""

        this_dir = os.path.dirname(os.path.abspath(__file__))
        path = os.path.join(this_dir, "st11/config.json")
        with ConfigFileParser(path) as cfp:
            self.c = cfp

            restrict = {"models": "well_mixed"}
            self.space = ComputationalSpace(self.c, restrict)
예제 #12
0
    def test_points(self):
        """Checks to see if the :class:`.ConsistencyError` error
        triggers if the point does not lie in the bounds of the container."""

        with self.assertRaises(ConsistencyError):
            with open(self.config_path) as f:
                config = json.load(f)
            for points in config["models"]["eddy_diffusion"][
                    "monitor_locations"]["points"].values():
                points["x"] = config["dimensions"]["x"] + 1
            with open(self.config_path, "w") as f:
                json.dump(config, f)
            ConfigFileParser(self.config_path)
예제 #13
0
    def test_planes_axis(self):
        """Checks to see if the :class:`.ConsistencyError` error
        triggers if a plane lies outside of the bounds of the container."""

        with self.assertRaises(ConfigFileParserValidationError):
            with open(self.config_path) as f:
                config = json.load(f)
            for planes in config["models"]["eddy_diffusion"][
                    "monitor_locations"]["planes"].values():
                planes["axis"] = "test"
            with open(self.config_path, "w") as f:
                json.dump(config, f)
            ConfigFileParser(self.config_path)
예제 #14
0
    def setUp(self) -> None:
        """setUp method that instantiates the
           :class:`~.RIDTConfig` class and the
           :class:`~.ComputationalSpace` class."""

        this_dir = os.path.dirname(os.path.abspath(__file__))
        with ConfigFileParser(os.path.join(this_dir,
                                           "st15/config.json")) as cfp:
            self.c = cfp

        self.time_array = np.linspace(0, self.c.total_time,
                                      self.c.time_samples)

        self.wm = WellMixed(self.c)
예제 #15
0
    def test_line_axis(self):
        """Checks to see if the :class:`.ConsistencyError` error
        triggers if the line does not lie in the bounds of the container
        or is not parallel to one of the principle axes."""

        with self.assertRaises(ConfigFileParserValidationError):
            with open(self.config_path) as f:
                config = json.load(f)
            for lines in config["models"]["eddy_diffusion"][
                    "monitor_locations"]["lines"].values():
                lines["parallel_axis"] = "test"
            with open(self.config_path, "w") as f:
                json.dump(config, f)
            ConfigFileParser(self.config_path)
예제 #16
0
    def setUp(self) -> None:

        """setUp method that instantiates the
           :class:`~.RIDTConfig` class and the
           :class:`~.ComputationalSpace` class."""

        self.this_dir = os.path.dirname(os.path.abspath(__file__))
        self.out_dir = os.path.join(self.this_dir, "st14/run")
        Path(self.out_dir).mkdir(parents=True, exist_ok=True)

        with ConfigFileParser(os.path.join(self.this_dir, "st14/config.json")) as cfp:
            self.c = cfp

        restrict = {"models": "well_mixed"}
        self.space = ComputationalSpace(self.c, restrict)
예제 #17
0
    def test_planes_distance(self):
        """Checks to see if the :class:`.ConsistencyError` error
        triggers if a plane lies outside of the bounds of the container."""

        with self.assertRaises(ConsistencyError):
            with open(self.config_path) as f:
                config = json.load(f)
            for planes in config["models"]["eddy_diffusion"][
                    "monitor_locations"]["planes"].values():
                axis = [
                    x for x in ["x", "y", "z"] if x not in list(planes["axis"])
                ]
                planes["distance"] = config["dimensions"][axis[0]] + 1
            with open(self.config_path, "w") as f:
                json.dump(config, f)
            ConfigFileParser(self.config_path)
예제 #18
0
    def setUp(self) -> None:

        this_dir = os.path.dirname(os.path.abspath(__file__))
        path = os.path.join(this_dir, "../../default/config.json")
        with ConfigFileParser(path) as cfp:
            self.c = cfp