Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 41 additions & 3 deletions tsvi/mth5_tsviewer/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,44 @@ def channel_summary_columns_to_display():
]
return displayed_columns


def set_channel_paths(df, file_name, file_version):
"""
ToDo: Consider making a class ChannelPathHandler
That has set_channel_paths method,
and also does the string unpacking
Parameters
----------
df: pandas.core.frame.DataFrame from mth5 channel_summary

Returns
-------

"""
df["file"] = file_name
if file_version == "0.1.0":
df["channel_path"] = (df["file"] + "/" +
df["station"] + "/" +
df["run"] + "/" +
df["component"])
elif file_version == "0.2.0":
df["channel_path"] = (df["file"] + "/" +
df["survey"] + "/" +
df["station"] + "/" +
df["run"] + "/" +
df["component"])
df.set_index("channel_path", inplace = True)
return

def parse_channel_path(selected_channel):
try: # m.file_version == "0.1.0"
selected_file, station, run, channel = selected_channel.split("/")
survey = None
except ValueError: # m.file_version == "0.2.0"
selected_file, survey, station, run, channel = selected_channel.split("/")
return selected_file, survey, station, run, channel


# def plot_bokeh(xarray, shaded = False, shared = False):
# plot = xarray.hvplot(
# width = 900,
Expand Down Expand Up @@ -136,7 +174,7 @@ def make_plots(obj):
# plot_cards = make_plots(data_dict)
# from holoviews.operation.datashader import datashade
for selected_channel,data in data_dict.items():
selected_file, station, run, channel = selected_channel.split("/")
selected_file, survey, station, run, channel = parse_channel_path(selected_channel)
ylabel = data.type
if obj.subtract_mean_checkbox.value == True:
data = data - data.mean()
Expand Down Expand Up @@ -214,9 +252,9 @@ def get_mth5_data_as_xarrays(selected_channels, file_paths):
m = MTH5()
m.open_mth5(file_paths[file], mode = "r")
for selected_channel in selected_channels:
selected_file, station, run, channel = selected_channel.split("/")
selected_file, survey, station, run, channel = parse_channel_path(selected_channel)
if selected_file == file:
data = m.get_channel(station, run, channel).to_channel_ts().to_xarray()
data = m.get_channel(station, run, channel, survey=survey).to_channel_ts().to_xarray()
# data = data.rename(data.attrs["mth5_type"]): "ex"--> "Electric"
#self.xarrays.append(data)
out_dict[selected_channel] = data
Expand Down
9 changes: 4 additions & 5 deletions tsvi/mth5_tsviewer/mth5_viewer_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
from tsvi.mth5_tsviewer.helpers import cpu_usage_widget
from tsvi.mth5_tsviewer.helpers import get_templates_dict
from tsvi.mth5_tsviewer.helpers import make_plots
from tsvi.mth5_tsviewer.helpers import list_h5s_to_plot
from tsvi.mth5_tsviewer.helpers import memory_usage_widget
from tsvi.mth5_tsviewer.helpers import set_channel_paths


hv.extension("bokeh")
Expand Down Expand Up @@ -232,10 +232,9 @@ def update_channels(self, event):
m = MTH5()
m.open_mth5(file_path, mode = "r")
df = m.channel_summary.to_dataframe()
file_version = m.file_version
m.close_mth5()
df["file"] = file_name
df["channel_path"] = (df["file"] + "/" + df["station"] + "/" + df["run"] + "/" + df["component"])
df.set_index("channel_path", inplace = True)
set_channel_paths(df, file_name, file_version)
self.channel_summary_dict[file_name] = df
new_channels.extend(self.channel_summary_dict[file_name].index)
self.channels.options = list(new_channels)
Expand Down Expand Up @@ -299,4 +298,4 @@ def clear_notes(self, event):


tsvi = Tsvi(plot_width=900, plot_height=200)
tsvi.show()
tsvi.show()