Skip to content

Commit bfd9857

Browse files
committed
added input/output channels as properties
1 parent fe52a25 commit bfd9857

File tree

2 files changed

+84
-2
lines changed

2 files changed

+84
-2
lines changed

mtpy/processing/kernel_dataset.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,58 @@ def has_remote_mth5(self):
382382
else:
383383
return self.remote_mth5_path.exists()
384384

385+
@property
386+
def input_channels(self):
387+
"""
388+
get input channels from data frame
389+
390+
:return: Input channels (sources)
391+
:rtype: list of strings
392+
393+
"""
394+
395+
if self._has_df():
396+
return self.local_df.input_channels[0]
397+
398+
@property
399+
def output_channels(self):
400+
"""
401+
get input channels from data frame
402+
403+
:return: Input channels (sources)
404+
:rtype: list of strings
405+
406+
"""
407+
408+
if self._has_df():
409+
return self.local_df.output_channels[0]
410+
411+
@property
412+
def local_df(self):
413+
"""
414+
split data frame to just the local station runs
415+
416+
:return: Local station runs
417+
:rtype: pd.DataFrame
418+
419+
"""
420+
421+
if self._has_df():
422+
return self.df[self.df.station == self.local_station_id]
423+
424+
@property
425+
def remote_df(self):
426+
"""
427+
split data frame to just the local station runs
428+
429+
:return: Local station runs
430+
:rtype: pd.DataFrame
431+
432+
"""
433+
434+
if self._has_df() and self.remote_station_id is not None:
435+
return self.df[self.df.station == self.remote_station_id]
436+
385437
@classmethod
386438
def set_path(self, value):
387439
return_path = None

tests/processing/test_kernel_dataset.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,32 @@ def test_str(self):
8888
mini_df = self.kd.mini_summary
8989
self.assertEqual(str(mini_df.head()), str(self.kd))
9090

91+
def test_input_channels(self):
92+
self.assertListEqual(["hx", "hy"], self.kd.input_channels)
93+
94+
def test_output_channels(self):
95+
self.assertListEqual(["ex", "ey", "hz"], self.kd.output_channels)
96+
97+
def test_local_df(self):
98+
with self.subTest("shape"):
99+
self.assertEqual(self.kd.local_df.shape, (1, 20))
100+
with self.subTest("local station only length"):
101+
self.assertEqual(len(self.kd.local_df.station.unqiue()), 1)
102+
with self.subTest("local station only"):
103+
self.assertListEqual(
104+
list(self.kd.local_df.station.unique()), ["test1"]
105+
)
106+
107+
def test_remote_df(self):
108+
with self.subTest("shape"):
109+
self.assertEqual(self.kd.remote_df.shape, (1, 20))
110+
with self.subTest("remote station only length"):
111+
self.assertEqual(len(self.kd.remote_df.station.unqiue()), 1)
112+
with self.subTest("remote station only"):
113+
self.assertListEqual(
114+
list(self.kd.remote_df.station.unique()), ["test1"]
115+
)
116+
91117
# @classmethod
92118
# def tearDownClass(self):
93119
# self.mth5_path.unlink()
@@ -111,11 +137,15 @@ def setUpClass(self):
111137
# hours
112138

113139
# shift the interval forward, leave it overlapping
114-
self.ti2_start = self.ti1_start + pd.Timedelta(hours=self.shift_1_hours)
140+
self.ti2_start = self.ti1_start + pd.Timedelta(
141+
hours=self.shift_1_hours
142+
)
115143
self.ti2_end = self.ti1_end + pd.Timedelta(hours=self.shift_1_hours)
116144

117145
# shift the interval forward, non-verlapping
118-
self.ti3_start = self.ti1_start + pd.Timedelta(hours=self.shift_2_hours)
146+
self.ti3_start = self.ti1_start + pd.Timedelta(
147+
hours=self.shift_2_hours
148+
)
119149
self.ti3_end = self.ti1_end + pd.Timedelta(hours=self.shift_2_hours)
120150

121151
def test_overlaps_boolean(self):

0 commit comments

Comments
 (0)