Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 364 #375

Closed
wants to merge 79 commits into from
Closed
Changes from 11 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
082fa73
housekeeping
kkappler Nov 9, 2024
f0c41d0
remove uneeded ipynb form tests
kkappler Dec 1, 2024
89e000d
Merge minor changes from fix_mtpy_issue_67
kkappler Dec 17, 2024
e4df7e6
housekeeping / doc strings
kkappler Dec 20, 2024
49b1f33
fix typehint
kkappler Dec 20, 2024
a7406dd
housekeeping & typehinting
kkappler Dec 21, 2024
c81729c
doc and typehints
kkappler Dec 21, 2024
b7cb76c
Minor change
kkappler Dec 21, 2024
080709c
doc / type hints
kkappler Dec 21, 2024
021ad30
Move recoloring boolean check above call to apply_recoloring
kkappler Dec 21, 2024
b4af28b
tidy doc
kkappler Dec 26, 2024
f914a30
Test new pathing for Band object in mt_metadata
kkappler Dec 26, 2024
cb86a49
Reduce number of instances for test and update mt_metadata branch
kkappler Dec 26, 2024
eed21ba
try suppress mtpy-v2 reinstall
kkappler Dec 26, 2024
cb1225e
update import get_fft_harmonics to new path in mt_metadata
kkappler Dec 26, 2024
df77152
replace some calls to decimation attrs with access to time_series_dec…
kkappler Dec 27, 2024
5fa3fe7
change var name and add dtype (local tests pass)
kkappler Dec 27, 2024
4931648
add some dtyping and doc
kkappler Dec 28, 2024
12d4cf4
add doc/notes
kkappler Dec 28, 2024
f0abee1
add TODO
kkappler Dec 28, 2024
f7cc243
add typehint, tests pass locally
kkappler Dec 28, 2024
65732fa
updates for partial compatability with mt_metadata issue 238 (local t…
kkappler Dec 28, 2024
ab90d8b
access recoloring via stft
kkappler Dec 29, 2024
264dfc6
add a variation on tests
kkappler Dec 29, 2024
c21793d
comment out notebooks for clearer error messages
kkappler Dec 29, 2024
503758b
towards mt_metadata 235
kkappler Dec 29, 2024
6e69bca
Update per changes in mt_metadata
kkappler Dec 29, 2024
6a27f92
try another way to make tests pass
kkappler Dec 30, 2024
c0a885d
add test (towards issue #363)
kkappler Dec 31, 2024
41a414b
echo some env info
kkappler Dec 31, 2024
5a630e2
fix typo
kkappler Jan 2, 2025
5b44182
update window imports
kkappler Jan 2, 2025
031202c
towards mth5 spectrograms (partial factoring)
kkappler Jan 2, 2025
14c6507
add TODO and clarify argument
kkappler Jan 2, 2025
f290c61
add some TODOs
kkappler Jan 2, 2025
5dab8b9
factor add_spectrogram_to_mth5 from add_fcs_to_mth5
kkappler Jan 2, 2025
e0601d7
try another way to make tests pass
kkappler Jan 3, 2025
91fbc7b
remane xrts to xrds
kkappler Jan 3, 2025
96b3844
modify tests to preinstall branches of mth5, mt_metadata
kkappler Jan 3, 2025
33e88c4
cleanup yaml
kkappler Jan 3, 2025
914998a
uncommnet ipynb tests
kkappler Jan 4, 2025
80ab668
Merge pull request #367 from simpeg/try_fix_tests
kkappler Jan 4, 2025
8484fb1
Merge pull request #366 from simpeg/fix_mth5_issue_271
kkappler Jan 4, 2025
5fc4a0f
Merge pull request #365 from simpeg/fix_mt_metadata_issue_241
kkappler Jan 4, 2025
a2a10ec
update doc and TODOs
kkappler Jan 4, 2025
831a58f
remove unused sample_rate validation
kkappler Jan 4, 2025
8f9172f
replace decimation.window with decimation.stft.window
kkappler Jan 4, 2025
e0e8e54
apply updates from mt_metadata to access stft attrs
kkappler Jan 4, 2025
2f4a10d
update syntax to new mt_metadata decimation
kkappler Jan 5, 2025
c229015
update ipynb for mt_metadata decimation
kkappler Jan 5, 2025
55557b5
update ipynb for mt_metadata decimation
kkappler Jan 5, 2025
3849b89
update syntax to new mt_metadata decimation
kkappler Jan 5, 2025
ae76455
remove spectrogram (will replace with mth5 Spectrogram)
Jan 6, 2025
aef6c2b
replace aurora's extract_band method with mth5 method
Jan 6, 2025
3ec3ed5
replace apply_prewhitening with mth5 method
Jan 6, 2025
384a08d
replace aurora's apply_recoloring method with mth5's version
Jan 6, 2025
5cd5a84
suppress ipynb from tests
Jan 6, 2025
57e7037
re-add tests
Jan 6, 2025
e7aaf4f
replace –_add_spectrorgrams_to_mth5 with mth5 method
Jan 6, 2025
614c889
replace –read_back_fcs with mth5 method
Jan 6, 2025
286a01e
suppress ipynb tests
Jan 6, 2025
962906e
replace duplicate method with mt_metadata
Jan 6, 2025
13fc2b8
add doc
kkappler Jan 7, 2025
966b911
replace imports from pipelines/fourier_coefficients with mth5
kkappler Jan 7, 2025
3d53ddc
remove fourier_coefficients.py
kkappler Jan 7, 2025
8eb8a24
reenable ipynb tests
kkappler Jan 7, 2025
eaea779
update imports in ipynb
kkappler Jan 7, 2025
9a53fee
replace run_ts_to_stft_scipy with mth5 method
kkappler Jan 7, 2025
07f55a2
add some typehints
kkappler Jan 10, 2025
cba95a2
minor changes to doc
kkappler Jan 10, 2025
b282dc3
update test now that FrequencyBands uses dataframe
kkappler Jan 10, 2025
0166cc6
update name of initialize_xrda_2d to initialize_xrda_2d_cov
kkappler Jan 11, 2025
1235919
remove tests (now in mth5) for initialize_xrda_1d
kkappler Jan 11, 2025
6f84bea
update to use xarray helpers from mth5
kkappler Jan 11, 2025
a2f40ef
update import
kkappler Jan 11, 2025
f1cec92
update flake8 to be consistent with mth5 (80lines)
kkappler Jan 18, 2025
8f5745e
Merge branch 'features' of kkappler-github:simpeg/aurora into features
kkappler Jan 18, 2025
2725077
minor updates to doc
kkappler Feb 8, 2025
242a50d
Add tap point for spectrograms
kkappler Feb 23, 2025
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
45 changes: 19 additions & 26 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -37,9 +37,8 @@ jobs:
echo $CONDA_PREFIX
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@main
# pip install git+https://github.com/kujaku11/mth5.git@master
# pip install git+https://github.com/MTgeophysics/mtpy-v2.git@main
pip install git+https://github.com/kujaku11/mt_metadata.git@features
pip install git+https://github.com/kujaku11/mth5.git@features
pip install git+https://github.com/MTgeophysics/mtpy-v2.git@main
pip uninstall aurora -y
@@ -48,32 +47,26 @@ jobs:
echo $CONDA_PREFIX
pip install -e .
echo "Install complete"
echo "Uninstalling mth5"
pip uninstall mth5 -y
echo "Uninstalling mt_metadata"
pip uninstall mt_metadata -y
pip install git+https://github.com/kujaku11/mt_metadata.git@fix_issue_235
pip install git+https://github.com/kujaku11/mth5.git@fix_issue_271
conda list
pip freeze
# - name: Install Jupyter and dependencies
# run: |
# pip install jupyter
# pip install ipykernel
# python -m ipykernel install --user --name aurora-test
# # Install any other dependencies you need
#
# - name: Execute Jupyter Notebooks
# run: |
# jupyter nbconvert --to notebook --execute docs/examples/dataset_definition.ipynb
# jupyter nbconvert --to notebook --execute docs/examples/operate_aurora.ipynb
# jupyter nbconvert --to notebook --execute docs/tutorials/pkd_units_check.ipynb
# jupyter nbconvert --to notebook --execute docs/tutorials/pole_zero_fitting/lemi_pole_zero_fitting_example.ipynb
# jupyter nbconvert --to notebook --execute docs/tutorials/processing_configuration.ipynb
# jupyter nbconvert --to notebook --execute docs/tutorials/process_cas04_multiple_station.ipynb
# jupyter nbconvert --to notebook --execute docs/tutorials/synthetic_data_processing.ipynb
# # Replace "notebook.ipynb" with your notebook's filename
- name: Install Jupyter and dependencies
run: |
pip install jupyter
pip install ipykernel
python -m ipykernel install --user --name aurora-test
# Install any other dependencies you need
- name: Execute Jupyter Notebooks
run: |
jupyter nbconvert --to notebook --execute docs/examples/dataset_definition.ipynb
jupyter nbconvert --to notebook --execute docs/examples/operate_aurora.ipynb
jupyter nbconvert --to notebook --execute docs/tutorials/pkd_units_check.ipynb
jupyter nbconvert --to notebook --execute docs/tutorials/pole_zero_fitting/lemi_pole_zero_fitting_example.ipynb
jupyter nbconvert --to notebook --execute docs/tutorials/processing_configuration.ipynb
jupyter nbconvert --to notebook --execute docs/tutorials/process_cas04_multiple_station.ipynb
jupyter nbconvert --to notebook --execute docs/tutorials/synthetic_data_processing.ipynb
# Replace "notebook.ipynb" with your notebook's filename
# - name: Commit changes (if any)
# run: |
94 changes: 71 additions & 23 deletions aurora/pipelines/fourier_coefficients.py
Original file line number Diff line number Diff line change
@@ -63,6 +63,7 @@

import mth5.mth5
import pathlib
import xarray as xr

from aurora.pipelines.time_series_helpers import calibrate_stft_obj
from aurora.pipelines.time_series_helpers import prototype_decimate
@@ -88,6 +89,7 @@ def fc_decimations_creator(
time_period: Optional[TimePeriod] = None,
) -> List[FCDecimation]:
"""
TODO: move this to mt_metadata / replace with mt_metadata method once moved.
Creates mt_metadata FCDecimation objects that parameterize Fourier coefficient decimation levels.
@@ -232,34 +234,79 @@ def add_fcs_to_mth5(m: MTH5, fc_decimations: Optional[Union[str, list]] = None)
# If timing corrections were needed they could go here, right before STFT

for i_dec_level, fc_decimation in enumerate(fc_decimations):
if i_dec_level != 0:
try:
assert i_dec_level == fc_decimation.time_series_decimation.level
except:
msg = "decimation level has unexpected value"
logger.warning(msg)

if (
i_dec_level != 0
): # TODO: take this number from fc_decimation.time_series_decimation.level
# Apply decimation
run_xrds = prototype_decimate(fc_decimation, run_xrds)

# check if this decimation level yields a valid spectrogram
if not fc_decimation.is_valid_for_time_series_length(
run_xrds.time.shape[0]
):
logger.info(
f"Decimation Level {i_dec_level} invalid, TS of {run_xrds.time.shape[0]} samples too short"
)
continue

stft_obj = run_ts_to_stft_scipy(fc_decimation, run_xrds)
stft_obj = calibrate_stft_obj(stft_obj, run_obj)

# Pack FCs into h5 and update metadata
fc_decimation_group: FCDecimationGroup = fc_group.add_decimation_level(
f"{i_dec_level}", decimation_level_metadata=fc_decimation
ts_decimation = fc_decimation.time_series_decimation
run_xrds = prototype_decimate(
ts_decimation, run_xrds
) # TODO: replace this with mth5 decimation

_add_spectrogram_to_mth5(
fc_decimation=fc_decimation,
run_obj=run_obj,
run_xrds=run_xrds,
fc_group=fc_group,
)
fc_decimation_group.from_xarray(
stft_obj, fc_decimation_group.metadata.sample_rate_decimation
)
fc_decimation_group.update_metadata()
fc_group.update_metadata()

return


def _add_spectrogram_to_mth5(
fc_decimation: FCDecimation,
run_obj: mth5.groups.RunGroup,
run_xrds: xr.Dataset,
fc_group: mth5.groups.FCGroup,
) -> None:
"""
This function has been factored out of add_fcs_to_mth5.
This is the most atomic level of adding FCs and will be useful as standalone method.
Parameters
----------
fc_decimation : FCDecimation
Metadata about how the decimation level is to be processed
run_xrds : xarray.core.dataset.Dataset
Time series to be converted to a spectrogram and stored in MTH5.
Returns
-------
run_xrds : xarray.core.dataset.Dataset
pre-whitened time series
"""

# check if this decimation level yields a valid spectrogram
if not fc_decimation.is_valid_for_time_series_length(run_xrds.time.shape[0]):
logger.info(
f"Decimation Level {fc_decimation.time_series_decimation.level} invalid, TS of {run_xrds.time.shape[0]} samples too short"
)
return

stft_obj = run_ts_to_stft_scipy(fc_decimation, run_xrds)
stft_obj = calibrate_stft_obj(stft_obj, run_obj)

# Pack FCs into h5 and update metadata
fc_decimation_group: FCDecimationGroup = fc_group.add_decimation_level(
f"{fc_decimation.time_series_decimation.level}",
decimation_level_metadata=fc_decimation,
)
fc_decimation_group.from_xarray(
stft_obj, fc_decimation_group.metadata.time_series_decimation.sample_rate
)
fc_decimation_group.update_metadata()
fc_group.update_metadata()


def get_degenerate_fc_decimation(sample_rate: float) -> list:
"""
@@ -289,6 +336,7 @@ def get_degenerate_fc_decimation(sample_rate: float) -> list:
return output


# TODO: Delete after mth5 issue #271 is closed and merged.
@path_or_mth5_object
def read_back_fcs(m: Union[MTH5, pathlib.Path, str], mode: str = "r") -> None:
"""
5 changes: 4 additions & 1 deletion aurora/pipelines/time_series_helpers.py
Original file line number Diff line number Diff line change
@@ -157,6 +157,7 @@ def run_ts_to_stft_scipy(
run_xrds_orig: xr.Dataset,
) -> xr.Dataset:
"""
TODO: Replace with mth5 run_ts_to_stft_scipy method
Converts a runts object into a time series of Fourier coefficients.
This method uses scipy.signal.spectrogram.
@@ -177,7 +178,9 @@ def run_ts_to_stft_scipy(
Time series of Fourier coefficients
"""
run_xrds = apply_prewhitening(decimation_obj, run_xrds_orig)
windowing_scheme = window_scheme_from_decimation(decimation_obj)
windowing_scheme = window_scheme_from_decimation(
decimation_obj
) # TODO: deprecate in favor of stft.window.taper

stft_obj = xr.Dataset()
for channel_id in run_xrds.data_vars:
12 changes: 6 additions & 6 deletions tests/synthetic/test_decimation_methods.py
Original file line number Diff line number Diff line change
@@ -49,16 +49,16 @@ def test_decimation_methods_agree():
if dec_level_id == 0:
run_obj = mth5_obj.get_run(station_id, run_id, survey=None)
run_ts = run_obj.to_runts(start=None, end=None)
run_xrts = run_ts.dataset
decimated_ts[dec_level_id]["run_xrts"] = run_xrts
run_xrds = run_ts.dataset
decimated_ts[dec_level_id]["run_xrds"] = run_xrds
current_sample_rate = run_obj.metadata.sample_rate

if dec_level_id > 0:
run_xrts = decimated_ts[dec_level_id - 1]["run_xrts"]
run_xrds = decimated_ts[dec_level_id - 1]["run_xrds"]
target_sample_rate = current_sample_rate / (dec_config.decimation.factor)

decimated_1 = prototype_decimate(dec_config.decimation, run_xrts)
decimated_2 = run_xrts.sps_filters.decimate(
decimated_1 = prototype_decimate(dec_config.decimation, run_xrds)
decimated_2 = run_xrds.sps_filters.decimate(
target_sample_rate=target_sample_rate
)

@@ -67,7 +67,7 @@ def test_decimation_methods_agree():
assert np.isclose(difference.to_array(), 0).all()

logger.info("prototype decimate aurora method agrees with mth5 decimate")
decimated_ts[dec_level_id]["run_xrts"] = decimated_1
decimated_ts[dec_level_id]["run_xrds"] = decimated_1
current_sample_rate = target_sample_rate
return

13 changes: 10 additions & 3 deletions tests/synthetic/test_fourier_coefficients.py
Original file line number Diff line number Diff line change
@@ -3,7 +3,8 @@
from aurora.config.config_creator import ConfigCreator
from aurora.pipelines.fourier_coefficients import add_fcs_to_mth5
from aurora.pipelines.fourier_coefficients import fc_decimations_creator
from aurora.pipelines.fourier_coefficients import read_back_fcs

# from aurora.pipelines.fourier_coefficients import read_back_fcs
from aurora.pipelines.process_mth5 import process_mth5
from aurora.test_utils.synthetic.make_processing_configs import (
create_test_run_config,
@@ -13,6 +14,7 @@
from mth5.data.make_mth5_from_asc import create_test2_h5
from mth5.data.make_mth5_from_asc import create_test3_h5
from mth5.data.make_mth5_from_asc import create_test12rr_h5
from mth5.timeseries.spectre.helpers import read_back_fcs

# from mtpy-v2
from mtpy.processing import RunSummary, KernelDataset
@@ -128,8 +130,13 @@ def test_123(self):
return tfc

def test_fc_decimations_creator(self):
""""""
cfgs = fc_decimations_creator(1.0)
"""
# TODO: Move this into mt_metadata
Returns
-------
"""
cfgs = fc_decimations_creator(initial_sample_rate=1.0)

# test time period must of of type
with self.assertRaises(NotImplementedError):