Skip to content

Commit

Permalink
one less arg into process_transfer_functions
Browse files Browse the repository at this point in the history
- the integer decimation level was not needed
- this propagates to some other functions, that now take dec_level_cfg
  instead of config
- only logic change was tfk validator now drops ref channels if no RR station
  • Loading branch information
kkappler committed Jan 9, 2024
1 parent d502e3e commit 76cdca1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
13 changes: 10 additions & 3 deletions aurora/pipelines/process_mth5.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

# =============================================================================


def make_stft_objects(
processing_config, i_dec_level, run_obj, run_xrds, station_id, units="MT"
):
Expand Down Expand Up @@ -122,6 +123,7 @@ def process_tf_decimation_level(
Processing pipeline for a single decimation_level
TODO: Add a check that the processing config sample rates agree with the data
TODO: Add units to local_stft_obj, remote_stft_obj
sampling rates otherwise raise Exception
This method can be single station or remote based on the process cfg
Expand All @@ -146,9 +148,9 @@ def process_tf_decimation_level(
"""
frequency_bands = config.decimations[i_dec_level].frequency_bands_obj()
transfer_function_obj = TTFZ(i_dec_level, frequency_bands, processing_config=config)

dec_level_config = config.decimations[i_dec_level]
transfer_function_obj = process_transfer_functions(
config, i_dec_level, local_stft_obj, remote_stft_obj, transfer_function_obj
dec_level_config, local_stft_obj, remote_stft_obj, transfer_function_obj
)

return transfer_function_obj
Expand Down Expand Up @@ -368,7 +370,12 @@ def process_mth5(
run_obj.metadata.id = row.run_id

stft_obj = make_stft_objects(
tfk.config, i_dec_level, run_obj, run_xrds, row.station_id, units,
tfk.config,
i_dec_level,
run_obj,
run_xrds,
row.station_id,
units,
)
# Pack FCs into h5
save_fourier_coefficients(
Expand Down
8 changes: 3 additions & 5 deletions aurora/pipelines/transfer_function_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ def select_channel(xrda, channel_label):


def process_transfer_functions(
config,
i_dec_level,
dec_level_config,
local_stft_obj,
remote_stft_obj,
transfer_function_obj,
Expand All @@ -103,7 +102,7 @@ def process_transfer_functions(
Parameters
----------
config
dec_level_config
local_stft_obj
remote_stft_obj
transfer_function_obj: aurora.transfer_function.TTFZ.TTFZ
Expand All @@ -129,12 +128,11 @@ def process_transfer_functions(
"""
# PUT COHERENCE SORTING HERE IF WIDE BAND?
dec_level_config = config.decimations[i_dec_level]
estimator_class = get_estimator_class(dec_level_config.estimator.engine)
for band in transfer_function_obj.frequency_bands.bands():
iter_control = set_up_iter_control(dec_level_config)
X, Y, RR = get_band_for_tf_estimate(
band, config, local_stft_obj, remote_stft_obj
band, dec_level_config, local_stft_obj, remote_stft_obj
)
# if there are segment weights apply them here
# if there are channel weights apply them here
Expand Down
8 changes: 5 additions & 3 deletions aurora/pipelines/transfer_function_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import pandas as pd
import psutil

from loguru import logger

from aurora.pipelines.helpers import initialize_config
from aurora.pipelines.time_series_helpers import prototype_decimate
from mth5.utils.exceptions import MTH5Error
Expand Down Expand Up @@ -322,7 +320,9 @@ def make_processing_summary(self):
df.dec_level.diff()[1:] == 1
).all() # dec levels increment by 1
except AssertionError:
logger.info(f"Skipping {group} because decimation levels are messy.")
logger.info(

Check warning on line 323 in aurora/pipelines/transfer_function_kernel.py

View check run for this annotation

Codecov / codecov/patch

aurora/pipelines/transfer_function_kernel.py#L323

Added line #L323 was not covered by tests
f"Skipping {group} because decimation levels are messy."
)
continue
assert df.dec_factor.iloc[0] == 1
assert df.dec_level.iloc[0] == 0
Expand Down Expand Up @@ -396,12 +396,14 @@ def validate_processing(self):
1. The default estimation engine from the json file is "RME_RR", which is fine (
we expect to in general to do more RR processing than SS) but if there is only
one station (no remote)then the RME_RR should be replaced by default with "RME".
- also if there is only one station, set reference channels to []
2. make sure local station id is defined (correctly from kernel dataset)
"""

# Make sure a RR method is not being called for a SS config
if not self.config.stations.remote:
self.config.drop_reference_channels()
for decimation in self.config.decimations:
if decimation.estimator.engine == "RME_RR":
logger.info("No RR station specified, switching RME_RR to RME")
Expand Down
5 changes: 2 additions & 3 deletions aurora/time_series/frequency_band_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from loguru import logger


def get_band_for_tf_estimate(band, config, local_stft_obj, remote_stft_obj):
def get_band_for_tf_estimate(band, dec_level_config, local_stft_obj, remote_stft_obj):
"""
Get data for TF estimation for a particular band.
Expand All @@ -28,13 +28,12 @@ def get_band_for_tf_estimate(band, config, local_stft_obj, remote_stft_obj):
reference_channels and also the frequency axes are restricted to
being within the frequency band given as an input argument.
"""
dec_level_config = config.decimations[0]
logger.info(f"Processing band {band.center_period:.6f}s")
band_dataset = extract_band(band, local_stft_obj)
X = band_dataset[dec_level_config.input_channels]
Y = band_dataset[dec_level_config.output_channels]
check_time_axes_synched(X, Y)
if config.stations.remote:
if dec_level_config.reference_channels:
band_dataset = extract_band(band, remote_stft_obj)
RR = band_dataset[dec_level_config.reference_channels]
check_time_axes_synched(Y, RR)
Expand Down

0 comments on commit 76cdca1

Please sign in to comment.