Skip to content

Commit eca1588

Browse files
committed
updating tests
1 parent 474f342 commit eca1588

File tree

2 files changed

+75
-2
lines changed

2 files changed

+75
-2
lines changed

mtpy/core/mt.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414

1515
from mt_metadata.transfer_functions.core import TF
1616

17+
from mtpy.core.transfer_function import (
18+
MT_TO_OHM_FACTOR,
19+
IMPEDANCE_UNITS,
20+
)
1721
from mtpy.core import (
1822
Z,
1923
Tipper,
2024
COORDINATE_REFERENCE_FRAME_OPTIONS,
21-
MT_TO_OHM_FACTOR,
22-
IMPEDANCE_UNITS,
2325
)
2426
from mtpy.core.mt_location import MTLocation
2527
from mtpy.core.mt_dataframe import MTDataFrame

tests/core/transfer_function/test_z.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
import unittest
1111
import numpy as np
1212

13+
from mtpy.core.transfer_function import MT_TO_OHM_FACTOR
1314
from mtpy.core.transfer_function.z import Z
1415

16+
1517
# =============================================================================
1618

1719

@@ -517,6 +519,75 @@ def test_depth_of_investigation(self):
517519
self.assertTrue(np.all(np.isclose(doi["period"], self.z.period)))
518520

519521

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+
520591
# =============================================================================
521592
# Run
522593
# =============================================================================

0 commit comments

Comments
 (0)