Skip to content

Commit

Permalink
partial merge from #337 for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
kkappler committed Jul 21, 2024
1 parent 211e556 commit 4eca1e8
Show file tree
Hide file tree
Showing 6 changed files with 227 additions and 129 deletions.
14 changes: 14 additions & 0 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Contributing to Aurora
----------------------


If you'd like to contribute, start by searching through the `issues <https://github.com/simpeg/aurora/issues>`_ to see whether someone else has raised a similar idea or question. If you don't see your idea listed, open an issue, and if there are code changes, also a pull request.


There are many ways to contribute to the aurora, such as:

* Report/fix bugs or issues encountered when using the software
* Suggest additional features or functionalities
* Fix editorial inconsistencies or inaccuracies

Aurora is hosted by simpeg, please refer to their `contributing guidelines page <https://docs.simpeg.xyz/latest/content/getting_started/contributing/index.html>`_. for more details.
105 changes: 57 additions & 48 deletions aurora/general_helper_functions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
"""
This module contains from miscellaneous functions and some global paths.
"""
import inspect
import os

# import os
import pathlib
import scipy.io as sio
import subprocess
Expand All @@ -20,19 +24,15 @@
BAND_SETUP_PATH = CONFIG_PATH.joinpath("emtf_band_setup")


def get_mth5_ascii_data_path():
def get_test_path() -> pathlib.Path:
"""
Get the path to the
Gets the path to where the test are.
Returns
-------
mth5_data_path: pathlib.Path
This is the place where the legacy test files (ascii MT data from EMTF) are archived
test_path: pathlib.Path
Object that points to where aurora's tests are.
"""
mth5_data_path = pathlib.Path(mth5.__file__).parent.joinpath("data")
return mth5_data_path


def get_test_path():
test_path = AURORA_PATH.joinpath("tests")
if not test_path.exists():
msg = (
Expand All @@ -44,6 +44,18 @@ def get_test_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 Expand Up @@ -79,58 +91,58 @@ def count_lines(file_name):

def execute_subprocess(cmd, **kwargs):
"""
A wrapper for subprocess.call
Parameters
----------
cmd : string
command as it would be typed in a terminal
kwargs
Returns
-------
kwargs: denotes keyword arguments that would be passed to subprocess
"""
"""
A wrapper for subprocess.call
"""
exit_status = subprocess.call([cmd], shell=True, **kwargs)
if exit_status != 0:
raise Exception("Failed to execute \n {}".format(cmd))
return


def execute_command(cmd, **kwargs):
"""
Executes command in terminal from script.
Parameters:
cmd (str): command to exectute from a terminal
kwargs: exec_dir (str): the directory from which to execute
kwargs: no_exception: suppress output if exception
Other Parameters:
exit_status: :code:`0` is good, otherwise there is some problem
.. note:: When executing :code:`rm *` this crashes if the directory we are removing
from is empty
.. note:: if you can you should probably use execute_subprocess() instead
"""
exec_dir = kwargs.get("exec_dir", os.path.expanduser("~/"))
allow_exception = kwargs.get("allow_exception", True)
logger.info("executing from {}".format(exec_dir))
cwd = os.getcwd()
os.chdir(exec_dir)
exit_status = os.system(cmd)
if exit_status != 0:
logger.info(f"exit_status of {cmd} = {exit_status}")
if allow_exception:
raise Exception(f"Failed to successfully execute \n {cmd}")
os.chdir(cwd)
# TODO: Add test for execute_command or delete.
# def execute_command(cmd, **kwargs):
# """
# Executes command in terminal from script.
#
# Parameters:
# ----------
# cmd : str
# command to execute from a terminal
# kwargs: exec_dir (str): the directory from which to execute
# kwargs: no_exception: suppress output if exception
#
# Other Parameters:
# exit_status: :code:`0` is good, otherwise there is some problem
#
# .. note:: When executing :code:`rm *` this crashes if the directory we are removing
# from is empty
#
# .. note:: if you can you should probably use execute_subprocess() instead
# """
# exec_dir = kwargs.get("exec_dir", os.path.expanduser("~/"))
# allow_exception = kwargs.get("allow_exception", True)
# logger.info("executing from {}".format(exec_dir))
# cwd = os.getcwd()
# os.chdir(exec_dir)
# exit_status = os.system(cmd)
# if exit_status != 0:
# logger.info(f"exit_status of {cmd} = {exit_status}")
# if allow_exception:
# raise Exception(f"Failed to successfully execute \n {cmd}")
# os.chdir(cwd)


def save_to_mat(data, variable_name, filename):
"""
Saves numpy array in matlab format.
Example Usage:
x = X.to_array(dim="channel")
save_to_mat(x.data, "x", "x.mat")
Expand All @@ -148,9 +160,6 @@ def save_to_mat(data, variable_name, filename):
filename : string
The filepath to output
Returns
-------
"""
sio.savemat(filename, {variable_name: data})
return
Expand Down
Loading

0 comments on commit 4eca1e8

Please sign in to comment.