コード例 #1
0
    def test__scan_folders(self):

        # 5 par files: 2 in each output folders, and 1 in the main SIMFACTORY
        self.assertEqual(len(self.sim.parfiles), 5)

        # 2 out files, one in each folder
        self.assertEqual(len(self.sim.logfiles), 2)

        # 2 err files, one in each folder
        self.assertEqual(len(self.sim.errfiles), 2)

        # 5 dirs: tov, tov/output-000i, tov/output-000i/static_tov
        self.assertEqual(len(self.sim.dirs), 5)

        # find . -type f | grep -v "SIMFACTORY" | grep -v "NODES" | wc -l
        # 446
        self.assertEqual(len(self.sim.allfiles), 446)

        # Checking max_depth
        sim_max_depth = sd.SimDir("tests/tov", max_depth=2)

        # 3 par files: 1 in each output folders, and 1 in the main SIMFACTORY
        self.assertEqual(len(sim_max_depth.parfiles), 3)

        # 2 out files, one in each folder
        self.assertEqual(len(sim_max_depth.logfiles), 2)

        # 2 err files, one in each folder
        self.assertEqual(len(sim_max_depth.errfiles), 2)

        # 3 dirs: tov, tov/output-000i
        self.assertEqual(len(sim_max_depth.dirs), 3)

        # find . -maxdepth 2 -type f | grep -v "SIMFACTORY" | grep -v "NODES" | wc -l
        # 8
        self.assertEqual(len(sim_max_depth.allfiles), 8)

        # Check that all the expected components are in
        # the string representation
        #
        self.assertIn(self.sim.ts.__str__(), self.sim.__str__())
        self.assertIn(self.sim.multipoles.__str__(), self.sim.__str__())

        # Test for a simdir with no information
        # This is a fake folder
        empty_sim = sd.SimDir("kuibit")
        self.assertIn("No horizon found", empty_sim.__str__())

        # Test symlink
        sim_with_symlink = sd.SimDir("tests/tov", ignore_symlinks=False)
        self.assertEqual(len(sim_with_symlink.allfiles), 447)
コード例 #2
0
    def setUp(self):
        # This folder contains all the files, but we will experiment also in
        # the case we only have AH files by looking at the subdir diagnostics
        self.files_dir = "tests/horizons"
        self.sim = sd.SimDir(self.files_dir)

        # All the information
        self.hor = self.sim.horizons

        # Only AH
        self.sim_ah = sd.SimDir(self.files_dir + "/diagnostics")
        self.ahs = ch.HorizonsDir(self.sim_ah)

        # QLM + SHAPE but not AH
        self.sim_shape = sd.SimDir(self.files_dir, max_depth=1)
        self.qlm_shape = ch.HorizonsDir(self.sim_shape)
コード例 #3
0
    def test__str(self):

        self.assertEqual(str(sd.SimDir("tests/tov").horizons),
                         "No horizon found")

        expected_str = "Horizons found:\n"
        expected_str += "3 horizons from QuasiLocalMeasures\n"
        expected_str += "2 horizons from AHFinderDirect"

        self.assertEqual(str(self.hor), expected_str)
コード例 #4
0
    def test_MultipolesDir(self):

        sim = sd.SimDir("tests/tov")
        cacdir = mp.MultipolesDir(sim)

        # multipoles from textfile
        with self.assertRaises(RuntimeError):
            cacdir._multipole_from_textfile(
                "tests/tov/output-0000/static_tov/carpet-timing..asc")

        path = "tests/tov/output-0000/static_tov/mp_Phi2_l2_m-1_r110.69.asc"
        path_h5 = "tests/tov/output-0000/static_tov/mp_harmonic.h5"
        t, real, imag = np.loadtxt(path).T

        with h5py.File(path_h5, "r") as data:
            # Loop over the groups in the hdf5
            a = data["l2_m2_r8.00"][()].T

        mpts = ts.TimeSeries(t, real + 1j * imag)
        ts_h5 = ts.TimeSeries(a[0], a[1] + 1j * a[2])

        self.assertEqual(mpts, cacdir._multipole_from_textfile(path))
        self.assertEqual(
            ts_h5,
            cacdir._multipoles_from_h5files([path_h5])[8.00](2, 2),
        )

        mpfiles = [(2, 2, 100, path)]

        # Check one specific case
        self.assertEqual(
            mpts,
            cacdir._multipoles_from_textfiles(mpfiles)[100](2, 2),
        )

        self.assertEqual(cacdir["phi2"][110.69](2, -1), mpts)
        self.assertEqual(cacdir["harmonic"][8.00](2, 2), ts_h5)

        # test get
        self.assertIs(cacdir.get("bubu"), None)
        self.assertEqual(cacdir.get("harmonic")[8.00](2, 2), ts_h5)

        # test __getitem__
        with self.assertRaises(KeyError):
            cacdir["bubu"]

        # test __contains__
        self.assertIn("phi2", cacdir)

        # test keys()
        self.assertCountEqual(cacdir.keys(), ["harmonic", "phi2", "psi4"])

        # test __str__()
        self.assertIn("harmonic", cacdir.__str__())
コード例 #5
0
ファイル: test_simdir.py プロジェクト: ekwessel/kuibit-IL
    def test_pickle(self):

        path = "/tmp/sim.pickle"

        self.sim.save(path)

        loaded_sim = sd.load_SimDir(path)

        self.assertCountEqual(self.sim.__dict__, loaded_sim.__dict__)

        # Test load from pickle

        loaded_sim2 = sd.SimDir("tests/tov",
                                max_depth=0,
                                pickle_file="/tmp/sim.pickle")

        self.assertCountEqual(self.sim.__dict__, loaded_sim2.__dict__)

        # Test as a context manager

        with sd.SimDir("tests/tov", pickle_file="/tmp/sim.pickle") as sim:
            self.assertCountEqual(self.sim.__dict__, sim.__dict__)
            # Make a change
            sim.max_depth = 10

        loaded_sim3 = sd.load_SimDir(path)
        self.assertEqual(loaded_sim3.max_depth, 10)

        os.remove(path)

        # Test with pickle not being a simdir

        with open(path, "wb") as file_:
            pickle.dump(1, file_)

        with self.assertRaises(RuntimeError):
            sd.load_SimDir(path)

        os.remove(path)
コード例 #6
0
    def setUp(self):
        # This folder contains all the files, but we will experiment also in
        # the case we only have AH files by looking at the subdir diagnostics
        self.files_dir = "tests/horizons"
        self.sim = sd.SimDir(self.files_dir)

        # All the information
        self.hor = self.sim.horizons

        # Only AH
        self.sim_ah = sd.SimDir(self.files_dir + "/diagnostics")
        self.ahs = ch.HorizonsDir(self.sim_ah)

        # QLM + SHAPE but not AH
        self.sim_shape = sd.SimDir(self.files_dir, max_depth=1)
        self.qlm_shape = ch.HorizonsDir(self.sim_shape)

        # One horizons in each
        self.ho = self.hor[(0, 1)]
        self.ah = self.ahs[(0, 1)]

        # Here we capture the warning
        with self.assertWarns(Warning):
            self.sh = self.qlm_shape[(0, 1)]
コード例 #7
0
    def test_AllScalars_magic_methods(self):

        reader = cs.AllScalars(sd.SimDir("tests/tov").allfiles, "average")
        self.assertIn("rho", reader)

        path1 = "tests/tov/output-0000/static_tov/hydrobase-rho.average.asc"
        path2 = "tests/tov/output-0001/static_tov/hydrobase-rho.average.asc"
        t1, y1 = np.loadtxt(path1, ndmin=2, unpack=True, usecols=(1, 2))
        t2, y2 = np.loadtxt(path2, ndmin=2, unpack=True, usecols=(1, 2))

        rho = ts.TimeSeries(np.append(t1, t2), np.append(y1, y2))

        self.assertEqual(rho, reader["rho"])
        self.assertEqual(rho, reader.get("rho"))

        self.assertEqual(1, reader.get("bubu", default=1))
コード例 #8
0
    def setUp(self):
        # First we set the correct number of ghost zones
        reader = sd.SimDir("tests/grid_functions").gf.xy
        reader.num_ghost = (3, 3)

        # ASCII
        self.rho_star = reader["rho_star"]
        # There's only one file
        self.rho_star_file = self.rho_star.allfiles[0]

        # We are going to test all the methods of the baseclass with
        # HDF5 files

        # HDF5
        self.P = reader["P"]
        # There's only one file
        self.P_file = self.P.allfiles[0]
コード例 #9
0
    def test_ScalarsDir(self):

        # Not a SimDir
        with self.assertRaises(TypeError):
            cs.ScalarsDir(0)

        scaldir = cs.ScalarsDir(sd.SimDir("tests/tov"))

        # Check that the getter (and []) work
        self.assertEqual(scaldir["average"].reduction_type, "average")
        self.assertEqual(scaldir.get("infnorm").reduction_type, "infnorm")
        self.assertIsNone(scaldir.get("bubu", default=None))

        self.assertIs(scaldir["maximum"], scaldir["max"])
        self.assertIs(scaldir["minimum"], scaldir["min"])

        # Check string representation
        # (this is a very weak check...)
        self.assertIn("io_count", scaldir.__str__())
コード例 #10
0
    def test_AllScalars(self):

        sim = sd.SimDir("tests/tov")

        reader = cs.AllScalars(sim.allfiles, "average")

        # Let's check that all the files are properly indexed
        vars_tov = [
            "H",
            "kxx",
            "kxy",
            "kxz",
            "kyy",
            "kyz",
            "kzz",
            "press",
            "alp",
            "gxx",
            "gxy",
            "gxz",
            "gyy",
            "gyz",
            "gzz",
            "M1",
            "M2",
            "M3",
            "eps",
            "rho",
            "vel[0]",
            "vel[1]",
            "vel[2]",
        ]

        self.assertCountEqual(reader._vars_readers, vars_tov)

        self.assertCountEqual(reader.keys(), vars_tov)

        self.assertTrue(
            reader.__str__().startswith("Available average timeseries:\n["))

        with self.assertRaises(KeyError):
            reader["BOB"]
コード例 #11
0
ファイル: test_simdir.py プロジェクト: rahulkashyap411/kuibit
    def setUp(self):

        # We use the output of a simple simulation to test that everything
        # is okay
        self.sim = sd.SimDir("tests/tov")
コード例 #12
0
 def setUp(self):
     self.gf = sd.SimDir("tests/grid_functions").gf.xy
コード例 #13
0
 def setUp(self):
     self.files_dir = "tests/grid_functions"
     self.sim = sd.SimDir(self.files_dir)
     self.gd = cg.GridFunctionsDir(self.sim)
コード例 #14
0
    def test_empty(self):

        # Test with no wave information
        empty_sim = sd.SimDir("kuibit")
        self.assertIs(empty_sim.gws.l_max, None)
コード例 #15
0
 def setUp(self):
     self.sim = sd.SimDir("tests/tov")
     self.gwdir = cw.GravitationalWavesDir(self.sim)
     self.psi4 = self.gwdir[110.69]