Skip to content

Commit

Permalink
Deprecate create_run_processing_object
Browse files Browse the repository at this point in the history
Cleanup, towards issue#150.
Also reduced to only one test (py3.8)

[Issue(s): #150]
  • Loading branch information
kkappler committed Sep 9, 2022
1 parent fcf1821 commit 0f5f6f9
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
fail-fast: false
matrix:
os: ["ubuntu-latest"]
python-version: [3.8, 3.7, 3.6]
python-version: [3.8,]# 3.7, 3.6]

steps:
- uses: actions/checkout@v2
Expand Down
42 changes: 36 additions & 6 deletions aurora/config/config_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""
from deprecated import deprecated
from pathlib import Path

from aurora.config import Processing, Station, Run, BANDS_DEFAULT_FILE
Expand All @@ -16,6 +17,35 @@ def __init__(self, **kwargs):
default_config_path = Path("config")
self.config_path = kwargs.get("config_path", default_config_path)

def processing_id(self, kernel_dataset):
"""
In the past, we used f"{local}-{remote}" or f"{local}-{run_id}"
Neither of these is sufficiently unique. In fact, they only describe the
dataset, and not the processing config. It is difficult to see how to make a
comprehensive, unique id without it being very long or involving hash
functions.
For now, will try to use {local}-{local_runs}-{remote}-{remote_runs},
which at least describes the dataset, then a string can be generated by the
config and appended if needed.
Parameters
----------
kernel_dataset
Returns
-------
"""
id = f"{kernel_dataset.local_station_id}-{kernel_dataset.remote_station_id}"
return id

def _create(
self, input_channels=["hx", "hy"], output_channels=["hz", "ex", "ey"], **kwargs
):
pass

def create_from_kernel_dataset(
self,
kernel_dataset,
Expand All @@ -27,13 +57,12 @@ def create_from_kernel_dataset(
**kwargs,
):

processing_id = (
f"{kernel_dataset.local_station_id}-{kernel_dataset.remote_station_id}"
)
processing_id = self.processing_id(kernel_dataset)
processing_obj = Processing(id=processing_id, **kwargs)

# pack station and run info into processing object
processing_obj.stations.from_dataset_dataframe(kernel_dataset.df)
# runs = []
# PACK RUNS HERE

processing_obj.set_frequency_bands(
emtf_band_file=emtf_band_file,
band_edges=band_edges,
Expand All @@ -50,6 +79,7 @@ def create_from_kernel_dataset(
pass
return processing_obj

@deprecated
def create_run_processing_object(
self,
station_id=None,
Expand All @@ -71,7 +101,7 @@ def create_run_processing_object(
Parameters
----------
station_id
run_id
run_id: string or list of strings.
mth5_path
sample_rate
input_channels
Expand Down
8 changes: 4 additions & 4 deletions aurora/config/metadata/channel_nomenclature.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# =============================================================================
attr_dict = get_schema("channel_nomenclature", SCHEMA_FN_PATHS)


DEFAULT_CHANNEL_MAP = {
CHANNEL_MAPS = {}
CHANNEL_MAPS["default"] = {
"hx": "hx",
"hy": "hy",
"hz": "hz",
Expand Down Expand Up @@ -105,13 +105,13 @@ def keyword(self, keyword):

def get_channel_map(self, keyword):
if keyword == "default":
channel_map = DEFAULT_CHANNEL_MAP
channel_map = CHANNEL_MAPS["default"]
elif keyword == "LEMI12":
channel_map = LEMI_CHANNEL_MAP_12
elif keyword == "LEMI34":
channel_map = LEMI_CHANNEL_MAP_34
elif keyword == "NIMS":
channel_map = DEFAULT_CHANNEL_MAP
channel_map = CHANNEL_MAPS["default"]
elif keyword == "PHOENIX123":
channel_map = PHOENIX_CHANNEL_MAP_123
else:
Expand Down
3 changes: 1 addition & 2 deletions aurora/transfer_function/kernel_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
8. This is now a TFKernel Dataset Definition (ish). Initialize a default
processing object and pass it this df:
cc = ConfigCreator(config_path=CONFIG_PATH)
p = cc.create_run_processing_object(emtf_band_file=emtf_band_setup_file)
p.stations.from_dataset_dataframe(dd_df)
p = cc.create_from_kernel_dataset(kernel_dataset, emtf_band_file=emtf_band_setup_file)
9. Edit the Processing appropriately,
"""
Expand Down
2 changes: 2 additions & 0 deletions aurora/transfer_function/weights/coherence_weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ def coherence_weights_v00(x, y, threshold=0.95): # 975):#0.98

def compute_coherence_weights(X, Y, RR, coh_type="local"):
"""
2022-09-09: This method is not yet supported. It needs to be made
tolerant of channel_nomenclature.
Parameters
----------
Expand Down
15 changes: 4 additions & 11 deletions tests/cas04/02b_process_cas04_mth5.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,7 @@ def process_station_runs(local_station_id, remote_station_id="", station_runs={}

cc = ConfigCreator()
cc = ConfigCreator(config_path=CONFIG_PATH)
pc = cc.create_run_processing_object(
emtf_band_file=BANDS_DEFAULT_FILE, sample_rate=1.0
)
pc.stations.from_dataset_dataframe(kernel_dataset.df)
pc = cc.create_from_kernel_dataset(kernel_dataset)
pc.validate()
z_file_name = tmp_station_runs.z_file_name(AURORA_RESULTS_PATH)
tf_result = process_mth5(
Expand Down Expand Up @@ -322,15 +319,11 @@ def process_with_remote(local, remote, band_setup_file="band_setup_emtf_nims.txt
kernel_dataset.drop_runs_shorter_than(15000)

# Add a method to ensure all samplintg rates are the same
sr = kernel_dataset.df.sample_rate.unique()

cc = ConfigCreator() # config_path=CONFIG_PATH)
band_setup_file = "band_setup_emtf_nims.txt"
# band_setup_file = BANDS_DEFAULT_FILE
config = cc.create_run_processing_object(
emtf_band_file=band_setup_file, sample_rate=sr[0]
cc = ConfigCreator()
config = cc.create_from_kernel_dataset(
kernel_dataset, emtf_band_file=band_setup_file
)
config.stations.from_dataset_dataframe(kernel_dataset.df)
for decimation in config.decimations:
decimation.window.type = "hamming"
show_plot = False
Expand Down
7 changes: 1 addition & 6 deletions tests/parkfield/test_process_parkfield_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,7 @@ def test_processing(return_collection=False, z_file_path=None, test_clock_zero=F
tfk_dataset.from_run_summary(run_summary, "PKD")

cc = ConfigCreator(config_path=CONFIG_PATH)
# config = cc.create_from_kernel_dataset(tfk_dataset, estimator={"engine": "RME"})
config = cc.create_run_processing_object(
emtf_band_file=BANDS_DEFAULT_FILE,
sample_rate=tfk_dataset.sample_rate,
estimator={"engine": "RME"},
)
config = cc.create_from_kernel_dataset(tfk_dataset, estimator={"engine": "RME"})

if test_clock_zero:
for dec_lvl_cfg in config.decimations:
Expand Down
17 changes: 4 additions & 13 deletions tests/synthetic/test_multi_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,9 @@ def test_each_run_individually():
]
keep_or_drop = "keep"
kernel_dataset.select_station_runs(station_runs_dict, keep_or_drop)
print(kernel_dataset.df)
cc = ConfigCreator()
sample_rate = kernel_dataset.df.sample_rate.iloc[0]
config = cc.create_run_processing_object(
emtf_band_file=BANDS_DEFAULT_FILE, sample_rate=sample_rate
)
config.stations.from_dataset_dataframe(kernel_dataset.df)
config = cc.create_from_kernel_dataset(kernel_dataset)

for decimation in config.decimations:
decimation.estimator.engine = "RME"
show_plot = False # True
Expand Down Expand Up @@ -62,13 +58,8 @@ def test_all_runs():
kernel_dataset = KernelDataset()
kernel_dataset.from_run_summary(run_summary, "test3")
cc = ConfigCreator()
sample_rate = kernel_dataset.df.sample_rate.iloc[0]
config = cc.create_run_processing_object(
emtf_band_file=BANDS_DEFAULT_FILE, sample_rate=sample_rate
)
config.stations.from_dataset_dataframe(kernel_dataset.df)
for decimation in config.decimations:
decimation.estimator.engine = "RME"
config = cc.create_from_kernel_dataset(kernel_dataset, estimator={"engine": "RME"})

show_plot = False # True
z_file_path = AURORA_RESULTS_PATH.joinpath("syn3_all.zss")
tf_cls = process_mth5(
Expand Down

0 comments on commit 0f5f6f9

Please sign in to comment.