コード例 #1
0
ファイル: test_vectors.py プロジェクト: open-biotech/bio-rtd
 def test_true_start(self):
     v = np.ones(100, dtype=bool)
     self.assertEqual(vectors.true_start(v), 0)
     v[:10] = False
     self.assertEqual(vectors.true_start(v), 10)
     v[-10:] = False
     self.assertEqual(vectors.true_start(v), 10)
     v[:] = False
     with self.assertRaises(ValueError):
         vectors.true_start(v)
コード例 #2
0
ファイル: test_pdf.py プロジェクト: open-biotech/bio-rtd
 def get_gauss_pdf_with_cutoff(t, rt_mean, sigma, cutoff) -> np.ndarray:
     p: np.ndarray = peak_shapes.gaussian(t, rt_mean, sigma)
     # cut at end
     p = p[:true_end(p >= cutoff * p.max())]
     # set to 0 at front
     p[:true_start(p >= cutoff * p.max())] = 0
     # return normalized profile (integral = 1)
     return p / p.sum() / t[1]
コード例 #3
0
ファイル: test_pdf.py プロジェクト: open-biotech/bio-rtd
 def get_tanks_in_series_pdf_with_cutoff(t, rt_mean, n_tanks,
                                         cutoff) -> np.ndarray:
     p: np.ndarray = peak_shapes.tanks_in_series(t, rt_mean, n_tanks)
     # cut at end
     p = p[:true_end(p >= cutoff * p.max())]
     # set to 0 at front
     p[:true_start(p >= cutoff * p.max())] = 0
     # return normalized profile (integral = 1)
     return p / p.sum() / t[1]
コード例 #4
0
ファイル: test_fc_uo.py プロジェクト: open-biotech/bio-rtd
    def test_calculate(self):
        # prepare
        self.uo.v_void = 15.2
        self.uo.v_init = 3.2
        self.uo.losses_share = 0.2
        self.uo.losses_species_list = [1]

        self.uo._calculate()

        self.assertTrue(hasattr(self.uo, '_v_void'))
        self.assertTrue(hasattr(self.uo, '_v_init'))
        self.assertTrue(hasattr(self.uo, '_c_init'))
        self.assertTrue(hasattr(self.uo, '_p'))

        self.assertAlmostEqual(0.56, self.uo._c.max())
        self.assertAlmostEqual(0.2726, self.uo._c.mean(), 5)
        self.assertEqual(51, vectors.true_start(self.uo._f > 0))
コード例 #5
0
ファイル: test_fc_uo.py プロジェクト: open-biotech/bio-rtd
    def test_sim_init_fill_up(self):
        # prepare
        self.uo._v_void = 15.5
        self.uo._v_init = 5.5
        self.uo._c_init = np.array([[0], [0.2]])

        self.assert_defined_values("_v_void", self.uo._sim_init_fill_up)
        self.assert_defined_values("_v_init", self.uo._sim_init_fill_up)
        self.assert_defined_values("_c_init", self.uo._sim_init_fill_up)

        # skip if `_v_init == _v_void`
        self.uo._v_init = self.uo._v_void
        c = self.uo._c.copy()
        f = self.uo._f.copy()
        c_init = self.uo._c_init
        self.uo._sim_init_fill_up()
        np.testing.assert_array_equal(c_init, self.uo._c_init)
        np.testing.assert_array_equal(f, self.uo._f)
        np.testing.assert_array_equal(c, self.uo._c)

        # set v_init to < v_void
        self.uo._v_init = 5.5
        # target
        vi = self.uo._v_init
        vv = self.uo._v_void
        c_init = (c_init * vi + c[:, 0:1] * (vv - vi)) / vv
        # noinspection PyTypeChecker
        i_v = vectors.true_start(np.cumsum(self.uo._f) * self.uo._dt >= vv - vi)
        f[:i_v] = 0
        c[:, :i_v] = 0
        # run sim
        self.uo._sim_init_fill_up()
        # compare results
        np.testing.assert_array_almost_equal(c_init, self.uo._c_init, 2)
        np.testing.assert_array_equal(f, self.uo._f)
        np.testing.assert_array_equal(c, self.uo._c)
コード例 #6
0
 def validate_point_on_slope(self, t: np.ndarray, p: np.ndarray, x: float,
                             y: float):
     i = true_start(t >= x)
     # y should be between p[i-1] and p[i]
     self.assertTrue(p[i - 1] < y <= p[i] or p[i - 1] > y >= p[i])