|
10 | 10 | import unittest
|
11 | 11 | import numpy as np
|
12 | 12 |
|
| 13 | +from mtpy.core.transfer_function import MT_TO_OHM_FACTOR |
13 | 14 | from mtpy.core.transfer_function.z import Z
|
14 | 15 |
|
| 16 | + |
15 | 17 | # =============================================================================
|
16 | 18 |
|
17 | 19 |
|
@@ -517,6 +519,75 @@ def test_depth_of_investigation(self):
|
517 | 519 | self.assertTrue(np.all(np.isclose(doi["period"], self.z.period)))
|
518 | 520 |
|
519 | 521 |
|
| 522 | +class TestUnits(unittest.TestCase): |
| 523 | + @classmethod |
| 524 | + def setUpClass(self): |
| 525 | + self.z = np.array( |
| 526 | + [ |
| 527 | + [-7.420305 - 15.02897j, 53.44306 + 114.4988j], |
| 528 | + [-49.96444 - 116.4191j, 11.95081 + 21.52367j], |
| 529 | + ] |
| 530 | + ) |
| 531 | + self.z_in_ohms = self.z / MT_TO_OHM_FACTOR |
| 532 | + |
| 533 | + def test_initialize_with_units_ohm(self): |
| 534 | + z_obj = Z(z=self.z_in_ohms, units="ohm") |
| 535 | + with self.subTest("data in mt units"): |
| 536 | + self.assertTrue( |
| 537 | + np.allclose(self.z, z_obj._dataset.transfer_function.values) |
| 538 | + ) |
| 539 | + with self.subTest("data in mt units"): |
| 540 | + self.assertTrue(np.allclose(self.z_in_ohms, z_obj.z)) |
| 541 | + with self.subTest("units"): |
| 542 | + self.assertEqual("ohm", z_obj.units) |
| 543 | + |
| 544 | + def test_initialize_with_units_mt(self): |
| 545 | + z_obj = Z(z=self.z, units="mt") |
| 546 | + with self.subTest("data in mt units"): |
| 547 | + self.assertTrue( |
| 548 | + np.allclose(self.z, z_obj._dataset.transfer_function.values) |
| 549 | + ) |
| 550 | + with self.subTest("data in mt units"): |
| 551 | + self.assertTrue(np.allclose(self.z, z_obj.z)) |
| 552 | + with self.subTest("units"): |
| 553 | + self.assertEqual("mt", z_obj.units) |
| 554 | + |
| 555 | + def test_units_change_ohm_to_mt(self): |
| 556 | + z_obj = Z(z=self.z_in_ohms, units="ohm") |
| 557 | + z_obj.units = "mt" |
| 558 | + with self.subTest("data in mt units"): |
| 559 | + self.assertTrue( |
| 560 | + np.allclose(self.z, z_obj._dataset.transfer_function.values) |
| 561 | + ) |
| 562 | + with self.subTest("data in mt units"): |
| 563 | + self.assertTrue(np.allclose(self.z, z_obj.z)) |
| 564 | + with self.subTest("units"): |
| 565 | + self.assertEqual("mt", z_obj.units) |
| 566 | + |
| 567 | + def test_units_change_mt_to_ohm(self): |
| 568 | + z_obj = Z(z=self.z, units="mt") |
| 569 | + z_obj.units = "ohm" |
| 570 | + with self.subTest("data in mt units"): |
| 571 | + self.assertTrue( |
| 572 | + np.allclose(self.z, z_obj._dataset.transfer_function.values) |
| 573 | + ) |
| 574 | + with self.subTest("data in ohm units"): |
| 575 | + self.assertTrue(np.allclose(self.z_in_ohms, z_obj.z)) |
| 576 | + with self.subTest("units"): |
| 577 | + self.assertEqual("ohm", z_obj.units) |
| 578 | + |
| 579 | + def test_set_unit_fail(self): |
| 580 | + z_obj = Z(z=self.z) |
| 581 | + |
| 582 | + def set_units(unit): |
| 583 | + z_obj.units = unit |
| 584 | + |
| 585 | + with self.subTest("bad type"): |
| 586 | + self.assertRaises(TypeError, set_units, 4) |
| 587 | + with self.subTest("bad choice"): |
| 588 | + self.assertRaises(ValueError, set_units, "ants") |
| 589 | + |
| 590 | + |
520 | 591 | # =============================================================================
|
521 | 592 | # Run
|
522 | 593 | # =============================================================================
|
|
0 commit comments