Skip to content

Commit

Permalink
Merge pull request #264 from simpeg/fix_issue_139
Browse files Browse the repository at this point in the history
Fix issue 139
  • Loading branch information
kkappler authored May 29, 2023
2 parents 8cdfffd + 1bdf737 commit 8cf0fdd
Show file tree
Hide file tree
Showing 14 changed files with 232 additions and 433 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
conda install -c conda-forge pytest pytest-cov certifi">=2017.4.17" pandoc
pip install -r requirements-dev.txt
pip install git+https://github.com/kujaku11/mt_metadata.git@fcs
pip install git+https://github.com/kujaku11/mth5.git
pip install git+https://github.com/kujaku11/mth5.git@fc
- name: Install Our Package
run: |
Expand Down
74 changes: 58 additions & 16 deletions aurora/config/metadata/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from aurora.time_series.windowing_scheme import window_scheme_from_decimation
from mt_metadata.transfer_functions.processing.aurora.processing import Processing
from mt_metadata.utils.list_dict import ListDict
from mth5.utils.helpers import initialize_mth5


Expand Down Expand Up @@ -81,7 +82,7 @@ def save_as_json(self, filename=None, nested=True, required=False):
with open(filename, "w") as f:
f.write(json_str)

def make_tf_header(self, dec_level_id):
def emtf_tf_header(self, dec_level_id):
"""
Parameters
Expand All @@ -93,19 +94,14 @@ def make_tf_header(self, dec_level_id):
-------
tfh: mt_metadata.transfer_functions.processing.aurora.transfer_function_header.TransferFunctionHeader
"""
from aurora.transfer_function.transfer_function_header import (
TransferFunctionHeader,
)

tfh = TransferFunctionHeader(
processing_scheme=self.decimations[dec_level_id].estimator.engine,
local_station=self.stations.local,
reference_station=self.stations.remote,
input_channels=self.decimations[dec_level_id].input_channels,
output_channels=self.decimations[dec_level_id].output_channels,
reference_channels=self.decimations[dec_level_id].reference_channels,
decimation_level_id=dec_level_id,
)
tfh = ListDict()
tfh.processing_scheme = self.decimations[dec_level_id].estimator.engine
tfh.local_station = self.stations.local
tfh.remote_station = self.stations.remote
tfh.input_channels = self.decimations[dec_level_id].input_channels
tfh.output_channels = self.decimations[dec_level_id].output_channels
tfh.reference_channels = self.decimations[dec_level_id].reference_channels
tfh.decimation_level_id = dec_level_id

return tfh

Expand All @@ -125,7 +121,53 @@ def make_tf_level(self, dec_level_id):
# from aurora.transfer_function.base import TransferFunction
from aurora.transfer_function.TTFZ import TTFZ

tf_header = self.make_tf_header(dec_level_id)
tf_obj = TTFZ(tf_header, self.decimations[dec_level_id].frequency_bands_obj())
tf_obj = TTFZ(
dec_level_id,
self.decimations[dec_level_id].frequency_bands_obj(),
processing_config=self,
)

return tf_obj


class EMTFTFHeader(ListDict):
"""
Convenince class for storing metadata for a TF estimate.
Based on Gary Egbert's TFHeader.m originally in
iris_mt_scratch/egbert_codes-20210121T193218Z-001/egbert_codes/matlabPrototype_10-13-20/TF/classes
It completely depends on the Processing class
"""

def __init__(self, **kwargs):
"""
Parameters
_local_station : mt_metadata.transfer_functions.tf.station.Station()
Station metadata object for the station to be estimated (
location, channel_azimuths, etc.)
_remote_station: same object type as local station
if no remote reference then this can be None
output_channels: list
Probably a list of channel keys -- usually ["ex","ey","hz"]
input_channels : list
Probably a list of channel keys -- usually ["hx","hy"]
These are the channels being provided as input to the regression.
reference_channels : list
These are the channels being used from the RR station. This is a
channel list -- usually ["hx", "hy"]
processing_scheme: str
Denotes the regression engine used to estimate the transfer
function. One of "OLS" or "RME", "RME_RR. Future
versions could include , "multivariate array", "multiple remote",
etc.
"""
super().__init__()
self.processing_scheme = kwargs.get("processing_scheme", None)
self.local_station = kwargs.get("local_station", None)
self.remote_station = kwargs.get("remote_station", None)
self.input_channels = kwargs.get("input_channels", ["hx", "hy"])
self.output_channels = kwargs.get("output_channels", ["ex", "ey"])
self.reference_channels = kwargs.get("reference_channels", [])
self.decimation_level_id = kwargs.get("decimation_level_id", None)
self.user_meta_data = None # placeholder for anything
3 changes: 1 addition & 2 deletions aurora/pipelines/process_mth5.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ def process_tf_decimation_level(
The transfer function values packed into an object
"""
frequency_bands = config.decimations[i_dec_level].frequency_bands_obj()
tf_header = config.make_tf_header(i_dec_level)
transfer_function_obj = TTFZ(tf_header, frequency_bands, processing_config=config)
transfer_function_obj = TTFZ(i_dec_level, frequency_bands, processing_config=config)

transfer_function_obj = process_transfer_functions(
config, i_dec_level, local_stft_obj, remote_stft_obj, transfer_function_obj
Expand Down
2 changes: 1 addition & 1 deletion aurora/pipelines/transfer_function_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def get_band_for_tf_estimate(
Parameters
----------
band : aurora.time_series.frequency_band.FrequencyBand
band : mt_metadata.transfer_functions.processing.aurora.FrequencyBands
object with lower_bound and upper_bound to tell stft object which
subarray to return
config : mt_metadata.transfer_functions.processing.aurora.decimation_level.DecimationLevel
Expand Down
2 changes: 1 addition & 1 deletion aurora/sandbox/plot_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def plot_tf_obj(tf_obj, out_filename=None, show=True):

plotter = RhoPlot(tf_obj)
fig, axs = plt.subplots(nrows=2)
ttl_str = tf_obj.tf_header.local_station_id
ttl_str = tf_obj.tf_header.local_station.id
plotter.rho_sub_plot(axs[0], ttl_str=ttl_str)
plotter.phase_sub_plot(axs[1], ttl_str=ttl_str)
if out_filename:
Expand Down
25 changes: 25 additions & 0 deletions aurora/test_utils/synthetic/processing_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,28 @@ class that has a df that describes the runs to be processed.
return_collection=return_collection,
)
return tf_collection


def tf_obj_from_synthetic_data(mth5_path):
"""Helper function for test_issue_139"""
from aurora.config.config_creator import ConfigCreator
from aurora.pipelines.run_summary import RunSummary
from aurora.transfer_function.kernel_dataset import KernelDataset

run_summary = RunSummary()
run_summary.from_mth5s(list((mth5_path,)))

kernel_dataset = KernelDataset()
kernel_dataset.from_run_summary(run_summary, "test1", "test2")

# Define the processing Configuration
cc = ConfigCreator()
config = cc.create_from_kernel_dataset(kernel_dataset)

tf_cls = process_mth5(
config,
kernel_dataset,
units="MT",
z_file_path="zzz.zz",
)
return tf_cls
Loading

0 comments on commit 8cf0fdd

Please sign in to comment.