Skip to content

Commit 12e3196

Browse files
committed
Update kernel_dataset.py
1 parent 8014735 commit 12e3196

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

mtpy/processing/kernel_dataset.py

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ def __init__(
152152
self._mini_summary_columns = MINI_SUMMARY_COLUMNS
153153
self.survey_metadata = {}
154154
self.initialized = False
155+
self.local_mth5_obj = None
156+
self.remote_mth5_obj = None
155157

156158
def __str__(self):
157159
return str(self.mini_summary.head())
@@ -797,6 +799,20 @@ def update_survey_metadata(
797799
if len(self.survey_metadata.keys()) > 1:
798800
raise NotImplementedError
799801

802+
@property
803+
def mth5_objs(self):
804+
"""
805+
806+
:return: dictionary [station_id: mth5_obj]
807+
:rtype: dict
808+
809+
"""
810+
mth5_obj_dict = {}
811+
mth5_obj_dict[self.local_station_id] = self.local_mth5_obj
812+
if self.remote_station_id is not None:
813+
mth5_obj_dict[self.remote_station_id] = self.remote_mth5_obj
814+
return mth5_obj_dict
815+
800816
def initialize_mth5s(self, mode="r"):
801817
"""
802818
returns a dict of open mth5 objects, keyed by station_id
@@ -811,18 +827,15 @@ def initialize_mth5s(self, mode="r"):
811827
local station id : mth5.mth5.MTH5
812828
remote station id: mth5.mth5.MTH5
813829
"""
814-
mth5_obj_dict = {}
815-
mth5_obj_dict[self.local_station_id] = initialize_mth5(
816-
self.local_mth5_path, mode=mode
817-
)
830+
self.local_mth5_obj = initialize_mth5(self.local_mth5_path, mode=mode)
818831
if self.remote_station_id:
819-
mth5_obj_dict[self.remote_station_id] = initialize_mth5(
832+
self.remote_mth5_obj = initialize_mth5(
820833
self.remote_mth5_path, mode="r"
821834
)
822835

823836
self.initialized = True
824837

825-
return mth5_obj_dict
838+
return self.mth5_objs
826839

827840
def initialize_dataframe_for_processing(self, mth5_objs: dict) -> None:
828841
"""
@@ -894,11 +907,17 @@ def add_columns_for_processing(self, mth5_objs) -> None:
894907
Keys are station_id, values are MTH5 objects.
895908
896909
"""
897-
# columns_to_add = ["run_dataarray", "stft", "run_reference"]
898-
mth5_obj_column = len(self.df) * [None]
899-
for i, station_id in enumerate(self.df["station"]):
900-
mth5_obj_column[i] = mth5_objs[station_id]
901-
self.df["mth5_obj"] = mth5_obj_column
910+
if not self.initialized:
911+
raise ValueError("mth5 objects have not been initialized yet.")
912+
913+
if self._has_df():
914+
self._df.loc[
915+
self._df.station == self.local_station_id, "mth5_obj"
916+
] = self.local_mth5_obj
917+
if self.remote_station_id is not None:
918+
self._df.loc[
919+
self._df.station == self.remote_station_id, "mth5_obj"
920+
] = self.remote_mth5_obj
902921

903922
def close_mth5s(self) -> None:
904923
"""

0 commit comments

Comments
 (0)