Skip to content

Commit

Permalink
Make synthetic data get stored in aurora, not mth5
Browse files Browse the repository at this point in the history
- move helper function for mth5 data path into the only moudle that uses
  it (synthetic/paths.py)
- reorganize tests
  • Loading branch information
kkappler committed Aug 24, 2024
1 parent 23bb00a commit 865350f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 40 deletions.
12 changes: 0 additions & 12 deletions aurora/general_helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,6 @@ def get_test_path() -> pathlib.Path:
return test_path


def get_mth5_ascii_data_path():
"""
Get the path to the
Returns
-------
mth5_data_path: pathlib.Path
This is the place where the legacy test files (ascii MT data from EMTF) are archived
"""
mth5_data_path = pathlib.Path(mth5.__file__).parent.joinpath("data")
return mth5_data_path


try:
FIGURES_PATH = DATA_PATH.joinpath("figures")
FIGURES_PATH.mkdir(exist_ok=True, parents=True)
Expand Down
32 changes: 21 additions & 11 deletions aurora/test_utils/synthetic/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,18 @@
- This class was built to handle Issue #303 (installation on read-only file system). https://github.com/simpeg/aurora/issues/303
"""
from mth5.data.paths import SyntheticTestPaths as MTH5SyntheticTestPaths

# synthetic_test_path = SyntheticTestPaths()

import pathlib


from aurora.general_helper_functions import DATA_PATH
from aurora.general_helper_functions import get_mth5_ascii_data_path
from loguru import logger
from mth5.data.paths import SyntheticTestPaths as MTH5SyntheticDataPaths

import mth5
import pathlib

DEFAULT_SANDBOX_PATH = DATA_PATH.joinpath("synthetic")


class SyntheticTestPaths(MTH5SyntheticTestPaths):
class SyntheticTestPaths(MTH5SyntheticDataPaths):
"""
sandbox path must be a place that has write access. This class was created because on some
installations we only have read access. Originally there was a data/ folder with the synthetic
Expand All @@ -33,7 +30,7 @@ class SyntheticTestPaths(MTH5SyntheticTestPaths):
"""

def __init__(self, sandbox_path=None, ascii_data_path=None):
def __init__(self, sandbox_path=DEFAULT_SANDBOX_PATH, ascii_data_path=None):
"""
Constructor
Expand All @@ -51,11 +48,11 @@ def __init__(self, sandbox_path=None, ascii_data_path=None):
"""
super(
MTH5SyntheticTestPaths, self
MTH5SyntheticDataPaths, self
).__init__() # sandbox_path=sandbox_path,ascii_data_path=ascii_data_path)
# READ ONLY OK
if ascii_data_path is None:
self.ascii_data_path = get_mth5_ascii_data_path()
self.ascii_data_path = _get_mth5_ascii_data_path()

# NEED WRITE ACCESS
# Consider using an environment variable for sandbox_path
Expand Down Expand Up @@ -93,3 +90,16 @@ def mkdirs(self):
self.config_path.mkdir(parents=True, exist_ok=True)
self.emtf_results_path.mkdir(parents=True, exist_ok=True)
self.mth5_path.mkdir(parents=True, exist_ok=True)


def _get_mth5_ascii_data_path() -> pathlib.Path:
"""
Get the path to the ascii synthetic data
Returns
-------
mth5_data_path: pathlib.Path
This is the place where the legacy test files (ascii MT data from EMTF) are archived
"""
mth5_data_path = pathlib.Path(mth5.__file__).parent.joinpath("data")
return mth5_data_path
18 changes: 18 additions & 0 deletions tests/synthetic/test_make_h5s.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
# from mth5.data.make_mth5_from_asc import create_test12rr_h5
# from mth5.data.make_mth5_from_asc import create_test2_h5
# from mth5.data.make_mth5_from_asc import create_test3_h5
from loguru import logger
from mth5.data.make_mth5_from_asc import create_test4_h5
from aurora.test_utils.synthetic.paths import SyntheticTestPaths
from aurora.test_utils.synthetic.paths import _get_mth5_ascii_data_path

synthetic_test_paths = SyntheticTestPaths()
synthetic_test_paths.mkdirs()
Expand All @@ -22,6 +24,22 @@ class TestMakeSyntheticMTH5(unittest.TestCase):
create_test3_h5(file_version=file_version)
"""

def test_get_mth5_ascii_data_path(self):
"""
Make sure that the ascii data are where we think they are.
Returns
-------
"""
mth5_data_path = _get_mth5_ascii_data_path()
ascii_file_paths = list(mth5_data_path.glob("*asc"))
file_names = [x.name for x in ascii_file_paths]
logger.info(f"mth5_data_path = {mth5_data_path}")
logger.info(f"file_names = {file_names}")

assert "test1.asc" in file_names
assert "test2.asc" in file_names

def test_make_upsampled_mth5(self):
file_version = "0.2.0"
create_test4_h5(file_version=file_version, source_folder=SOURCE_PATH)
Expand Down
17 changes: 0 additions & 17 deletions tests/test_general_helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from aurora.general_helper_functions import count_lines
from aurora.general_helper_functions import DotDict
from aurora.general_helper_functions import get_mth5_ascii_data_path
from aurora.general_helper_functions import get_test_path
from loguru import logger

Expand Down Expand Up @@ -37,22 +36,6 @@ def test_dot_dict(self):
assert dot_dict.a == tmp["a"]
assert dot_dict.b == "bb"

def test_get_mth5_ascii_data_path(self):
"""
Make sure that the ascii data are where we think they are.
Returns
-------
"""
mth5_data_path = get_mth5_ascii_data_path()
ascii_file_paths = list(mth5_data_path.glob("*asc"))
file_names = [x.name for x in ascii_file_paths]
logger.info(f"mth5_data_path = {mth5_data_path}")
logger.info(f"file_names = {file_names}")

assert "test1.asc" in file_names
assert "test2.asc" in file_names


def main():
# tmp = TestMetadataValuesSetCorrect()
Expand Down

0 comments on commit 865350f

Please sign in to comment.