Skip to content

Commit

Permalink
Merge pull request #232 from kujaku11/fix_issue_209a
Browse files Browse the repository at this point in the history
Minor multivariate updates

Probably should have pushed this direct to patches
  • Loading branch information
kkappler authored Aug 15, 2024
2 parents 11016dc + f33f023 commit 4600075
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
15 changes: 12 additions & 3 deletions mth5/utils/fc_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"""

from dataclasses import dataclass

from loguru import logger
from mth5.utils.exceptions import MTH5Error
from typing import Optional, Tuple , Union
import mth5.mth5
import pandas as pd
Expand Down Expand Up @@ -248,8 +248,17 @@ def make_multistation_spectrogram(
for i_fcrc, fcrc in enumerate(fc_run_chunks):
station_obj = m.get_station(fcrc.station_id, fcrc.survey_id)
station_fc_group = station_obj.fourier_coefficients_group
logger.info(f"Available FC Groups for station {fcrc.station_id}: {station_fc_group.groups_list}")
run_fc_group = station_obj.fourier_coefficients_group.get_fc_group(fcrc.run_id)
try:
run_fc_group = station_obj.fourier_coefficients_group.get_fc_group(fcrc.run_id)
except MTH5Error as e:
error_msg = f"Failed to get fc group {fcrc.run_id}"
logger.error(error_msg)
msg = f"Available FC Groups for station {fcrc.station_id}: "
msg = f"{msg} {station_fc_group.groups_list}"
logger.error(msg)
logger.error(f"Maybe try adding FCs for {fcrc.run_id}")
raise e #MTH5Error(error_msg)

# print(run_fc_group)
fc_dec_level = run_fc_group.get_decimation_level(fcrc.decimation_level_id)
if fcrc.channels:
Expand Down
9 changes: 8 additions & 1 deletion tests/version_1/test_fcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import xarray as xr

from mth5.mth5 import MTH5
from mth5.utils.exceptions import MTH5Error
from mth5.utils.fc_tools import make_multistation_spectrogram
from mth5.utils.fc_tools import FCRunChunk
from mth5.utils.fc_tools import MultivariateDataset
Expand Down Expand Up @@ -390,6 +391,8 @@ def test_multi_station_spectrogram(self):

# TODO: These tests should go in their own module, but need test dataset (issue #227)
xrds = make_multistation_spectrogram(self.m, fc_run_chunks, rtype="xrds")


assert isinstance(xrds, xarray.Dataset)
mvds = make_multistation_spectrogram(self.m, fc_run_chunks, rtype=None)
assert isinstance(mvds, MultivariateDataset)
Expand All @@ -405,7 +408,11 @@ def test_multi_station_spectrogram(self):
total_channels += len(mvds.station_channels(station_id))
assert total_channels == len(mvds.channels)

# print("OK")
# Now assert MTH5 error when making a multistation spectrogram and no data available
with self.assertRaises(MTH5Error):
fc_run_chunks[0].run_id = "wont find this run name"
mvds = make_multistation_spectrogram(self.m, fc_run_chunks, rtype=None)
print("OK")


@classmethod
Expand Down

0 comments on commit 4600075

Please sign in to comment.