Beispiel #1
0
    def test_create_SIM_dir(self):
        """Tests the function that creates the Simulation directories and the
        copies the necessary files from the specfem directory."""

        with tempfile.TemporaryDirectory() as tmp_dir:

            # Cmtfile path
            cmtfile = os.path.join(DATA_DIR, "CMTSOLUTION")

            # create CMT
            cmt = CMTSource.from_CMTSOLUTION_file(cmtfile)

            # Create CMTSource to extract the file name
            eq_id = cmt.eventname

            # Earthquake directory
            eq_dir = os.path.join(tmp_dir, "eq_" + eq_id)

            # Initialize database skeleton class
            DB = DataBaseSkeleton(basedir=tmp_dir,
                                  cmt_fn=cmtfile,
                                  specfem_dir=self.specfem_dir,
                                  overwrite=0,
                                  verbose=True)

            # Create earthquake solution directory
            DB.create_eq_dirs()

            # Create CMT simulation directory
            DB.create_CMT_SIM_dir()

            # Parameters
            attr = [
                "CMT", "CMT_rr", "CMT_tt", "CMT_pp", "CMT_rt", "CMT_rp",
                "CMT_tp", "CMT_depth", "CMT_lat", "CMT_lon"
            ]

            # Subdirectories
            subdirs = ["DATA", "DATABASES_MPI", "OUTPUT_FILES"]

            # Check for all directories
            for at in attr:

                # Attribute path
                test_dir = os.path.join(eq_dir, "CMT_SIMs", at)

                self.assertTrue(os.path.isdir(test_dir))

                # Check if yaml path file exist.
                self.assertTrue(
                    os.path.isfile(os.path.join(test_dir, at + ".yml")))

                # Now check if subdirectories are created
                for _k, _subdir in enumerate(subdirs):
                    test_dir2 = os.path.join(test_dir, _subdir)

                    self.assertTrue(os.path.isdir(test_dir2))

                # Check if link is created
                self.assertTrue(os.path.islink(os.path.join(test_dir, "bin")))
Beispiel #2
0
    def test_create_eq_dir(self):
        """Tests creation of earthquake directory and copying of the cmt
        solution"""

        # Check one cmt file
        with tempfile.TemporaryDirectory() as tmp_dir:

            # Cmtfile path
            cmtfile = os.path.join(DATA_DIR, "CMTSOLUTION")
            # create CMT
            cmt = CMTSource.from_CMTSOLUTION_file(cmtfile)

            # Create CMTSource to extract the file name
            eq_id = cmt.eventname

            # Earthquake directory
            eq_dir = os.path.join(tmp_dir, "eq_" + eq_id)

            # Initialize database skeleton class
            DB = DataBaseSkeleton(basedir=tmp_dir,
                                  cmt_fn=cmtfile,
                                  specfem_dir=self.specfem_dir,
                                  verbose=True)

            # Create eq directory
            DB.create_eq_dirs()

            # check if new path exists
            new_cmt_path = os.path.join(eq_dir, "eq_" + eq_id + ".cmt")
            self.assertTrue(
                os.path.exists(new_cmt_path) and os.path.isfile(new_cmt_path))
            self.assertTrue(
                CMTSource.from_CMTSOLUTION_file(new_cmt_path) == cmt)
Beispiel #3
0
    def test_create_eq_dir_mult(self):
        """Tests creation of earthquake directory and copying of the cmt
                solution for multiple cmt solution files."""

        # Check multiple cmt files
        with tempfile.TemporaryDirectory() as tmp_dir:

            # Cmtfile path
            cmtfile1 = os.path.join(DATA_DIR, "CMTSOLUTION_TRUE")
            cmtfile2 = os.path.join(DATA_DIR, "CMTSOLUTION_VAR")

            # create CMT
            cmt1 = CMTSource.from_CMTSOLUTION_file(cmtfile1)
            cmt2 = CMTSource.from_CMTSOLUTION_file(cmtfile2)

            # Create CMTSource to extract the file name
            eq_id1 = cmt1.eventname
            eq_id2 = cmt2.eventname

            # Earthquake directory
            eq_dir1 = os.path.join(tmp_dir, "eq_" + eq_id1)
            eq_dir2 = os.path.join(tmp_dir, "eq_" + eq_id2)

            # Initialize database skeleton class
            DB = DataBaseSkeleton(basedir=tmp_dir,
                                  cmt_fn=os.path.join(DATA_DIR,
                                                      "CMTSOLUTION_*"),
                                  specfem_dir=self.specfem_dir,
                                  verbose=True)

            # Create eq directory
            DB.create_eq_dirs()

            # check if new path exists
            new_cmt_path1 = os.path.join(eq_dir1, "eq_" + eq_id1 + ".cmt")
            new_cmt_path2 = os.path.join(eq_dir2, "eq_" + eq_id2 + ".cmt")

            self.assertTrue(
                os.path.exists(new_cmt_path1)
                and os.path.isfile(new_cmt_path1))
            self.assertTrue(
                os.path.exists(new_cmt_path2)
                and os.path.isfile(new_cmt_path2))