Skip to content

Commit

Permalink
Updated DRT tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vyrjana committed Oct 27, 2024
1 parent f99485e commit a3fcfa7
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions tests/test_drt.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
concatenate,
exp,
float64,
isclose,
log10 as log,
ndarray,
sort,
Expand Down Expand Up @@ -101,26 +102,25 @@ def progress_callback(*args, **kwargs):
PROGRESS.register(progress_callback)


# Note: The results may vary depending on the platforms that is being used.
# Similar results should be returned if a little bit of noise is included
# in the impedance spectrum. However, this will result in a lot peaks.
class TestLoewnerMethod(TestCase):
@classmethod
def setUpClass(cls):
cls.data: DataSet = generate_mock_data(
"R{R=140}L{L=1e-4}(R{R=230}C{C=1e-6})(R{R=576}C{C=1e-4})(R{R=150}L{L=4e1})",
)[0]
cls.expected_time_constants = list(map(TimeConstant, (
3.6e-8,
4.2e-8,
230.0 * 1e-6,
576.0 * 1e-4,
4e1 / 150.0,
)))
cls.expected_gammas_RC = list(map(Gamma, (
1445.9,
230.0,
576.0,
)))
cls.expected_gammas_RL = list(map(Gamma, (
1155.9,
150.0,
)))
cls.result: LMResult = calculate_drt(cls.data, method="lm")
Expand Down Expand Up @@ -187,11 +187,13 @@ def test_result_to_peaks_dataframe(self):

def test_result_get_drt_data(self):
time_constants_RC: TimeConstants
gamma_RC: Gammas
gammas_RC: Gammas
time_constants_RL: TimeConstants
gamma_RL: Gammas
gammas_RL: Gammas
time_constants_RC, gammas_RC, time_constants_RL, gammas_RL = self.result.get_drt_data()

time_constants: TimeConstants
gammas: Gammas
for time_constants, gammas in (
(time_constants_RC, gammas_RC),
(time_constants_RL, gammas_RL),
Expand All @@ -204,36 +206,30 @@ def test_result_get_drt_data(self):

def test_result_get_time_constants(self):
time_constants: TimeConstants = self.result.get_time_constants()
self.assertEqual(len(time_constants), 5)
self.assertGreaterEqual(len(time_constants), 3)
self.assertEqual(time_constants.dtype, TimeConstant)

i: int
t: TimeConstant
for i, t in enumerate(time_constants):
self.assertAlmostEqual(
t,
self.expected_time_constants[i],
msg=f"{i=}: {t=} != {self.expected_time_constants[i]}",
)
for t in self.expected_time_constants:
self.assertTrue(isclose(time_constants, t).any())

def test_result_get_gammas(self):
gammas: Tuple[Gammas, Gammas] = self.result.get_gammas()
self.assertIsInstance(gammas, tuple)
self.assertEqual(len(gammas), 2)

gammas_RC, gammas_RL = gammas
self.assertEqual(gammas_RC.shape, (3,))
self.assertEqual(gammas_RL.shape, (2,))
self.assertGreaterEqual(gammas_RC.shape, (3,))
self.assertGreaterEqual(gammas_RL.shape, (2,))
self.assertEqual(gammas_RC.dtype, Gamma)
self.assertEqual(gammas_RL.dtype, Gamma)

i: int
g: float64
for i, g in enumerate(gammas_RC):
self.assertAlmostEqual(g, self.expected_gammas_RC[i], places=1)
for g in self.expected_gammas_RC:
self.assertTrue(isclose(gammas_RC, g).any())

for i, g in enumerate(gammas_RL):
self.assertAlmostEqual(g, self.expected_gammas_RL[i], places=1)
for g in self.expected_gammas_RL:
self.assertTrue(isclose(gammas_RL, g).any())


seed(28041948) # GNU STP
Expand Down

0 comments on commit a3fcfa7

Please sign in to comment.