Exemple #1
0
    def multipoles(self):
        """Return all the available multipole data.

        :returns: Interface to all the multipole data in the directory.
        :rtype: :py:class:`~.MultipolesDir`
        """
        return cactus_multipoles.MultipolesDir(self)
    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__())