-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #845 from spedas/mth5
Merge mth5 into master (pre-release)
- Loading branch information
Showing
9 changed files
with
1,053 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Make sure that download folder exists | ||
import os, pyspedas | ||
from .config import CONFIG | ||
|
||
if not os.path.exists(CONFIG['local_data_dir']): | ||
os.makedirs(CONFIG['local_data_dir']) | ||
|
||
# Remove imported | ||
del os, CONFIG | ||
|
||
# Determine if MTH5 is in the scope | ||
try: | ||
import mth5 | ||
del mth5, pyspedas | ||
except ImportError: | ||
pyspedas.logging.error(f'MTH5 must be installed to use module {__name__}.') | ||
pyspedas.logging.error('Please install it using: pip install mth5') | ||
raise | ||
|
||
# # Synchronize mth5 logging output level with pyspedas logging output level | ||
try: | ||
import loguru, pyspedas | ||
from mth5 import config as mth5_logger_config | ||
from pyspedas import logging_level | ||
from pyspedas.mth5.load_fdsn import _disable_loguru_warnings | ||
|
||
# This is how to disable all together | ||
# import warnings | ||
# warnings.filterwarnings('ignore') | ||
|
||
# TODO: terminate this code if handler logging_level is the same as in loguru | ||
|
||
mth5_logger_config['handlers'][0]['level'] = logging_level | ||
mth5_logger_config['handlers'][0]["filter"] = _disable_loguru_warnings | ||
mth5_logger_config['extra']['no_warning'] = False | ||
if loguru.logger._core.handlers: | ||
handler_id = next(iter(loguru.logger._core.handlers.keys())) | ||
loguru.logger.remove(handler_id) | ||
loguru.logger.configure(**mth5_logger_config) | ||
pyspedas.logging.debug('loguru synchronized with pyspedas logging') | ||
except: | ||
pyspedas.logging.error('loguru synchronization error') | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import os | ||
|
||
CONFIG = {'local_data_dir': 'mth5/', | ||
'remote_data_dir': ''} # Reserved for the future use | ||
|
||
# override local data directory with environment variables | ||
if os.environ.get('SPEDAS_DATA_DIR'): | ||
CONFIG['local_data_dir'] = os.sep.join([os.environ['SPEDAS_DATA_DIR'], | ||
'mth5']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Example of getting MTH5 datasets availability | ||
|
||
from pyspedas.mth5.utilities import datasets | ||
|
||
# Getting a dictionary of valid datasets for a given time range | ||
valid_dataset = datasets(trange=["2015-06-22", "2015-06-23"]) | ||
|
||
# List of all the networks | ||
nets = valid_dataset.keys() | ||
print("Networks: ", nets) | ||
|
||
# List of all the stations for a given network | ||
net = list(nets)[0] | ||
print("Stations: ", valid_dataset[net].keys()) | ||
|
||
# Getting data availability for a given network and station in 2015 | ||
res = datasets(trange=["2015-01-01", "2016-01-01"], network="4P", station="TNU48") | ||
print("Data availability", res) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Load and show tplot variable created using load_fdsn | ||
|
||
from pyspedas.mth5.load_fdsn import load_fdsn | ||
import pytplot | ||
import numpy as np | ||
|
||
load_fdsn(network="4P", station="ALW48", trange=['2015-06-22', '2015-06-24']) | ||
pytplot.tplot('fdsn_4P_ALW48') | ||
|
||
# Get data | ||
time, mag = pytplot.get_data('fdsn_4P_ALW48') | ||
|
||
# Re-normalize magnetometer data removing the baseline | ||
mag -= np.mean(mag, axis=0) | ||
|
||
pytplot.store_data('fdsn_4P_ALW48_norm', data={'x': time, 'y':mag}) | ||
|
||
# Plot | ||
pytplot.tplot('fdsn_4P_ALW48_norm') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Relocated jupyter notebooks | ||
|
||
Jupyter notebooks from current folder have been relocated to [pyspedas_example](https://github.com/spedas/pyspedas_examples) project. | ||
|
||
You can find the notebooks by the following link: | ||
[https://github.com/spedas/pyspedas_examples/tree/mth5/pyspedas_examples/notebooks/mth5](https://github.com/spedas/pyspedas_examples/tree/mth5/pyspedas_examples/notebooks/mth5) | ||
|
||
# The python scripts | ||
|
||
The Python scripts in this folder are basic examples of MTH5. We strongly encourage you to check the Jupyter notebooks specified above. |
Oops, something went wrong.